Set down migrations as noops and add CI job (#4186)

This commit is contained in:
Miguel de la Cruz 2022-11-10 17:04:40 +01:00 committed by GitHub
parent fedcf57fb6
commit a96fa493eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 39 additions and 175 deletions

View file

@ -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

View file

@ -1 +1 @@
DROP TABLE {{.prefix}}blocks;
SELECT 1;

View file

@ -1 +1 @@
DROP TABLE {{.prefix}}system_settings;
SELECT 1;

View file

@ -1,2 +1 @@
ALTER TABLE {{.prefix}}blocks
DROP COLUMN root_id;
SELECT 1;

View file

@ -1,2 +1 @@
DROP TABLE {{.prefix}}users;
DROP TABLE {{.prefix}}sessions;
SELECT 1;

View file

@ -1,2 +1 @@
ALTER TABLE {{.prefix}}blocks
DROP COLUMN modified_by;
SELECT 1;

View file

@ -1 +1 @@
DROP TABLE {{.prefix}}sharing;
SELECT 1;

View file

@ -1 +1 @@
DROP TABLE {{.prefix}}workspaces;
SELECT 1;

View file

@ -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;

View file

@ -1,2 +1 @@
DROP TABLE {{.prefix}}blocks;
ALTER TABLE {{.prefix}}blocks_history RENAME TO {{.prefix}}blocks;
SELECT 1;

View file

@ -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;

View file

@ -1,3 +1 @@
-- Nothing to be done here
-- This page is intentionally left blank
SELECT 1;

View file

@ -1,3 +1 @@
-- Nothing to be done here
-- This page is intentionally left blank
SELECT 1;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -1,2 +1 @@
DROP TABLE {{.prefix}}subscriptions;
DROP TABLE {{.prefix}}notification_hints;
SELECT 1;

View file

@ -1 +1 @@
DROP TABLE IF EXISTS {{.prefix}}file_info;
SELECT 1;

View file

@ -1 +1 @@
DELETE from {{.prefix}}categories;
SELECT 1;

View file

@ -1 +1 @@
DELETE from {{.prefix}}category_boards;
SELECT 1;

View file

@ -1 +1 @@
DROP TABLE {{.prefix}}board_members_history;
SELECT 1;

View file

@ -1,3 +1 @@
ALTER TABLE {{.prefix}}boards DROP COLUMN minimum_role;
ALTER TABLE {{.prefix}}boards_history DROP COLUMN minimum_role;
SELECT 1;

View file

@ -1 +1 @@
ALTER TABLE {{.prefix}}categories DROP COLUMN collapsed;
SELECT 1;

View file

@ -1 +1 @@
UPDATE {{.prefix}}categories SET collapsed = false;
SELECT 1;

View file

@ -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;

View file

@ -1 +1 @@
DROP TABLE {{.prefix}}preferences;
SELECT 1;

View file

@ -1 +1 @@
ALTER TABLE {{.prefix}}categories DROP COLUMN type;
SELECT 1;