2021-07-21 06:35:18 +00:00
|
|
|
"""documents
|
|
|
|
|
|
|
|
Revision ID: 7ecb8ff7abad
|
|
|
|
Revises: 3a3601ac8224
|
|
|
|
Create Date: 2021-07-19 14:46:42.375331
|
|
|
|
|
|
|
|
"""
|
|
|
|
from alembic import op
|
|
|
|
import sqlalchemy as sa
|
|
|
|
import sqlalchemy_utils
|
|
|
|
import citext
|
|
|
|
import teal
|
|
|
|
|
|
|
|
from alembic import op
|
|
|
|
from alembic import context
|
|
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
|
|
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
|
|
revision = '7ecb8ff7abad'
|
2021-08-04 16:03:40 +00:00
|
|
|
down_revision = '0103a9c96b2d'
|
2021-07-21 06:35:18 +00:00
|
|
|
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
|
|
|
|
|
2021-07-21 13:02:23 +00:00
|
|
|
|
2021-07-21 06:35:18 +00:00
|
|
|
def upgrade():
|
|
|
|
# Document table
|
|
|
|
op.create_table('document',
|
|
|
|
sa.Column('id', sa.BigInteger(), nullable=False),
|
|
|
|
sa.Column('updated', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'),
|
|
|
|
nullable=False,
|
|
|
|
comment='The last time Document 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 Document created this.'),
|
2021-08-10 10:55:47 +00:00
|
|
|
sa.Column('document_type', sa.Unicode(), nullable=False),
|
2021-07-21 06:35:18 +00:00
|
|
|
sa.Column('date', sa.TIMESTAMP(timezone=True), nullable=True),
|
|
|
|
sa.Column('id_document', sa.Unicode(), nullable=True),
|
|
|
|
sa.Column('owner_id', postgresql.UUID(as_uuid=True), nullable=False),
|
|
|
|
sa.Column('file_name', sa.Unicode(), nullable=False),
|
|
|
|
sa.Column('file_hash', sa.Unicode(), nullable=False),
|
2021-08-06 09:08:58 +00:00
|
|
|
sa.Column('url', sa.Unicode(), nullable=True),
|
2021-07-21 06:35:18 +00:00
|
|
|
|
|
|
|
sa.ForeignKeyConstraint(['owner_id'], ['common.user.id'], ),
|
|
|
|
sa.PrimaryKeyConstraint('id'),
|
|
|
|
schema=f'{get_inv()}'
|
|
|
|
)
|
|
|
|
op.create_index('generic_document_id', 'document', ['id'], unique=False, postgresql_using='hash', schema=f'{get_inv()}')
|
|
|
|
op.create_index(op.f('ix_document_created'), 'document', ['created'], unique=False, schema=f'{get_inv()}')
|
|
|
|
op.create_index(op.f('ix_document_updated'), 'document', ['updated'], unique=False, schema=f'{get_inv()}')
|
2021-08-10 10:55:47 +00:00
|
|
|
op.create_index('document_type_index', 'document', ['document_type'], unique=False, postgresql_using='hash', schema=f'{get_inv()}')
|
2021-07-21 06:35:18 +00:00
|
|
|
|
|
|
|
|
2021-07-29 13:46:49 +00:00
|
|
|
# DataWipeDocument table
|
|
|
|
op.create_table('data_wipe_document',
|
|
|
|
sa.Column('id', sa.BigInteger(), nullable=False),
|
|
|
|
sa.Column('software', sa.Unicode(), nullable=True),
|
|
|
|
sa.Column('success', sa.Boolean(), nullable=False),
|
|
|
|
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.document.id'], ),
|
|
|
|
sa.PrimaryKeyConstraint('id'),
|
|
|
|
schema=f'{get_inv()}'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-07-29 10:45:43 +00:00
|
|
|
# DataWipe table
|
|
|
|
op.create_table('data_wipe',
|
2021-08-04 16:15:15 +00:00
|
|
|
sa.Column('document_id', sa.BigInteger(), nullable=False),
|
2021-07-21 06:35:18 +00:00
|
|
|
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
2021-07-21 13:02:23 +00:00
|
|
|
sa.ForeignKeyConstraint(['document_id'], [f'{get_inv()}.document.id'], ),
|
2021-07-21 06:35:18 +00:00
|
|
|
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
|
|
|
sa.PrimaryKeyConstraint('id'),
|
|
|
|
schema=f'{get_inv()}'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def downgrade():
|
2021-07-29 10:45:43 +00:00
|
|
|
op.drop_table('data_wipe', schema=f'{get_inv()}')
|
2021-07-29 13:55:59 +00:00
|
|
|
op.drop_table('data_wipe_document', schema=f'{get_inv()}')
|
2021-07-21 06:35:18 +00:00
|
|
|
op.drop_table('document', schema=f'{get_inv()}')
|