|
| 1 | +"""add file caching |
| 2 | +
|
| 3 | +Revision ID: 11675e102ac4 |
| 4 | +Revises: 1118c7327b96 |
| 5 | +Create Date: 2024-10-09 15:37:46.744638 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | +from sqlalchemy.dialects import postgresql |
| 11 | + |
| 12 | +# revision identifiers, used by Alembic. |
| 13 | +revision = '11675e102ac4' |
| 14 | +down_revision = '1118c7327b96' |
| 15 | +branch_labels = None |
| 16 | +depends_on = None |
| 17 | + |
| 18 | + |
| 19 | +def upgrade(): |
| 20 | + # ### commands auto generated by Alembic - please adjust! ### |
| 21 | + op.create_table('file_reference', |
| 22 | + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), |
| 23 | + sa.Column('organization_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 24 | + sa.Column('hash', sa.String(), nullable=True), |
| 25 | + sa.Column('minio_path', sa.String(), nullable=True), |
| 26 | + sa.Column('bucket', sa.String(), nullable=True), |
| 27 | + sa.Column('created_at', sa.DateTime(), nullable=True), |
| 28 | + sa.Column('created_by', postgresql.UUID(as_uuid=True), nullable=True), |
| 29 | + sa.Column('file_size_bytes', sa.BigInteger(), nullable=True), |
| 30 | + sa.Column('content_type', sa.String(), nullable=True), |
| 31 | + sa.Column('original_file_name', sa.String(), nullable=True), |
| 32 | + sa.Column('state', sa.String(), nullable=True), |
| 33 | + sa.Column('meta_data', sa.JSON(), nullable=True), |
| 34 | + sa.ForeignKeyConstraint(['created_by'], ['user.id'], ondelete='SET NULL'), |
| 35 | + sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ondelete='CASCADE'), |
| 36 | + sa.PrimaryKeyConstraint('id'), |
| 37 | + sa.UniqueConstraint('organization_id', 'hash', 'file_size_bytes', name='unique_file_reference'), |
| 38 | + schema='cognition' |
| 39 | + ) |
| 40 | + op.create_index(op.f('ix_cognition_file_reference_created_by'), 'file_reference', ['created_by'], unique=False, schema='cognition') |
| 41 | + op.create_index(op.f('ix_cognition_file_reference_hash'), 'file_reference', ['hash'], unique=False, schema='cognition') |
| 42 | + op.create_index(op.f('ix_cognition_file_reference_organization_id'), 'file_reference', ['organization_id'], unique=False, schema='cognition') |
| 43 | + op.create_table('file_extraction', |
| 44 | + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), |
| 45 | + sa.Column('organization_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 46 | + sa.Column('file_reference_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 47 | + sa.Column('extraction_key', sa.String(), nullable=True), |
| 48 | + sa.Column('minio_path', sa.String(), nullable=True), |
| 49 | + sa.Column('bucket', sa.String(), nullable=True), |
| 50 | + sa.Column('created_at', sa.DateTime(), nullable=True), |
| 51 | + sa.Column('created_by', postgresql.UUID(as_uuid=True), nullable=True), |
| 52 | + sa.Column('state', sa.String(), nullable=True), |
| 53 | + sa.ForeignKeyConstraint(['created_by'], ['user.id'], ondelete='SET NULL'), |
| 54 | + sa.ForeignKeyConstraint(['file_reference_id'], ['cognition.file_reference.id'], ondelete='CASCADE'), |
| 55 | + sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ondelete='CASCADE'), |
| 56 | + sa.PrimaryKeyConstraint('id'), |
| 57 | + sa.UniqueConstraint('organization_id', 'file_reference_id', 'extraction_key', name='unique_file_extraction'), |
| 58 | + schema='cognition' |
| 59 | + ) |
| 60 | + op.create_index(op.f('ix_cognition_file_extraction_created_by'), 'file_extraction', ['created_by'], unique=False, schema='cognition') |
| 61 | + op.create_index(op.f('ix_cognition_file_extraction_file_reference_id'), 'file_extraction', ['file_reference_id'], unique=False, schema='cognition') |
| 62 | + op.create_index(op.f('ix_cognition_file_extraction_organization_id'), 'file_extraction', ['organization_id'], unique=False, schema='cognition') |
| 63 | + op.create_table('file_transformation', |
| 64 | + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), |
| 65 | + sa.Column('organization_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 66 | + sa.Column('file_extraction_id', postgresql.UUID(as_uuid=True), nullable=True), |
| 67 | + sa.Column('transformation_key', sa.String(), nullable=True), |
| 68 | + sa.Column('minio_path', sa.String(), nullable=True), |
| 69 | + sa.Column('bucket', sa.String(), nullable=True), |
| 70 | + sa.Column('created_at', sa.DateTime(), nullable=True), |
| 71 | + sa.Column('created_by', postgresql.UUID(as_uuid=True), nullable=True), |
| 72 | + sa.Column('state', sa.String(), nullable=True), |
| 73 | + sa.ForeignKeyConstraint(['created_by'], ['user.id'], ondelete='SET NULL'), |
| 74 | + sa.ForeignKeyConstraint(['file_extraction_id'], ['cognition.file_extraction.id'], ondelete='CASCADE'), |
| 75 | + sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ondelete='CASCADE'), |
| 76 | + sa.PrimaryKeyConstraint('id'), |
| 77 | + sa.UniqueConstraint('organization_id', 'file_extraction_id', 'transformation_key', name='unique_file_transformation'), |
| 78 | + schema='cognition' |
| 79 | + ) |
| 80 | + op.create_index(op.f('ix_cognition_file_transformation_created_by'), 'file_transformation', ['created_by'], unique=False, schema='cognition') |
| 81 | + op.create_index(op.f('ix_cognition_file_transformation_file_extraction_id'), 'file_transformation', ['file_extraction_id'], unique=False, schema='cognition') |
| 82 | + op.create_index(op.f('ix_cognition_file_transformation_organization_id'), 'file_transformation', ['organization_id'], unique=False, schema='cognition') |
| 83 | + # ### end Alembic commands ### |
| 84 | + |
| 85 | + |
| 86 | +def downgrade(): |
| 87 | + # ### commands auto generated by Alembic - please adjust! ### |
| 88 | + op.drop_index(op.f('ix_cognition_file_transformation_organization_id'), table_name='file_transformation', schema='cognition') |
| 89 | + op.drop_index(op.f('ix_cognition_file_transformation_file_extraction_id'), table_name='file_transformation', schema='cognition') |
| 90 | + op.drop_index(op.f('ix_cognition_file_transformation_created_by'), table_name='file_transformation', schema='cognition') |
| 91 | + op.drop_table('file_transformation', schema='cognition') |
| 92 | + op.drop_index(op.f('ix_cognition_file_extraction_organization_id'), table_name='file_extraction', schema='cognition') |
| 93 | + op.drop_index(op.f('ix_cognition_file_extraction_file_reference_id'), table_name='file_extraction', schema='cognition') |
| 94 | + op.drop_index(op.f('ix_cognition_file_extraction_created_by'), table_name='file_extraction', schema='cognition') |
| 95 | + op.drop_table('file_extraction', schema='cognition') |
| 96 | + op.drop_index(op.f('ix_cognition_file_reference_organization_id'), table_name='file_reference', schema='cognition') |
| 97 | + op.drop_index(op.f('ix_cognition_file_reference_hash'), table_name='file_reference', schema='cognition') |
| 98 | + op.drop_index(op.f('ix_cognition_file_reference_created_by'), table_name='file_reference', schema='cognition') |
| 99 | + op.drop_table('file_reference', schema='cognition') |
| 100 | + # ### end Alembic commands ### |
0 commit comments