diff --git a/lib/new-settings-loader.js b/lib/new-settings-loader.js index 199c2481..229ed2dd 100644 --- a/lib/new-settings-loader.js +++ b/lib/new-settings-loader.js @@ -161,13 +161,13 @@ function loadLatest (schemaVersion) { function loadLatestConfig () { const sql = `SELECT data FROM user_config - WHERE type = $1 - AND schema_version = $2 + WHERE type = 'config' + AND schema_version = $1 AND valid ORDER BY id DESC LIMIT 1` - return db.one(sql, ['config', NEW_SETTINGS_LOADER_SCHEMA_VERSION]) + return db.one(sql, [NEW_SETTINGS_LOADER_SCHEMA_VERSION]) .then(row => row ? row.data.config : {}) .catch(err => { throw err @@ -177,24 +177,25 @@ function loadLatestConfig () { function loadLatestConfigOrNoneReturningVersion (schemaVersion) { const sql = `SELECT data, id FROM user_config - WHERE type = $1 - AND schema_version = $2 + WHERE type = 'config' + AND schema_version = $1 + AND valid ORDER BY id DESC LIMIT 1` - return db.oneOrNone(sql, ['config', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION]) + return db.oneOrNone(sql, [schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION]) .then(row => row ? { config: row.data.config, version: row.id } : {}) } function loadLatestConfigOrNone (schemaVersion) { const sql = `SELECT data FROM user_config - WHERE type = $1 - AND schema_version = $2 + WHERE type = 'config' + AND schema_version = $1 ORDER BY id DESC LIMIT 1` - return db.oneOrNone(sql, ['config', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION]) + return db.oneOrNone(sql, [schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION]) .then(row => row ? row.data.config : {}) } @@ -202,11 +203,11 @@ function loadConfig (versionId) { const sql = `SELECT data FROM user_config WHERE id = $1 - AND type = $2 - AND schema_version = $3 + AND type = 'config' + AND schema_version = $2 AND valid` - return db.one(sql, [versionId, 'config', NEW_SETTINGS_LOADER_SCHEMA_VERSION]) + return db.one(sql, [versionId, NEW_SETTINGS_LOADER_SCHEMA_VERSION]) .then(row => row.data.config) .catch(err => { if (err.name === 'QueryResultError') {