diff --git a/db/migrations/mysql/000087_sidebar_categories_index.down.sql b/db/migrations/mysql/000087_sidebar_categories_index.down.sql new file mode 100644 index 0000000000..4590499137 --- /dev/null +++ b/db/migrations/mysql/000087_sidebar_categories_index.down.sql @@ -0,0 +1,14 @@ +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS + WHERE table_name = 'SidebarCategories' + AND table_schema = DATABASE() + AND index_name = 'idx_sidebarcategories_userid_teamid' + ) > 0, + 'DROP INDEX idx_sidebarcategories_userid_teamid on SidebarCategories;', + 'SELECT 1;' +)); + +PREPARE removeIndexIfExists FROM @preparedStatement; +EXECUTE removeIndexIfExists; +DEALLOCATE PREPARE removeIndexIfExists; diff --git a/db/migrations/mysql/000087_sidebar_categories_index.up.sql b/db/migrations/mysql/000087_sidebar_categories_index.up.sql new file mode 100644 index 0000000000..9f77256683 --- /dev/null +++ b/db/migrations/mysql/000087_sidebar_categories_index.up.sql @@ -0,0 +1,14 @@ +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS + WHERE table_name = 'SidebarCategories' + AND table_schema = DATABASE() + AND index_name = 'idx_sidebarcategories_userid_teamid' + ) > 0, + 'SELECT 1;', + 'CREATE INDEX idx_sidebarcategories_userid_teamid on SidebarCategories(UserId, TeamId) LOCK=NONE;' +)); + +PREPARE createIndexIfNotExists FROM @preparedStatement; +EXECUTE createIndexIfNotExists; +DEALLOCATE PREPARE createIndexIfNotExists; diff --git a/db/migrations/postgres/000087_sidebar_categories_index.down.sql b/db/migrations/postgres/000087_sidebar_categories_index.down.sql new file mode 100644 index 0000000000..c1e4114d7c --- /dev/null +++ b/db/migrations/postgres/000087_sidebar_categories_index.down.sql @@ -0,0 +1 @@ +DROP INDEX IF exists idx_sidebarcategories_userid_teamid; \ No newline at end of file diff --git a/db/migrations/postgres/000087_sidebar_categories_index.up.sql b/db/migrations/postgres/000087_sidebar_categories_index.up.sql new file mode 100644 index 0000000000..42e40d8093 --- /dev/null +++ b/db/migrations/postgres/000087_sidebar_categories_index.up.sql @@ -0,0 +1 @@ +CREATE INDEX IF NOT EXISTS idx_sidebarcategories_userid_teamid on sidebarcategories (userid, teamid); \ No newline at end of file