mirror of
https://github.com/karpathy/nanochat.git
synced 2026-05-09 09:20:04 +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>
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
"""create users table
|
|
|
|
Revision ID: 001_create_users
|
|
Revises:
|
|
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 = "001_create_users"
|
|
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:
|
|
op.execute("CREATE EXTENSION IF NOT EXISTS pgcrypto")
|
|
op.create_table(
|
|
"users",
|
|
sa.Column(
|
|
"id",
|
|
postgresql.UUID(as_uuid=True),
|
|
primary_key=True,
|
|
server_default=sa.text("gen_random_uuid()"),
|
|
),
|
|
sa.Column("email", sa.String(length=255), nullable=False, unique=True),
|
|
sa.Column("name", sa.String(length=255), nullable=True),
|
|
sa.Column("avatar_url", sa.Text(), nullable=True),
|
|
sa.Column("provider", sa.String(length=50), nullable=False),
|
|
sa.Column("provider_id", sa.String(length=255), nullable=False),
|
|
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()"),
|
|
),
|
|
sa.Column(
|
|
"last_login_at",
|
|
sa.TIMESTAMP(timezone=True),
|
|
server_default=sa.text("NOW()"),
|
|
),
|
|
sa.UniqueConstraint("provider", "provider_id", name="uq_users_provider_identity"),
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_table("users")
|