mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
add new key_type table
* single-column static data table that currently contains two types: 'normal' and 'team' * key_type foreign-keyed from api_keys - must be not null - existing rows set to 'normal' * key_type foreign-keyed from notifications - nullable - existing rows set to null * api_key foreign-keyed from notifications - nullable - existing rows set to null
This commit is contained in:
@@ -47,4 +47,4 @@ def downgrade():
|
||||
op.get_bind()
|
||||
op.execute('DROP TYPE notify_status_type')
|
||||
op.alter_column('notifications', 'status', nullable=False)
|
||||
### end Alembic commands ###
|
||||
### end Alembic commands ###
|
||||
|
||||
59
migrations/versions/0033_api_key_type.py
Normal file
59
migrations/versions/0033_api_key_type.py
Normal file
@@ -0,0 +1,59 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0033_api_key_type
|
||||
Revises: 0032_notification_created_status
|
||||
Create Date: 2016-06-24 12:02:10.915817
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0033_api_key_type'
|
||||
down_revision = '0032_notification_created_status'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
def upgrade():
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('key_types',
|
||||
sa.Column('name', sa.String(length=255), nullable=False),
|
||||
sa.PrimaryKeyConstraint('name')
|
||||
)
|
||||
op.add_column('api_keys', sa.Column('key_type', sa.String(length=255), nullable=True))
|
||||
op.add_column('api_keys_history', sa.Column('key_type', sa.String(length=255), nullable=True))
|
||||
op.add_column('notifications', sa.Column('api_key_id', postgresql.UUID(as_uuid=True), nullable=True))
|
||||
op.add_column('notifications', sa.Column('key_type', sa.String(length=255), nullable=True))
|
||||
|
||||
op.create_index(op.f('ix_api_keys_key_type'), 'api_keys', ['key_type'], unique=False)
|
||||
op.create_index(op.f('ix_api_keys_history_key_type'), 'api_keys_history', ['key_type'], unique=False)
|
||||
op.create_index(op.f('ix_notifications_api_key_id'), 'notifications', ['api_key_id'], unique=False)
|
||||
op.create_index(op.f('ix_notifications_key_type'), 'notifications', ['key_type'], unique=False)
|
||||
op.create_foreign_key(None, 'api_keys', 'key_types', ['key_type'], ['name'])
|
||||
op.create_foreign_key(None, 'notifications', 'api_keys', ['api_key_id'], ['id'])
|
||||
op.create_foreign_key(None, 'notifications', 'key_types', ['key_type'], ['name'])
|
||||
|
||||
op.execute("insert into key_types values ('normal'), ('team')")
|
||||
op.execute("update api_keys set key_type = 'normal'")
|
||||
op.execute("update api_keys_history set key_type = 'normal'")
|
||||
|
||||
op.alter_column('api_keys', 'key_type', nullable=False)
|
||||
op.alter_column('api_keys_history', 'key_type', nullable=False)
|
||||
### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint('notifications_key_type_fkey', 'notifications', type_='foreignkey')
|
||||
op.drop_constraint('notifications_api_key_id_fkey', 'notifications', type_='foreignkey')
|
||||
op.drop_index(op.f('ix_notifications_key_type'), table_name='notifications')
|
||||
op.drop_index(op.f('ix_notifications_api_key_id'), table_name='notifications')
|
||||
op.drop_column('notifications', 'key_type')
|
||||
op.drop_column('notifications', 'api_key_id')
|
||||
op.drop_index(op.f('ix_api_keys_history_key_type'), table_name='api_keys_history')
|
||||
op.drop_column('api_keys_history', 'key_type')
|
||||
op.drop_constraint('api_keys_key_type_fkey', 'api_keys', type_='foreignkey')
|
||||
op.drop_index(op.f('ix_api_keys_key_type'), table_name='api_keys')
|
||||
op.drop_column('api_keys', 'key_type')
|
||||
op.drop_table('key_types')
|
||||
### end Alembic commands ###
|
||||
Reference in New Issue
Block a user