mirror of
https://github.com/karpathy/nanochat.git
synced 2026-05-12 10:50:16 +00:00
- Alembic async migrations: users, conversations, messages, is_favorited - FastAPI auth service: Google + GitHub OAuth, RS256 JWT, refresh cookie - /auth/me, /auth/refresh, /auth/validate (service-to-service) - rate limiting 10/min on OAuth routes, CORS locked to FRONTEND_URL Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
65 lines
1.7 KiB
Python
65 lines
1.7 KiB
Python
"""create conversations table
|
|
|
|
Revision ID: 002_create_conversations
|
|
Revises: 001_create_users
|
|
Create Date: 2026-04-16
|
|
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
revision: str = "002_create_conversations"
|
|
down_revision: Union[str, None] = "001_create_users"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"conversations",
|
|
sa.Column(
|
|
"id",
|
|
postgresql.UUID(as_uuid=True),
|
|
primary_key=True,
|
|
server_default=sa.text("gen_random_uuid()"),
|
|
),
|
|
sa.Column(
|
|
"user_id",
|
|
postgresql.UUID(as_uuid=True),
|
|
sa.ForeignKey("users.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
),
|
|
sa.Column("title", sa.String(length=500), nullable=True),
|
|
sa.Column(
|
|
"model_tag",
|
|
sa.String(length=100),
|
|
nullable=True,
|
|
server_default=sa.text("'default'"),
|
|
),
|
|
sa.Column(
|
|
"created_at",
|
|
sa.TIMESTAMP(timezone=True),
|
|
server_default=sa.text("NOW()"),
|
|
),
|
|
sa.Column(
|
|
"updated_at",
|
|
sa.TIMESTAMP(timezone=True),
|
|
server_default=sa.text("NOW()"),
|
|
),
|
|
)
|
|
op.create_index(
|
|
"idx_conversations_user",
|
|
"conversations",
|
|
["user_id", sa.text("updated_at DESC")],
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("idx_conversations_user", table_name="conversations")
|
|
op.drop_table("conversations")
|