fix check_constraint in database

This commit is contained in:
Cayo Puigdefabregas 2023-08-02 17:16:55 +02:00
parent e2c04e3e48
commit fa55ac017d
2 changed files with 66 additions and 1 deletions

View File

@ -5,7 +5,7 @@ Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from alembic import op
from alembic import op, context
import sqlalchemy as sa
import sqlalchemy_utils
import citext

View File

@ -0,0 +1,65 @@
"""reset check_constraint of placeholders
Revision ID: 57e6201f280c
Revises: 8ccba3cb37c2
Create Date: 2023-08-02 15:56:12.484340
"""
import sqlalchemy as sa
from alembic import context, op
# revision identifiers, used by Alembic.
revision = '57e6201f280c'
down_revision = '8ccba3cb37c2'
branch_labels = None
depends_on = None
def get_inv():
INV = context.get_x_argument(as_dictionary=True).get('inventory')
if not INV:
raise ValueError("Inventory value is not specified")
return INV
def upgrade():
op.drop_constraint(
'device_depth_check', "device", type_="check", schema=f'{get_inv()}'
)
op.drop_constraint(
'device_height_check', "device", type_="check", schema=f'{get_inv()}'
)
op.drop_constraint(
'device_width_check', "device", type_="check", schema=f'{get_inv()}'
)
op.drop_constraint(
'device_weight_check', "device", type_="check", schema=f'{get_inv()}'
)
op.create_check_constraint(
"device_depth_check",
"device",
sa.Column("depth") >= (0.1),
schema=f'{get_inv()}',
)
op.create_check_constraint(
"device_height_check",
"device",
sa.Column("depth") >= (0.1),
schema=f'{get_inv()}',
)
op.create_check_constraint(
"device_width_check",
"device",
sa.Column("depth") >= (0.1),
schema=f'{get_inv()}',
)
op.create_check_constraint(
"device_weight_check",
"device",
sa.Column("depth") >= (0.1),
schema=f'{get_inv()}',
)
def downgrade():
pass