From 31082e5227a54f0262781406a37963d0b4cd1448 Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Thu, 4 Mar 2021 13:43:52 +0100 Subject: [PATCH] fix: don't use hardcoded timestamps as default values (#745) fixes: #741 --- ...4115810-change-default-timestamp-to-now.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/migrations/20210304115810-change-default-timestamp-to-now.js diff --git a/src/migrations/20210304115810-change-default-timestamp-to-now.js b/src/migrations/20210304115810-change-default-timestamp-to-now.js new file mode 100644 index 0000000000..e1dfe617e1 --- /dev/null +++ b/src/migrations/20210304115810-change-default-timestamp-to-now.js @@ -0,0 +1,30 @@ +'use strict'; + +exports.up = function(db, cb) { + db.runSql( + ` + ALTER TABLE client_applications ALTER COLUMN created_at SET DEFAULT now(); + ALTER TABLE client_applications ALTER COLUMN updated_at SET DEFAULT now(); + ALTER TABLE context_fields ALTER COLUMN created_at SET DEFAULT now(); + ALTER TABLE context_fields ALTER COLUMN updated_at SET DEFAULT now(); + ALTER TABLE projects ALTER COLUMN created_at SET DEFAULT now(); + ALTER TABLE users ALTER COLUMN created_at SET DEFAULT now(); + `, + cb, + ); +}; + +exports.down = function(db, cb) { + db.runSql( + ` + ALTER TABLE client_applications ALTER COLUMN created_at SET DEFAULT 'now()'; + ALTER TABLE client_applications ALTER COLUMN updated_at SET DEFAULT 'now()'; + ALTER TABLE context_fields ALTER COLUMN created_at SET DEFAULT 'now()'; + ALTER TABLE context_fields ALTER COLUMN updated_at SET DEFAULT 'now()'; + ALTER TABLE projects ALTER COLUMN created_at SET DEFAULT 'now()'; + ALTER TABLE users ALTER COLUMN created_at SET DEFAULT 'now()'; + + `, + cb, + ); +};