-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.ts
55 lines (49 loc) · 1.4 KB
/
init.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
import * as fs from "fs";
import * as AWS from "aws-sdk";
import { Client } from "pg";
const s3 = new AWS.S3(
JSON.parse(fs.readFileSync("src/config/local.connection.json").toString())
);
const buckets = [
"cloudnet-test-volatile",
"cloudnet-test-versioning",
"cloudnet-test-versioning-1",
"cloudnet-product-volatile",
"cloudnet-product",
"cloudnet-img",
"cloudnet-upload",
];
(async () => {
if (process.env.NODE_ENV == "production" || process.env.SS_MODE != "local") {
console.log(
"Not running in local mode. Skipping bucket and table creation."
);
return;
}
process.stdout.write("Initializing buckets... ");
try {
await Promise.all(
buckets.map((bucket) => s3.createBucket({ Bucket: bucket }).promise())
);
} catch (e) {
console.error("Failed to create buckets", e);
}
const params = {
Bucket: buckets[1],
VersioningConfiguration: {
MFADelete: "Disabled",
Status: "Enabled",
},
};
await s3.putBucketVersioning(params).promise();
params.Bucket = buckets[4];
await s3.putBucketVersioning(params).promise();
console.log("OK");
process.stdout.write("Initializing db... ");
const client = new Client();
await client.connect();
await client.query(fs.readFileSync("src/db/createtable.sql", "utf-8"));
await client.query(fs.readFileSync("src/db/createtable-test.sql", "utf-8"));
console.log("OK");
process.exit(0);
})();