2026-03-18 17:18:23 +08:00
|
|
|
|
"""create_initial_schema
|
|
|
|
|
|
|
|
|
|
|
|
从 Base.metadata 创建所有表(新库部署用)。
|
|
|
|
|
|
对已有数据库:若已 stamp 0001_baseline,本迁移会跳过已存在的表(create_all checkfirst)。
|
|
|
|
|
|
|
|
|
|
|
|
Revision ID: 0002_schema
|
|
|
|
|
|
Revises: 0001_baseline
|
|
|
|
|
|
Create Date: 2026-03-18
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
2026-03-19 14:36:14 +08:00
|
|
|
|
|
2026-03-18 17:18:23 +08:00
|
|
|
|
from typing import Sequence, Union
|
|
|
|
|
|
|
|
|
|
|
|
from alembic import op
|
|
|
|
|
|
from sqlalchemy import text
|
|
|
|
|
|
|
|
|
|
|
|
revision: str = "0002_schema"
|
|
|
|
|
|
down_revision: Union[str, None] = "0001_baseline"
|
|
|
|
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def upgrade() -> None:
|
|
|
|
|
|
conn = op.get_bind()
|
|
|
|
|
|
conn.execute(text("CREATE EXTENSION IF NOT EXISTS vector"))
|
|
|
|
|
|
|
|
|
|
|
|
# 导入所有 model 以注册到 Base.metadata
|
|
|
|
|
|
from app.core.db import Base
|
|
|
|
|
|
from app.features.auth import models as _auth_models # noqa: F401
|
|
|
|
|
|
from app.features.conversation import models as _conv_models # noqa: F401
|
|
|
|
|
|
from app.features.memory import models as _memory_models # noqa: F401
|
|
|
|
|
|
from app.features.memoir import models as _memoir_models # noqa: F401
|
|
|
|
|
|
from app.features.payment import models as _payment_models # noqa: F401
|
|
|
|
|
|
from app.features.user import models as _user_models # noqa: F401
|
|
|
|
|
|
|
|
|
|
|
|
Base.metadata.create_all(bind=conn)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def downgrade() -> None:
|
|
|
|
|
|
conn = op.get_bind()
|
|
|
|
|
|
from app.core.db import Base
|
|
|
|
|
|
from app.features.auth import models as _auth_models # noqa: F401
|
|
|
|
|
|
from app.features.conversation import models as _conv_models # noqa: F401
|
|
|
|
|
|
from app.features.memory import models as _memory_models # noqa: F401
|
|
|
|
|
|
from app.features.memoir import models as _memoir_models # noqa: F401
|
|
|
|
|
|
from app.features.payment import models as _payment_models # noqa: F401
|
|
|
|
|
|
from app.features.user import models as _user_models # noqa: F401
|
|
|
|
|
|
|
|
|
|
|
|
Base.metadata.drop_all(bind=conn)
|