初始化数据库
(self)
| 137 | return False |
| 138 | |
| 139 | def initialize_database(self) -> bool: |
| 140 | """初始化数据库""" |
| 141 | logger.info("初始化数据库...") |
| 142 | |
| 143 | try: |
| 144 | # 运行数据库初始化脚本 |
| 145 | init_script = self.schema_path / "init_database.py" |
| 146 | if not init_script.exists(): |
| 147 | logger.error("错误:找不到数据库初始化脚本") |
| 148 | return False |
| 149 | |
| 150 | result = subprocess.run( |
| 151 | [sys.executable, str(init_script)], |
| 152 | cwd=self.schema_path, |
| 153 | capture_output=True, |
| 154 | text=True |
| 155 | ) |
| 156 | |
| 157 | if result.returncode == 0: |
| 158 | logger.info("数据库初始化成功") |
| 159 | return True |
| 160 | else: |
| 161 | logger.error(f"数据库初始化失败: {result.stderr}") |
| 162 | return False |
| 163 | |
| 164 | except Exception as e: |
| 165 | logger.exception(f"数据库初始化异常: {e}") |
| 166 | return False |
| 167 | |
| 168 | def check_dependencies(self) -> bool: |
| 169 | """检查依赖环境""" |
no test coverage detected