Skip to content

Commit

Permalink
Merge pull request #166 from gunsluo/master
Browse files Browse the repository at this point in the history
Support for Oracle database in Command line program.
  • Loading branch information
rubenv committed Feb 12, 2020
2 parents c8d4be6 + 6817a62 commit 64f95ea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Expand Up @@ -130,6 +130,25 @@ production:

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

### Oracle
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).

#### Install with Oracle support

To install the library and command line program, use the following:

```bash
go get -tags oracle -v github.com/rubenv/sql-migrate/...
```

```yml
development:
dialect: oci8
datasource: user/password@localhost:1521/sid
dir: migrations/oracle
table: migrations
```

### As a library

Import sql-migrate into your application:
Expand Down
4 changes: 4 additions & 0 deletions migrate.go
Expand Up @@ -457,6 +457,10 @@ func (ms MigrationSet) ExecMax(db *sql.DB, dialect string, m MigrationSource, di
}

for _, stmt := range migration.Queries {
// remove the semicolon from stmt, fix ORA-00922 issue in database oracle
stmt = strings.TrimSuffix(stmt, "\n")
stmt = strings.TrimSuffix(stmt, " ")
stmt = strings.TrimSuffix(stmt, ";")
if _, err := executor.Exec(stmt); err != nil {
if trans, ok := executor.(*gorp.Transaction); ok {
_ = trans.Rollback()
Expand Down
12 changes: 12 additions & 0 deletions sql-migrate/oracle.go
@@ -0,0 +1,12 @@
// +build oracle

package main

import (
_ "github.com/mattn/go-oci8"
migrate "github.com/rubenv/sql-migrate"
)

func init() {
dialects["oci8"] = migrate.OracleDialect{}
}

0 comments on commit 64f95ea

Please sign in to comment.