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/b4bd1538bad5_update_live.py

94 lines
2.7 KiB
Python
Raw Permalink Normal View History

2020-12-29 19:39:04 +00:00
"""update_live
Revision ID: b4bd1538bad5
Revises: 3eb50297c365
Create Date: 2020-12-29 20:19:46.981207
"""
import sqlalchemy as sa
2023-03-21 16:31:43 +00:00
from ereuse_devicehub import teal
2022-05-24 12:06:56 +00:00
from alembic import context, op
from sqlalchemy.dialects import postgresql
2020-12-29 19:39:04 +00:00
# revision identifiers, used by Alembic.
revision = 'b4bd1538bad5'
down_revision = '3eb50297c365'
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
2022-05-24 12:06:56 +00:00
2020-12-29 19:39:04 +00:00
def upgrade():
2022-05-24 12:08:23 +00:00
# op.execute("COMMIT")
op.execute("ALTER TYPE snapshotsoftware ADD VALUE 'WorkbenchDesktop'")
SOFTWARE = sa.dialects.postgresql.ENUM(
2022-05-24 12:08:23 +00:00
'Workbench',
'WorkbenchAndroid',
'AndroidApp',
'Web',
'DesktopApp',
'WorkbenchDesktop',
name='snapshotsoftware',
create_type=False,
checkfirst=True,
)
2020-12-29 19:39:04 +00:00
# Live action
2020-12-29 19:55:11 +00:00
op.drop_table('live', schema=f'{get_inv()}')
2022-05-24 12:06:56 +00:00
op.create_table(
'live',
2020-12-29 19:55:11 +00:00
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
2022-05-24 12:06:56 +00:00
sa.Column(
'serial_number',
sa.Unicode(),
nullable=True,
comment='The serial number of the Hard Disk in lower case.',
),
2020-12-29 19:55:11 +00:00
sa.Column('usage_time_hdd', sa.Interval(), nullable=True),
sa.Column('snapshot_uuid', postgresql.UUID(as_uuid=True), nullable=False),
2022-05-24 12:06:56 +00:00
sa.Column(
'software_version', teal.db.StrictVersionType(length=32), nullable=False
),
sa.Column(
'licence_version', teal.db.StrictVersionType(length=32), nullable=False
),
2022-05-24 12:08:23 +00:00
sa.Column('software', SOFTWARE, nullable=False),
2022-05-24 12:06:56 +00:00
sa.ForeignKeyConstraint(
['id'],
[f'{get_inv()}.action.id'],
),
2020-12-29 19:55:11 +00:00
sa.PrimaryKeyConstraint('id'),
2022-05-24 12:06:56 +00:00
schema=f'{get_inv()}',
2020-12-29 19:55:11 +00:00
)
2020-12-29 19:39:04 +00:00
2022-05-24 12:06:56 +00:00
2020-12-29 19:39:04 +00:00
def downgrade():
2020-12-29 19:55:11 +00:00
op.drop_table('live', schema=f'{get_inv()}')
2022-05-24 12:06:56 +00:00
op.create_table(
'live',
2020-12-29 19:55:11 +00:00
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
2022-05-24 12:06:56 +00:00
sa.Column(
'serial_number',
sa.Unicode(),
nullable=True,
comment='The serial number of the Hard Disk in lower case.',
),
2020-12-29 19:55:11 +00:00
sa.Column('usage_time_hdd', sa.Interval(), nullable=True),
sa.Column('snapshot_uuid', postgresql.UUID(as_uuid=True), nullable=False),
2022-05-24 12:06:56 +00:00
sa.ForeignKeyConstraint(
['id'],
[f'{get_inv()}.action.id'],
),
2020-12-29 19:55:11 +00:00
sa.PrimaryKeyConstraint('id'),
2022-05-24 12:06:56 +00:00
schema=f'{get_inv()}',
2020-12-29 19:55:11 +00:00
)
2022-05-24 12:08:23 +00:00
op.execute(
"select e.enumlabel FROM pg_enum e JOIN pg_type t ON e.enumtypid = t.oid WHERE t.typname = 'snapshotsoftware'"
)