diff --git a/README.md b/README.md index c87ee09a..856784f6 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/migrate.go b/migrate.go index fae3b4c5..41585811 100644 --- a/migrate.go +++ b/migrate.go @@ -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() diff --git a/sql-migrate/oracle.go b/sql-migrate/oracle.go new file mode 100644 index 00000000..d12e4a78 --- /dev/null +++ b/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{} +}