From 7293f5ac66d9fa43dc3ec79813f7d19558d460b3 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 7 Feb 2022 16:42:46 +0800 Subject: [PATCH 1/3] No longer show the db-downgrade SQL in production --- models/migrations/migrations.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 5aaf283bd39fa..be357b52b65c8 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -450,9 +450,12 @@ Please try upgrading to a lower version first (suggested v1.6.4), then upgrade t // Downgrading Gitea's database version not supported if int(v-minDBVersion) > len(migrations) { - msg := fmt.Sprintf("Downgrading database version from '%d' to '%d' is not supported and may result in loss of data integrity.\nIf you really know what you're doing, execute `UPDATE version SET version=%d WHERE id=1;`\n", - v, minDBVersion+len(migrations), minDBVersion+len(migrations)) - fmt.Fprint(os.Stderr, msg) + msg := fmt.Sprintf("Your database (migration version: %d) is for a newer Gita, you can not use the newer database for this old Gitea release (%d).", v, minDBVersion+len(migrations)) + msg += "\nForcing setting the migration version to a lower number may result in loss of data integrity." + if !setting.IsProd { + msg += "\n" + fmt.Sprintf("If you are in development and really know what you're doing, you can force changing the migration version by executing: UPDATE version SET version=%d WHERE id=1;\n", minDBVersion+len(migrations)) + } + _, _ = fmt.Fprintln(os.Stderr, msg) log.Fatal(msg) return nil } From 4220398ff26939663cf5cadab2bb76367275e805 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 7 Feb 2022 17:17:12 +0800 Subject: [PATCH 2/3] Update models/migrations/migrations.go --- models/migrations/migrations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index be357b52b65c8..3cf19d9bdf234 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -453,7 +453,7 @@ Please try upgrading to a lower version first (suggested v1.6.4), then upgrade t msg := fmt.Sprintf("Your database (migration version: %d) is for a newer Gita, you can not use the newer database for this old Gitea release (%d).", v, minDBVersion+len(migrations)) msg += "\nForcing setting the migration version to a lower number may result in loss of data integrity." if !setting.IsProd { - msg += "\n" + fmt.Sprintf("If you are in development and really know what you're doing, you can force changing the migration version by executing: UPDATE version SET version=%d WHERE id=1;\n", minDBVersion+len(migrations)) + msg += fmt.Sprintf("\nIf you are in development and really know what you're doing, you can force changing the migration version by executing: UPDATE version SET version=%d WHERE id=1;\n", minDBVersion+len(migrations)) } _, _ = fmt.Fprintln(os.Stderr, msg) log.Fatal(msg) From 587446b63020c0ebb0582a61b3f8c5ee56e95efd Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 7 Feb 2022 17:32:39 +0800 Subject: [PATCH 3/3] make messages more friendly --- models/migrations/migrations.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 3cf19d9bdf234..0aa9c7c7ea45f 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -451,9 +451,9 @@ Please try upgrading to a lower version first (suggested v1.6.4), then upgrade t // Downgrading Gitea's database version not supported if int(v-minDBVersion) > len(migrations) { msg := fmt.Sprintf("Your database (migration version: %d) is for a newer Gita, you can not use the newer database for this old Gitea release (%d).", v, minDBVersion+len(migrations)) - msg += "\nForcing setting the migration version to a lower number may result in loss of data integrity." + msg += "\nGitea will exit to keep your database safe and unchanged. Please use the correct Gitea release, do not change the migration version manually (incorrect manual operation may lose data)." if !setting.IsProd { - msg += fmt.Sprintf("\nIf you are in development and really know what you're doing, you can force changing the migration version by executing: UPDATE version SET version=%d WHERE id=1;\n", minDBVersion+len(migrations)) + msg += fmt.Sprintf("\nIf you are in development and really know what you're doing, you can force changing the migration version by executing: UPDATE version SET version=%d WHERE id=1;", minDBVersion+len(migrations)) } _, _ = fmt.Fprintln(os.Stderr, msg) log.Fatal(msg)