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/0360_remove_sched_notifications_.py b/migrations/versions/0360_remove_sched_notifications_.py new file mode 100644 index 000000000..d6bb17fb5 --- /dev/null +++ b/migrations/versions/0360_remove_sched_notifications_.py @@ -0,0 +1,35 @@ +""" + +Revision ID: 0360_remove_sched_notifications +Revises: 0359_more_permissions +Create Date: 2021-06-07 09:09:06.376862 + +""" +import sqlalchemy as sa +from alembic import op +from sqlalchemy.dialects import postgresql + +revision = '0360_remove_sched_notifications' +down_revision = '0359_more_permissions' + + +def upgrade(): + # 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), + 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') + )