migrations/versions/d0dd70559107_attribute_limits.py
"""refactor allowed_attributes to attribute_limits
Revision ID: d0dd70559107
Revises: d6163d3432c1
Create Date: 2022-08-12 11:21:45.698624
"""
# revision identifiers, used by Alembic.
revision = 'd0dd70559107'
down_revision = 'd6163d3432c1'
from alembic import op
import sqlalchemy as sa
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('application_templates', sa.Column('attribute_limits', sa.Text(), nullable=True))
op.drop_column('application_templates', 'allowed_attrs')
op.add_column('applications', sa.Column('attribute_limits', sa.Text(), nullable=True))
op.drop_column('applications', 'allowed_attrs')
# add default limits for templates and applications that already exist in the database
attr_limits = '[{"name": "maximum_lifetime", "min": 0, "max": 43200}, {"name": "memory_gib", "min": 0, "max": 8}]'
op.execute('''
UPDATE applications a
SET attribute_limits='%s'
WHERE a.attribute_limits is NULL
''' % attr_limits)
op.execute('''
UPDATE application_templates t
SET attribute_limits='%s'
WHERE t.attribute_limits is NULL
''' % attr_limits)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('applications', sa.Column('allowed_attrs', sa.TEXT(), autoincrement=False, nullable=True))
op.drop_column('applications', 'attribute_limits')
op.add_column('application_templates', sa.Column('allowed_attrs', sa.TEXT(), autoincrement=False, nullable=True))
op.drop_column('application_templates', 'attribute_limits')
# ### end Alembic commands ###