diff --git a/db/migrations/postgres/000001_create_teams.up.sql b/db/migrations/postgres/000001_create_teams.up.sql index 31b2f781c9..9afd4b7114 100644 --- a/db/migrations/postgres/000001_create_teams.up.sql +++ b/db/migrations/postgres/000001_create_teams.up.sql @@ -35,6 +35,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'teams' + AND table_schema = current_schema() AND column_name = 'alloweddomains' AND NOT data_type = 'varchar(1000)'; IF column_exist THEN @@ -49,6 +50,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'teams' + AND table_schema = current_schema() AND column_name = 'groupconstrained' AND NOT data_type = 'boolean'; IF column_exist THEN @@ -63,6 +65,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'teams' + AND table_schema = current_schema() AND column_name = 'type' AND NOT data_type = 'varchar(255)'; IF column_exist THEN @@ -77,6 +80,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'teams' + AND table_schema = current_schema() AND column_name = 'schemeid' AND NOT data_type = 'varchar(26)'; IF column_exist THEN diff --git a/db/migrations/postgres/000013_create_incoming_webhooks.up.sql b/db/migrations/postgres/000013_create_incoming_webhooks.up.sql index f001f828eb..4f2cd6a70d 100644 --- a/db/migrations/postgres/000013_create_incoming_webhooks.up.sql +++ b/db/migrations/postgres/000013_create_incoming_webhooks.up.sql @@ -63,6 +63,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'incomingwebhooks' + AND table_schema = current_schema() AND column_name = 'description' AND NOT data_type = 'VARCHAR(500)'; IF column_exist THEN diff --git a/db/migrations/postgres/000014_create_outgoing_webhooks.up.sql b/db/migrations/postgres/000014_create_outgoing_webhooks.up.sql index b0d16b5929..699edec9d3 100644 --- a/db/migrations/postgres/000014_create_outgoing_webhooks.up.sql +++ b/db/migrations/postgres/000014_create_outgoing_webhooks.up.sql @@ -30,6 +30,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'outgoingwebhooks' + AND table_schema = current_schema() AND column_name = 'description' AND NOT data_type = 'VARCHAR(500)'; IF column_exist THEN @@ -44,6 +45,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'outgoingwebhooks' + AND table_schema = current_schema() AND column_name = 'iconurl' AND NOT data_type = 'VARCHAR(1024)'; IF column_exist THEN @@ -56,7 +58,7 @@ BEGIN IF ( SELECT column_default::bigint FROM information_schema.columns - WHERE table_schema='public' + WHERE table_schema=current_schema() AND table_name='outgoingwebhooks' AND column_name='username' ) = 0 THEN @@ -69,7 +71,7 @@ BEGIN IF ( SELECT column_default::bigint FROM information_schema.columns - WHERE table_schema='public' + WHERE table_schema=current_schema() AND table_name='outgoingwebhooks' AND column_name='iconurl' ) = 0 THEN diff --git a/db/migrations/postgres/000020_create_posts.up.sql b/db/migrations/postgres/000020_create_posts.up.sql index c3968372f4..fa347c73e4 100644 --- a/db/migrations/postgres/000020_create_posts.up.sql +++ b/db/migrations/postgres/000020_create_posts.up.sql @@ -42,6 +42,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'posts' + AND table_schema = current_schema() AND column_name = 'fileids' AND NOT data_type = 'varchar(300)'; IF column_exist THEN diff --git a/db/migrations/postgres/000026_create_preferences.up.sql b/db/migrations/postgres/000026_create_preferences.up.sql index a46991f3b4..7ce8a4259f 100644 --- a/db/migrations/postgres/000026_create_preferences.up.sql +++ b/db/migrations/postgres/000026_create_preferences.up.sql @@ -18,11 +18,13 @@ BEGIN SELECT count(*) != 0 INTO col_exists FROM information_schema.columns WHERE table_name = 'preferences' + AND table_schema = current_schema() AND column_name = 'value'; SELECT count(*) != 0 INTO type_exists FROM information_schema.columns WHERE table_name = 'preferences' + AND table_schema = current_schema() AND column_name = 'value' AND data_type = 'character varying' AND character_maximum_length = 2000; diff --git a/db/migrations/postgres/000028_create_tokens.up.sql b/db/migrations/postgres/000028_create_tokens.up.sql index 71e12c0c85..c160b79da2 100644 --- a/db/migrations/postgres/000028_create_tokens.up.sql +++ b/db/migrations/postgres/000028_create_tokens.up.sql @@ -16,11 +16,13 @@ BEGIN SELECT count(*) != 0 INTO col_exists FROM information_schema.columns WHERE table_name = 'tokens' + AND table_schema = current_schema() AND column_name = 'extra'; SELECT count(*) != 0 INTO type_exists FROM information_schema.columns WHERE table_name = 'tokens' + AND table_schema = current_schema() AND column_name = 'extra' AND data_type = 'character varying' AND character_maximum_length = 2048; diff --git a/db/migrations/postgres/000033_create_sidebar_channels.down.sql b/db/migrations/postgres/000033_create_sidebar_channels.down.sql index c48c68451c..7a839aef0f 100644 --- a/db/migrations/postgres/000033_create_sidebar_channels.down.sql +++ b/db/migrations/postgres/000033_create_sidebar_channels.down.sql @@ -6,6 +6,7 @@ BEGIN SELECT count(*) != 0 INTO col_exist_and_type_different FROM information_schema.columns WHERE table_name = 'sidebarchannels' + AND table_schema = current_schema() AND column_name = 'categoryid' AND data_type = 'character varying' AND NOT character_maximum_length = 26; diff --git a/db/migrations/postgres/000033_create_sidebar_channels.up.sql b/db/migrations/postgres/000033_create_sidebar_channels.up.sql index ebdddc1267..ba48ecc617 100644 --- a/db/migrations/postgres/000033_create_sidebar_channels.up.sql +++ b/db/migrations/postgres/000033_create_sidebar_channels.up.sql @@ -14,6 +14,7 @@ BEGIN SELECT count(*) != 0 INTO col_exist_and_type_different FROM information_schema.columns WHERE table_name = 'sidebarchannels' + AND table_schema = current_schema() AND column_name = 'categoryid' AND data_type = 'character varying' AND NOT character_maximum_length = 128; diff --git a/db/migrations/postgres/000034_create_oauthauthdata.up.sql b/db/migrations/postgres/000034_create_oauthauthdata.up.sql index ad36fe9198..b83c1349cf 100644 --- a/db/migrations/postgres/000034_create_oauthauthdata.up.sql +++ b/db/migrations/postgres/000034_create_oauthauthdata.up.sql @@ -19,11 +19,13 @@ BEGIN SELECT count(*) != 0 INTO col_exists FROM information_schema.columns WHERE table_name = 'oauthauthdata' + AND table_schema = current_schema() AND column_name = 'state'; SELECT count(*) != 0 INTO type_exists FROM information_schema.columns WHERE table_name = 'oauthauthdata' + AND table_schema = current_schema() AND column_name = 'state' AND data_type = 'character varying' AND character_maximum_length = 1024; diff --git a/db/migrations/postgres/000040_create_sidebar_categories.down.sql b/db/migrations/postgres/000040_create_sidebar_categories.down.sql index 0e4813b60a..dd026b59b4 100644 --- a/db/migrations/postgres/000040_create_sidebar_categories.down.sql +++ b/db/migrations/postgres/000040_create_sidebar_categories.down.sql @@ -9,6 +9,7 @@ BEGIN SELECT count(*) != 0 INTO col_exist_and_type_different FROM information_schema.columns WHERE table_name = 'sidebarcategories' + AND table_schema = current_schema() AND column_name = 'id' AND data_type = 'character varying' AND NOT character_maximum_length = 26; diff --git a/db/migrations/postgres/000040_create_sidebar_categories.up.sql b/db/migrations/postgres/000040_create_sidebar_categories.up.sql index 29fd9ea657..ad2d71d938 100644 --- a/db/migrations/postgres/000040_create_sidebar_categories.up.sql +++ b/db/migrations/postgres/000040_create_sidebar_categories.up.sql @@ -17,6 +17,7 @@ BEGIN SELECT count(*) != 0 INTO col_exist_and_type_different FROM information_schema.columns WHERE table_name = 'sidebarcategories' + AND table_schema = current_schema() AND column_name = 'id' AND data_type = 'character varying' AND NOT character_maximum_length = 128; diff --git a/db/migrations/postgres/000045_create_plugin_key_value_store.down.sql b/db/migrations/postgres/000045_create_plugin_key_value_store.down.sql index c5ead89d03..dcf3cd8ff9 100644 --- a/db/migrations/postgres/000045_create_plugin_key_value_store.down.sql +++ b/db/migrations/postgres/000045_create_plugin_key_value_store.down.sql @@ -2,7 +2,7 @@ DO $$BEGIN IF ( SELECT column_default::bigint FROM information_schema.columns - WHERE table_schema='public' + WHERE table_schema=current_schema() AND table_name='pluginkeyvaluestore' AND column_name='expireat' ) IS NULL THEN diff --git a/db/migrations/postgres/000045_create_plugin_key_value_store.up.sql b/db/migrations/postgres/000045_create_plugin_key_value_store.up.sql index f7001f2d79..59e8da0690 100644 --- a/db/migrations/postgres/000045_create_plugin_key_value_store.up.sql +++ b/db/migrations/postgres/000045_create_plugin_key_value_store.up.sql @@ -11,7 +11,7 @@ DO $$BEGIN IF ( SELECT column_default::bigint FROM information_schema.columns - WHERE table_schema='public' + WHERE table_schema=current_schema() AND table_name='pluginkeyvaluestore' AND column_name='expireat' ) = 0 THEN diff --git a/db/migrations/postgres/000046_create_users.up.sql b/db/migrations/postgres/000046_create_users.up.sql index 9a0d70d878..ef88ea0581 100644 --- a/db/migrations/postgres/000046_create_users.up.sql +++ b/db/migrations/postgres/000046_create_users.up.sql @@ -54,6 +54,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'users' + AND table_schema = current_schema() AND column_name = 'roles' AND NOT data_type = 'varchar(256)'; IF column_exist THEN diff --git a/db/migrations/postgres/000049_create_channels.down.sql b/db/migrations/postgres/000049_create_channels.down.sql index 59524ef76f..4d14bc8f6a 100644 --- a/db/migrations/postgres/000049_create_channels.down.sql +++ b/db/migrations/postgres/000049_create_channels.down.sql @@ -12,6 +12,7 @@ BEGIN SELECT count(*) != 0 INTO col_exist_and_type_different FROM information_schema.columns WHERE table_name = 'channels' + AND table_schema = current_schema() AND column_name = 'groupconstrained' AND NOT data_type = 'boolean'; @@ -36,6 +37,7 @@ BEGIN SELECT count(*) != 0 INTO col_exist_and_type_different FROM information_schema.columns WHERE table_name = 'channels' + AND table_schema = current_schema() AND column_name = 'purpose' AND data_type = 'character varying' AND NOT character_maximum_length = 64; diff --git a/db/migrations/postgres/000049_create_channels.up.sql b/db/migrations/postgres/000049_create_channels.up.sql index 9fc5e3d3ed..cbd4ea97be 100644 --- a/db/migrations/postgres/000049_create_channels.up.sql +++ b/db/migrations/postgres/000049_create_channels.up.sql @@ -35,6 +35,7 @@ BEGIN SELECT count(*) != 0 INTO col_exist_and_type_different FROM information_schema.columns WHERE table_name = 'channels' + AND table_schema = current_schema() AND column_name = 'purpose' AND data_type = 'character varying' AND NOT character_maximum_length = 250; @@ -60,6 +61,7 @@ BEGIN SELECT count(*) != 0 INTO col_exist_and_type_different FROM information_schema.columns WHERE table_name = 'channels' + AND table_schema = current_schema() AND column_name = 'groupconstrained' AND NOT data_type = 'boolean'; diff --git a/db/migrations/postgres/000051_create_msg_root_count.up.sql b/db/migrations/postgres/000051_create_msg_root_count.up.sql index ee9113d2ca..5acb8466cd 100644 --- a/db/migrations/postgres/000051_create_msg_root_count.up.sql +++ b/db/migrations/postgres/000051_create_msg_root_count.up.sql @@ -10,11 +10,13 @@ BEGIN SELECT count(*) != 0 INTO msg_count_root_exist FROM information_schema.columns WHERE table_name = 'channels' + AND table_schema = current_schema() AND column_name = 'totalmsgcountroot'; SELECT count(*) != 0 INTO mention_count_root_exist FROM information_schema.columns WHERE table_name = 'channelmembers' + AND table_schema = current_schema() AND column_name = 'mentioncountroot'; IF mention_count_root_exist THEN diff --git a/db/migrations/postgres/000057_upgrade_command_webhooks_v6.0.up.sql b/db/migrations/postgres/000057_upgrade_command_webhooks_v6.0.up.sql index fc7b49f213..d85393fd5d 100644 --- a/db/migrations/postgres/000057_upgrade_command_webhooks_v6.0.up.sql +++ b/db/migrations/postgres/000057_upgrade_command_webhooks_v6.0.up.sql @@ -6,6 +6,7 @@ BEGIN SELECT count(*) != 0 INTO parentid_exist FROM information_schema.columns WHERE table_name = 'commandwebhooks' + AND table_schema = current_schema() AND column_name = 'parentid'; IF parentid_exist THEN UPDATE commandwebhooks SET rootid = parentid WHERE rootid = '' AND rootid != parentid; diff --git a/db/migrations/postgres/000066_upgrade_posts_v6.0.up.sql b/db/migrations/postgres/000066_upgrade_posts_v6.0.up.sql index 277aba8ec7..4840163021 100644 --- a/db/migrations/postgres/000066_upgrade_posts_v6.0.up.sql +++ b/db/migrations/postgres/000066_upgrade_posts_v6.0.up.sql @@ -8,16 +8,19 @@ BEGIN SELECT count(*) != 0 INTO parentid_exist FROM information_schema.columns WHERE table_name = 'posts' + AND table_schema = current_schema() AND column_name = 'parentid'; SELECT count(*) != 0 INTO alter_fileids FROM information_schema.columns WHERE table_name = 'posts' + AND table_schema = current_schema() AND column_name = 'fileids' AND data_type = 'character varying' AND character_maximum_length != 300; SELECT count(*) != 0 INTO alter_props FROM information_schema.columns WHERE table_name = 'posts' + AND table_schema = current_schema() AND column_name = 'props' AND data_type != 'jsonb'; IF alter_fileids OR alter_props THEN diff --git a/db/migrations/postgres/000067_upgrade_channelmembers_v6.1.down.sql b/db/migrations/postgres/000067_upgrade_channelmembers_v6.1.down.sql index 2a280730e4..422c9a9ae3 100644 --- a/db/migrations/postgres/000067_upgrade_channelmembers_v6.1.down.sql +++ b/db/migrations/postgres/000067_upgrade_channelmembers_v6.1.down.sql @@ -5,6 +5,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'channelmembers' + AND table_schema = current_schema() AND column_name = 'roles' AND NOT data_type = 'varchar(64)'; IF column_exist THEN diff --git a/db/migrations/postgres/000067_upgrade_channelmembers_v6.1.up.sql b/db/migrations/postgres/000067_upgrade_channelmembers_v6.1.up.sql index 09947201f7..596f352715 100644 --- a/db/migrations/postgres/000067_upgrade_channelmembers_v6.1.up.sql +++ b/db/migrations/postgres/000067_upgrade_channelmembers_v6.1.up.sql @@ -5,6 +5,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'channelmembers' + AND table_schema = current_schema() AND column_name = 'roles' AND NOT data_type = 'varchar(256)'; IF column_exist THEN diff --git a/db/migrations/postgres/000068_upgrade_teammembers_v6.1.down.sql b/db/migrations/postgres/000068_upgrade_teammembers_v6.1.down.sql index 0e86aeac83..ba2ef2efa0 100644 --- a/db/migrations/postgres/000068_upgrade_teammembers_v6.1.down.sql +++ b/db/migrations/postgres/000068_upgrade_teammembers_v6.1.down.sql @@ -5,6 +5,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'teammembers' + AND table_schema = current_schema() AND column_name = 'roles' AND NOT data_type = 'varchar(64)'; IF column_exist THEN diff --git a/db/migrations/postgres/000068_upgrade_teammembers_v6.1.up.sql b/db/migrations/postgres/000068_upgrade_teammembers_v6.1.up.sql index d8992f9063..dd04d44961 100644 --- a/db/migrations/postgres/000068_upgrade_teammembers_v6.1.up.sql +++ b/db/migrations/postgres/000068_upgrade_teammembers_v6.1.up.sql @@ -5,6 +5,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'teammembers' + AND table_schema = current_schema() AND column_name = 'roles' AND NOT data_type = 'varchar(256)'; IF column_exist THEN diff --git a/db/migrations/postgres/000070_upgrade_cte_v6.1.up.sql b/db/migrations/postgres/000070_upgrade_cte_v6.1.up.sql index 25a2275165..8c1b0b4773 100644 --- a/db/migrations/postgres/000070_upgrade_cte_v6.1.up.sql +++ b/db/migrations/postgres/000070_upgrade_cte_v6.1.up.sql @@ -9,6 +9,7 @@ BEGIN information_schema.columns WHERE table_name = 'channels' + AND table_schema = current_schema() AND column_name = 'lastrootpostat'; IF NOT column_exist THEN ALTER TABLE channels ADD COLUMN lastrootpostat bigint DEFAULT '0'::bigint; diff --git a/db/migrations/postgres/000071_upgrade_sessions_v6.1.down.sql b/db/migrations/postgres/000071_upgrade_sessions_v6.1.down.sql index bef3815cc0..7a6e0034e3 100644 --- a/db/migrations/postgres/000071_upgrade_sessions_v6.1.down.sql +++ b/db/migrations/postgres/000071_upgrade_sessions_v6.1.down.sql @@ -5,6 +5,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'sessions' + AND table_schema = current_schema() AND column_name = 'roles' AND NOT data_type = 'varchar(64)'; IF column_exist THEN diff --git a/db/migrations/postgres/000071_upgrade_sessions_v6.1.up.sql b/db/migrations/postgres/000071_upgrade_sessions_v6.1.up.sql index d599c59759..ba995bb6a8 100644 --- a/db/migrations/postgres/000071_upgrade_sessions_v6.1.up.sql +++ b/db/migrations/postgres/000071_upgrade_sessions_v6.1.up.sql @@ -5,6 +5,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'sessions' + AND table_schema = current_schema() AND column_name = 'roles' AND NOT data_type = 'varchar(256)'; IF column_exist THEN diff --git a/db/migrations/postgres/000073_upgrade_plugin_key_value_store_v6.3.down.sql b/db/migrations/postgres/000073_upgrade_plugin_key_value_store_v6.3.down.sql index dbb7c91f0d..f90fb6a7c8 100644 --- a/db/migrations/postgres/000073_upgrade_plugin_key_value_store_v6.3.down.sql +++ b/db/migrations/postgres/000073_upgrade_plugin_key_value_store_v6.3.down.sql @@ -5,6 +5,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'pluginkeyvaluestore' + AND table_schema = current_schema() AND column_name = 'pkey' AND NOT data_type = 'varchar(50)'; IF column_exist THEN diff --git a/db/migrations/postgres/000073_upgrade_plugin_key_value_store_v6.3.up.sql b/db/migrations/postgres/000073_upgrade_plugin_key_value_store_v6.3.up.sql index 9b196d2ce5..950a9e13bb 100644 --- a/db/migrations/postgres/000073_upgrade_plugin_key_value_store_v6.3.up.sql +++ b/db/migrations/postgres/000073_upgrade_plugin_key_value_store_v6.3.up.sql @@ -5,6 +5,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'pluginkeyvaluestore' + AND table_schema = current_schema() AND column_name = 'pkey' AND NOT data_type = 'varchar(150)'; IF column_exist THEN diff --git a/db/migrations/postgres/000076_upgrade_lastrootpostat.up.sql b/db/migrations/postgres/000076_upgrade_lastrootpostat.up.sql index 4d8a542f52..6378a08db3 100644 --- a/db/migrations/postgres/000076_upgrade_lastrootpostat.up.sql +++ b/db/migrations/postgres/000076_upgrade_lastrootpostat.up.sql @@ -3,7 +3,7 @@ BEGIN IF ( SELECT count(*) FROM information_schema.columns - WHERE table_schema='public' + WHERE table_schema=current_schema() AND table_name='channels' AND column_name='lastrootpostat' AND (column_default IS NULL OR column_default != '''0''::bigint') diff --git a/db/migrations/postgres/000082_upgrade_oauth_mattermost_app_id.down.sql b/db/migrations/postgres/000082_upgrade_oauth_mattermost_app_id.down.sql index 163eb60aff..59faa51046 100644 --- a/db/migrations/postgres/000082_upgrade_oauth_mattermost_app_id.down.sql +++ b/db/migrations/postgres/000082_upgrade_oauth_mattermost_app_id.down.sql @@ -5,6 +5,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'oauthapps' + AND table_schema = current_schema() AND column_name = 'mattermostappid'; IF column_exist THEN ALTER TABLE OAuthApps ALTER COLUMN MattermostAppID DROP NOT NULL; diff --git a/db/migrations/postgres/000082_upgrade_oauth_mattermost_app_id.up.sql b/db/migrations/postgres/000082_upgrade_oauth_mattermost_app_id.up.sql index 7192a87385..45837769fa 100644 --- a/db/migrations/postgres/000082_upgrade_oauth_mattermost_app_id.up.sql +++ b/db/migrations/postgres/000082_upgrade_oauth_mattermost_app_id.up.sql @@ -5,6 +5,7 @@ BEGIN SELECT count(*) != 0 INTO column_exist FROM information_schema.columns WHERE table_name = 'oauthapps' + AND table_schema = current_schema() AND column_name = 'mattermostappid'; IF column_exist THEN UPDATE OAuthApps SET MattermostAppID = '' WHERE MattermostAppID IS NULL; diff --git a/db/migrations/postgres/000088_remaining_migrations.up.sql b/db/migrations/postgres/000088_remaining_migrations.up.sql index 9a2e4652bb..246a408920 100644 --- a/db/migrations/postgres/000088_remaining_migrations.up.sql +++ b/db/migrations/postgres/000088_remaining_migrations.up.sql @@ -10,6 +10,7 @@ BEGIN SELECT count(*) != 0 INTO col_exist FROM information_schema.columns WHERE table_name = 'users' + AND table_schema = current_schema() AND column_name = 'themeprops'; IF col_exist THEN