waffle/src/database/init.ts

25 lines
773 B
TypeScript
Raw Normal View History

2022-04-05 22:34:06 +03:00
import { query } from ".";
export default async function databaseInit() {
console.log(await query(`
2022-04-06 18:50:36 +03:00
CREATE TABLE IF NOT EXISTS users(
2022-04-05 22:34:06 +03:00
id SERIAL PRIMARY KEY,
username VARCHAR(32) UNIQUE NOT NULL,
password TEXT
);
2022-04-06 18:50:36 +03:00
CREATE TABLE IF NOT EXISTS channels(
id SERIAL PRIMARY KEY,
name VARCHAR(32) NOT NULL,
owner_id SERIAL REFERENCES users ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS messages(
id SERIAL PRIMARY KEY,
content VARCHAR(4000) NOT NULL,
channel_id SERIAL REFERENCES channels ON DELETE CASCADE,
author_id SERIAL REFERENCES users ON DELETE CASCADE,
created_at BIGINT
2022-04-06 18:50:36 +03:00
);
2022-04-05 22:34:06 +03:00
`));
}