新增统一项目根实体及三库迁移并验证项目备份恢复
This commit is contained in:
1 parent
adb7d7f536
commit
6b72ac2e20
20 files changed
+846
-4
No files matched your search
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/config"
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/database"
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/domain"
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/repository"
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/secretstore"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
@@ -82,6 +83,7 @@ func TestSQLiteBusinessUpgradeStandaloneCLI(t *testing.T) {
|
||||
runSQLiteProductCLI(t, binary, fixture, "backup", "--output", archive)
|
||||
runSQLiteProductCLI(t, binary, fixture, "certificate", "list")
|
||||
assertSQLiteCLIUpgradeUsable(t, fixture)
|
||||
createSQLiteProjectForBackup(t, fixture)
|
||||
upgraded := snapshotSQLiteCLIState(t, *cfg)
|
||||
currentArchive := filepath.Join(t.TempDir(), "upgraded-backup")
|
||||
runSQLiteProductCLI(t, binary, fixture, "backup", "--output", currentArchive)
|
||||
@@ -99,6 +101,10 @@ func TestSQLiteBusinessUpgradeStandaloneCLI(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := current.DB.ExecContext(t.Context(), "UPDATE projects SET name = ?", "待恢复的项目名称"); err != nil {
|
||||
_ = current.Close()
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := current.DB.ExecContext(t.Context(), "UPDATE tasks SET message = '不应保留'; DELETE FROM domain_servers"); err != nil {
|
||||
_ = current.Close()
|
||||
t.Fatal(err)
|
||||
@@ -130,6 +136,19 @@ func TestSQLiteBusinessUpgradeStandaloneCLI(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func createSQLiteProjectForBackup(t *testing.T, fixture sqliteBusinessFixture) {
|
||||
t.Helper()
|
||||
db, err := database.Open(t.Context(), fixture.config.Database)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
item := domain.Project{ID: "backup-project", Name: "独立程序备份项目", Description: "恢复时必须保留的项目说明"}
|
||||
if err := repository.NewSQLProjectRepository(db.DB).CreateProject(t.Context(), item); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func runSQLiteProductCLI(t *testing.T, binary string, fixture sqliteBusinessFixture, args ...string) {
|
||||
t.Helper()
|
||||
ctx, cancel := context.WithTimeout(t.Context(), 30*time.Second)
|
||||
@@ -199,9 +218,13 @@ func assertSQLiteCLIUpgradeUsable(t *testing.T, fixture sqliteBusinessFixture) {
|
||||
}
|
||||
defer db.Close()
|
||||
var version, bindings int
|
||||
if err := db.DB.QueryRowContext(t.Context(), "SELECT MAX(version) FROM schema_migrations").Scan(&version); err != nil || version != 9 {
|
||||
if err := db.DB.QueryRowContext(t.Context(), "SELECT MAX(version) FROM schema_migrations").Scan(&version); err != nil || version != 10 {
|
||||
t.Fatalf("正式应用入口未完成历史升级:%d,%v", version, err)
|
||||
}
|
||||
project, err := repository.NewSQLProjectRepository(db.DB).GetProject(t.Context(), domain.DefaultProjectID)
|
||||
if err != nil || project.Name != "默认项目" {
|
||||
t.Fatalf("正式应用入口未保留默认项目:%+v,%v", project, err)
|
||||
}
|
||||
task, err := repository.NewSQLTaskRepository(db.DB).GetTask(t.Context(), "task")
|
||||
if err != nil || task.Message != "历史任务" || task.DomainID != "domain" || task.Status != "success" {
|
||||
t.Fatalf("历史任务不可用:%v", err)
|
||||
|
||||
Reference in new issue
Block a user