upload project source code
This commit is contained in:
1
后端源码/yifan.action-ai.cn/api/app/alembic/README
Normal file
1
后端源码/yifan.action-ai.cn/api/app/alembic/README
Normal file
@@ -0,0 +1 @@
|
||||
Generic single-database configuration.
|
||||
131
后端源码/yifan.action-ai.cn/api/app/alembic/env.py
Normal file
131
后端源码/yifan.action-ai.cn/api/app/alembic/env.py
Normal file
@@ -0,0 +1,131 @@
|
||||
import asyncio
|
||||
from logging.config import fileConfig
|
||||
from sqlalchemy.engine import Connection
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from sqlalchemy import pool
|
||||
from alembic import context
|
||||
|
||||
from app.config.path_conf import ALEMBIC_VERSION_DIR
|
||||
from app.utils.import_util import ImportUtil
|
||||
from app.core.base_model import MappedBase
|
||||
from app.config.setting import settings
|
||||
|
||||
# 确保 alembic 版本目录存在
|
||||
ALEMBIC_VERSION_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# 清除MappedBase.metadata中的表定义,避免重复注册
|
||||
if hasattr(MappedBase, 'metadata') and MappedBase.metadata.tables:
|
||||
print(f"🧹 清除已存在的表定义,当前有 {len(MappedBase.metadata.tables)} 个表")
|
||||
# 创建一个新的空metadata对象
|
||||
from sqlalchemy import MetaData
|
||||
MappedBase.metadata = MetaData()
|
||||
print("✅️ 已重置metadata")
|
||||
|
||||
# 自动查找所有模型
|
||||
print("🔍 开始查找模型...")
|
||||
found_models = ImportUtil.find_models(MappedBase)
|
||||
print(f"📊 找到 {len(found_models)} 个有效模型")
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
alembic_config = context.config
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
if alembic_config.config_file_name is not None:
|
||||
fileConfig(alembic_config.config_file_name)
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
target_metadata = MappedBase.metadata
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
# can be acquired:
|
||||
# my_important_option = config.get_main_option("my_important_option")
|
||||
# ... etc.
|
||||
alembic_config.set_main_option("sqlalchemy.url", settings.ASYNC_DB_URI)
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
"""Run migrations in 'offline' mode.
|
||||
|
||||
This configures the context with just a URL
|
||||
and not an Engine, though an Engine is acceptable
|
||||
here as well. By skipping the Engine creation
|
||||
we don't even need a DBAPI to be available.
|
||||
|
||||
Calls to context.execute() here emit the given string to the
|
||||
script output.
|
||||
|
||||
"""
|
||||
url = alembic_config.get_main_option("sqlalchemy.url")
|
||||
# 确保URL不为None
|
||||
if url is None:
|
||||
raise ValueError("数据库URL未正确配置,请检查环境配置文件")
|
||||
|
||||
context.configure(
|
||||
url=url,
|
||||
target_metadata=target_metadata,
|
||||
literal_binds=True,
|
||||
dialect_opts={"paramstyle": "named"},
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
"""Run migrations in 'online' mode.
|
||||
|
||||
In this scenario we need to create an Engine
|
||||
and associate a connection with the context.
|
||||
|
||||
"""
|
||||
url = alembic_config.get_main_option("sqlalchemy.url")
|
||||
# 确保URL不为None
|
||||
if url is None:
|
||||
raise ValueError("数据库URL未正确配置,请检查环境配置文件")
|
||||
|
||||
connectable = create_async_engine(url, poolclass=pool.NullPool)
|
||||
|
||||
async def run_async_migrations():
|
||||
async with connectable.connect() as connection:
|
||||
await connection.run_sync(do_run_migrations)
|
||||
await connectable.dispose()
|
||||
|
||||
def do_run_migrations(connection: Connection) -> None:
|
||||
def process_revision_directives(context, revision, directives):
|
||||
script = directives[0]
|
||||
|
||||
# 检查所有操作集是否为空
|
||||
all_empty = all(ops.is_empty() for ops in script.upgrade_ops_list)
|
||||
|
||||
if all_empty:
|
||||
# 如果没有实际变更,不生成迁移文件
|
||||
directives[:] = []
|
||||
print('❎️ 未检测到模型变更,不生成迁移文件')
|
||||
else:
|
||||
print('✅️ 检测到模型变更,生成迁移文件')
|
||||
|
||||
context.configure(
|
||||
connection=connection,
|
||||
target_metadata=target_metadata,
|
||||
compare_type=True,
|
||||
compare_server_default=True,
|
||||
transaction_per_migration=True,
|
||||
process_revision_directives=process_revision_directives,
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
asyncio.run(run_async_migrations())
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
||||
26
后端源码/yifan.action-ai.cn/api/app/alembic/script.py.mako
Normal file
26
后端源码/yifan.action-ai.cn/api/app/alembic/script.py.mako
Normal file
@@ -0,0 +1,26 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
${imports if imports else ""}
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = ${repr(up_revision)}
|
||||
down_revision: Union[str, None] = ${repr(down_revision)}
|
||||
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
||||
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
${downgrades if downgrades else "pass"}
|
||||
@@ -0,0 +1,30 @@
|
||||
"""add success_time to yifan_wx_pay_order
|
||||
|
||||
Revision ID: 7b2c6f1a9d3e
|
||||
Revises: e1db2024739c
|
||||
Create Date: 2026-01-15 10:50:00
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "7b2c6f1a9d3e"
|
||||
down_revision: Union[str, None] = "e1db2024739c"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"yifan_wx_pay_order",
|
||||
sa.Column("success_time", sa.DateTime(), nullable=True, comment="支付成功时间"),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column("yifan_wx_pay_order", "success_time")
|
||||
@@ -0,0 +1,32 @@
|
||||
"""add inviter_id to sys_user
|
||||
|
||||
Revision ID: 9c4f1d2a6b7e
|
||||
Revises: 7b2c6f1a9d3e
|
||||
Create Date: 2026-01-15 14:15:00
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "9c4f1d2a6b7e"
|
||||
down_revision: Union[str, None] = "7b2c6f1a9d3e"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"sys_user",
|
||||
sa.Column("inviter_id", sa.Integer(), nullable=True, comment="邀请人ID"),
|
||||
)
|
||||
op.create_index(op.f("ix_sys_user_inviter_id"), "sys_user", ["inviter_id"], unique=False)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index(op.f("ix_sys_user_inviter_id"), table_name="sys_user")
|
||||
op.drop_column("sys_user", "inviter_id")
|
||||
@@ -0,0 +1,115 @@
|
||||
"""add yifan membership tables
|
||||
|
||||
Revision ID: b2f7c1a4e9d3
|
||||
Revises: 9c4f1d2a6b7e
|
||||
Create Date: 2026-04-17 10:00:00
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "b2f7c1a4e9d3"
|
||||
down_revision: Union[str, None] = "9c4f1d2a6b7e"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"yifan_member_discount_config",
|
||||
sa.Column("member_level", sa.String(length=20), nullable=False, comment="会员等级(junior:初级 senior:高级)"),
|
||||
sa.Column("discount_rate", sa.Numeric(5, 2), nullable=False, comment="折扣比例(0.00-1.00)"),
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False, comment="主键ID"),
|
||||
sa.Column("uuid", sa.String(length=64), nullable=False, comment="UUID全局唯一标识"),
|
||||
sa.Column("status", sa.String(length=10), nullable=False, comment="是否启用(0:启用 1:禁用)"),
|
||||
sa.Column("description", sa.Text(), nullable=True, comment="备注/描述"),
|
||||
sa.Column("created_time", sa.DateTime(), nullable=False, comment="创建时间"),
|
||||
sa.Column("updated_time", sa.DateTime(), nullable=False, comment="更新时间"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("member_level", name="uq_yifan_member_discount_level"),
|
||||
sa.UniqueConstraint("uuid"),
|
||||
comment="会员折扣配置",
|
||||
)
|
||||
op.create_table(
|
||||
"yifan_member_account",
|
||||
sa.Column("user_id", sa.Integer(), nullable=False, comment="用户ID"),
|
||||
sa.Column("member_level", sa.String(length=20), nullable=False, comment="会员等级(normal/junior/senior)"),
|
||||
sa.Column("free_rename_quota", sa.Integer(), nullable=False, comment="剩余免费改名名额"),
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False, comment="主键ID"),
|
||||
sa.Column("uuid", sa.String(length=64), nullable=False, comment="UUID全局唯一标识"),
|
||||
sa.Column("status", sa.String(length=10), nullable=False, comment="是否启用(0:启用 1:禁用)"),
|
||||
sa.Column("description", sa.Text(), nullable=True, comment="备注/描述"),
|
||||
sa.Column("created_time", sa.DateTime(), nullable=False, comment="创建时间"),
|
||||
sa.Column("updated_time", sa.DateTime(), nullable=False, comment="更新时间"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("user_id", name="uq_yifan_member_account_user"),
|
||||
sa.UniqueConstraint("uuid"),
|
||||
comment="用户会员账户",
|
||||
)
|
||||
op.create_index(op.f("ix_yifan_member_account_user_id"), "yifan_member_account", ["user_id"], unique=False)
|
||||
|
||||
op.create_table(
|
||||
"yifan_member_daily_detect_usage",
|
||||
sa.Column("user_id", sa.Integer(), nullable=False, comment="用户ID"),
|
||||
sa.Column("usage_date", sa.Date(), nullable=False, comment="使用日期"),
|
||||
sa.Column("used_count", sa.Integer(), nullable=False, comment="已使用次数"),
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False, comment="主键ID"),
|
||||
sa.Column("uuid", sa.String(length=64), nullable=False, comment="UUID全局唯一标识"),
|
||||
sa.Column("status", sa.String(length=10), nullable=False, comment="是否启用(0:启用 1:禁用)"),
|
||||
sa.Column("description", sa.Text(), nullable=True, comment="备注/描述"),
|
||||
sa.Column("created_time", sa.DateTime(), nullable=False, comment="创建时间"),
|
||||
sa.Column("updated_time", sa.DateTime(), nullable=False, comment="更新时间"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("user_id", "usage_date", name="uq_yifan_member_daily_detect"),
|
||||
sa.UniqueConstraint("uuid"),
|
||||
comment="每日检测使用记录",
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_yifan_member_daily_detect_usage_user_id"),
|
||||
"yifan_member_daily_detect_usage",
|
||||
["user_id"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"yifan_member_rename_consume_log",
|
||||
sa.Column("user_id", sa.Integer(), nullable=False, comment="用户ID"),
|
||||
sa.Column("member_level", sa.String(length=20), nullable=False, comment="会员等级"),
|
||||
sa.Column("rename_scene", sa.String(length=20), nullable=False, comment="改名场景(personal/company)"),
|
||||
sa.Column("consume_mode", sa.String(length=20), nullable=False, comment="使用方式(free_quota/discount_pay)"),
|
||||
sa.Column("original_price", sa.Numeric(10, 2), nullable=False, comment="原价"),
|
||||
sa.Column("discount_rate", sa.Numeric(5, 2), nullable=False, comment="实际折扣比例"),
|
||||
sa.Column("payable_price", sa.Numeric(10, 2), nullable=False, comment="应付价格"),
|
||||
sa.Column("operation_time", sa.DateTime(), nullable=False, comment="操作时间"),
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False, comment="主键ID"),
|
||||
sa.Column("uuid", sa.String(length=64), nullable=False, comment="UUID全局唯一标识"),
|
||||
sa.Column("status", sa.String(length=10), nullable=False, comment="是否启用(0:启用 1:禁用)"),
|
||||
sa.Column("description", sa.Text(), nullable=True, comment="备注/描述"),
|
||||
sa.Column("created_time", sa.DateTime(), nullable=False, comment="创建时间"),
|
||||
sa.Column("updated_time", sa.DateTime(), nullable=False, comment="更新时间"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("uuid"),
|
||||
comment="改名权益消费记录",
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_yifan_member_rename_consume_log_user_id"),
|
||||
"yifan_member_rename_consume_log",
|
||||
["user_id"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index(op.f("ix_yifan_member_rename_consume_log_user_id"), table_name="yifan_member_rename_consume_log")
|
||||
op.drop_table("yifan_member_rename_consume_log")
|
||||
op.drop_index(op.f("ix_yifan_member_daily_detect_usage_user_id"), table_name="yifan_member_daily_detect_usage")
|
||||
op.drop_table("yifan_member_daily_detect_usage")
|
||||
op.drop_index(op.f("ix_yifan_member_account_user_id"), table_name="yifan_member_account")
|
||||
op.drop_table("yifan_member_account")
|
||||
op.drop_table("yifan_member_discount_config")
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
"""add yifan member operation log
|
||||
|
||||
Revision ID: c3a9d4f1b2e7
|
||||
Revises: b2f7c1a4e9d3
|
||||
Create Date: 2026-04-17 17:40:00
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "c3a9d4f1b2e7"
|
||||
down_revision: Union[str, None] = "b2f7c1a4e9d3"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"yifan_member_operation_log",
|
||||
sa.Column("user_id", sa.Integer(), nullable=False, comment="用户ID"),
|
||||
sa.Column("operation_type", sa.String(length=20), nullable=False, comment="操作类型(renaming/scoring/naming)"),
|
||||
sa.Column("consume_mode", sa.String(length=20), nullable=False, comment="使用方式(free_quota/discount_pay)"),
|
||||
sa.Column("operation_time", sa.DateTime(), nullable=False, comment="操作时间"),
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False, comment="主键ID"),
|
||||
sa.Column("uuid", sa.String(length=64), nullable=False, comment="UUID全局唯一标识"),
|
||||
sa.Column("status", sa.String(length=10), nullable=False, comment="是否启用(0:启用 1:禁用)"),
|
||||
sa.Column("description", sa.Text(), nullable=True, comment="备注/描述"),
|
||||
sa.Column("created_time", sa.DateTime(), nullable=False, comment="创建时间"),
|
||||
sa.Column("updated_time", sa.DateTime(), nullable=False, comment="更新时间"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("uuid"),
|
||||
comment="会员操作记录",
|
||||
)
|
||||
op.create_index(op.f("ix_yifan_member_operation_log_user_id"), "yifan_member_operation_log", ["user_id"], unique=False)
|
||||
op.create_index(
|
||||
op.f("ix_yifan_member_operation_log_operation_type"),
|
||||
"yifan_member_operation_log",
|
||||
["operation_type"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_yifan_member_operation_log_consume_mode"),
|
||||
"yifan_member_operation_log",
|
||||
["consume_mode"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_yifan_member_operation_log_operation_time"),
|
||||
"yifan_member_operation_log",
|
||||
["operation_time"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index(op.f("ix_yifan_member_operation_log_operation_time"), table_name="yifan_member_operation_log")
|
||||
op.drop_index(op.f("ix_yifan_member_operation_log_consume_mode"), table_name="yifan_member_operation_log")
|
||||
op.drop_index(op.f("ix_yifan_member_operation_log_operation_type"), table_name="yifan_member_operation_log")
|
||||
op.drop_index(op.f("ix_yifan_member_operation_log_user_id"), table_name="yifan_member_operation_log")
|
||||
op.drop_table("yifan_member_operation_log")
|
||||
@@ -0,0 +1,48 @@
|
||||
"""add yifan member service price config
|
||||
|
||||
Revision ID: d4f8b2c1a9e6
|
||||
Revises: c3a9d4f1b2e7
|
||||
Create Date: 2026-04-17 18:30:00
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "d4f8b2c1a9e6"
|
||||
down_revision: Union[str, None] = "c3a9d4f1b2e7"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"yifan_member_service_price_config",
|
||||
sa.Column("service_type", sa.String(length=30), nullable=False, comment="服务类型(naming/renaming/daily_fortune/monthly_fortune)"),
|
||||
sa.Column("price", sa.Numeric(10, 2), nullable=False, comment="费用"),
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False, comment="主键ID"),
|
||||
sa.Column("uuid", sa.String(length=64), nullable=False, comment="UUID全局唯一标识"),
|
||||
sa.Column("status", sa.String(length=10), nullable=False, comment="是否启用(0:启用 1:禁用)"),
|
||||
sa.Column("description", sa.Text(), nullable=True, comment="备注/描述"),
|
||||
sa.Column("created_time", sa.DateTime(), nullable=False, comment="创建时间"),
|
||||
sa.Column("updated_time", sa.DateTime(), nullable=False, comment="更新时间"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("service_type", name="uq_yifan_member_service_price_type"),
|
||||
sa.UniqueConstraint("uuid"),
|
||||
comment="会员服务价格配置",
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_yifan_member_service_price_config_service_type"),
|
||||
"yifan_member_service_price_config",
|
||||
["service_type"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index(op.f("ix_yifan_member_service_price_config_service_type"), table_name="yifan_member_service_price_config")
|
||||
op.drop_table("yifan_member_service_price_config")
|
||||
@@ -0,0 +1,142 @@
|
||||
"""迁移脚本
|
||||
|
||||
Revision ID: e1db2024739c
|
||||
Revises:
|
||||
Create Date: 2025-12-22 17:27:01.532822
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'e1db2024739c'
|
||||
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:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('miniapp_user',
|
||||
sa.Column('openid', sa.String(length=64), nullable=False, comment='微信openid'),
|
||||
sa.Column('unionid', sa.String(length=64), nullable=True, comment='微信unionid'),
|
||||
sa.Column('session_key', sa.String(length=64), nullable=True, comment='会话密钥'),
|
||||
sa.Column('nickname', sa.String(length=64), nullable=True, comment='昵称'),
|
||||
sa.Column('avatar', sa.String(length=512), nullable=True, comment='头像URL'),
|
||||
sa.Column('phone', sa.String(length=20), nullable=True, comment='手机号'),
|
||||
sa.Column('last_login', sa.DateTime(timezone=True), nullable=True, comment='最后登录时间'),
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='主键ID'),
|
||||
sa.Column('uuid', sa.String(length=64), nullable=False, comment='UUID全局唯一标识'),
|
||||
sa.Column('status', sa.String(length=10), nullable=False, comment='是否启用(0:启用 1:禁用)'),
|
||||
sa.Column('description', sa.Text(), nullable=True, comment='备注/描述'),
|
||||
sa.Column('created_time', sa.DateTime(), nullable=False, comment='创建时间'),
|
||||
sa.Column('updated_time', sa.DateTime(), nullable=False, comment='更新时间'),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('unionid'),
|
||||
sa.UniqueConstraint('uuid'),
|
||||
comment='小程序用户表'
|
||||
)
|
||||
op.create_index(op.f('ix_miniapp_user_openid'), 'miniapp_user', ['openid'], unique=True)
|
||||
op.drop_index('ix_apscheduler_jobs_next_run_time', table_name='apscheduler_jobs')
|
||||
op.drop_table('apscheduler_jobs')
|
||||
op.alter_column('gen_table_column', 'is_pk',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text('false'),
|
||||
existing_comment='是否主键',
|
||||
existing_nullable=False)
|
||||
op.alter_column('gen_table_column', 'is_increment',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text('false'),
|
||||
existing_comment='是否自增',
|
||||
existing_nullable=False)
|
||||
op.alter_column('gen_table_column', 'is_nullable',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text('true'),
|
||||
existing_comment='是否允许为空',
|
||||
existing_nullable=False)
|
||||
op.alter_column('gen_table_column', 'is_unique',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text('false'),
|
||||
existing_comment='是否唯一',
|
||||
existing_nullable=False)
|
||||
op.alter_column('gen_table_column', 'is_insert',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text('true'),
|
||||
existing_comment='是否为新增字段',
|
||||
existing_nullable=False)
|
||||
op.alter_column('gen_table_column', 'is_edit',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text('true'),
|
||||
existing_comment='是否编辑字段',
|
||||
existing_nullable=False)
|
||||
op.alter_column('gen_table_column', 'is_list',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text('true'),
|
||||
existing_comment='是否列表字段',
|
||||
existing_nullable=False)
|
||||
op.alter_column('gen_table_column', 'is_query',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text('false'),
|
||||
existing_comment='是否查询字段',
|
||||
existing_nullable=False)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.alter_column('gen_table_column', 'is_query',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text("'0'"),
|
||||
existing_comment='是否查询字段',
|
||||
existing_nullable=False)
|
||||
op.alter_column('gen_table_column', 'is_list',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text("'1'"),
|
||||
existing_comment='是否列表字段',
|
||||
existing_nullable=False)
|
||||
op.alter_column('gen_table_column', 'is_edit',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text("'1'"),
|
||||
existing_comment='是否编辑字段',
|
||||
existing_nullable=False)
|
||||
op.alter_column('gen_table_column', 'is_insert',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text("'1'"),
|
||||
existing_comment='是否为新增字段',
|
||||
existing_nullable=False)
|
||||
op.alter_column('gen_table_column', 'is_unique',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text("'0'"),
|
||||
existing_comment='是否唯一',
|
||||
existing_nullable=False)
|
||||
op.alter_column('gen_table_column', 'is_nullable',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text("'1'"),
|
||||
existing_comment='是否允许为空',
|
||||
existing_nullable=False)
|
||||
op.alter_column('gen_table_column', 'is_increment',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text("'0'"),
|
||||
existing_comment='是否自增',
|
||||
existing_nullable=False)
|
||||
op.alter_column('gen_table_column', 'is_pk',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
server_default=sa.text("'0'"),
|
||||
existing_comment='是否主键',
|
||||
existing_nullable=False)
|
||||
op.create_table('apscheduler_jobs',
|
||||
sa.Column('id', mysql.VARCHAR(length=191), nullable=False),
|
||||
sa.Column('next_run_time', mysql.DOUBLE(asdecimal=True), nullable=True),
|
||||
sa.Column('job_state', sa.BLOB(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
mysql_collate='utf8mb4_0900_ai_ci',
|
||||
mysql_default_charset='utf8mb4',
|
||||
mysql_engine='InnoDB'
|
||||
)
|
||||
op.create_index('ix_apscheduler_jobs_next_run_time', 'apscheduler_jobs', ['next_run_time'], unique=False)
|
||||
op.drop_index(op.f('ix_miniapp_user_openid'), table_name='miniapp_user')
|
||||
op.drop_table('miniapp_user')
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,52 @@
|
||||
"""add yifan member daily naming rename usage
|
||||
|
||||
Revision ID: f1e2d3c4b5a6
|
||||
Revises: d4f8b2c1a9e6
|
||||
Create Date: 2026-04-18 12:00:00
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "f1e2d3c4b5a6"
|
||||
down_revision: Union[str, None] = "d4f8b2c1a9e6"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"yifan_member_daily_naming_rename_usage",
|
||||
sa.Column("user_id", sa.Integer(), nullable=False, comment="用户ID"),
|
||||
sa.Column("usage_date", sa.Date(), nullable=False, comment="使用日期"),
|
||||
sa.Column("used_count", sa.Integer(), nullable=False, comment="当日已使用次数(0/1)"),
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False, comment="主键ID"),
|
||||
sa.Column("uuid", sa.String(length=64), nullable=False, comment="UUID全局唯一标识"),
|
||||
sa.Column("status", sa.String(length=10), nullable=False, comment="是否启用(0:启用 1:禁用)"),
|
||||
sa.Column("description", sa.Text(), nullable=True, comment="备注/描述"),
|
||||
sa.Column("created_time", sa.DateTime(), nullable=False, comment="创建时间"),
|
||||
sa.Column("updated_time", sa.DateTime(), nullable=False, comment="更新时间"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("user_id", "usage_date", name="uq_yifan_member_daily_naming_rename"),
|
||||
sa.UniqueConstraint("uuid"),
|
||||
comment="每日起名改名共用名额",
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_yifan_member_daily_naming_rename_usage_user_id"),
|
||||
"yifan_member_daily_naming_rename_usage",
|
||||
["user_id"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index(
|
||||
op.f("ix_yifan_member_daily_naming_rename_usage_user_id"),
|
||||
table_name="yifan_member_daily_naming_rename_usage",
|
||||
)
|
||||
op.drop_table("yifan_member_daily_naming_rename_usage")
|
||||
Reference in New Issue
Block a user