-
Notifications
You must be signed in to change notification settings - Fork 1
/
handlers.ts
68 lines (52 loc) · 2.08 KB
/
handlers.ts
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as l from 'aws-lambda';
import { Migration } from './migration'
export let up: l.Handler = async (event: any, context: l.Context, callback: l.Callback) => {
context.callbackWaitsForEmptyEventLoop = false;
const migration = new Migration(process.env.DATABASE_URL)
const results = await migration.up();
console.log(`Transmogrify Migrations: ${results}`)
return callback(undefined, `ok: ${results}`);
};
export let down: l.Handler = async (event: any, context: l.Context, callback: l.Callback) => {
context.callbackWaitsForEmptyEventLoop = false;
const migration = new Migration(process.env.DATABASE_URL)
const results = await migration.down();
console.log(`Transmogrify Migrations: ${results}`)
return callback(undefined, `ok: ${results}`);
};
export let create: l.Handler = async (event: any, context: l.Context, callback: l.Callback) => {
context.callbackWaitsForEmptyEventLoop = false;
if (!event.name) {
return callback(new Error('Name is required'), undefined);
}
try {
let migration = new Migration(process.env.DATABASE_URL)
let password = await migration.create(event.name)
return callback(undefined, `Created Database and User ${event.name} with password '${password}'`);
} catch(err) {
return callback(err, undefined);
}
};
export let drop: l.Handler = async (event: any, context: l.Context, callback: l.Callback) => {
context.callbackWaitsForEmptyEventLoop = false;
if (!event.name) {
return callback(new Error('Name is required'), undefined);
}
try {
let migration = new Migration(process.env.DATABASE_URL)
migration.drop(event.name)
return callback(undefined, `Dropped Database and User ${event.name}`);
} catch(err) {
return callback(err, undefined);
}
};
export let check: l.Handler = async (event: any, context: l.Context, callback: l.Callback) => {
context.callbackWaitsForEmptyEventLoop = false;
try {
let migration = new Migration(process.env.DATABASE_URL)
await migration.check();
return callback(undefined, 'Connection ok');
} catch(err) {
return callback(err, undefined);
}
};