Skip to content

Commit dba63d9

Browse files
authored
Set up lastmod trigger for settings, searches tables (#296)
1 parent f1fe080 commit dba63d9

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
var dbm;
4+
var type;
5+
var seed;
6+
7+
/**
8+
* We receive the dbmigrate dependency from dbmigrate initially.
9+
* This enables us to not have to rely on NODE_PATH.
10+
*/
11+
exports.setup = function (options, seedLink) {
12+
dbm = options.dbmigrate;
13+
type = dbm.dataType;
14+
seed = seedLink;
15+
};
16+
17+
exports.up = function (db, callback) {
18+
db.runSql(
19+
`CREATE TRIGGER
20+
settings_last_updated
21+
BEFORE UPDATE ON
22+
settings
23+
FOR EACH ROW EXECUTE PROCEDURE
24+
sync_lastmod();
25+
26+
CREATE TRIGGER
27+
searches_last_updated
28+
BEFORE UPDATE ON
29+
searches
30+
FOR EACH ROW EXECUTE PROCEDURE
31+
sync_lastmod();
32+
`,
33+
callback,
34+
);
35+
};
36+
37+
exports.down = function (db, callback) {
38+
db.runSql(
39+
`DROP TRIGGER IF EXISTS settings_last_updated ON settings;
40+
41+
DROP TRIGGER IF EXISTS searches_last_updated ON searches;
42+
`,
43+
callback,
44+
);
45+
};
46+
47+
exports._meta = {
48+
version: 1,
49+
};

0 commit comments

Comments
 (0)