mirror of
https://github.com/ProjectSegfault/website.git
synced 2024-11-26 16:52:08 +05:30
fix
This commit is contained in:
parent
f2f97caf80
commit
13462b5f8a
@ -1,26 +0,0 @@
|
|||||||
import knex from "knex";
|
|
||||||
import { env } from "$env/dynamic/private";
|
|
||||||
|
|
||||||
const 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();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default db;
|
|
30
src/lib/server/db.ts
Normal file
30
src/lib/server/db.ts
Normal file
@ -0,0 +1,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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import type { PageServerLoad } from "./$types";
|
import type { PageServerLoad } from "./$types";
|
||||||
import { compile } from "mdsvex";
|
import { compile } from "mdsvex";
|
||||||
import sanitizeHtml from "sanitize-html";
|
import sanitizeHtml from "sanitize-html";
|
||||||
import db from "$lib/db";
|
import { db } from "$lib/server/db";
|
||||||
|
|
||||||
export const load: PageServerLoad = async () => {
|
export const load: PageServerLoad = async () => {
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import type { Actions } from "./$types";
|
import type { Actions } from "./$types";
|
||||||
import Joi from "joi";
|
import Joi from "joi";
|
||||||
import { fail } from "@sveltejs/kit";
|
import { fail } from "@sveltejs/kit";
|
||||||
import db from "$lib/db";
|
import { db } from "$lib/server/db";
|
||||||
|
|
||||||
export const actions: Actions = {
|
export const actions: Actions = {
|
||||||
add: async ({ request, locals }) => {
|
add: async ({ request, locals }) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user