This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/ereuse_devicehub/migrations/versions/aeca9fb50cc6_add_placeholde...

61 lines
1.8 KiB
Python
Raw Normal View History

2022-06-28 15:38:05 +00:00
"""add placeholder
Revision ID: aeca9fb50cc6
Revises: 8d4fe4b497b3
Create Date: 2022-06-27 13:09:30.497678
"""
import citext
import sqlalchemy as sa
from alembic import context, op
# revision identifiers, used by Alembic.
revision = 'aeca9fb50cc6'
down_revision = '8d4fe4b497b3'
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():
# creating placeholder table
op.create_table(
'placeholder',
sa.Column(
'updated',
sa.TIMESTAMP(timezone=True),
server_default=sa.text('CURRENT_TIMESTAMP'),
nullable=False,
),
sa.Column(
'created',
sa.TIMESTAMP(timezone=True),
server_default=sa.text('CURRENT_TIMESTAMP'),
nullable=False,
),
sa.Column('id', sa.BigInteger(), nullable=False),
2022-07-04 09:26:24 +00:00
sa.Column('phid', sa.Unicode(), nullable=False),
2022-06-28 15:38:05 +00:00
sa.Column('id_device_supplier', sa.Unicode(), nullable=True),
sa.Column('pallet', sa.Unicode(), nullable=True),
sa.Column('info', citext.CIText(), nullable=True),
sa.Column('device_id', sa.BigInteger(), nullable=False),
2022-07-12 11:23:24 +00:00
sa.Column('binding_id', sa.BigInteger(), nullable=True),
2022-06-28 15:38:05 +00:00
sa.ForeignKeyConstraint(['device_id'], [f'{get_inv()}.device.id']),
2022-07-12 11:23:24 +00:00
sa.ForeignKeyConstraint(['binding_id'], [f'{get_inv()}.device.id']),
2022-06-28 15:38:05 +00:00
sa.PrimaryKeyConstraint('id'),
2022-07-12 11:23:24 +00:00
schema=f'{get_inv()}',
2022-06-28 15:38:05 +00:00
)
2022-07-07 14:32:00 +00:00
op.execute("CREATE SEQUENCE placeholder_seq START 1;")
2022-06-28 15:38:05 +00:00
def downgrade():
2022-07-12 11:23:24 +00:00
op.drop_table('placeholder', schema=f'{get_inv()}')
2022-07-07 14:32:00 +00:00
op.execute("DROP SEQUENCE placeholder_seq;")