From 561c3d22e9ba091db1435236c6150271d26e1cd8 Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Fri, 10 Sep 2021 12:27:20 +0200 Subject: [PATCH] fix: Added indices and primary key to feature_tag (#936) * fix: Added indices and primary key as recommended by dbcritic --- .../20210907124058-add-dbcritic-indices.js | 37 +++++++++++++++++++ ...0210907124850-add-dbcritic-primary-keys.js | 25 +++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/migrations/20210907124058-add-dbcritic-indices.js create mode 100644 src/migrations/20210907124850-add-dbcritic-primary-keys.js diff --git a/src/migrations/20210907124058-add-dbcritic-indices.js b/src/migrations/20210907124058-add-dbcritic-indices.js new file mode 100644 index 0000000000..cc2beb8647 --- /dev/null +++ b/src/migrations/20210907124058-add-dbcritic-indices.js @@ -0,0 +1,37 @@ +exports.up = function (db, cb) { + db.runSql( + ` + CREATE INDEX feature_environments_feature_name_idx ON feature_environments(feature_name); + CREATE INDEX feature_strategies_environment_idx ON feature_strategies(environment); + CREATE INDEX feature_strategies_feature_name_idx ON feature_strategies(feature_name); + CREATE INDEX feature_tag_tag_type_and_value_idx ON feature_tag(tag_type, tag_value); + CREATE INDEX project_environments_environment_idx ON project_environments(environment_name); + CREATE INDEX reset_tokens_user_id_idx ON reset_tokens(user_id); + CREATE INDEX role_permission_role_id_idx ON role_permission(role_id); + CREATE INDEX role_user_user_id_idx ON role_user(user_id); + + `, + cb, + ); +}; + +exports.down = function (db, cb) { + db.runSql( + ` + DROP INDEX feature_environments_feature_name_idx; + DROP INDEX feature_strategies_environment_idx; + DROP INDEX feature_strategies_feature_name_idx; + DROP INDEX feature_tag_tag_type_and_value_idx; + DROP INDEX project_environments_environment_idx; + DROP INDEX reset_tokens_user_id_idx; + DROP INDEX role_permission_role_id_idx; + DROP INDEX role_user_user_id_idx; + + `, + cb, + ); +}; + +exports._meta = { + version: 1, +}; diff --git a/src/migrations/20210907124850-add-dbcritic-primary-keys.js b/src/migrations/20210907124850-add-dbcritic-primary-keys.js new file mode 100644 index 0000000000..d883597701 --- /dev/null +++ b/src/migrations/20210907124850-add-dbcritic-primary-keys.js @@ -0,0 +1,25 @@ +exports.up = function (db, cb) { + db.runSql( + ` + ALTER TABLE feature_tag + DROP CONSTRAINT feature_tag_feature_name_tag_type_tag_value_key; + ALTER TABLE feature_tag + ADD PRIMARY KEY (feature_name, tag_type, tag_value); + `, + cb, + ); +}; + +exports.down = function (db, cb) { + db.runSql( + `ALTER TABLE feature_tag + DROP constraint feature_tag_pkey; + ALTER TABLE feature_tag + ADD CONSTRAINT feature_tag_feature_name_tag_type_tag_value_key UNIQUE (feature_name, tag_type, tag_value)`, + cb, + ); +}; + +exports._meta = { + version: 1, +};