From edde5f40cded4e525fc5383a43a78c2510eb3360 Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Sun, 18 Jan 2026 20:57:06 -0800 Subject: [PATCH] Set up lastmod trigger for settings, searches tables --- .../20260119045451-settings-sync-lastmod.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 api/migrations/20260119045451-settings-sync-lastmod.js 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, +};