Skip to content

Commit

Permalink
update test oracle migrations, support 19c
Browse files Browse the repository at this point in the history
  • Loading branch information
Michelle Laurenti committed Apr 4, 2024
1 parent f20d143 commit ff4404c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions internal/dialect/dialectquery/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ var _ Querier = (*Oracle)(nil)

func (p *Oracle) CreateTable(tableName string) string {
q := `CREATE TABLE %s (
id NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY,
version_id NUMBER(10) NOT NULL,
is_applied BOOLEAN NOT NULL,
id NUMBER(38) GENERATED BY DEFAULT ON NULL AS IDENTITY,
version_id NUMBER(38) NOT NULL,
is_applied NUMBER(1) NOT NULL,
tstamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(id)
)`
Expand Down
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
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
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;
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;

0 comments on commit ff4404c

Please sign in to comment.