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/e93aec8fc41f_added_assigned...

111 lines
3.0 KiB
Python
Raw Permalink Normal View History

2020-11-17 12:36:26 +00:00
"""Added Assigned action
Revision ID: e93aec8fc41f
Revises: b9b0ee7d9dca
Create Date: 2020-11-17 13:22:56.790956
"""
from alembic import op
import sqlalchemy as sa
from alembic import context
import sqlalchemy_utils
import citext
2023-03-21 16:31:43 +00:00
from ereuse_devicehub import teal
2020-11-17 12:36:26 +00:00
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = 'e93aec8fc41f'
down_revision = 'b9b0ee7d9dca'
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
2023-03-21 16:31:43 +00:00
2020-11-17 12:36:26 +00:00
def upgrade():
2020-11-19 14:25:56 +00:00
# Allocate action
2020-11-18 17:21:22 +00:00
op.drop_table('allocate', schema=f'{get_inv()}')
2023-03-21 16:31:43 +00:00
op.create_table(
'allocate',
sa.Column(
'final_user_code',
citext.CIText(),
default='',
nullable=True,
comment="This is a internal code for mainteing the secrets of the personal datas of the new holder",
),
sa.Column(
'transaction',
citext.CIText(),
nullable=True,
comment='The code used from the owner for relation with external tool.',
),
2020-11-26 17:44:08 +00:00
sa.Column('end_users', sa.Numeric(precision=4), nullable=True),
2020-11-18 17:13:13 +00:00
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
2023-03-21 16:31:43 +00:00
sa.ForeignKeyConstraint(
['id'],
[f'{get_inv()}.action.id'],
),
2020-11-18 17:13:13 +00:00
sa.PrimaryKeyConstraint('id'),
2023-03-21 16:31:43 +00:00
schema=f'{get_inv()}',
2020-11-18 17:13:13 +00:00
)
2020-11-21 12:17:23 +00:00
# Deallocate action
2020-11-18 17:21:22 +00:00
op.drop_table('deallocate', schema=f'{get_inv()}')
2023-03-21 16:31:43 +00:00
op.create_table(
'deallocate',
sa.Column(
'transaction',
citext.CIText(),
nullable=True,
comment='The code used from the owner for relation with external tool.',
),
2020-11-21 12:17:23 +00:00
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
2023-03-21 16:31:43 +00:00
sa.ForeignKeyConstraint(
['id'],
[f'{get_inv()}.action.id'],
),
2020-11-21 12:17:23 +00:00
sa.PrimaryKeyConstraint('id'),
2023-03-21 16:31:43 +00:00
schema=f'{get_inv()}',
2020-11-21 12:17:23 +00:00
)
2020-11-17 12:36:26 +00:00
2020-11-19 14:25:56 +00:00
# Add allocate as a column in device
2023-03-21 16:31:43 +00:00
op.add_column(
'device',
sa.Column('allocated', sa.Boolean(), nullable=True),
schema=f'{get_inv()}',
)
2020-11-17 12:36:26 +00:00
2020-11-19 14:25:56 +00:00
# Receive action
op.drop_table('receive', schema=f'{get_inv()}')
2020-11-23 17:42:31 +00:00
# Live action
op.drop_table('live', schema=f'{get_inv()}')
2023-03-21 16:31:43 +00:00
op.create_table(
'live',
2020-11-23 17:42:31 +00:00
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
2023-03-21 16:31:43 +00:00
sa.Column(
'serial_number',
sa.Unicode(),
nullable=True,
comment='The serial number of the Hard Disk in lower case.',
),
sa.Column('usage_time_hdd', sa.Interval(), nullable=True),
sa.Column('snapshot_uuid', postgresql.UUID(as_uuid=True), nullable=False),
2023-03-21 16:31:43 +00:00
sa.ForeignKeyConstraint(
['id'],
[f'{get_inv()}.action.id'],
),
2020-11-23 17:42:31 +00:00
sa.PrimaryKeyConstraint('id'),
2023-03-21 16:31:43 +00:00
schema=f'{get_inv()}',
2020-11-23 17:42:31 +00:00
)
2023-03-21 16:31:43 +00:00
2020-11-17 12:36:26 +00:00
def downgrade():
2020-11-18 17:21:22 +00:00
op.drop_table('allocate', schema=f'{get_inv()}')