webcompile/src/lib/server/db.ts

31 lines
789 B
TypeScript
Raw Normal View History

2023-01-07 00:53:14 +05:30
import knex from "knex";
import type { Knex } from "knex";
import { env } from "$env/dynamic/private";
import { building } from "$app/environment";
export let db: Knex;
if (!building) {
db = knex({
client: "pg",
connection: {
host: String(env.DB_HOST),
port: Number(env.DB_PORT),
user: String(env.DB_USERNAME),
password: String(env.DB_PASSWORD),
database: "website"
}
})
if (! await db.schema.hasTable("Announcements")) {
await db.schema.createTable("Announcements", (table) => {
table.increments("id");
table.text("title").notNullable();
table.string("severity").notNullable();
table.string("author").notNullable();
table.string("link").nullable();
table.bigInteger("created").notNullable();
2023-01-09 00:58:00 +05:30
table.timestamps(true, true, true);
2023-01-07 00:53:14 +05:30
});
}
}