Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Apply 'nightly' idempotent silent upgrade semantics to 'rc' and 'beta' also.

Kailash Nadh6a59d7b3457e
diff --git a/cmd/main.go b/cmd/main.go
index bbc561dd..fc250b50 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -144,17 +144,23 @@ func init() {
// Initialize the embedded filesystem with static assets.
fs = initFS(appDir, ko.String("static-dir"), ko.String("i18n-dir"))
+ isNonFinal := isNonFinalBuild(versionString)
+
// Installer mode? This runs before the SQL queries are loaded and prepared
// as the installer needs to work on an empty DB.
if ko.Bool("install") {
- // Save the version of the last listed migration.
- install(migList[len(migList)-1].version, db, fs, !ko.Bool("yes"), ko.Bool("idempotent"))
+ // For non-final builds, record the last final version only in the DB
+ // so that ephemeral non-final builds (eg: vX-beta.1, beta.2 etc.) run
+ // everytime but don't get recorded.
+ last := len(migList) - 1
+ if isNonFinal {
+ last--
+ }
+
+ install(migList[last].version, db, fs, !ko.Bool("yes"), ko.Bool("idempotent"))
os.Exit(0)
}
- // Is this a nightly build?
- isNightly := strings.Contains(versionString, "nightly")
-
// Check if the DB schema is installed.
if ok, err := checkSchema(db); err != nil {
log.Fatalf("error checking schema in DB: %v", err)
@@ -163,18 +169,18 @@ func init() {
}
if ko.Bool("upgrade") {
- // Even on explicit upgrade runs, for nightly builds, do not record the last
+ // Even on explicit upgrade runs, for unstable builds, do not record the last
// migration version in the DB.
lo.Printf("running upgrade...")
- upgrade(db, fs, !ko.Bool("yes"), !isNightly)
+ upgrade(db, fs, !ko.Bool("yes"), !isNonFinal)
os.Exit(0)
}
- // For nightly builds, always auto-run pending migrations without
+ // For nightly, beta, and RC builds, always auto-run pending migrations without
// recording the last version in the DB. Migrations are idempotent, and between
- // nightly releases, they may change multiple times.
- if isNightly {
- lo.Printf("auto-running all migrations for nightly %s since last major version", versionString)
+ // non-final releases, they may change multiple times.
+ if isNonFinal {
+ lo.Printf("auto-running pending migrations for non-final build %s", versionString)
upgrade(db, fs, false, false)
} else {
// Before the queries are prepared, see if there are pending upgrades.
diff --git a/cmd/upgrade.go b/cmd/upgrade.go
index 08ff8971..22b6548f 100644
--- a/cmd/upgrade.go
+++ b/cmd/upgrade.go
@@ -50,7 +50,7 @@ var migList = []migFunc{
// upgrade upgrades the database to the current version by running SQL migration files
// for all version from the last known version to the current one.
-// If record is false, migration versions are not recorded in the DB (used for nightly builds).
+// If record is false, migration versions are not recorded in the DB (used for non-final builds).
func upgrade(db *sqlx.DB, fs stuffbin.FileSystem, prompt bool, record bool) {
if prompt {
var ok string
@@ -85,7 +85,7 @@ func upgrade(db *sqlx.DB, fs stuffbin.FileSystem, prompt bool, record bool) {
// Record the migration version in the settings table. There was no
// settings table until v0.7.0, so ignore the no-table errors.
- // For nightly builds, skip recording so migrations re-run on each boot.
+ // For non-final builds, skip recording so migrations re-run on each boot.
if record {
if err := recordMigrationVersion(m.version, db); err != nil {
if isTableNotExistErr(err) {
@@ -169,3 +169,12 @@ func isTableNotExistErr(err error) bool {
}
return false
}
+
+// isNonFinalBuild checks whether migrations may change between builds (nightly, RC, beta).
+// This is used to decide whether to run upgrades automatically on boot and not record
+// the non-release versions in the table so that when the actual release is out, the
+// migrations are applied correctly + the final version is recorded in the table.
+func isNonFinalBuild(version string) bool {
+ pre := semver.Prerelease(version)
+ return strings.Contains(version, "nightly") || strings.HasPrefix(pre, "-beta") || strings.HasPrefix(pre, "-rc")
+}