Skip to content

Commit

Permalink
added date_modified column to record table (#64)
Browse files Browse the repository at this point in the history
Co-authored-by: Stefano Ricci <[email protected]>
  • Loading branch information
SteRiccio and SteRiccio authored Aug 3, 2023
1 parent 168cd16 commit 6436582
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict'

var dbm
var type
var seed
var fs = require('fs')
var path = require('path')
var Promise

/**
* 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
Promise = options.Promise
}

exports.up = function (db) {
var filePath = path.join(__dirname, 'sqls', '20230802195435-alter-table-record-add-column-date-modified-up.sql')
return new Promise(function (resolve, reject) {
fs.readFile(filePath, { encoding: 'utf-8' }, function (err, data) {
if (err) return reject(err)
console.log('received data: ' + data)

resolve(data)
})
}).then(function (data) {
return db.runSql(data)
})
}

exports.down = function (db) {
var filePath = path.join(__dirname, 'sqls', '20230802195435-alter-table-record-add-column-date-modified-down.sql')
return new Promise(function (resolve, reject) {
fs.readFile(filePath, { encoding: 'utf-8' }, function (err, data) {
if (err) return reject(err)
console.log('received data: ' + data)

resolve(data)
})
}).then(function (data) {
return db.runSql(data)
})
}

exports._meta = {
version: 1,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Replace with your SQL commands */
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ALTER TABLE record
ADD COLUMN date_modified TIMESTAMP NOT NULL DEFAULT (now() AT TIME ZONE 'UTC');

UPDATE
record r
SET
date_modified =(
SELECT
MAX(date_modified)
FROM
node
WHERE
node.record_uuid = r.uuid
GROUP BY
node.record_uuid);

1 change: 1 addition & 0 deletions src/db/table/schemaSurvey/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class TableRecord extends TableSchemaSurvey {
readonly step: Column = new Column(this, 'step', ColumnType.varchar)
readonly cycle: Column = new Column(this, 'cycle', ColumnType.varchar)
readonly dateCreated: Column = new Column(this, 'date_created', ColumnType.timeStamp)
readonly dateModified: Column = new Column(this, 'date_modified', ColumnType.timeStamp)
readonly preview: Column = new Column(this, 'preview', ColumnType.boolean)
readonly validation: Column = new Column(this, 'validation', ColumnType.jsonb)

Expand Down

0 comments on commit 6436582

Please sign in to comment.