MCPcopy Index your code
hub / github.com/vastsa/FileCodeBox / init_db

Function init_db

core/database.py:80–102  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

78
79
80async def init_db():
81 try:
82 db_config = get_db_config()
83
84 if not Tortoise._inited:
85 await Tortoise.init(config=db_config)
86
87 async with db_startup_lock():
88 # 创建migrations表
89 await Tortoise.get_connection("default").execute_script("""
90 CREATE TABLE IF NOT EXISTS migrates (
91 id INTEGER PRIMARY KEY AUTOINCREMENT,
92 migration_file VARCHAR(255) NOT NULL UNIQUE,
93 executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
94 )
95 """)
96
97 # 执行迁移
98 await execute_migrations()
99
100 except Exception as e:
101 logger.error(f"数据库初始化失败: {str(e)}")
102 raise
103
104
105async def execute_migrations():

Callers 1

lifespanFunction · 0.90

Calls 3

get_db_configFunction · 0.85
db_startup_lockFunction · 0.85
execute_migrationsFunction · 0.85

Tested by

no test coverage detected