travelappbackend-jco6pe/alembic/versions/001_initial_migration.py
Automated Action 2de9589e3d Initial Travel App Backend Implementation
- FastAPI application with user management, destinations, and trip planning
- SQLite database with SQLAlchemy ORM
- Database models for Users, Destinations, and Trips
- Pydantic schemas for request/response validation
- Full CRUD API endpoints for all resources
- Alembic migrations setup
- Health check endpoint
- CORS configuration for development
- Comprehensive documentation and README
2025-06-20 01:25:27 +00:00

107 lines
3.7 KiB
Python

"""Initial migration
Revision ID: 001
Revises:
Create Date: 2024-01-01 12:00:00.000000
"""
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() -> None:
# Create users table
op.create_table(
"users",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("email", sa.String(), nullable=False),
sa.Column("full_name", sa.String(), nullable=False),
sa.Column("hashed_password", sa.String(), nullable=False),
sa.Column("is_active", sa.Boolean(), nullable=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_users_email"), "users", ["email"], unique=True)
op.create_index(op.f("ix_users_id"), "users", ["id"], unique=False)
# Create destinations table
op.create_table(
"destinations",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("country", sa.String(), nullable=False),
sa.Column("city", sa.String(), nullable=False),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("latitude", sa.Float(), nullable=True),
sa.Column("longitude", sa.Float(), nullable=True),
sa.Column("rating", sa.Float(), nullable=True),
sa.Column("image_url", sa.String(), nullable=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_destinations_id"), "destinations", ["id"], unique=False)
op.create_index(
op.f("ix_destinations_name"), "destinations", ["name"], unique=False
)
# Create trips table
op.create_table(
"trips",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("title", sa.String(), nullable=False),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("user_id", sa.Integer(), nullable=False),
sa.Column("destination_id", sa.Integer(), nullable=False),
sa.Column("start_date", sa.DateTime(), nullable=False),
sa.Column("end_date", sa.DateTime(), nullable=False),
sa.Column("budget", sa.Float(), nullable=True),
sa.Column("status", sa.String(), nullable=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.ForeignKeyConstraint(
["destination_id"],
["destinations.id"],
),
sa.ForeignKeyConstraint(
["user_id"],
["users.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f("ix_trips_id"), "trips", ["id"], unique=False)
def downgrade() -> None:
op.drop_index(op.f("ix_trips_id"), table_name="trips")
op.drop_table("trips")
op.drop_index(op.f("ix_destinations_name"), table_name="destinations")
op.drop_index(op.f("ix_destinations_id"), table_name="destinations")
op.drop_table("destinations")
op.drop_index(op.f("ix_users_id"), table_name="users")
op.drop_index(op.f("ix_users_email"), table_name="users")
op.drop_table("users")