-
Notifications
You must be signed in to change notification settings - Fork 1
/
prebuild.ts
47 lines (40 loc) · 1.27 KB
/
prebuild.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
import { loadEnvConfig } from "@next/env";
import { SingleStoreClient } from "@singlestore/client";
import { readCertificate } from "@/read-certificate";
const dir = process.cwd();
const env = loadEnvConfig(dir).combinedEnv;
(async () => {
try {
const client = new SingleStoreClient();
const databaseName = env.DB_NAME || "singlestore_client_notes";
const connection = client.connect({
host: env.DB_HOST,
user: env.DB_USER,
port: Number(env.DB_PORT),
database: databaseName,
password: env.DB_PASSWORD,
ssl: { ca: readCertificate() },
});
let database;
if (Number(env.IS_FREE_TIER)) {
database = connection.database.use(databaseName);
} else {
database = await connection.database.create({ name: databaseName });
}
await database.table.create({
name: "notes",
columns: {
id: { type: "BIGINT", primaryKey: true, autoIncrement: true },
title: { type: "VARCHAR(64)" },
content: { type: "TEXT" },
createdAt: { type: "DATETIME(6)", default: "CURRENT_TIMESTAMP(6)" },
updatedAt: { type: "DATETIME(6)" },
content_v: { type: "VECTOR(1536)" },
},
});
process.exit(0);
} catch (error) {
console.error(error);
process.exit(1);
}
})();