From 94c4a8f2381c161d37dcd9d18b9feeae92aba309 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 7 Jun 2021 09:36:41 +0100 Subject: [PATCH 1/4] Remove scheduled_notifications All code has been removed for ScheduledNotifications. This PR just removes the table, it has never been used. --- app/models.py | 10 ------ .../0358_remove_sched_notifications_.py | 32 +++++++++++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 migrations/versions/0358_remove_sched_notifications_.py diff --git a/app/models.py b/app/models.py index 913c42e85..cda2b3509 100644 --- a/app/models.py +++ b/app/models.py @@ -1776,16 +1776,6 @@ class NotificationHistory(db.Model, HistoryModel): self.status = original.status -class ScheduledNotification(db.Model): - __tablename__ = 'scheduled_notifications' - - id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) - notification_id = db.Column(UUID(as_uuid=True), db.ForeignKey('notifications.id'), index=True, nullable=False) - notification = db.relationship('Notification', uselist=False) - scheduled_for = db.Column(db.DateTime, index=False, nullable=False) - pending = db.Column(db.Boolean, nullable=False, default=True) - - INVITE_PENDING = 'pending' INVITE_ACCEPTED = 'accepted' INVITE_CANCELLED = 'cancelled' diff --git a/migrations/versions/0358_remove_sched_notifications_.py b/migrations/versions/0358_remove_sched_notifications_.py new file mode 100644 index 000000000..2a0ada696 --- /dev/null +++ b/migrations/versions/0358_remove_sched_notifications_.py @@ -0,0 +1,32 @@ +""" + +Revision ID: 0358_remove_sched_notifications +Revises: 0357_validate_constraint +Create Date: 2021-06-07 09:09:06.376862 + +""" +import sqlalchemy as sa +from alembic import op +from sqlalchemy.dialects import postgresql + +revision = '0358_remove_sched_notifications' +down_revision = '0357_validate_constraint' + + +def upgrade(): + op.drop_index('ix_scheduled_notifications_notification_id', table_name='scheduled_notifications') + op.drop_table('scheduled_notifications') + + +def downgrade(): + op.create_table('scheduled_notifications', + sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False), + sa.Column('notification_id', postgresql.UUID(), autoincrement=False, nullable=False), + sa.Column('scheduled_for', postgresql.TIMESTAMP(), autoincrement=False, nullable=False), + sa.Column('pending', sa.BOOLEAN(), autoincrement=False, nullable=False), + sa.ForeignKeyConstraint(['notification_id'], ['notifications.id'], + name='scheduled_notifications_notification_id_fkey'), + sa.PrimaryKeyConstraint('id', name='scheduled_notifications_pkey') + ) + op.create_index('ix_scheduled_notifications_notification_id', 'scheduled_notifications', ['notification_id'], + unique=False) From ae29ae28e5bdcd2440830b3791f0a8e1c36dfe7d Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Thu, 10 Jun 2021 09:05:16 +0100 Subject: [PATCH 2/4] Adding CONCURRENTLY to the drop index statement. Drop index concurrently will drop the index without locking out concurrent selects, inserts, updates, and deletes on the index's table namely on notifications. --- migrations/versions/0358_remove_sched_notifications_.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/migrations/versions/0358_remove_sched_notifications_.py b/migrations/versions/0358_remove_sched_notifications_.py index 2a0ada696..6e629db21 100644 --- a/migrations/versions/0358_remove_sched_notifications_.py +++ b/migrations/versions/0358_remove_sched_notifications_.py @@ -14,11 +14,16 @@ down_revision = '0357_validate_constraint' def upgrade(): - op.drop_index('ix_scheduled_notifications_notification_id', table_name='scheduled_notifications') + # drop index concurrently will drop the index without locking out concurrent + # selects, inserts, updates, and deletes on the index's table namely on notifications + # First we need to issue a commit to clear the transaction block. + op.execute('COMMIT') + op.execute('DROP INDEX CONCURRENTLY ix_scheduled_notifications_notification_id') op.drop_table('scheduled_notifications') def downgrade(): + # I've intentionally removed adding the index back from the downgrade method op.create_table('scheduled_notifications', sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False), sa.Column('notification_id', postgresql.UUID(), autoincrement=False, nullable=False), @@ -28,5 +33,3 @@ def downgrade(): name='scheduled_notifications_notification_id_fkey'), sa.PrimaryKeyConstraint('id', name='scheduled_notifications_pkey') ) - op.create_index('ix_scheduled_notifications_notification_id', 'scheduled_notifications', ['notification_id'], - unique=False) From bcd8d8556943b5ea9dbb72a11033ffae44c6e234 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 21 Jun 2021 13:34:06 +0100 Subject: [PATCH 3/4] Fix merge conflicts --- ...ifications_.py => 0359_remove_sched_notifications_.py} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename migrations/versions/{0358_remove_sched_notifications_.py => 0359_remove_sched_notifications_.py} (89%) diff --git a/migrations/versions/0358_remove_sched_notifications_.py b/migrations/versions/0359_remove_sched_notifications_.py similarity index 89% rename from migrations/versions/0358_remove_sched_notifications_.py rename to migrations/versions/0359_remove_sched_notifications_.py index 6e629db21..3046d3dfb 100644 --- a/migrations/versions/0358_remove_sched_notifications_.py +++ b/migrations/versions/0359_remove_sched_notifications_.py @@ -1,7 +1,7 @@ """ -Revision ID: 0358_remove_sched_notifications -Revises: 0357_validate_constraint +Revision ID: 0359_remove_sched_notifications +Revises: 0358_operator_channel Create Date: 2021-06-07 09:09:06.376862 """ @@ -9,8 +9,8 @@ import sqlalchemy as sa from alembic import op from sqlalchemy.dialects import postgresql -revision = '0358_remove_sched_notifications' -down_revision = '0357_validate_constraint' +revision = '0359_remove_sched_notifications' +down_revision = '0358_operator_channel' def upgrade(): From 5fcf65422c892d27f5aed78cf94839fc257b585a Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Thu, 8 Jul 2021 08:14:03 +0100 Subject: [PATCH 4/4] Fix version conflicts. --- ...ifications_.py => 0360_remove_sched_notifications_.py} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename migrations/versions/{0359_remove_sched_notifications_.py => 0360_remove_sched_notifications_.py} (89%) diff --git a/migrations/versions/0359_remove_sched_notifications_.py b/migrations/versions/0360_remove_sched_notifications_.py similarity index 89% rename from migrations/versions/0359_remove_sched_notifications_.py rename to migrations/versions/0360_remove_sched_notifications_.py index 3046d3dfb..d6bb17fb5 100644 --- a/migrations/versions/0359_remove_sched_notifications_.py +++ b/migrations/versions/0360_remove_sched_notifications_.py @@ -1,7 +1,7 @@ """ -Revision ID: 0359_remove_sched_notifications -Revises: 0358_operator_channel +Revision ID: 0360_remove_sched_notifications +Revises: 0359_more_permissions Create Date: 2021-06-07 09:09:06.376862 """ @@ -9,8 +9,8 @@ import sqlalchemy as sa from alembic import op from sqlalchemy.dialects import postgresql -revision = '0359_remove_sched_notifications' -down_revision = '0358_operator_channel' +revision = '0360_remove_sched_notifications' +down_revision = '0359_more_permissions' def upgrade():