Skip to content
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

fix(migrations): change the order of queries for mysql #3039

Merged
merged 1 commit into from
May 2, 2024
Merged
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
30 changes: 14 additions & 16 deletions config/migrations/mysql/5_namespaces_relationships.up.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-- Drop previously created foreign key
ALTER TABLE constraints DROP FOREIGN KEY `constraints_ibfk_1`;
ALTER TABLE rules DROP FOREIGN KEY `rules_ibfk_1`;
ALTER TABLE rules DROP FOREIGN KEY `rules_ibfk_2`;
ALTER TABLE variants DROP FOREIGN KEY `variants_ibfk_1`;

-- Flags

-- Add column namespace_key with a default value
Expand All @@ -6,19 +12,18 @@ ALTER TABLE flags ADD COLUMN namespace_key VARCHAR(255) NOT NULL DEFAULT 'defaul
-- Drop previously created unique index
ALTER TABLE flags DROP INDEX `key`, ADD INDEX `key` (`key`) USING BTREE;

-- Add foreign key constraint on namespace_key column referencing key column of namespaces table
ALTER TABLE flags ADD FOREIGN KEY (namespace_key) REFERENCES namespaces(`key`) ON DELETE CASCADE;

-- Drop primary key constraint and add a new composite primary key on namespace_key and key columns
ALTER TABLE flags DROP PRIMARY KEY, ADD PRIMARY KEY (`namespace_key`, `key`);

-- Add foreign key constraint on namespace_key column referencing key column of namespaces table
ALTER TABLE flags ADD FOREIGN KEY (namespace_key) REFERENCES namespaces(`key`) ON DELETE CASCADE;

-- Variants

-- Add column namespace_key with a default value
ALTER TABLE variants ADD COLUMN namespace_key VARCHAR(255) NOT NULL DEFAULT 'default';

-- Drop previously created foreign key
ALTER TABLE variants DROP FOREIGN KEY `variants_ibfk_1`;

-- Drop previously created unique index and add a new unique index on namespace_key, flag_key and key columns
ALTER TABLE variants DROP INDEX `variants_flag_key_key`, ADD UNIQUE INDEX `variants_namespace_flag_key` (`namespace_key`, `flag_key`, `key`) USING BTREE;
Expand All @@ -31,26 +36,23 @@ ALTER TABLE variants ADD FOREIGN KEY (namespace_key, flag_key) REFERENCES flags(

-- Segments

-- Add column namespace_key with a default value
ALTER TABLE segments ADD COLUMN namespace_key VARCHAR(255) NOT NULL DEFAULT 'default';

-- Drop previously created unique index and add a new unique index on namespace_key and key columns
ALTER TABLE segments DROP INDEX `key`, ADD INDEX `key` (`key`) USING BTREE;

-- Add foreign key constraint on namespace_key column referencing key column of namespaces table
ALTER TABLE segments ADD FOREIGN KEY (namespace_key) REFERENCES namespaces(`key`) ON DELETE CASCADE;
-- Add column namespace_key with a default value
ALTER TABLE segments ADD COLUMN namespace_key VARCHAR(255) NOT NULL DEFAULT 'default';

-- Drop primary key constraint and add a new composite primary key on namespace_key and key columns
ALTER TABLE segments DROP PRIMARY KEY, ADD PRIMARY KEY (`namespace_key`, `key`);

-- Add foreign key constraint on namespace_key column referencing key column of namespaces table
ALTER TABLE segments ADD FOREIGN KEY (namespace_key) REFERENCES namespaces(`key`) ON DELETE CASCADE;

-- Constraints

-- Add column namespace_key with a default value
ALTER TABLE constraints ADD COLUMN namespace_key VARCHAR(255) NOT NULL DEFAULT 'default';

-- Drop previously created foreign key
ALTER TABLE constraints DROP FOREIGN KEY `constraints_ibfk_1`;

-- Drop previously created index and add a new index on namespace_key and segment_key columns
ALTER TABLE constraints DROP INDEX `segment_key`, ADD INDEX `constraints_namespace_segment_key` (`namespace_key`, `segment_key`) USING BTREE;

Expand All @@ -65,10 +67,6 @@ ALTER TABLE constraints ADD FOREIGN KEY (namespace_key, segment_key) REFERENCES
-- Add column namespace_key with a default value
ALTER TABLE rules ADD COLUMN namespace_key VARCHAR(255) NOT NULL DEFAULT 'default';

-- Drop previously created foreign keys
ALTER TABLE rules DROP FOREIGN KEY `rules_ibfk_1`;
ALTER TABLE rules DROP FOREIGN KEY `rules_ibfk_2`;

-- Drop previously created index and add a new index on namespace_key, flag_key and segment_key columns
ALTER TABLE rules DROP INDEX `flag_key`, ADD INDEX `rules_namespace_flag_key` (`namespace_key`, `flag_key`) USING BTREE;
ALTER TABLE rules DROP INDEX `segment_key`, ADD INDEX `rules_namespace_segment_key` (`namespace_key`, `segment_key`) USING BTREE;
Expand Down