Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
customer-recall
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tools
customer-recall
Commits
49954751
Commit
49954751
authored
Sep 10, 2025
by
luoqi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:数据库备份方案
parent
8d193eaa
Pipeline
#3228
passed with stage
in 1 minute 27 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
39 deletions
+2
-39
Dockerfile
+1
-0
database/scripts/migration_manager.py
+1
-39
No files found.
Dockerfile
View file @
49954751
...
...
@@ -13,6 +13,7 @@ ENV FLASK_ENV=production
RUN
apt-get update
&&
apt-get install
-y
\
gcc
\
default-libmysqlclient-dev
\
default-mysql-client
\
pkg-config
\
&&
rm
-rf
/var/lib/apt/lists/
*
...
...
database/scripts/migration_manager.py
View file @
49954751
...
...
@@ -9,7 +9,6 @@ import os
import
sys
import
subprocess
from
pathlib
import
Path
from
datetime
import
datetime
# 添加项目根目录到Python路径
project_root
=
Path
(
__file__
)
.
parent
.
parent
.
parent
...
...
@@ -81,23 +80,7 @@ def generate_migration(message="Auto migration"):
os
.
environ
[
'FLASK_APP'
]
=
'app.py'
return
run_command
(
f
'flask db migrate -m "{message}"'
,
'生成迁移文件'
)
def
backup_database
():
"""备份数据库到database/backups目录"""
print
(
"📦 备份数据库..."
)
# 确保备份目录存在
backup_dir
=
project_root
/
"database"
/
"backups"
backup_dir
.
mkdir
(
exist_ok
=
True
)
# 生成带时间戳的备份文件名
timestamp
=
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d_
%
H
%
M
%
S"
)
backup_file
=
backup_dir
/
f
"backup_before_migration_{timestamp}.sql"
# 构建备份命令
backup_command
=
f
"mysqldump -h mysql -u callback_user -pdev_password_123 callback_system > {backup_file}"
print
(
f
"📁 备份文件: {backup_file}"
)
return
run_command
(
backup_command
,
f
"备份数据库到 {backup_file.name}"
)
def
upgrade_database
():
"""执行数据库迁移"""
...
...
@@ -128,17 +111,7 @@ def check_alembic_version_table():
print
(
f
"⚠️ 检查alembic_version表失败: {e}"
)
return
False
def
backup_only
():
"""仅执行数据库备份"""
print
(
"🚀 数据库备份工具启动"
)
print
(
f
"📍 项目根目录: {project_root}"
)
if
backup_database
():
print
(
"🎉 数据库备份完成"
)
return
True
else
:
print
(
"❌ 数据库备份失败"
)
return
False
def
main
():
"""主函数 - 完整的迁移流程"""
...
...
@@ -168,14 +141,7 @@ def main():
# 步骤4: 获取当前状态
get_current_revision
()
# 步骤4.5: 备份数据库(在迁移前)
print
(
"🔄 迁移前备份数据库..."
)
if
not
backup_database
():
print
(
"❌ 数据库备份失败,取消迁移"
)
return
False
print
(
"✅ 数据库备份完成"
)
# 步骤5: 执行迁移
# 步骤4.5: 执行迁移
if
not
upgrade_database
():
print
(
"❌ 数据库迁移失败"
)
return
False
...
...
@@ -184,9 +150,5 @@ def main():
return
True
if
__name__
==
'__main__'
:
# 检查命令行参数
if
len
(
sys
.
argv
)
>
1
and
sys
.
argv
[
1
]
==
'backup'
:
success
=
backup_only
()
else
:
success
=
main
()
sys
.
exit
(
0
if
success
else
1
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment