From 803148d5a23afe207fb5de9ac73c986a324feb9c Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 31 Oct 2015 14:09:39 +0100 Subject: core: o Improved transaction handling. web: o Supporting changing a device's name and description. --- migrations/20151031124713-name-checks.js | 30 ++++++++++++++++++++++ .../sqls/20151031124713-name-checks-down.sql | 1 + migrations/sqls/20151031124713-name-checks-up.sql | 7 +++++ 3 files changed, 38 insertions(+) create mode 100644 migrations/20151031124713-name-checks.js create mode 100644 migrations/sqls/20151031124713-name-checks-down.sql create mode 100644 migrations/sqls/20151031124713-name-checks-up.sql (limited to 'migrations') diff --git a/migrations/20151031124713-name-checks.js b/migrations/20151031124713-name-checks.js new file mode 100644 index 0000000..a541f23 --- /dev/null +++ b/migrations/20151031124713-name-checks.js @@ -0,0 +1,30 @@ +var dbm = global.dbm || require('db-migrate'); +var type = dbm.dataType; +var fs = require('fs'); +var path = require('path'); + +exports.up = function(db, callback) { + var filePath = path.join(__dirname + '/sqls/20151031124713-name-checks-up.sql'); + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return callback(err); + console.log('received data: ' + data); + + db.runSql(data, function(err) { + if (err) return callback(err); + callback(); + }); + }); +}; + +exports.down = function(db, callback) { + var filePath = path.join(__dirname + '/sqls/20151031124713-name-checks-down.sql'); + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return callback(err); + console.log('received data: ' + data); + + db.runSql(data, function(err) { + if (err) return callback(err); + callback(); + }); + }); +}; diff --git a/migrations/sqls/20151031124713-name-checks-down.sql b/migrations/sqls/20151031124713-name-checks-down.sql new file mode 100644 index 0000000..44f074e --- /dev/null +++ b/migrations/sqls/20151031124713-name-checks-down.sql @@ -0,0 +1 @@ +/* Replace with your SQL commands */ \ No newline at end of file diff --git a/migrations/sqls/20151031124713-name-checks-up.sql b/migrations/sqls/20151031124713-name-checks-up.sql new file mode 100644 index 0000000..840cd1e --- /dev/null +++ b/migrations/sqls/20151031124713-name-checks-up.sql @@ -0,0 +1,7 @@ +ALTER TABLE device +ADD CHECK (length(trim(name)) > 0), +ADD CHECK (length(trim(description)) > 0); + +ALTER TABLE device_property +ADD CHECK (length(trim(name)) > 0), +ADD CHECK (length(trim(description)) > 0); -- cgit v1.2.3