
Implemented a complete FastAPI backend with: - Project structure with FastAPI and SQLAlchemy - SQLite database with proper configuration - Alembic for database migrations - Generic Item resource with CRUD operations - REST API endpoints with proper validation - Health check endpoint - Documentation and setup instructions
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
"""create item table
|
|
|
|
Revision ID: 01_create_item_table
|
|
Revises:
|
|
Create Date: 2023-10-01
|
|
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = "01_create_item_table"
|
|
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(), nullable=True),
|
|
sa.Column("description", sa.String(), nullable=True),
|
|
sa.Column("is_active", sa.Boolean(), nullable=True, default=True),
|
|
sa.Column(
|
|
"created_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.text("(CURRENT_TIMESTAMP)"),
|
|
nullable=True,
|
|
),
|
|
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)
|
|
op.create_index(op.f("ix_item_description"), "item", ["description"], unique=False)
|
|
|
|
|
|
def downgrade():
|
|
op.drop_index(op.f("ix_item_description"), table_name="item")
|
|
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")
|