diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-10-26 21:45:27 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-10-26 21:45:27 +0200 |
| commit | 4304300012a87d9a769559dc25df71a1db48bf53 (patch) | |
| tree | 485d6c1106a84f114d02d32b1cab29741f7152b7 | |
| parent | 63775b9587dff25e51dedfb3551aa40a4e53ceeb (diff) | |
migrations?
| -rw-r--r-- | z/migrations/.migrate | 1 | ||||
| -rw-r--r-- | z/migrations/001-init-users.js | 8 | ||||
| -rw-r--r-- | z/migrations/db.js | 35 |
3 files changed, 44 insertions, 0 deletions
diff --git a/z/migrations/.migrate b/z/migrations/.migrate new file mode 100644 index 0000000..ea2ad45 --- /dev/null +++ b/z/migrations/.migrate @@ -0,0 +1 @@ +{"migrations":[],"path":"migrations/.migrate","pos":0,"_events":{}}
\ No newline at end of file diff --git a/z/migrations/001-init-users.js b/z/migrations/001-init-users.js new file mode 100644 index 0000000..939238c --- /dev/null +++ b/z/migrations/001-init-users.js @@ -0,0 +1,8 @@ + +exports.up = function(next){ + next(); +}; + +exports.down = function(next){ + next(); +}; diff --git a/z/migrations/db.js b/z/migrations/db.js new file mode 100644 index 0000000..12d85b3 --- /dev/null +++ b/z/migrations/db.js @@ -0,0 +1,35 @@ + +var pg = require('pg'), + config = require('../config'); + +var DATABASE_URI = process.env.DATABASE_URL || ('postgres://postgres@localhost/' + config.name) + +var db = module.exports = {} +db.statements = [] + +pg.connect(DATABASE_URI, ready); + +function ready (err, client, done){ + if (err) { + return console.error('error fetching client from pool', err); + } + db.client = client + db.done = done + db.run() +} + +db.query = function (statement) { + db.statements.push(statement) +} + +db.run = function(){ + var statement = db.statements.shift() + if (! statement) { + return db.done() + } + + db.client.query('SELECT $1::int AS number', ['1'], function(err, result) { + console.log(result) + db.done(); + }); +} |
