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: workflow_dispatch:
env: env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }} BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
EXCLUDE_ENTERPRISE: true EXCLUDE_ENTERPRISE: true
jobs: 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: golangci:
name: plugin name: plugin
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
@ -27,14 +39,14 @@ jobs:
continue-on-error: true continue-on-error: true
with: with:
repository: "mattermost/mattermost-server" repository: "mattermost/mattermost-server"
fetch-depth: "20" fetch-depth: "20"
path: "mattermost-server" path: "mattermost-server"
ref: ${{ env.BRANCH_NAME }} ref: ${{ env.BRANCH_NAME }}
- uses: actions/checkout@v3 - uses: actions/checkout@v3
if: steps.mattermostServer.outcome == 'failure' if: steps.mattermostServer.outcome == 'failure'
with: with:
repository: "mattermost/mattermost-server" repository: "mattermost/mattermost-server"
fetch-depth: "20" fetch-depth: "20"
path: "mattermost-server" path: "mattermost-server"
ref : "master" ref : "master"
- name: set up golangci-lint - 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 SELECT 1;
DROP COLUMN root_id;

View file

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

View file

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

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 SELECT 1;
DROP COLUMN workspace_id;
ALTER TABLE {{.prefix}}sharing
DROP COLUMN workspace_id;
ALTER TABLE {{.prefix}}sessions
DROP COLUMN auth_service;

View file

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

View file

@ -1,63 +1 @@
ALTER TABLE {{.prefix}}blocks RENAME TO {{.prefix}}blocks_old; SELECT 1;
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;

View file

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

View file

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

View file

@ -1,18 +1 @@
SELECT 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;

View file

@ -1,9 +1 @@
{{if .mysql}} SELECT 1;
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}}

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; SELECT 1;

View file

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

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; SELECT 1;
ALTER TABLE {{.prefix}}boards_history DROP COLUMN minimum_role;

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; SELECT 1;
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}}

View file

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

View file

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