Skip to content

Commit a5ed8b3

Browse files
committed
Added timezone to timestamp trigger.
1 parent 2bc59b2 commit a5ed8b3

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

js/setup/database.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ const lovTable = (f, tableName) =>
6969
const lovTableWithSchema = (f, tableName) =>
7070
schema + '."' + lovTable(f, tableName) + '"';
7171

72+
const nowColumn = (name) =>
73+
name + " timestamp" + noTZ + " DEFAULT timezone('utc', now())";
74+
7275
function sqlInsert(tableNameSchema, m, data) {
7376
const { pKey, fieldsH } = m;
7477
let sqlData = "";
@@ -217,7 +220,7 @@ function sqlSchemaWithData() {
217220
" AS $$\n" +
218221
" BEGIN\n NEW." +
219222
config.updatedDateColumn +
220-
" = now();\n RETURN NEW;\n END;\n$$;\n\n";
223+
" = timezone('utc', now());\n RETURN NEW;\n END;\n$$;\n\n";
221224
}
222225
for (let mid in models) {
223226
const sqls = sqlModel(mid);
@@ -325,18 +328,8 @@ function sqlModel(mid) {
325328

326329
// - "timestamp" columns to track creation and last modification.
327330
if (config.wTimestamp) {
328-
fs.push(
329-
config.createdDateColumn +
330-
" timestamp" +
331-
noTZ +
332-
" DEFAULT timezone('utc'::text, now())"
333-
);
334-
fs.push(
335-
config.updatedDateColumn +
336-
" timestamp" +
337-
noTZ +
338-
" DEFAULT timezone('utc'::text, now())"
339-
);
331+
fs.push(nowColumn(createdDateCol));
332+
fs.push(nowColumn(updatedDateCol));
340333
}
341334
// - "who-is" columns to track user who created and last modified the record.
342335
if (config.wWhoIs) {

0 commit comments

Comments
 (0)