Skip to content

Commit 64f95ea

Browse files
authored
Merge pull request #166 from gunsluo/master
Support for Oracle database in Command line program.
2 parents c8d4be6 + 6817a62 commit 64f95ea

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,25 @@ production:
130130

131131
See [here](https://github.com/go-sql-driver/mysql#parsetime) for more information.
132132

133+
### Oracle
134+
Oracle Driver is [oci8](https://github.com/mattn/go-oci8), it is not pure golang code and rely on Oracle Office Client([Instant Client](https://www.oracle.com/technetwork/database/database-technologies/instant-client/downloads/index.html)), more detail information is [oci8 repo](https://github.com/mattn/go-oci8).
135+
136+
#### Install with Oracle support
137+
138+
To install the library and command line program, use the following:
139+
140+
```bash
141+
go get -tags oracle -v github.com/rubenv/sql-migrate/...
142+
```
143+
144+
```yml
145+
development:
146+
dialect: oci8
147+
datasource: user/password@localhost:1521/sid
148+
dir: migrations/oracle
149+
table: migrations
150+
```
151+
133152
### As a library
134153

135154
Import sql-migrate into your application:

migrate.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ func (ms MigrationSet) ExecMax(db *sql.DB, dialect string, m MigrationSource, di
457457
}
458458

459459
for _, stmt := range migration.Queries {
460+
// remove the semicolon from stmt, fix ORA-00922 issue in database oracle
461+
stmt = strings.TrimSuffix(stmt, "\n")
462+
stmt = strings.TrimSuffix(stmt, " ")
463+
stmt = strings.TrimSuffix(stmt, ";")
460464
if _, err := executor.Exec(stmt); err != nil {
461465
if trans, ok := executor.(*gorp.Transaction); ok {
462466
_ = trans.Rollback()

sql-migrate/oracle.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// +build oracle
2+
3+
package main
4+
5+
import (
6+
_ "github.com/mattn/go-oci8"
7+
migrate "github.com/rubenv/sql-migrate"
8+
)
9+
10+
func init() {
11+
dialects["oci8"] = migrate.OracleDialect{}
12+
}

0 commit comments

Comments
 (0)