2020-07-28 08:30:52 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
Revision ID: 0327_idx_notification_history
|
|
|
|
|
Revises: 0326_broadcast_event
|
|
|
|
|
Create Date: 2020-07-28 08:11:07.666708
|
|
|
|
|
|
|
|
|
|
"""
|
2024-04-01 15:12:33 -07:00
|
|
|
|
2020-07-28 08:30:52 +01:00
|
|
|
import os
|
2023-12-08 21:43:52 -05:00
|
|
|
|
2020-07-28 08:30:52 +01:00
|
|
|
from alembic import op
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
revision = "0327_idx_notification_history"
|
|
|
|
|
down_revision = "0326_broadcast_event"
|
2020-07-28 08:30:52 +01:00
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
environment = os.environ["NOTIFY_ENVIRONMENT"]
|
2020-07-28 08:30:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def upgrade():
|
|
|
|
|
if environment not in ["live", "production"]:
|
2023-08-29 14:54:30 -07:00
|
|
|
op.execute("DROP INDEX IF EXISTS ix_notifications_service_id_created_at")
|
|
|
|
|
op.execute("DROP INDEX IF EXISTS ix_notification_history_created_at")
|
|
|
|
|
op.execute("DROP INDEX IF EXISTS ix_notification_history_service_id_created_at")
|
2020-07-28 08:30:52 +01:00
|
|
|
|
|
|
|
|
index = """
|
2023-11-17 09:47:32 -05:00
|
|
|
CREATE INDEX IF NOT EXISTS ix_notification_history_service_id_composite
|
2020-07-28 08:30:52 +01:00
|
|
|
on notification_history(service_id, key_type, notification_type, created_at)
|
|
|
|
|
"""
|
|
|
|
|
op.execute(index)
|
|
|
|
|
|
|
|
|
|
composite_index = """
|
2023-11-17 09:47:32 -05:00
|
|
|
CREATE INDEX IF NOT EXISTS ix_notifications_notification_type_composite
|
2020-07-28 08:30:52 +01:00
|
|
|
on notifications(notification_type, notification_status, created_at)
|
|
|
|
|
"""
|
|
|
|
|
op.execute(composite_index)
|
|
|
|
|
|
|
|
|
|
# need to run on PROD
|
2023-08-29 14:54:30 -07:00
|
|
|
op.execute("DROP INDEX IF EXISTS ix_notification_history_service_id")
|
|
|
|
|
op.execute("DROP INDEX IF EXISTS ix_notification_history_template_id")
|
|
|
|
|
op.execute("DROP INDEX IF EXISTS ix_notification_history_notification_status")
|
|
|
|
|
op.execute("DROP INDEX IF EXISTS ix_notification_history_notification_type")
|
2020-07-28 08:30:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def downgrade():
|
|
|
|
|
if environment not in ["live", "production"]:
|
2023-08-29 14:54:30 -07:00
|
|
|
op.execute(
|
|
|
|
|
"""
|
2023-11-17 09:47:32 -05:00
|
|
|
CREATE INDEX IF NOT EXISTS ix_notifications_service_id_created_at
|
2020-07-28 08:30:52 +01:00
|
|
|
ON notifications(service_id, date(created_at))
|
2023-08-29 14:54:30 -07:00
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
op.execute(
|
|
|
|
|
"""
|
2023-11-17 09:47:32 -05:00
|
|
|
CREATE INDEX IF NOT EXISTS ix_notification_history_created_at
|
2020-07-28 08:30:52 +01:00
|
|
|
on notification_history(created_at)
|
2023-08-29 14:54:30 -07:00
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
op.execute(
|
|
|
|
|
"""
|
2023-11-17 09:47:32 -05:00
|
|
|
CREATE INDEX IF NOT EXISTS ix_notification_history_service_id_created_at
|
2020-07-28 08:30:52 +01:00
|
|
|
on notification_history(created_at)
|
2023-08-29 14:54:30 -07:00
|
|
|
"""
|
|
|
|
|
)
|
2020-07-28 08:30:52 +01:00
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
op.execute("DROP INDEX IF EXISTS ix_notification_history_service_id_composite")
|
2020-07-28 08:30:52 +01:00
|
|
|
|
|
|
|
|
# need to run on PROD
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
op.execute("DROP INDEX IF EXISTS ix_notifications_notification_type_composite")
|
|
|
|
|
op.execute(
|
|
|
|
|
"CREATE INDEX IF NOT EXISTS ix_notification_history_service_id on notification_history (service_id)"
|
|
|
|
|
)
|
|
|
|
|
op.execute(
|
|
|
|
|
"""
|
2020-07-28 08:30:52 +01:00
|
|
|
CREATE INDEX IF NOT EXISTS ix_notification_history_template_id on notification_history (template_id)
|
2023-08-29 14:54:30 -07:00
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
op.execute(
|
|
|
|
|
"""
|
2023-11-17 09:47:32 -05:00
|
|
|
CREATE INDEX IF NOT EXISTS ix_notification_history_notification_status
|
2020-07-28 08:30:52 +01:00
|
|
|
on notification_history (notification_status)
|
2023-08-29 14:54:30 -07:00
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
op.execute(
|
|
|
|
|
"""
|
2023-11-17 09:47:32 -05:00
|
|
|
CREATE INDEX IF NOT EXISTS ix_notification_history_notification_type
|
2020-07-28 08:30:52 +01:00
|
|
|
on notification_history (notification_type)
|
2023-08-29 14:54:30 -07:00
|
|
|
"""
|
|
|
|
|
)
|