diff --git a/api/migrations/20260119045451-settings-sync-lastmod.js b/api/migrations/20260119045451-settings-sync-lastmod.js new file mode 100644 index 0000000..c87e10e --- /dev/null +++ b/api/migrations/20260119045451-settings-sync-lastmod.js @@ -0,0 +1,49 @@ +'use strict'; + +var dbm; +var type; +var seed; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function (options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; +}; + +exports.up = function (db, callback) { + db.runSql( + `CREATE TRIGGER + settings_last_updated + BEFORE UPDATE ON + settings + FOR EACH ROW EXECUTE PROCEDURE + sync_lastmod(); + + CREATE TRIGGER + searches_last_updated + BEFORE UPDATE ON + searches + FOR EACH ROW EXECUTE PROCEDURE + sync_lastmod(); + `, + callback, + ); +}; + +exports.down = function (db, callback) { + db.runSql( + `DROP TRIGGER IF EXISTS settings_last_updated ON settings; + + DROP TRIGGER IF EXISTS searches_last_updated ON searches; + `, + callback, + ); +}; + +exports._meta = { + version: 1, +};