45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
"""create dogs table
|
|
|
|
Revision ID: b2c3d4e5f6g7
|
|
Revises:
|
|
Create Date: 2024-01-09 10:00:00.000000
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.sql import func
|
|
import uuid
|
|
|
|
# revision identifiers
|
|
revision = 'b2c3d4e5f6g7'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
def upgrade():
|
|
op.create_table(
|
|
'dogs',
|
|
sa.Column('id', sa.String(), primary_key=True, default=lambda: str(uuid.uuid4())),
|
|
sa.Column('name', sa.String(), nullable=False),
|
|
sa.Column('breed', sa.String(), nullable=False),
|
|
sa.Column('age', sa.Integer()),
|
|
sa.Column('color', sa.String()),
|
|
sa.Column('weight', sa.Integer()),
|
|
sa.Column('is_vaccinated', sa.Boolean(), default=False),
|
|
sa.Column('owner_name', sa.String()),
|
|
sa.Column('owner_contact', sa.String()),
|
|
sa.Column('created_at', sa.DateTime(), server_default=sa.func.now()),
|
|
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.now(), onupdate=sa.func.now()),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
|
|
# Create indexes
|
|
op.create_index('ix_dogs_name', 'dogs', ['name'])
|
|
op.create_index('ix_dogs_breed', 'dogs', ['breed'])
|
|
|
|
def downgrade():
|
|
# Drop indexes
|
|
op.drop_index('ix_dogs_breed', 'dogs')
|
|
op.drop_index('ix_dogs_name', 'dogs')
|
|
|
|
# Drop table
|
|
op.drop_table('dogs') |