Skip to content

Align Resource Group Tables with Trino v476 #713

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions gateway-ha/src/main/resources/mysql/V3__align_with_trino_476.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- Align `exact_match_source_selectors` table

-- Adjust primary key
ALTER TABLE exact_match_source_selectors
DROP PRIMARY KEY;

ALTER TABLE exact_match_source_selectors
ADD PRIMARY KEY (environment, source(128), resource_group_id);

-- Modify `query_type` to be nullable
ALTER TABLE exact_match_source_selectors
MODIFY COLUMN query_type VARCHAR(512) DEFAULT NULL;


-- Align `resource_groups` table

-- Drop the unique constraint on `name`
ALTER TABLE resource_groups
DROP INDEX name;

-- Make `soft_memory_limit` nullable
ALTER TABLE resource_groups
MODIFY COLUMN soft_memory_limit VARCHAR(128) DEFAULT NULL;

-- Drop and recreate the `parent` foreign key with ON DELETE CASCADE
ALTER TABLE resource_groups
DROP FOREIGN KEY resource_groups_ibfk_1;

ALTER TABLE resource_groups
ADD CONSTRAINT resource_groups_ibfk_1
FOREIGN KEY (parent) REFERENCES resource_groups(resource_group_id)
ON DELETE CASCADE;


-- Align `selectors` table

-- Add missing columns
ALTER TABLE selectors
ADD COLUMN user_group_regex VARCHAR(2048) DEFAULT NULL,
ADD COLUMN original_user_regex VARCHAR(512) DEFAULT NULL,
ADD COLUMN authenticated_user_regex VARCHAR(512) DEFAULT NULL,
ADD COLUMN id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY;

-- Drop and recreate the `resource_group_id` foreign key with ON DELETE CASCADE
ALTER TABLE selectors DROP FOREIGN KEY selectors_ibfk_1;

ALTER TABLE selectors
ADD CONSTRAINT selectors_ibfk_1
FOREIGN KEY (resource_group_id)
REFERENCES resource_groups(resource_group_id)
ON DELETE CASCADE;
21 changes: 21 additions & 0 deletions gateway-ha/src/main/resources/oracle/V3__align_with_trino_476.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Align `exact_match_source_selectors` table

-- Shrink `environment` column length
ALTER TABLE exact_match_source_selectors MODIFY environment VARCHAR(128);


-- Align `resource_groups` table

-- Make `soft_memory_limit` nullable
ALTER TABLE resource_groups MODIFY soft_memory_limit VARCHAR(128) NULL;


-- Align `selectors` table

-- Add missing columns
ALTER TABLE selectors ADD (
user_group_regex VARCHAR2(2048),
original_user_regex VARCHAR2(512),
authenticated_user_regex VARCHAR2(512),
id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1) PRIMARY KEY
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- Align `exact_match_source_selectors` table

-- Adjust primary key
ALTER TABLE exact_match_source_selectors
DROP CONSTRAINT IF EXISTS exact_match_source_selectors_pkey;

ALTER TABLE exact_match_source_selectors
ADD PRIMARY KEY (environment, source, resource_group_id);

-- Extend the length of `query_type`
ALTER TABLE exact_match_source_selectors
ALTER COLUMN query_type TYPE VARCHAR(512);


-- Align resource_groups table

-- Drop the unique constraint on `name` if it exists
ALTER TABLE resource_groups DROP CONSTRAINT IF EXISTS resource_groups_name_key;

-- Alter `resource_group_id` from integer to bigint
ALTER TABLE resource_groups ALTER COLUMN resource_group_id TYPE bigint;

-- Make `soft_memory_limit` nullable
ALTER TABLE resource_groups ALTER COLUMN soft_memory_limit DROP NOT NULL;

-- Drop and recreate the `parent` foreign key with ON DELETE CASCADE
ALTER TABLE resource_groups DROP CONSTRAINT IF EXISTS resource_groups_parent_fkey;

ALTER TABLE resource_groups
ADD CONSTRAINT resource_groups_parent_fkey
FOREIGN KEY (parent) REFERENCES resource_groups(resource_group_id) ON DELETE CASCADE;


-- Align `selectors` table

-- Add missing columns
ALTER TABLE selectors
ADD COLUMN user_group_regex VARCHAR(2048),
ADD COLUMN original_user_regex VARCHAR(512),
ADD COLUMN authenticated_user_regex VARCHAR(512),
ADD COLUMN id BIGSERIAL PRIMARY KEY;

-- Drop and recreate the `resource_group_id` foreign key with ON DELETE CASCADE
ALTER TABLE selectors DROP CONSTRAINT IF EXISTS selectors_resource_group_id_fkey;

ALTER TABLE selectors
ADD CONSTRAINT selectors_resource_group_id_fkey
FOREIGN KEY (resource_group_id)
REFERENCES resource_groups(resource_group_id)
ON DELETE CASCADE;
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void createGatewaySchema()
");";
String resourceGroupsTable = "CREATE TABLE resource_groups (\n" +
" resource_group_id BIGINT NOT NULL AUTO_INCREMENT,\n" +
" name VARCHAR(250) NOT NULL,\n" +
" name VARCHAR(250) NOT NULL UNIQUE,\n" +
" soft_memory_limit VARCHAR(128) NOT NULL,\n" +
" max_queued INT NOT NULL,\n" +
" soft_concurrency_limit INT NULL,\n" +
Expand Down