28 lines
872 B
Python
28 lines
872 B
Python
from flask_prompt_master import create_app, db
|
|
from flask_prompt_master.models import PromptTemplate
|
|
import pymysql
|
|
|
|
def migrate_to_mysql():
|
|
"""迁移数据到MySQL"""
|
|
app = create_app()
|
|
|
|
with app.app_context():
|
|
# 创建所有表
|
|
db.create_all()
|
|
|
|
try:
|
|
# 检查是否已有数据
|
|
if PromptTemplate.query.first() is None:
|
|
# 执行init_db中的初始化
|
|
from flask_prompt_master.init_db import init_db
|
|
init_db()
|
|
print("模板数据迁移完成!")
|
|
else:
|
|
print("数据库中已存在模板数据,跳过迁移。")
|
|
|
|
except Exception as e:
|
|
print(f"迁移过程中出错: {str(e)}")
|
|
db.session.rollback()
|
|
|
|
if __name__ == '__main__':
|
|
migrate_to_mysql() |