Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down