-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathhandlers.js
More file actions
32 lines (26 loc) · 748 Bytes
/
Copy pathhandlers.js
File metadata and controls
32 lines (26 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const Migration = require("./migration");
const success = response => ({
statusCode: 200,
body: JSON.stringify(response)
});
const failure = response => ({
statusCode: 500,
body: JSON.stringify(response)
});
const handler = handlerName => (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
const migration = new Migration(process.env.DATABASE_URL);
migration
[handlerName]()
.then(migrations => {
const response = migrations.map(({ file }) => file).join("\n");
migration.close();
callback(null, success(response));
})
.catch(err => {
migration.close();
callback(err);
});
};
module.exports.up = handler("up");
module.exports.down = handler("down");