diff --git a/db/migrations/migrations.list b/db/migrations/migrations.list index b5b1349f2f..6f8dd5ac80 100644 --- a/db/migrations/migrations.list +++ b/db/migrations/migrations.list @@ -178,6 +178,8 @@ db/migrations/mysql/000088_remaining_migrations.down.sql db/migrations/mysql/000088_remaining_migrations.up.sql db/migrations/mysql/000089_add-channelid-to-reaction.down.sql db/migrations/mysql/000089_add-channelid-to-reaction.up.sql +db/migrations/mysql/000090_create_enums.down.sql +db/migrations/mysql/000090_create_enums.up.sql db/migrations/postgres/000001_create_teams.down.sql db/migrations/postgres/000001_create_teams.up.sql db/migrations/postgres/000002_create_team_members.down.sql @@ -356,3 +358,5 @@ db/migrations/postgres/000088_remaining_migrations.down.sql db/migrations/postgres/000088_remaining_migrations.up.sql db/migrations/postgres/000089_add-channelid-to-reaction.down.sql db/migrations/postgres/000089_add-channelid-to-reaction.up.sql +db/migrations/postgres/000090_create_enums.down.sql +db/migrations/postgres/000090_create_enums.up.sql diff --git a/db/migrations/mysql/000090_create_enums.down.sql b/db/migrations/mysql/000090_create_enums.down.sql new file mode 100644 index 0000000000..2fa58b3e6e --- /dev/null +++ b/db/migrations/mysql/000090_create_enums.down.sql @@ -0,0 +1,47 @@ +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'Channels' + AND table_schema = DATABASE() + AND column_name = 'Type' + AND column_type != 'varchar(1)' + ) > 0, + 'ALTER TABLE Channels MODIFY COLUMN Type varchar(1);', + 'SELECT 1' +)); + +PREPARE alterIfExists FROM @preparedStatement; +EXECUTE alterIfExists; +DEALLOCATE PREPARE alterIfExists; + +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'Teams' + AND table_schema = DATABASE() + AND column_name = 'Type' + AND column_type != 'varchar(255)' + ) > 0, + 'ALTER TABLE Teams MODIFY COLUMN Type varchar(255);', + 'SELECT 1' +)); + +PREPARE alterIfExists FROM @preparedStatement; +EXECUTE alterIfExists; +DEALLOCATE PREPARE alterIfExists; + +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'UploadSessions' + AND table_schema = DATABASE() + AND column_name = 'Type' + AND column_type != 'varchar(32)' + ) > 0, + 'ALTER TABLE UploadSessions MODIFY COLUMN Type varchar(32);', + 'SELECT 1' +)); + +PREPARE alterIfExists FROM @preparedStatement; +EXECUTE alterIfExists; +DEALLOCATE PREPARE alterIfExists; \ No newline at end of file diff --git a/db/migrations/mysql/000090_create_enums.up.sql b/db/migrations/mysql/000090_create_enums.up.sql new file mode 100644 index 0000000000..3181aa953c --- /dev/null +++ b/db/migrations/mysql/000090_create_enums.up.sql @@ -0,0 +1,47 @@ +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'Channels' + AND table_schema = DATABASE() + AND column_name = 'Type' + AND column_type != 'ENUM("D", "O", "G", "P")' + ) > 0, + 'ALTER TABLE Channels MODIFY COLUMN Type ENUM("D", "O", "G", "P");', + 'SELECT 1' +)); + +PREPARE alterIfExists FROM @preparedStatement; +EXECUTE alterIfExists; +DEALLOCATE PREPARE alterIfExists; + +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'Teams' + AND table_schema = DATABASE() + AND column_name = 'Type' + AND column_type != 'ENUM("I", "O")' + ) > 0, + 'ALTER TABLE Teams MODIFY COLUMN Type ENUM("I", "O");', + 'SELECT 1' +)); + +PREPARE alterIfExists FROM @preparedStatement; +EXECUTE alterIfExists; +DEALLOCATE PREPARE alterIfExists; + +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'UploadSessions' + AND table_schema = DATABASE() + AND column_name = 'Type' + AND column_type != 'ENUM("attachment", "import")' + ) > 0, + 'ALTER TABLE UploadSessions MODIFY COLUMN Type ENUM("attachment", "import");', + 'SELECT 1' +)); + +PREPARE alterIfExists FROM @preparedStatement; +EXECUTE alterIfExists; +DEALLOCATE PREPARE alterIfExists; \ No newline at end of file diff --git a/db/migrations/postgres/000090_create_enums.down.sql b/db/migrations/postgres/000090_create_enums.down.sql new file mode 100644 index 0000000000..d36e9bc359 --- /dev/null +++ b/db/migrations/postgres/000090_create_enums.down.sql @@ -0,0 +1,44 @@ +ALTER TABLE channels alter column type type varchar(1); + +DO +$$ +BEGIN + IF EXISTS (SELECT * FROM pg_type typ + INNER JOIN pg_namespace nsp ON nsp.oid = typ.typnamespace + WHERE nsp.nspname = current_schema() + AND typ.typname = 'channel_type') THEN + DROP TYPE channel_type; + END IF; +END; +$$ +LANGUAGE plpgsql; + +ALTER TABLE teams alter column type type varchar(255); + +DO +$$ +BEGIN + IF EXISTS (SELECT * FROM pg_type typ + INNER JOIN pg_namespace nsp ON nsp.oid = typ.typnamespace + WHERE nsp.nspname = current_schema() + AND typ.typname = 'team_type') THEN + DROP TYPE team_type; + END IF; +END; +$$ +LANGUAGE plpgsql; + +ALTER TABLE uploadsessions alter column type type varchar(32); + +DO +$$ +BEGIN + IF EXISTS (SELECT * FROM pg_type typ + INNER JOIN pg_namespace nsp ON nsp.oid = typ.typnamespace + WHERE nsp.nspname = current_schema() + AND typ.typname = 'upload_session_type') THEN + DROP TYPE upload_session_type; + END IF; +END; +$$ +LANGUAGE plpgsql; diff --git a/db/migrations/postgres/000090_create_enums.up.sql b/db/migrations/postgres/000090_create_enums.up.sql new file mode 100644 index 0000000000..4c5af5ebfc --- /dev/null +++ b/db/migrations/postgres/000090_create_enums.up.sql @@ -0,0 +1,44 @@ +DO +$$ +BEGIN + IF NOT EXISTS (SELECT * FROM pg_type typ + INNER JOIN pg_namespace nsp ON nsp.oid = typ.typnamespace + WHERE nsp.nspname = current_schema() + AND typ.typname = 'channel_type') THEN + CREATE TYPE channel_type AS ENUM ('P', 'G', 'O', 'D'); + END IF; +END; +$$ +LANGUAGE plpgsql; + +ALTER TABLE channels alter column type type channel_type using type::channel_type; + +DO +$$ +BEGIN + IF NOT EXISTS (SELECT * FROM pg_type typ + INNER JOIN pg_namespace nsp ON nsp.oid = typ.typnamespace + WHERE nsp.nspname = current_schema() + AND typ.typname = 'team_type') THEN + CREATE TYPE team_type AS ENUM ('I', 'O'); + END IF; +END; +$$ +LANGUAGE plpgsql; + +ALTER TABLE teams alter column type type team_type using type::team_type; + +DO +$$ +BEGIN + IF NOT EXISTS (SELECT * FROM pg_type typ + INNER JOIN pg_namespace nsp ON nsp.oid = typ.typnamespace + WHERE nsp.nspname = current_schema() + AND typ.typname = 'upload_session_type') THEN + CREATE TYPE upload_session_type AS ENUM ('attachment', 'import'); + END IF; +END; +$$ +LANGUAGE plpgsql; + +ALTER TABLE uploadsessions alter column type type upload_session_type using type::upload_session_type;