From db637a99ac367cc0fcb03329c6618d27436ea4db Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 4 Apr 2022 19:37:06 +0200 Subject: [PATCH] add migrations for snapshot errors --- .../23d9e7ebbd7d_add_snapshot_errors.py | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 ereuse_devicehub/migrations/versions/23d9e7ebbd7d_add_snapshot_errors.py diff --git a/ereuse_devicehub/migrations/versions/23d9e7ebbd7d_add_snapshot_errors.py b/ereuse_devicehub/migrations/versions/23d9e7ebbd7d_add_snapshot_errors.py new file mode 100644 index 00000000..c51de914 --- /dev/null +++ b/ereuse_devicehub/migrations/versions/23d9e7ebbd7d_add_snapshot_errors.py @@ -0,0 +1,54 @@ +"""add snapshot errors + +Revision ID: 23d9e7ebbd7d +Revises: 17288b2a7440 +Create Date: 2022-04-04 19:27:48.675387 + +""" +import citext +import sqlalchemy as sa +from alembic import context, op +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = '23d9e7ebbd7d' +down_revision = '17288b2a7440' +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.create_table( + 'snapshot_errors', + sa.Column( + 'updated', + sa.TIMESTAMP(timezone=True), + server_default=sa.text('CURRENT_TIMESTAMP'), + nullable=False, + comment='The last time Devicehub recorded a change for \n this thing.\n ', + ), + sa.Column( + 'created', + sa.TIMESTAMP(timezone=True), + server_default=sa.text('CURRENT_TIMESTAMP'), + nullable=False, + comment='When Devicehub created this.', + ), + sa.Column('id', sa.BigInteger(), nullable=False), + sa.Column('description', citext.CIText(), nullable=False), + sa.Column('snapshot_uuid', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('severity', sa.SmallInteger(), nullable=False), + sa.PrimaryKeyConstraint('id'), + schema=f'{get_inv()}', + ) + + +def downgrade(): + op.drop_table('snapshot_errors', schema=f'{get_inv()}')