重构项目结构
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
数据库迁移脚本:将销售订单中的日期字段从 TIMESTAMP 改为 DATE 类型
|
||||
"""
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
project_root = Path(__file__).parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
sys.path.insert(0, str(project_root / "src"))
|
||||
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from sqlalchemy import text
|
||||
from config.settings import settings
|
||||
|
||||
|
||||
async def migrate():
|
||||
"""执行数据库迁移"""
|
||||
if not settings.DATABASE_URL:
|
||||
print("错误:未配置数据库连接")
|
||||
return
|
||||
|
||||
engine = create_async_engine(
|
||||
settings.DATABASE_URL,
|
||||
echo=True
|
||||
)
|
||||
|
||||
async with engine.begin() as conn:
|
||||
# 修改日期字段类型
|
||||
alter_sql = """
|
||||
ALTER TABLE sales_orders
|
||||
ALTER COLUMN delivery_date TYPE DATE,
|
||||
ALTER COLUMN manufacturing_date TYPE DATE,
|
||||
ALTER COLUMN actual_delivery_date TYPE DATE,
|
||||
ALTER COLUMN actual_payment_date TYPE DATE
|
||||
"""
|
||||
await conn.execute(text(alter_sql))
|
||||
print("成功将销售订单的日期字段类型改为 DATE")
|
||||
|
||||
await engine.dispose()
|
||||
print("迁移完成")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(migrate())
|
||||
Reference in New Issue
Block a user