From a96fa493eb3193f8cf6b66594f54f71c3f5c2036 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Thu, 10 Nov 2022 17:04:40 +0100 Subject: [PATCH] Set down migrations as noops and add CI job (#4186) --- .github/workflows/lint-server.yml | 20 ++++-- .../sqlstore/migrations/000001_init.down.sql | 2 +- .../000002_system_settings_table.down.sql | 2 +- .../migrations/000003_blocks_rootid.down.sql | 3 +- .../migrations/000004_auth_table.down.sql | 3 +- .../000005_blocks_modifiedby.down.sql | 3 +- .../migrations/000006_sharing_table.down.sql | 2 +- .../000007_workspaces_table.down.sql | 2 +- .../sqlstore/migrations/000008_teams.down.sql | 9 +-- .../migrations/000009_blocks_history.down.sql | 3 +- .../000010_blocks_created_by.down.sql | 64 +------------------ .../000011_match_collation.down.sql | 2 - .../000012_match_column_collation.down.sql | 2 - .../000013_millisecond_timestamps.down.sql | 19 +----- .../000014_add_not_null_constraint.down.sql | 10 +-- .../000015_blocks_history_no_nulls.down.sql | 5 -- .../000016_subscriptions_table.down.sql | 3 +- .../migrations/000017_add_file_info.down.sql | 2 +- .../000019_populate_categories.down.sql | 2 +- .../000020_populate_category_blocks.down.sql | 2 +- ...021_create_boards_members_history.down.sql | 2 +- .../000022_create_default_board_role.down.sql | 4 +- ..._persist_category_collapsed_state.down.sql | 2 +- ...rk_existsing_categories_collapsed.down.sql | 2 +- .../migrations/000025_indexes_update.down.sql | 40 +----------- .../000026_create_preferences_table.down.sql | 2 +- .../000029_add_category_type_field.down.sql | 2 +- 27 files changed, 39 insertions(+), 175 deletions(-) diff --git a/.github/workflows/lint-server.yml b/.github/workflows/lint-server.yml index 32e237db5..eb5093406 100644 --- a/.github/workflows/lint-server.yml +++ b/.github/workflows/lint-server.yml @@ -8,10 +8,22 @@ on: workflow_dispatch: env: - BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} EXCLUDE_ENTERPRISE: true - + jobs: + down-migrations: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v3 + with: + path: "focalboard" + - name: assert that down migrations are SELECT 1 scripts + run: | + cd focalboard + echo 'SELECT 1;' > downmigration + for file in server/services/store/sqlstore/migrations/*.down.sql; do diff -Bw downmigration $file; done + golangci: name: plugin runs-on: ubuntu-18.04 @@ -27,14 +39,14 @@ jobs: continue-on-error: true with: repository: "mattermost/mattermost-server" - fetch-depth: "20" + fetch-depth: "20" path: "mattermost-server" ref: ${{ env.BRANCH_NAME }} - uses: actions/checkout@v3 if: steps.mattermostServer.outcome == 'failure' with: repository: "mattermost/mattermost-server" - fetch-depth: "20" + fetch-depth: "20" path: "mattermost-server" ref : "master" - name: set up golangci-lint diff --git a/server/services/store/sqlstore/migrations/000001_init.down.sql b/server/services/store/sqlstore/migrations/000001_init.down.sql index cd2854e8b..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000001_init.down.sql +++ b/server/services/store/sqlstore/migrations/000001_init.down.sql @@ -1 +1 @@ -DROP TABLE {{.prefix}}blocks; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000002_system_settings_table.down.sql b/server/services/store/sqlstore/migrations/000002_system_settings_table.down.sql index 353d31b88..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000002_system_settings_table.down.sql +++ b/server/services/store/sqlstore/migrations/000002_system_settings_table.down.sql @@ -1 +1 @@ -DROP TABLE {{.prefix}}system_settings; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000003_blocks_rootid.down.sql b/server/services/store/sqlstore/migrations/000003_blocks_rootid.down.sql index 309061426..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000003_blocks_rootid.down.sql +++ b/server/services/store/sqlstore/migrations/000003_blocks_rootid.down.sql @@ -1,2 +1 @@ -ALTER TABLE {{.prefix}}blocks -DROP COLUMN root_id; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000004_auth_table.down.sql b/server/services/store/sqlstore/migrations/000004_auth_table.down.sql index 26345d6c4..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000004_auth_table.down.sql +++ b/server/services/store/sqlstore/migrations/000004_auth_table.down.sql @@ -1,2 +1 @@ -DROP TABLE {{.prefix}}users; -DROP TABLE {{.prefix}}sessions; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000005_blocks_modifiedby.down.sql b/server/services/store/sqlstore/migrations/000005_blocks_modifiedby.down.sql index c77bb8050..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000005_blocks_modifiedby.down.sql +++ b/server/services/store/sqlstore/migrations/000005_blocks_modifiedby.down.sql @@ -1,2 +1 @@ -ALTER TABLE {{.prefix}}blocks -DROP COLUMN modified_by; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000006_sharing_table.down.sql b/server/services/store/sqlstore/migrations/000006_sharing_table.down.sql index 9228b6e84..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000006_sharing_table.down.sql +++ b/server/services/store/sqlstore/migrations/000006_sharing_table.down.sql @@ -1 +1 @@ -DROP TABLE {{.prefix}}sharing; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000007_workspaces_table.down.sql b/server/services/store/sqlstore/migrations/000007_workspaces_table.down.sql index 254c10692..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000007_workspaces_table.down.sql +++ b/server/services/store/sqlstore/migrations/000007_workspaces_table.down.sql @@ -1 +1 @@ -DROP TABLE {{.prefix}}workspaces; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000008_teams.down.sql b/server/services/store/sqlstore/migrations/000008_teams.down.sql index 98d6eca6d..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000008_teams.down.sql +++ b/server/services/store/sqlstore/migrations/000008_teams.down.sql @@ -1,8 +1 @@ -ALTER TABLE {{.prefix}}blocks -DROP COLUMN workspace_id; - -ALTER TABLE {{.prefix}}sharing -DROP COLUMN workspace_id; - -ALTER TABLE {{.prefix}}sessions -DROP COLUMN auth_service; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000009_blocks_history.down.sql b/server/services/store/sqlstore/migrations/000009_blocks_history.down.sql index aec3f78e0..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000009_blocks_history.down.sql +++ b/server/services/store/sqlstore/migrations/000009_blocks_history.down.sql @@ -1,2 +1 @@ -DROP TABLE {{.prefix}}blocks; -ALTER TABLE {{.prefix}}blocks_history RENAME TO {{.prefix}}blocks; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000010_blocks_created_by.down.sql b/server/services/store/sqlstore/migrations/000010_blocks_created_by.down.sql index 5b10c6a10..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000010_blocks_created_by.down.sql +++ b/server/services/store/sqlstore/migrations/000010_blocks_created_by.down.sql @@ -1,63 +1 @@ -ALTER TABLE {{.prefix}}blocks RENAME TO {{.prefix}}blocks_old; -CREATE TABLE IF NOT EXISTS {{.prefix}}blocks ( - id VARCHAR(36), - {{if .postgres}}insert_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),{{end}} - {{if .sqlite}}insert_at DATETIME NOT NULL DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),{{end}} - {{if .mysql}}insert_at DATETIME(6) NOT NULL DEFAULT NOW(6),{{end}} - parent_id VARCHAR(36), - {{if .mysql}}`schema`{{else}}schema{{end}} BIGINT, - type TEXT, - title TEXT, - fields {{if .postgres}}JSON{{else}}TEXT{{end}}, - create_at BIGINT, - update_at BIGINT, - delete_at BIGINT, - root_id VARCHAR(36), - modified_by VARCHAR(36), - workspace_id VARCHAR(36), - PRIMARY KEY (workspace_id,id) - ) {{if .mysql}}DEFAULT CHARACTER SET utf8mb4{{end}}; - -{{if .mysql}} -INSERT IGNORE INTO {{.prefix}}blocks (SELECT * FROM {{.prefix}}blocks_old ORDER BY insert_at DESC); -{{end}} -{{if .postgres}} -INSERT INTO {{.prefix}}blocks (SELECT * FROM {{.prefix}}blocks_old ORDER BY insert_at DESC) ON CONFLICT DO NOTHING; -{{end}} -{{if .sqlite}} -INSERT OR IGNORE INTO {{.prefix}}blocks SELECT * FROM {{.prefix}}blocks_old ORDER BY insert_at DESC; -{{end}} -DELETE FROM {{.prefix}}blocks where delete_at > 0; -DROP TABLE {{.prefix}}blocks_old; - - -ALTER TABLE {{.prefix}}blocks_history RENAME TO {{.prefix}}blocks_history_old; -CREATE TABLE IF NOT EXISTS {{.prefix}}blocks_history ( - id VARCHAR(36), - {{if .postgres}}insert_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),{{end}} - {{if .sqlite}}insert_at DATETIME NOT NULL DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),{{end}} - {{if .mysql}}insert_at DATETIME(6) NOT NULL DEFAULT NOW(6),{{end}} - parent_id VARCHAR(36), - {{if .mysql}}`schema`{{else}}schema{{end}} BIGINT, - type TEXT, - title TEXT, - fields {{if .postgres}}JSON{{else}}TEXT{{end}}, - create_at BIGINT, - update_at BIGINT, - delete_at BIGINT, - root_id VARCHAR(36), - modified_by VARCHAR(36), - workspace_id VARCHAR(36), - PRIMARY KEY (workspace_id,id) - ) {{if .mysql}}DEFAULT CHARACTER SET utf8mb4{{end}}; - -{{if .mysql}} -INSERT IGNORE INTO {{.prefix}}blocks_history (SELECT * FROM {{.prefix}}blocks_history_old ORDER BY insert_at DESC); -{{end}} -{{if .postgres}} -INSERT INTO {{.prefix}}blocks_history (SELECT * FROM {{.prefix}}blocks_history_old ORDER BY insert_at DESC) ON CONFLICT DO NOTHING; -{{end}} -{{if .sqlite}} -INSERT OR IGNORE INTO {{.prefix}}blocks_history SELECT * FROM {{.prefix}}blocks_history_old ORDER BY insert_at DESC; -{{end}} -DROP TABLE {{.prefix}}blocks_history_old; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000011_match_collation.down.sql b/server/services/store/sqlstore/migrations/000011_match_collation.down.sql index e6c0ce8c6..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000011_match_collation.down.sql +++ b/server/services/store/sqlstore/migrations/000011_match_collation.down.sql @@ -1,3 +1 @@ --- Nothing to be done here --- This page is intentionally left blank SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000012_match_column_collation.down.sql b/server/services/store/sqlstore/migrations/000012_match_column_collation.down.sql index e6c0ce8c6..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000012_match_column_collation.down.sql +++ b/server/services/store/sqlstore/migrations/000012_match_column_collation.down.sql @@ -1,3 +1 @@ --- Nothing to be done here --- This page is intentionally left blank SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000013_millisecond_timestamps.down.sql b/server/services/store/sqlstore/migrations/000013_millisecond_timestamps.down.sql index 0ab3998f8..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000013_millisecond_timestamps.down.sql +++ b/server/services/store/sqlstore/migrations/000013_millisecond_timestamps.down.sql @@ -1,18 +1 @@ - -UPDATE {{.prefix}}users SET create_at = create_at/1000, update_at = update_at/1000, delete_at = delete_at/1000 - WHERE create_at > 1000000000000; - -UPDATE {{.prefix}}blocks SET create_at = create_at/1000, update_at = update_at/1000, delete_at = delete_at/1000 - WHERE create_at > 1000000000000; - -UPDATE {{.prefix}}blocks_history SET create_at = create_at/1000, update_at = update_at/1000, delete_at = delete_at/1000 - WHERE create_at > 1000000000000; - -UPDATE {{.prefix}}workspaces SET update_at = update_at/1000 - WHERE update_at > 1000000000000; - -UPDATE {{.prefix}}sharing SET update_at = update_at/1000 - WHERE update_at > 1000000000000; - -UPDATE {{.prefix}}sessions SET create_at = create_at/1000, update_at = update_at/1000 - WHERE create_at > 1000000000000; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000014_add_not_null_constraint.down.sql b/server/services/store/sqlstore/migrations/000014_add_not_null_constraint.down.sql index adc8ccae5..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000014_add_not_null_constraint.down.sql +++ b/server/services/store/sqlstore/migrations/000014_add_not_null_constraint.down.sql @@ -1,9 +1 @@ -{{if .mysql}} -ALTER TABLE {{.prefix}}blocks MODIFY created_by varchar(36); -ALTER TABLE {{.prefix}}blocks MODIFY modified_by varchar(36); -{{end}} - -{{if .postgres}} -ALTER TABLE {{.prefix}}blocks ALTER COLUMN created_by DROP NOT NULL; -ALTER TABLE {{.prefix}}blocks ALTER COLUMN modified_by DROP NOT NULL; -{{end}} +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000015_blocks_history_no_nulls.down.sql b/server/services/store/sqlstore/migrations/000015_blocks_history_no_nulls.down.sql index f24ef405b..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000015_blocks_history_no_nulls.down.sql +++ b/server/services/store/sqlstore/migrations/000015_blocks_history_no_nulls.down.sql @@ -1,6 +1 @@ --- no reverse migration for this version - --- We need a query here otherwise the migration will result --- in an empty query when the if condition is false. --- Empty query causes a "Query was empty" error. SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000016_subscriptions_table.down.sql b/server/services/store/sqlstore/migrations/000016_subscriptions_table.down.sql index 2b8b6fc20..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000016_subscriptions_table.down.sql +++ b/server/services/store/sqlstore/migrations/000016_subscriptions_table.down.sql @@ -1,2 +1 @@ -DROP TABLE {{.prefix}}subscriptions; -DROP TABLE {{.prefix}}notification_hints; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000017_add_file_info.down.sql b/server/services/store/sqlstore/migrations/000017_add_file_info.down.sql index 84c0b6f59..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000017_add_file_info.down.sql +++ b/server/services/store/sqlstore/migrations/000017_add_file_info.down.sql @@ -1 +1 @@ -DROP TABLE IF EXISTS {{.prefix}}file_info; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000019_populate_categories.down.sql b/server/services/store/sqlstore/migrations/000019_populate_categories.down.sql index e01b744a7..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000019_populate_categories.down.sql +++ b/server/services/store/sqlstore/migrations/000019_populate_categories.down.sql @@ -1 +1 @@ -DELETE from {{.prefix}}categories; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000020_populate_category_blocks.down.sql b/server/services/store/sqlstore/migrations/000020_populate_category_blocks.down.sql index 43e2da5e4..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000020_populate_category_blocks.down.sql +++ b/server/services/store/sqlstore/migrations/000020_populate_category_blocks.down.sql @@ -1 +1 @@ -DELETE from {{.prefix}}category_boards; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000021_create_boards_members_history.down.sql b/server/services/store/sqlstore/migrations/000021_create_boards_members_history.down.sql index ec72954bc..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000021_create_boards_members_history.down.sql +++ b/server/services/store/sqlstore/migrations/000021_create_boards_members_history.down.sql @@ -1 +1 @@ -DROP TABLE {{.prefix}}board_members_history; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000022_create_default_board_role.down.sql b/server/services/store/sqlstore/migrations/000022_create_default_board_role.down.sql index f8c9d8c4c..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000022_create_default_board_role.down.sql +++ b/server/services/store/sqlstore/migrations/000022_create_default_board_role.down.sql @@ -1,3 +1 @@ -ALTER TABLE {{.prefix}}boards DROP COLUMN minimum_role; -ALTER TABLE {{.prefix}}boards_history DROP COLUMN minimum_role; - +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000023_persist_category_collapsed_state.down.sql b/server/services/store/sqlstore/migrations/000023_persist_category_collapsed_state.down.sql index ccf963529..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000023_persist_category_collapsed_state.down.sql +++ b/server/services/store/sqlstore/migrations/000023_persist_category_collapsed_state.down.sql @@ -1 +1 @@ -ALTER TABLE {{.prefix}}categories DROP COLUMN collapsed; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000024_mark_existsing_categories_collapsed.down.sql b/server/services/store/sqlstore/migrations/000024_mark_existsing_categories_collapsed.down.sql index 920aab237..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000024_mark_existsing_categories_collapsed.down.sql +++ b/server/services/store/sqlstore/migrations/000024_mark_existsing_categories_collapsed.down.sql @@ -1 +1 @@ -UPDATE {{.prefix}}categories SET collapsed = false; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000025_indexes_update.down.sql b/server/services/store/sqlstore/migrations/000025_indexes_update.down.sql index d0c90c1fa..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000025_indexes_update.down.sql +++ b/server/services/store/sqlstore/migrations/000025_indexes_update.down.sql @@ -1,39 +1 @@ -DROP INDEX idx_subscriptions_subscriber_id ON {{.prefix}}subscriptions; -DROP INDEX idx_blocks_board_id_parent_id ON {{.prefix}}blocks; - -{{if .mysql}} -ALTER TABLE {{.prefix}}blocks DROP PRIMARY KEY; -ALTER TABLE {{.prefix}}blocks ADD PRIMARY KEY (channel_id, id); -{{end}} - -{{if .postgres}} -ALTER TABLE {{.prefix}}blocks DROP CONSTRAINT {{.prefix}}blocks_pkey1; -ALTER TABLE {{.prefix}}blocks ADD PRIMARY KEY (channel_id, id); -{{end}} - -{{if .sqlite}} -ALTER TABLE {{.prefix}}blocks RENAME TO {{.prefix}}blocks_tmp; - -CREATE TABLE {{.prefix}}blocks ( - id VARCHAR(36), - insert_at DATETIME NOT NULL DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), - parent_id VARCHAR(36), - schema BIGINT, - type TEXT, - title TEXT, - fields TEXT, - create_at BIGINT, - update_at BIGINT, - delete_at BIGINT, - root_id VARCHAR(36), - modified_by VARCHAR(36), - channel_id VARCHAR(36), - created_by VARCHAR(36), - board_id VARCHAR(36), - PRIMARY KEY (channel_id, id) -); - -INSERT INTO {{.prefix}}blocks SELECT * FROM {{.prefix}}blocks_tmp; - -DROP TABLE {{.prefix}}blocks_tmp; -{{end}} +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000026_create_preferences_table.down.sql b/server/services/store/sqlstore/migrations/000026_create_preferences_table.down.sql index 4f9e86f9c..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000026_create_preferences_table.down.sql +++ b/server/services/store/sqlstore/migrations/000026_create_preferences_table.down.sql @@ -1 +1 @@ -DROP TABLE {{.prefix}}preferences; +SELECT 1; diff --git a/server/services/store/sqlstore/migrations/000029_add_category_type_field.down.sql b/server/services/store/sqlstore/migrations/000029_add_category_type_field.down.sql index dc45b39e6..e0ac49d1e 100644 --- a/server/services/store/sqlstore/migrations/000029_add_category_type_field.down.sql +++ b/server/services/store/sqlstore/migrations/000029_add_category_type_field.down.sql @@ -1 +1 @@ -ALTER TABLE {{.prefix}}categories DROP COLUMN type; +SELECT 1;