Complete v0.5.0 implementation: Database (@db-engineer): - 3 migrations: users, api_keys, report_schedules tables - Foreign keys, indexes, constraints, enums Backend (@backend-dev): - JWT authentication service with bcrypt (cost=12) - Auth endpoints: /register, /login, /refresh, /me - API Keys service with hash storage and prefix validation - API Keys endpoints: CRUD + rotate - Security module with JWT HS256 Frontend (@frontend-dev): - Login/Register pages with validation - AuthContext with localStorage persistence - Protected routes implementation - API Keys management UI (create, revoke, rotate) - Header with user dropdown DevOps (@devops-engineer): - .env.example and .env.production.example - docker-compose.scheduler.yml - scripts/setup-secrets.sh - INFRASTRUCTURE_SETUP.md QA (@qa-engineer): - 85 E2E tests: auth.spec.ts, apikeys.spec.ts, scenarios.spec.ts, regression-v050.spec.ts - auth-helpers.ts with 20+ utility functions - Test plans and documentation Architecture (@spec-architect): - SECURITY.md with best practices - SECURITY-CHECKLIST.md pre-deployment - Updated architecture.md with auth flows - Updated README.md with v0.5.0 features Documentation: - Updated todo.md with v0.5.0 status - Added docs/README.md index - Complete setup instructions Dependencies added: - bcrypt, python-jose, passlib, email-validator Tested: JWT auth flow, API keys CRUD, protected routes, 85 E2E tests ready Closes: v0.5.0 milestone
87 lines
2.4 KiB
Python
87 lines
2.4 KiB
Python
"""create users table
|
|
|
|
Revision ID: 60582e23992d
|
|
Revises: 0892c44b2a58
|
|
Create Date: 2026-04-07 14:00:00.000000
|
|
|
|
"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = "60582e23992d"
|
|
down_revision: Union[str, Sequence[str], None] = "0892c44b2a58"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
"""Upgrade schema."""
|
|
# Create users table
|
|
op.create_table(
|
|
"users",
|
|
sa.Column(
|
|
"id",
|
|
postgresql.UUID(as_uuid=True),
|
|
primary_key=True,
|
|
server_default=sa.text("uuid_generate_v4()"),
|
|
),
|
|
sa.Column("email", sa.String(255), nullable=False, unique=True),
|
|
sa.Column("password_hash", sa.String(255), nullable=False),
|
|
sa.Column("full_name", sa.String(255), nullable=True),
|
|
sa.Column(
|
|
"is_active", sa.Boolean(), nullable=False, server_default=sa.text("true")
|
|
),
|
|
sa.Column(
|
|
"is_superuser",
|
|
sa.Boolean(),
|
|
nullable=False,
|
|
server_default=sa.text("false"),
|
|
),
|
|
sa.Column(
|
|
"created_at",
|
|
sa.TIMESTAMP(timezone=True),
|
|
server_default=sa.text("NOW()"),
|
|
nullable=False,
|
|
),
|
|
sa.Column(
|
|
"updated_at",
|
|
sa.TIMESTAMP(timezone=True),
|
|
server_default=sa.text("NOW()"),
|
|
nullable=False,
|
|
),
|
|
sa.Column("last_login", sa.TIMESTAMP(timezone=True), nullable=True),
|
|
)
|
|
|
|
# Add indexes
|
|
op.create_index("idx_users_email", "users", ["email"], unique=True)
|
|
op.create_index(
|
|
"idx_users_created_at", "users", ["created_at"], postgresql_using="brin"
|
|
)
|
|
|
|
# Create trigger for updated_at
|
|
op.execute("""
|
|
CREATE TRIGGER update_users_updated_at
|
|
BEFORE UPDATE ON users
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION update_updated_at_column();
|
|
""")
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Downgrade schema."""
|
|
# Drop trigger
|
|
op.execute("DROP TRIGGER IF EXISTS update_users_updated_at ON users;")
|
|
|
|
# Drop indexes
|
|
op.drop_index("idx_users_created_at", table_name="users")
|
|
op.drop_index("idx_users_email", table_name="users")
|
|
|
|
# Drop table
|
|
op.drop_table("users")
|