genericrestapi-sxso1t/alembic/versions/001_create_items_table.py
Automated Action a4ffe78f61 Create REST API with FastAPI and SQLAlchemy
- Set up project structure with FastAPI
- Create SQLite database with SQLAlchemy
- Implement Alembic for database migrations
- Add CRUD operations for items resource
- Create health endpoint
- Update documentation

generated with BackendIM... (backend.im)
2025-05-14 10:26:10 +00:00

36 lines
1.0 KiB
Python

"""create items table
Revision ID: 001
Revises:
Create Date: 2025-05-14
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '001'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
op.create_table(
'item',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=100), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_item_id'), 'item', ['id'], unique=False)
op.create_index(op.f('ix_item_title'), 'item', ['title'], unique=False)
def downgrade():
op.drop_index(op.f('ix_item_title'), table_name='item')
op.drop_index(op.f('ix_item_id'), table_name='item')
op.drop_table('item')