-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d477553
commit a601110
Showing
37 changed files
with
934 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
so the multi statements can be separated with a line separator(default to triple-dash separator ---), for example: | ||
|
||
``` | ||
statement 1 | ||
--- | ||
statement 2 | ||
``` | ||
|
||
Check the [multi statements' migration files](examples/migrations-multistmt) as an example. | ||
|
||
## Supported & tested version | ||
|
||
- 18-xe | ||
|
||
## Build cli | ||
|
||
```bash | ||
$ cd /path/to/repo/dir | ||
$ go build -tags 'oracle' -o bin/migrate github.com/golang-migrate/migrate/v4/cli | ||
``` | ||
|
||
## Run test code | ||
|
||
There are two ways to run the test code: | ||
|
||
- Run the test code locally with an existing Oracle Instance(Recommended) | ||
- Run the test code inside a container just like CI, It will require to start an Oracle container every time, and it's | ||
very time expense. | ||
|
||
### Run the test code locally with an existing Oracle Instance | ||
|
||
1. Start the `Oracle Database Instance` via docker first, so that you can reuse whenever you want to run the test code. | ||
|
||
```bash | ||
$ cat docker-compose.yaml | ||
--- | ||
services: | ||
oracle-db: | ||
container_name: oracle-db | ||
image: gvenzl/oracle-free:23.5-slim | ||
environment: | ||
ORACLE_PASSWORD: SuperPassword@2025 | ||
ports: | ||
- 1521:1521 | ||
healthcheck: | ||
test: ["CMD", "healthcheck.sh"] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 10 | ||
start_period: 5s | ||
start_interval: 5s | ||
volumes: | ||
- ${HOME}/database/oracle/testdata/init.sql:/docker-entrypoint-initdb.d/init.sql | ||
``` | ||
|
||
2. Go into the sqlplus console | ||
|
||
```bash | ||
$ docker exec -it orclxe bash | ||
# su oracle | ||
$ sqlplus / as sysdba | ||
``` | ||
|
||
3. Create a test DB | ||
|
||
```sql | ||
alter session set container=FREEPDB1; | ||
create user orcl identified by orcl; | ||
grant dba to orcl; | ||
grant create session to orcl; | ||
grant connect, resource to orcl; | ||
grant all privileges to orcl; | ||
``` | ||
|
||
4. Run the test code | ||
|
||
```bash | ||
$ cd /path/to/repo/database/oracle/dir | ||
$ ORACLE_DSN=oracle://orcl:orcl@localhost:1521/FREEPDB1 go test -tags "oracle" -race -v -covermode atomic ./... -coverprofile .coverage -timeout 20m | ||
``` |
2 changes: 2 additions & 0 deletions
2
database/oracle/examples/migrations-multistmt/1085649617_create_users_table.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DROP TABLE IF EXISTS USERS_MS; | ||
--- |
17 changes: 17 additions & 0 deletions
17
database/oracle/examples/migrations-multistmt/1085649617_create_users_table.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
--- | ||
|
||
CREATE TABLE USERS_MS ( | ||
USER_ID integer unique, | ||
NAME varchar(40), | ||
EMAIL varchar(40) | ||
); |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations-multistmt/1185749658_add_city_to_users.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE USERS_MS DROP COLUMN CITY; |
3 changes: 3 additions & 0 deletions
3
database/oracle/examples/migrations-multistmt/1185749658_add_city_to_users.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
2 changes: 2 additions & 0 deletions
2
database/oracle/examples/migrations-multistmt/1285849751_add_index_on_user_emails.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DROP INDEX users_ms_email_index; | ||
--- |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations-multistmt/1285849751_add_index_on_user_emails.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE UNIQUE INDEX users_ms_email_index ON users_ms (email); |
2 changes: 2 additions & 0 deletions
2
database/oracle/examples/migrations-multistmt/1385949617_create_books_table.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DROP TABLE IF EXISTS BOOKS_MS; | ||
--- |
5 changes: 5 additions & 0 deletions
5
database/oracle/examples/migrations-multistmt/1385949617_create_books_table.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations-multistmt/1485949617_create_movies_table.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS MOVIES_MS |
5 changes: 5 additions & 0 deletions
5
database/oracle/examples/migrations-multistmt/1485949617_create_movies_table.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations-multistmt/1585849751_just_a_comment.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations-multistmt/1685849751_another_comment.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations-multistmt/1785849751_another_comment.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations-multistmt/1885849751_another_comment.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations/1085649617_create_users_table.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS USERS |
5 changes: 5 additions & 0 deletions
5
database/oracle/examples/migrations/1085649617_create_users_table.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations/1185749658_add_city_to_users.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE USERS DROP COLUMN CITY |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations/1185749658_add_city_to_users.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE USERS ADD CITY varchar(100) |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations/1285849751_add_index_on_user_emails.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP INDEX IF EXISTS users_email_index |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations/1285849751_add_index_on_user_emails.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE UNIQUE INDEX users_email_index ON users (email) |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations/1385949617_create_books_table.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS BOOKS |
5 changes: 5 additions & 0 deletions
5
database/oracle/examples/migrations/1385949617_create_books_table.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations/1485949617_create_movies_table.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS MOVIES |
5 changes: 5 additions & 0 deletions
5
database/oracle/examples/migrations/1485949617_create_movies_table.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations/1585849751_just_a_comment.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations/1685849751_another_comment.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations/1785849751_another_comment.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
1 change: 1 addition & 0 deletions
1
database/oracle/examples/migrations/1885849751_another_comment.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.