mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
add version to provider_details and _history
set all existing rows to have a version of 1 (also copy across values to populate the new provider_details_history table in the upgrade script) in dao_update_provider_details bump the provider_details.version by 1 and then duplicate into the history table as a new row (done manually as opposed to the decorator used in template_history since this is only edited in this one place and the decorator is icky)
This commit is contained in:
@@ -16,9 +16,13 @@ from sqlalchemy.dialects import postgresql
|
||||
|
||||
def upgrade():
|
||||
op.get_bind()
|
||||
op.execute('UPDATE provider_details SET active = false WHERE active is null')
|
||||
|
||||
op.alter_column('provider_details', 'active', existing_type=sa.BOOLEAN(), nullable=False)
|
||||
op.execute('UPDATE provider_details SET active = false WHERE active is null')
|
||||
op.alter_column('provider_details', 'active', nullable=False)
|
||||
|
||||
op.add_column('provider_details', sa.Column('version', sa.Integer()))
|
||||
op.execute('UPDATE provider_details SET version = 1')
|
||||
op.alter_column('provider_details', 'version', nullable=False)
|
||||
|
||||
op.create_table('provider_details_history',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
@@ -27,12 +31,18 @@ def upgrade():
|
||||
sa.Column('priority', sa.Integer(), nullable=False),
|
||||
sa.Column('notification_type', postgresql.ENUM('email', 'sms', 'letter', name='notification_type', create_type=False), nullable=False),
|
||||
sa.Column('active', sa.Boolean(), nullable=False),
|
||||
sa.Column('version', sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.execute(
|
||||
'INSERT INTO provider_details_history' +
|
||||
' (id, display_name, identifier, priority, notification_type, active, version)' +
|
||||
' SELECT id, display_name, identifier, priority, notification_type, active, version FROM provider_details'
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('provider_details_history')
|
||||
|
||||
op.alter_column('provider_details_history', 'active', existing_type=sa.BOOLEAN(), nullable=True)
|
||||
op.alter_column('provider_details', 'active', existing_type=sa.BOOLEAN(), nullable=True)
|
||||
op.drop_column('provider_details', 'version')
|
||||
|
||||
Reference in New Issue
Block a user