perf: 新增数据库迁移doc说明文档,优化datetime字段平滑迁移

This commit is contained in:
xiaojunnuo
2025-12-09 00:45:10 +08:00
parent ff7006e232
commit 45fbce0c2a
15 changed files with 74 additions and 5 deletions
+50 -5
View File
@@ -65,9 +65,54 @@ docker-compose up -d
## 二、从旧版的sqlite切换数据库
1. 先将`旧certd`升级到最新版 `建议:备份sqlite数据库`
2. 按照上面全新安装方式部署一套`新的certd` `注意:新旧版本的certd要一致`
3. 使用数据库工具将数据从sqlite导入到mysql或postgresql `注意:flyway_history数据表不要导入`
4. 重启新certd
5. 确认没有问题之后,删除旧版certd
从旧版`sqlite`迁移到`mysql``postgresql`数据库
下面以 `SQLite``MySQL` 为例进行演示
![db-0.png](images/db-0.png)
#### 0.前提条件:
1. SQLite版Certd站点已经`升级到最新版` `建议:备份sqlite数据库`
2. `全新安装`MySQL版本Certd`确保是全新的,因为里面的数据会被清空覆盖`
3. 两套Certd站点版本一致
#### 1. 安装DBeaver工具
[https://dbeaver.io/download/](https://dbeaver.io/download/)
![db-1.png](images/db-1.png)
#### 2. 连接到sqlite数据库
![db-2.png](images/db-sqlite-1.png)
![db-3.png](images/db-sqlite-2.png)
#### 3. 连接到mysql或postgresql数据库
![db-4.png](images/db-mysql-1.png)
![db-5.png](images/db-mysql-2.png)
#### 4. 开始同步数据
选择mysql数据库,选择所有的表(`flyway_history除外`),右键导入数据
> 切记flyway_history数据表不要导入
![db-6.png](images/db-sync-1.jpg)
![db-7.png](images/db-sync-2.png)
![db-8.png](images/db-sync-3.png)
下一步、下一步,直到数据加载设置,勾选`在加载前截断目标表`(此选项很重要,并且会清空mysql certd数据库中的数据)
![db-7.png](images/db-sync-4.png)
#### 5. 导入完成
![db-9.png](images/db-success.png)
#### 6. 重启MySQL版本Certd
访问MySQL版本测试,数据已成功迁移
确认没有问题之后,删除旧版certd
Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

@@ -0,0 +1,2 @@
ALTER TABLE `sys_settings` MODIFY COLUMN `setting` longtext NULL;
ALTER TABLE `user_settings` MODIFY COLUMN `setting` longtext NULL;
@@ -0,0 +1,2 @@
alter table sys_settings alter column setting type text using setting::text;
alter table user_settings alter column setting type text using setting::text;
@@ -0,0 +1,20 @@
update cd_access set create_time = "2024-08-08 00:00:00.000" where create_time < '999999999999999999999';
update cd_access set update_time = "2024-08-08 00:00:00.000" where update_time < '999999999999999999999';
update pi_history set create_time = "2024-08-08 00:00:00.000" where create_time < '999999999999999999999';
update pi_history set update_time = "2024-08-08 00:00:00.000" where update_time < '999999999999999999999';
update pi_history_log set create_time = "2024-08-08 00:00:00.000" where create_time < '999999999999999999999';
update pi_history_log set update_time = "2024-08-08 00:00:00.000" where update_time < '999999999999999999999';
update pi_pipeline set create_time = "2024-08-08 00:00:00.000" where create_time < '999999999999999999999';
update pi_pipeline set update_time = "2024-08-08 00:00:00.000" where update_time < '999999999999999999999';
update sys_permission set create_time = "2024-08-08 00:00:00.000" where create_time < '999999999999999999999';
update sys_permission set update_time = "2024-08-08 00:00:00.000" where update_time < '999999999999999999999';
update sys_role set create_time = "2024-08-08 00:00:00.000" where create_time < '999999999999999999999';
update sys_role set update_time = "2024-08-08 00:00:00.000" where update_time < '999999999999999999999';
update sys_user set create_time = "2024-08-08 00:00:00.000" where create_time < '999999999999999999999';
update sys_user set update_time = "2024-08-08 00:00:00.000" where update_time < '999999999999999999999';