-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add OracleDB support to golang-migrate #1230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -44,7 +44,8 @@ Database drivers run migrations. [Add a new database?](database/driver.go) | |||
| * [Firebird](database/firebird) | ||||
| * [MS SQL Server](database/sqlserver) | ||||
| * [rqlite](database/rqlite) | ||||
|
|
||||
| * [Oracle](database/oracle) | ||||
| * | ||||
|
||||
| * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. The blank bullet point after the Oracle entry has been removed.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,110 @@ | ||||||||||||||||||||||||||||||||||||||||||
| # oracle | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| The supported oracle specific options can be configured in the query section of the oracle | ||||||||||||||||||||||||||||||||||||||||||
| URL `oracle://user:password@host:port/ServiceName?query` | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| | URL Query | WithInstance Config | Description | | ||||||||||||||||||||||||||||||||||||||||||
| |--------------------------|----------------------|-------------------------------------------------------------------------------------------------------------------------| | ||||||||||||||||||||||||||||||||||||||||||
| | `x-migrations-table` | `MigrationsTable` | Name of the migrations table in UPPER case | | ||||||||||||||||||||||||||||||||||||||||||
| | `x-multi-stmt-enabled` | `MultiStmtEnabled` | If the migration files are in multi-statements style | | ||||||||||||||||||||||||||||||||||||||||||
| | `x-multi-stmt-separator` | `MultiStmtSeparator` | a single line which use as the token to spilt multiple statements in single migration file, triple-dash separator `---` | | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ## Write migration files | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| There are two ways to write the migration files, | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| 1. Single statement file in which it contains only one SQL statement or one PL/SQL statement(Default) | ||||||||||||||||||||||||||||||||||||||||||
| 2. Multi statements file in which it can have multi statements(can be SQL or PL/SQL or mixed) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ### Single statement file | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Oracle godor driver support process one statement at a time, so it is natural to support single statement per file as | ||||||||||||||||||||||||||||||||||||||||||
| the default. | ||||||||||||||||||||||||||||||||||||||||||
| Check the [single statement migration files](examples/migrations) as an example. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ### Multi statements file | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Although the golang oracle driver [godror](https://github.com/godror/godror) does not natively support executing | ||||||||||||||||||||||||||||||||||||||||||
| multiple | ||||||||||||||||||||||||||||||||||||||||||
| statements in a single query, it's more friendly and handy to support multi statements in a single migration file in | ||||||||||||||||||||||||||||||||||||||||||
| some case, | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
| Oracle godor driver support process one statement at a time, so it is natural to support single statement per file as | |
| the default. | |
| Check the [single statement migration files](examples/migrations) as an example. | |
| ### Multi statements file | |
| Although the golang oracle driver [godror](https://github.com/godror/godror) does not natively support executing | |
| multiple | |
| statements in a single query, it's more friendly and handy to support multi statements in a single migration file in | |
| some case, | |
| The Oracle [go-ora](https://github.com/sijms/go-ora) driver supports processing one statement at a time, so it is natural to support a single statement per file as | |
| the default. | |
| Check the [single statement migration files](examples/migrations) as an example. | |
| ### Multi statements file | |
| Although the Oracle driver used by this package, [go-ora](https://github.com/sijms/go-ora), does not natively support executing | |
| multiple | |
| statements in a single query, it's more friendly and handy to support multi statements in a single migration file in | |
| some cases, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. The README now correctly references sijms/go-ora (the actual driver imported by this package) instead of godror/godror in both the single-statement and multi-statement sections.
Copilot
AI
Mar 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are multiple typos/grammar issues in this section (e.g. "godor", "spilt", "some case", "very time expense"). Please correct them for clarity in the driver documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Corrected all typos and grammar issues: "godor" → "sijms/go-ora", "spilt" → "split", "some case" → "some cases", "very time expense" → "very time-consuming".
Outdated
Copilot
AI
Mar 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docker-compose example uses container_name: oracle-db, but the next step runs docker exec -it orclxe ..., which won’t work as written. Update the command to match the declared container name (or update the compose snippet) so the instructions are runnable.
| $ docker exec -it orclxe bash | |
| $ docker exec -it oracle-db bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Updated the docker exec command to use oracle-db to match the container_name declared in the compose snippet.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,2 @@ | ||||||||||||||||||||||
| DROP TABLE IF EXISTS USERS_MS; | ||||||||||||||||||||||
|
||||||||||||||||||||||
| DROP TABLE IF EXISTS USERS_MS; | |
| BEGIN | |
| EXECUTE IMMEDIATE 'DROP TABLE USERS_MS'; | |
| EXCEPTION | |
| WHEN OTHERS THEN | |
| IF SQLCODE != -942 THEN | |
| RAISE; | |
| END IF; | |
| END; | |
| / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Replaced with a PL/SQL block that catches ORA-00942 and re-raises for any other error.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||||||||||||||||||
| CREATE TABLE USERS_MS ( | ||||||||||||||||||||||
| USER_ID integer unique, | ||||||||||||||||||||||
| NAME varchar(40), | ||||||||||||||||||||||
| EMAIL varchar(40) | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| --- | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| DROP TABLE IF EXISTS USERS_MS; | ||||||||||||||||||||||
|
||||||||||||||||||||||
| DROP TABLE IF EXISTS USERS_MS; | |
| BEGIN | |
| EXECUTE IMMEDIATE 'DROP TABLE USERS_MS'; | |
| EXCEPTION | |
| WHEN OTHERS THEN | |
| IF SQLCODE != -942 THEN | |
| RAISE; | |
| END IF; | |
| END; | |
| / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Replaced with a PL/SQL conditional drop block that catches ORA-00942 and re-raises any other exception.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE USERS_MS DROP COLUMN CITY; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ALTER TABLE USERS_MS ADD CITY varchar(100); | ||
| --- | ||
| ALTER TABLE USERS_MS ADD ALIAS varchar(100); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| DROP INDEX users_ms_email_index; | ||
| --- |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CREATE UNIQUE INDEX users_ms_email_index ON users_ms (email); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,2 @@ | ||||||||||||||||||||||
| DROP TABLE IF EXISTS BOOKS_MS; | ||||||||||||||||||||||
|
||||||||||||||||||||||
| DROP TABLE IF EXISTS BOOKS_MS; | |
| BEGIN | |
| EXECUTE IMMEDIATE 'DROP TABLE BOOKS_MS'; | |
| EXCEPTION | |
| WHEN OTHERS THEN | |
| IF SQLCODE != -942 THEN | |
| RAISE; | |
| END IF; | |
| END; | |
| / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Replaced with a PL/SQL block that catches ORA-00942 and re-raises for any other error.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| CREATE TABLE BOOKS_MS ( | ||
| USER_ID integer, | ||
| NAME varchar(40), | ||
| AUTHOR varchar(40) | ||
| ); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||||||||||||||||||
| DROP TABLE IF EXISTS MOVIES_MS | ||||||||||||||||||||||
|
||||||||||||||||||||||
| DROP TABLE IF EXISTS MOVIES_MS | |
| BEGIN | |
| EXECUTE IMMEDIATE 'DROP TABLE MOVIES_MS'; | |
| EXCEPTION | |
| WHEN OTHERS THEN | |
| IF SQLCODE != -942 THEN | |
| RAISE; | |
| END IF; | |
| END; | |
| / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Replaced with a PL/SQL block that catches ORA-00942 and re-raises for any other error.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| CREATE TABLE MOVIES_MS ( | ||
| USER_ID integer, | ||
| NAME varchar(40), | ||
| DIRECTOR varchar(40) | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sed interdum velit, tristique iaculis justo. Pellentesque ut porttitor dolor. Donec sit amet pharetra elit. Cras vel ligula ex. Phasellus posuere. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sed interdum velit, tristique iaculis justo. Pellentesque ut porttitor dolor. Donec sit amet pharetra elit. Cras vel ligula ex. Phasellus posuere. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sed interdum velit, tristique iaculis justo. Pellentesque ut porttitor dolor. Donec sit amet pharetra elit. Cras vel ligula ex. Phasellus posuere. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sed interdum velit, tristique iaculis justo. Pellentesque ut porttitor dolor. Donec sit amet pharetra elit. Cras vel ligula ex. Phasellus posuere. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||||||||||||||||||
| DROP TABLE IF EXISTS USERS | ||||||||||||||||||||||
|
||||||||||||||||||||||
| DROP TABLE IF EXISTS USERS | |
| BEGIN | |
| EXECUTE IMMEDIATE 'DROP TABLE USERS'; | |
| EXCEPTION | |
| WHEN OTHERS THEN | |
| IF SQLCODE != -942 THEN | |
| RAISE; | |
| END IF; | |
| END; | |
| / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Replaced with a PL/SQL block that catches ORA-00942 and re-raises for any other error.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| CREATE TABLE USERS ( | ||
| USER_ID integer unique, | ||
| NAME varchar(40), | ||
| EMAIL varchar(40) | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE USERS DROP COLUMN CITY |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE USERS ADD CITY varchar(100) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||||||||||||||||||||
| DROP INDEX IF EXISTS users_email_index | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| DROP INDEX IF EXISTS users_email_index | |
| BEGIN | |
| EXECUTE IMMEDIATE 'DROP INDEX users_email_index'; | |
| EXCEPTION | |
| WHEN OTHERS THEN | |
| -- ORA-01418: specified index does not exist | |
| IF SQLCODE != -1418 THEN | |
| RAISE; | |
| END IF; | |
| END; | |
| / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Replaced with a PL/SQL block that uses EXECUTE IMMEDIATE 'DROP INDEX users_email_index' and catches ORA-01418 (specified index does not exist), re-raising for any other error code.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CREATE UNIQUE INDEX users_email_index ON users (email) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||||||||||||||||||
| DROP TABLE IF EXISTS BOOKS | ||||||||||||||||||||||
|
||||||||||||||||||||||
| DROP TABLE IF EXISTS BOOKS | |
| BEGIN | |
| EXECUTE IMMEDIATE 'DROP TABLE BOOKS'; | |
| EXCEPTION | |
| WHEN OTHERS THEN | |
| IF SQLCODE != -942 THEN | |
| RAISE; | |
| END IF; | |
| END; | |
| / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Replaced with a PL/SQL block that catches ORA-00942 and re-raises for any other error.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| CREATE TABLE BOOKS ( | ||
| USER_ID integer, | ||
| NAME varchar(40), | ||
| AUTHOR varchar(40) | ||
| ) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||||||||||||||||||
| DROP TABLE IF EXISTS MOVIES | ||||||||||||||||||||||
|
||||||||||||||||||||||
| DROP TABLE IF EXISTS MOVIES | |
| BEGIN | |
| EXECUTE IMMEDIATE 'DROP TABLE MOVIES'; | |
| EXCEPTION | |
| WHEN OTHERS THEN | |
| IF SQLCODE != -942 THEN | |
| RAISE; | |
| END IF; | |
| END; | |
| / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Replaced with a PL/SQL BEGIN...EXECUTE IMMEDIATE...EXCEPTION WHEN OTHERS block that ignores ORA-00942 (table or view does not exist) and re-raises any other error.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| CREATE TABLE MOVIES ( | ||
| USER_ID integer, | ||
| NAME varchar(40), | ||
| DIRECTOR varchar(40) | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sed interdum velit, tristique iaculis justo. Pellentesque ut porttitor dolor. Donec sit amet pharetra elit. Cras vel ligula ex. Phasellus posuere. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sed interdum velit, tristique iaculis justo. Pellentesque ut porttitor dolor. Donec sit amet pharetra elit. Cras vel ligula ex. Phasellus posuere. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sed interdum velit, tristique iaculis justo. Pellentesque ut porttitor dolor. Donec sit amet pharetra elit. Cras vel ligula ex. Phasellus posuere. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sed interdum velit, tristique iaculis justo. Pellentesque ut porttitor dolor. Donec sit amet pharetra elit. Cras vel ligula ex. Phasellus posuere. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds
oracletoDATABASE_TEST, so it will be included inmake test, butoracleis still missing from theDATABASElist used bymake build/build-clitags. If Oracle support is intended to ship with the CLI, addoracletoDATABASEas well (database/driver.go also documents this requirement).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Added
oracleto theDATABASElist in the Makefile so it is included inmake build/build-cli. Thesijms/go-oradriver is pure Go (CGO_ENABLED=0compatible), so this doesn't break static builds.