You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ly...@apache.org on 2024/06/25 12:23:36 UTC
(incubator-devlake) branch dev0625-2 created (now 96bbc380d)
This is an automated email from the ASF dual-hosted git repository.
lynwee pushed a change to branch dev0625-2
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
at 96bbc380d fix(migrator): save migration script before executing it
This branch includes the following new commits:
new 96bbc380d fix(migrator): save migration script before executing it
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(incubator-devlake) 01/01: fix(migrator): save migration script before executing it
Posted by ly...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lynwee pushed a commit to branch dev0625-2
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit 96bbc380d472546cd119211689961e671333dc5e
Author: d4x1 <15...@qq.com>
AuthorDate: Tue Jun 25 20:23:25 2024 +0800
fix(migrator): save migration script before executing it
---
backend/core/migration/migrator.go | 20 +++++++++++++++-----
backend/server/services/init.go | 2 +-
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/backend/core/migration/migrator.go b/backend/core/migration/migrator.go
index d60c9b8f9..14dce1f2d 100644
--- a/backend/core/migration/migrator.go
+++ b/backend/core/migration/migrator.go
@@ -97,18 +97,28 @@ func (m *migratorImpl) Execute() errors.Error {
for _, swc := range m.pending {
scriptId := getScriptId(swc.script.Name(), swc.script.Version())
m.logger.Info("applying migration script %s", scriptId)
- err := swc.script.Up(m.basicRes)
- if err != nil {
- return err
- }
- err = db.Create(&MigrationHistory{
+ tx := db.Begin()
+ err := db.Create(&MigrationHistory{
ScriptVersion: swc.script.Version(),
ScriptName: swc.script.Name(),
Comment: swc.comment,
})
if err != nil {
+ if err := tx.Rollback(); err != nil {
+ return err
+ }
return errors.Default.Wrap(err, fmt.Sprintf("failed to execute migration script %s", scriptId))
}
+
+ if err := swc.script.Up(m.basicRes); err != nil {
+ if err := tx.Rollback(); err != nil {
+ return err
+ }
+ return err
+ }
+ if err := tx.Commit(); err != nil {
+ return err
+ }
m.executed[scriptId] = true
m.pending = m.pending[1:]
}
diff --git a/backend/server/services/init.go b/backend/server/services/init.go
index e75af65bf..fb32bb8ee 100644
--- a/backend/server/services/init.go
+++ b/backend/server/services/init.go
@@ -96,7 +96,7 @@ func registerPluginsMigrationScripts() {
func InitExecuteMigration() {
// check if there are pending migration
- logger.Info("has pending scripts? %v, FORCE_MIGRATION: %s", migrator.HasPendingScripts(), cfg.GetBool("FORCE_MIGRATION"))
+ logger.Info("has pending scripts? %v, FORCE_MIGRATION: %v", migrator.HasPendingScripts(), cfg.GetBool("FORCE_MIGRATION"))
if migrator.HasPendingScripts() {
if cfg.GetBool("FORCE_MIGRATION") {
errors.Must(ExecuteMigration())