From c5f4882f0a268843e893be6e60635b2dafce27ed Mon Sep 17 00:00:00 2001 From: Ibrahim Serdar Acikgoz Date: Tue, 25 Oct 2022 16:32:34 +0300 Subject: [PATCH] db/migrations: ensure to drop parentid from posts table (#21493) --- db/migrations/migrations.list | 4 ++++ .../mysql/000095_remove_posts_parentid.down.sql | 1 + .../mysql/000095_remove_posts_parentid.up.sql | 17 +++++++++++++++++ .../000095_remove_posts_parentid.down.sql | 1 + .../000095_remove_posts_parentid.up.sql | 4 ++++ 5 files changed, 27 insertions(+) create mode 100644 db/migrations/mysql/000095_remove_posts_parentid.down.sql create mode 100644 db/migrations/mysql/000095_remove_posts_parentid.up.sql create mode 100644 db/migrations/postgres/000095_remove_posts_parentid.down.sql create mode 100644 db/migrations/postgres/000095_remove_posts_parentid.up.sql diff --git a/db/migrations/migrations.list b/db/migrations/migrations.list index 1576dca650..1bab52d768 100644 --- a/db/migrations/migrations.list +++ b/db/migrations/migrations.list @@ -188,6 +188,8 @@ db/migrations/mysql/000093_notify_admin.down.sql db/migrations/mysql/000093_notify_admin.up.sql db/migrations/mysql/000094_threads_teamid.down.sql db/migrations/mysql/000094_threads_teamid.up.sql +db/migrations/mysql/000095_remove_posts_parentid.down.sql +db/migrations/mysql/000095_remove_posts_parentid.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 @@ -376,3 +378,5 @@ db/migrations/postgres/000093_notify_admin.down.sql db/migrations/postgres/000093_notify_admin.up.sql db/migrations/postgres/000094_threads_teamid.down.sql db/migrations/postgres/000094_threads_teamid.up.sql +db/migrations/postgres/000095_remove_posts_parentid.down.sql +db/migrations/postgres/000095_remove_posts_parentid.up.sql diff --git a/db/migrations/mysql/000095_remove_posts_parentid.down.sql b/db/migrations/mysql/000095_remove_posts_parentid.down.sql new file mode 100644 index 0000000000..abdf428361 --- /dev/null +++ b/db/migrations/mysql/000095_remove_posts_parentid.down.sql @@ -0,0 +1 @@ +-- Intentionally left blank as forward migration is not reversible. diff --git a/db/migrations/mysql/000095_remove_posts_parentid.up.sql b/db/migrations/mysql/000095_remove_posts_parentid.up.sql new file mode 100644 index 0000000000..269febfac0 --- /dev/null +++ b/db/migrations/mysql/000095_remove_posts_parentid.up.sql @@ -0,0 +1,17 @@ +-- While upgrading from 5.x to 6.x with manual queries, there is a chance that this +-- migration is skipped. In that case, we need to make sure that the column is dropped. + +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'Posts' + AND table_schema = DATABASE() + AND column_name = 'ParentId' + ) > 0, + 'ALTER TABLE Posts DROP COLUMN ParentId;', + 'SELECT 1' +)); + +PREPARE alterIfExists FROM @preparedStatement; +EXECUTE alterIfExists; +DEALLOCATE PREPARE alterIfExists; diff --git a/db/migrations/postgres/000095_remove_posts_parentid.down.sql b/db/migrations/postgres/000095_remove_posts_parentid.down.sql new file mode 100644 index 0000000000..abdf428361 --- /dev/null +++ b/db/migrations/postgres/000095_remove_posts_parentid.down.sql @@ -0,0 +1 @@ +-- Intentionally left blank as forward migration is not reversible. diff --git a/db/migrations/postgres/000095_remove_posts_parentid.up.sql b/db/migrations/postgres/000095_remove_posts_parentid.up.sql new file mode 100644 index 0000000000..173d58abef --- /dev/null +++ b/db/migrations/postgres/000095_remove_posts_parentid.up.sql @@ -0,0 +1,4 @@ +-- While upgrading from 5.x to 6.x with manual queries, there is a chance that this +-- migration is skipped. In that case, we need to make sure that the column is dropped. + +ALTER TABLE posts DROP COLUMN IF EXISTS parentid;