diff --git a/migrations.go b/migrations.go index 7df18890..e02c5b8e 100644 --- a/migrations.go +++ b/migrations.go @@ -86,6 +86,15 @@ var migrations = []Migration{ Name: "repair_webhook_use_proxy", UpSQL: repairWebhookUseProxySQL, }, + { + // wmiau.go reads days_to_sync_history when deciding how much history + // to request on connect, but no migration ever creates the column, so + // on a fresh install the query fails and the feature silently never + // runs (it only logs a warning and falls through to 0). + ID: 13, + Name: "add_days_to_sync_history", + UpSQL: addDaysToSyncHistorySQL, + }, } const changeIDToStringSQL = ` @@ -255,6 +264,17 @@ const repairWebhookUseProxySQL = ` ALTER TABLE users ADD COLUMN IF NOT EXISTS webhook_use_proxy BOOLEAN DEFAULT TRUE; ` +const addDaysToSyncHistorySQL = ` +-- PostgreSQL version +DO $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'users' AND column_name = 'days_to_sync_history') THEN + ALTER TABLE users ADD COLUMN days_to_sync_history INTEGER DEFAULT 0; + END IF; +END $$; +-- SQLite version (handled in code) +` + // GenerateRandomID creates a random string ID func GenerateRandomID() (string, error) { bytes := make([]byte, 16) // 128 bits @@ -522,6 +542,12 @@ func applyMigration(db *sqlx.DB, migration Migration) error { } else { _, err = tx.Exec(migration.UpSQL) } + } else if migration.ID == 13 { + if db.DriverName() == "sqlite" { + err = addColumnIfNotExistsSQLite(tx, "users", "days_to_sync_history", "INTEGER DEFAULT 0") + } else { + _, err = tx.Exec(migration.UpSQL) + } } else if migration.ID == 10 || migration.ID == 12 { if db.DriverName() == "sqlite" { err = addColumnIfNotExistsSQLite(tx, "users", "webhook_use_proxy", "BOOLEAN DEFAULT 1")