54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Migration helper methods
|
|
* @type {Object}
|
|
*/
|
|
module.exports = {
|
|
|
|
get_db_type(knex) {
|
|
switch(knex.client.config.client) {
|
|
case 'postgresql':
|
|
case 'postgres':
|
|
case 'pg':
|
|
return 'pg';
|
|
|
|
default:
|
|
return knex.client.config.client;
|
|
}
|
|
},
|
|
|
|
pg_timestamp_update_function () {
|
|
return `CREATE OR REPLACE FUNCTION progblog_update_modified_column()
|
|
RETURNS TRIGGER AS $$
|
|
BEGIN
|
|
NEW.updated_at = now();
|
|
RETURN NEW;
|
|
END;
|
|
$$ language 'plpgsql';`;
|
|
},
|
|
|
|
pg_create_timestamp_update_trigger(table) {
|
|
return `CREATE TRIGGER update_${table}_modtime
|
|
BEFORE UPDATE ON "${table}"
|
|
FOR EACH ROW
|
|
EXECUTE PROCEDURE progblog_update_modified_column();`;
|
|
},
|
|
|
|
pg_delete_timestamp_update_trigger(table) {
|
|
return `DROP TRIGGER IF EXISTS update_${table}_modtime ON "${table}";`;
|
|
},
|
|
|
|
sqlite3_create_timestamp_update_trigger(table) {
|
|
return `CREATE TRIGGER IF NOT EXISTS [UpdateModified]
|
|
BEFORE UPDATE ON "${table}"
|
|
FOR EACH ROW
|
|
BEGIN
|
|
UPDATE "${table}" SET updated_at = CURRENT_TIMESTAMP WHERE id = old.id;
|
|
END`;
|
|
},
|
|
|
|
sqlite3_delete_timestamp_update_trigger() {
|
|
return `DROP TRIGGER IF EXISTS [UpdateModified]`;
|
|
},
|
|
}; |