forked from pressly/goose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update test oracle migrations, support 19c
- Loading branch information
Michelle Laurenti
committed
Apr 4, 2024
1 parent
f20d143
commit ff4404c
Showing
5 changed files
with
36 additions
and
36 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
21 changes: 9 additions & 12 deletions
21
internal/testing/integration/testdata/migrations/oracle/00001_table.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 |
---|---|---|
@@ -1,25 +1,22 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
CREATE TYPE owner_type as ENUM('user', 'organization'); | ||
|
||
CREATE TABLE owners ( | ||
owner_id BIGSERIAL PRIMARY KEY, | ||
owner_name text NOT NULL, | ||
owner_type owner_type NOT NULL | ||
owner_id NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY, | ||
owner_name NVARCHAR2(255) NOT NULL, | ||
owner_type NVARCHAR2(255) NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS repos ( | ||
repo_id BIGSERIAL NOT NULL, | ||
repo_full_name text NOT NULL, | ||
repo_owner_id bigint NOT NULL REFERENCES owners(owner_id) ON DELETE CASCADE, | ||
CREATE TABLE repos ( | ||
repo_id NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY NOT NULL, | ||
repo_full_name VARCHAR(255) NOT NULL, | ||
repo_owner_id NUMBER NOT NULL REFERENCES owners(owner_id) ON DELETE CASCADE, | ||
|
||
PRIMARY KEY (repo_id) | ||
); | ||
-- +goose StatementEnd | ||
|
||
-- +goose Down | ||
-- +goose StatementBegin | ||
DROP TABLE IF EXISTS repos; | ||
DROP TABLE IF EXISTS owners; | ||
DROP TYPE owner_type; | ||
DROP TABLE repos; | ||
DROP TABLE owners; | ||
-- +goose StatementEnd |
9 changes: 6 additions & 3 deletions
9
internal/testing/integration/testdata/migrations/oracle/00003_alter.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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
ALTER TABLE repos | ||
ADD COLUMN IF NOT EXISTS homepage_url text, | ||
ADD COLUMN is_private boolean NOT NULL DEFAULT false; | ||
ADD ( | ||
homepage_url NVARCHAR2(255), | ||
is_private NUMBER(1) DEFAULT 0 NOT NULL | ||
); | ||
-- +goose StatementEnd | ||
|
||
-- +goose Down | ||
-- +goose StatementBegin | ||
ALTER TABLE repos | ||
DROP COLUMN IF EXISTS homepage_url, | ||
DROP COLUMN homepage_url; | ||
ALTER TABLE repos | ||
DROP COLUMN is_private; | ||
-- +goose StatementEnd |
4 changes: 2 additions & 2 deletions
4
internal/testing/integration/testdata/migrations/oracle/00005_no_tx.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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
-- +goose NO TRANSACTION | ||
|
||
-- +goose Up | ||
CREATE UNIQUE INDEX CONCURRENTLY ON owners(owner_name); | ||
CREATE UNIQUE INDEX owners_owner_name_idx ON owners(owner_name); | ||
|
||
-- +goose Down | ||
DROP INDEX IF EXISTS owners_owner_name_idx; | ||
DROP INDEX owners_owner_name_idx; |
32 changes: 16 additions & 16 deletions
32
internal/testing/integration/testdata/migrations/oracle/00006_complex.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 |
---|---|---|
@@ -1,36 +1,36 @@ | ||
-- +goose up | ||
|
||
CREATE OR REPLACE TYPE insert_repository_result AS object (v_owner_id NUMBER(38), v_repo_id NUMBER(38)); | ||
|
||
-- +goose statementbegin | ||
CREATE OR REPLACE FUNCTION insert_repository( | ||
p_repo_full_name TEXT, | ||
p_owner_name TEXT, | ||
p_owner_type OWNER_TYPE | ||
) RETURNS VOID AS $$ | ||
DECLARE | ||
v_owner_id BIGINT; | ||
v_repo_id BIGINT; | ||
p_repo_full_name NVARCHAR2, | ||
p_owner_name NVARCHAR2, | ||
p_owner_type NVARCHAR2 | ||
) RETURN insert_repository_result IS result insert_repository_result; | ||
BEGIN | ||
-- Check if the owner already exists | ||
SELECT owner_id INTO v_owner_id | ||
SELECT owner_id INTO result.v_owner_id | ||
FROM owners | ||
WHERE owner_name = p_owner_name AND owner_type = p_owner_type; | ||
|
||
-- If the owner does not exist, insert a new owner | ||
IF v_owner_id IS NULL THEN | ||
IF result.v_owner_id IS NULL THEN | ||
|
||
INSERT INTO owners (owner_name, owner_type) | ||
VALUES (p_owner_name, p_owner_type) | ||
RETURNING owner_id INTO v_owner_id; | ||
RETURNING owner_id INTO result.v_owner_id; | ||
END IF; | ||
|
||
-- Insert the repository using the obtained owner_id | ||
INSERT INTO repos (repo_full_name, repo_owner_id) | ||
VALUES (p_repo_full_name, v_owner_id) | ||
RETURNING repo_id INTO v_repo_id; | ||
VALUES (p_repo_full_name, result.v_owner_id) | ||
RETURNING repo_id INTO result.v_repo_id; | ||
|
||
-- Commit the transaction | ||
COMMIT; | ||
RETURN result; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
-- +goose statementend | ||
|
||
-- +goose down | ||
DROP FUNCTION IF EXISTS insert_repository(TEXT, TEXT, OWNER_TYPE); | ||
DROP FUNCTION insert_repository; | ||
DROP TYPE insert_repository_result; |