|
| 1 | +"""Add images and image variants tables |
| 2 | +
|
| 3 | +Revision ID: db8bf70fc16a |
| 4 | +Revises: 1a31ce608336 |
| 5 | +Create Date: 2025-11-19 03:59:49.501431 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | +import sqlmodel.sql.sqltypes |
| 11 | + |
| 12 | + |
| 13 | +# revision identifiers, used by Alembic. |
| 14 | +revision = 'db8bf70fc16a' |
| 15 | +down_revision = '1a31ce608336' |
| 16 | +branch_labels = None |
| 17 | +depends_on = None |
| 18 | + |
| 19 | + |
| 20 | +def upgrade(): |
| 21 | + # ### commands auto generated by Alembic - please adjust! ### |
| 22 | + op.create_table('image', |
| 23 | + sa.Column('filename', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False), |
| 24 | + sa.Column('original_filename', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False), |
| 25 | + sa.Column('content_type', sqlmodel.sql.sqltypes.AutoString(length=100), nullable=False), |
| 26 | + sa.Column('file_size', sa.BigInteger(), nullable=False), |
| 27 | + sa.Column('width', sa.Integer(), nullable=True), |
| 28 | + sa.Column('height', sa.Integer(), nullable=True), |
| 29 | + sa.Column('s3_bucket', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False), |
| 30 | + sa.Column('s3_key', sqlmodel.sql.sqltypes.AutoString(length=500), nullable=False), |
| 31 | + sa.Column('s3_url', sqlmodel.sql.sqltypes.AutoString(length=1000), nullable=False), |
| 32 | + sa.Column('processing_status', sqlmodel.sql.sqltypes.AutoString(length=20), nullable=True, server_default='pending'), |
| 33 | + sa.Column('alt_text', sqlmodel.sql.sqltypes.AutoString(length=500), nullable=True), |
| 34 | + sa.Column('description', sqlmodel.sql.sqltypes.AutoString(length=1000), nullable=True), |
| 35 | + sa.Column('tags', sqlmodel.sql.sqltypes.AutoString(length=500), nullable=True), |
| 36 | + sa.Column('id', sa.UUID(), nullable=False), |
| 37 | + sa.Column('owner_id', sa.UUID(), nullable=False), |
| 38 | + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), |
| 39 | + sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), |
| 40 | + sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ondelete='CASCADE'), |
| 41 | + sa.PrimaryKeyConstraint('id') |
| 42 | + ) |
| 43 | + op.create_index(op.f('ix_image_filename'), 'image', ['filename'], unique=False) |
| 44 | + op.create_index(op.f('ix_image_owner_id'), 'image', ['owner_id'], unique=False) |
| 45 | + op.create_index(op.f('ix_image_processing_status'), 'image', ['processing_status'], unique=False) |
| 46 | + |
| 47 | + op.create_table('imagevariant', |
| 48 | + sa.Column('variant_type', sqlmodel.sql.sqltypes.AutoString(length=20), nullable=False), |
| 49 | + sa.Column('width', sa.Integer(), nullable=True), |
| 50 | + sa.Column('height', sa.Integer(), nullable=True), |
| 51 | + sa.Column('file_size', sa.BigInteger(), nullable=False), |
| 52 | + sa.Column('s3_bucket', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False), |
| 53 | + sa.Column('s3_key', sqlmodel.sql.sqltypes.AutoString(length=500), nullable=False), |
| 54 | + sa.Column('s3_url', sqlmodel.sql.sqltypes.AutoString(length=1000), nullable=False), |
| 55 | + sa.Column('quality', sa.Integer(), nullable=True, server_default='85'), |
| 56 | + sa.Column('format', sqlmodel.sql.sqltypes.AutoString(length=10), nullable=True, server_default='jpeg'), |
| 57 | + sa.Column('id', sa.UUID(), nullable=False), |
| 58 | + sa.Column('image_id', sa.UUID(), nullable=False), |
| 59 | + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), |
| 60 | + sa.ForeignKeyConstraint(['image_id'], ['image.id'], ondelete='CASCADE'), |
| 61 | + sa.PrimaryKeyConstraint('id') |
| 62 | + ) |
| 63 | + op.create_index(op.f('ix_imagevariant_image_id'), 'imagevariant', ['image_id'], unique=False) |
| 64 | + op.create_index(op.f('ix_imagevariant_variant_type'), 'imagevariant', ['variant_type'], unique=False) |
| 65 | + |
| 66 | + op.create_table('imageprocessingjob', |
| 67 | + sa.Column('status', sqlmodel.sql.sqltypes.AutoString(length=20), nullable=True, server_default='pending'), |
| 68 | + sa.Column('error_message', sqlmodel.sql.sqltypes.AutoString(length=1000), nullable=True), |
| 69 | + sa.Column('retry_count', sa.Integer(), nullable=True, server_default='0'), |
| 70 | + sa.Column('id', sa.UUID(), nullable=False), |
| 71 | + sa.Column('image_id', sa.UUID(), nullable=False), |
| 72 | + sa.ForeignKeyConstraint(['image_id'], ['image.id'], ondelete='CASCADE'), |
| 73 | + sa.PrimaryKeyConstraint('id') |
| 74 | + ) |
| 75 | + op.create_index(op.f('ix_imageprocessingjob_image_id'), 'imageprocessingjob', ['image_id'], unique=False) |
| 76 | + op.create_index(op.f('ix_imageprocessingjob_status'), 'imageprocessingjob', ['status'], unique=False) |
| 77 | + # ### end Alembic commands ### |
| 78 | + |
| 79 | + |
| 80 | +def downgrade(): |
| 81 | + # ### commands auto generated by Alembic - please adjust! ### |
| 82 | + op.drop_index(op.f('ix_imageprocessingjob_status'), table_name='imageprocessingjob') |
| 83 | + op.drop_index(op.f('ix_imageprocessingjob_image_id'), table_name='imageprocessingjob') |
| 84 | + op.drop_table('imageprocessingjob') |
| 85 | + op.drop_index(op.f('ix_imagevariant_variant_type'), table_name='imagevariant') |
| 86 | + op.drop_index(op.f('ix_imagevariant_image_id'), table_name='imagevariant') |
| 87 | + op.drop_table('imagevariant') |
| 88 | + op.drop_index(op.f('ix_image_processing_status'), table_name='image') |
| 89 | + op.drop_index(op.f('ix_image_owner_id'), table_name='image') |
| 90 | + op.drop_index(op.f('ix_image_filename'), table_name='image') |
| 91 | + op.drop_table('image') |
| 92 | + # ### end Alembic commands ### |
0 commit comments