genericrestapi-7xivrj/migrations/versions/001_create_item_table.py
Automated Action a030964e07 Implement REST API with FastAPI and SQLite
- Set up project structure and dependencies
- Implement database models with SQLAlchemy
- Set up Alembic migrations
- Create FastAPI application with CORS support
- Implement API endpoints (CRUD operations)
- Add health check endpoint
- Update README with setup and usage instructions
2025-06-03 12:23:52 +00:00

45 lines
1.4 KiB
Python

"""Create item table
Revision ID: 001
Revises:
Create Date: 2023-11-15
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '001'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# Create item table
op.create_table(
'item',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(255), nullable=False, index=True),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('price', sa.Integer(), nullable=False),
sa.Column('is_active', sa.Boolean(), default=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now()),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now()),
sa.PrimaryKeyConstraint('id')
)
# Create index on name for faster lookups
op.create_index(op.f('ix_item_name'), 'item', ['name'], unique=False)
# Create index on id column
op.create_index(op.f('ix_item_id'), 'item', ['id'], unique=False)
def downgrade() -> None:
# Drop indexes
op.drop_index(op.f('ix_item_name'), table_name='item')
op.drop_index(op.f('ix_item_id'), table_name='item')
# Drop item table
op.drop_table('item')