mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 14:08:47 -04:00
populate notification_status_types table, and add foreign keys
This commit is contained in:
@@ -15,19 +15,49 @@ import sqlalchemy as sa
|
|||||||
|
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
op.create_table('notification_status',
|
status_table = op.create_table('notification_status_types',
|
||||||
sa.Column('name', sa.String(), nullable=False),
|
sa.Column('name', sa.String(), nullable=False),
|
||||||
sa.PrimaryKeyConstraint('name')
|
sa.PrimaryKeyConstraint('name')
|
||||||
)
|
)
|
||||||
|
op.bulk_insert(status_table,
|
||||||
|
[
|
||||||
|
{'name': x} for x in {
|
||||||
|
'created',
|
||||||
|
'sending',
|
||||||
|
'delivered',
|
||||||
|
'pending',
|
||||||
|
'failed',
|
||||||
|
'technical-failure',
|
||||||
|
'temporary-failure',
|
||||||
|
'permanent-failure',
|
||||||
|
'sent',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
op.execute('ALTER TABLE notifications ADD COLUMN notification_status text')
|
op.execute('ALTER TABLE notifications ADD COLUMN notification_status text')
|
||||||
op.execute('ALTER TABLE notification_history ADD COLUMN notification_status text')
|
op.execute('ALTER TABLE notification_history ADD COLUMN notification_status text')
|
||||||
|
|
||||||
op.create_index(op.f('ix_notifications_notification_status'), 'notifications', ['notification_status'])
|
op.create_index(op.f('ix_notifications_notification_status'), 'notifications', ['notification_status'])
|
||||||
op.create_index(op.f('ix_notification_history_notification_status'), 'notification_history', ['notification_status'])
|
op.create_index(op.f('ix_notification_history_notification_status'), 'notification_history', ['notification_status'])
|
||||||
|
op.create_foreign_key(
|
||||||
|
'fk_notifications_notification_status',
|
||||||
|
'notifications',
|
||||||
|
'notification_status_types',
|
||||||
|
['notification_status'],
|
||||||
|
['name'],
|
||||||
|
)
|
||||||
|
op.create_foreign_key(
|
||||||
|
'fk_notification_history_notification_status',
|
||||||
|
'notification_history',
|
||||||
|
'notification_status_types',
|
||||||
|
['notification_status'],
|
||||||
|
['name'],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
op.execute('ALTER TABLE notifications DROP COLUMN notification_status')
|
op.execute('ALTER TABLE notifications DROP COLUMN notification_status')
|
||||||
op.execute('ALTER TABLE notification_history DROP COLUMN notification_status')
|
op.execute('ALTER TABLE notification_history DROP COLUMN notification_status')
|
||||||
op.execute('DROP TABLE notification_status')
|
op.execute('DROP TABLE notification_status_types')
|
||||||
|
|||||||
Reference in New Issue
Block a user