diff --git a/db/migrations/mysql/000082_upgrade_oauth_mattermost_app_id.down.sql b/db/migrations/mysql/000082_upgrade_oauth_mattermost_app_id.down.sql new file mode 100644 index 0000000000..981177557c --- /dev/null +++ b/db/migrations/mysql/000082_upgrade_oauth_mattermost_app_id.down.sql @@ -0,0 +1,14 @@ +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'OAuthApps' + AND table_schema = DATABASE() + AND column_name = 'MattermostAppID' + ) > 0, + 'ALTER TABLE OAuthApps MODIFY MattermostAppID varchar(32);', + 'SELECT 1' +)); + +PREPARE alterIfExists FROM @preparedStatement; +EXECUTE alterIfExists; +DEALLOCATE PREPARE alterIfExists; diff --git a/db/migrations/mysql/000082_upgrade_oauth_mattermost_app_id.up.sql b/db/migrations/mysql/000082_upgrade_oauth_mattermost_app_id.up.sql new file mode 100644 index 0000000000..aa65f0de26 --- /dev/null +++ b/db/migrations/mysql/000082_upgrade_oauth_mattermost_app_id.up.sql @@ -0,0 +1,29 @@ +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'OAuthApps' + AND table_schema = DATABASE() + AND column_name = 'MattermostAppID' + ) > 0, + 'UPDATE OAuthApps SET MattermostAppID = "" WHERE MattermostAppID IS NULL;', + 'SELECT 1' +)); + +PREPARE alterIfExists FROM @preparedStatement; +EXECUTE alterIfExists; +DEALLOCATE PREPARE alterIfExists; + +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'OAuthApps' + AND table_schema = DATABASE() + AND column_name = 'MattermostAppID' + ) > 0, + 'ALTER TABLE OAuthApps MODIFY MattermostAppID varchar(32) NOT NULL DEFAULT "";', + 'SELECT 1' +)); + +PREPARE alterIfExists FROM @preparedStatement; +EXECUTE alterIfExists; +DEALLOCATE PREPARE alterIfExists; 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 new file mode 100644 index 0000000000..163eb60aff --- /dev/null +++ b/db/migrations/postgres/000082_upgrade_oauth_mattermost_app_id.down.sql @@ -0,0 +1,13 @@ +DO $$ +DECLARE + column_exist boolean := false; +BEGIN +SELECT count(*) != 0 INTO column_exist + FROM information_schema.columns + WHERE table_name = 'oauthapps' + AND column_name = 'mattermostappid'; +IF column_exist THEN + ALTER TABLE OAuthApps ALTER COLUMN MattermostAppID DROP NOT NULL; + ALTER TABLE OAuthApps ALTER COLUMN MattermostAppID DROP DEFAULT; +END IF; +END $$; 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 new file mode 100644 index 0000000000..7192a87385 --- /dev/null +++ b/db/migrations/postgres/000082_upgrade_oauth_mattermost_app_id.up.sql @@ -0,0 +1,14 @@ +DO $$ +DECLARE + column_exist boolean := false; +BEGIN +SELECT count(*) != 0 INTO column_exist + FROM information_schema.columns + WHERE table_name = 'oauthapps' + AND column_name = 'mattermostappid'; +IF column_exist THEN + UPDATE OAuthApps SET MattermostAppID = '' WHERE MattermostAppID IS NULL; + ALTER TABLE OAuthApps ALTER COLUMN MattermostAppID SET DEFAULT ''; + ALTER TABLE OAuthApps ALTER COLUMN MattermostAppID SET NOT NULL; +END IF; +END $$;