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,
|
2022-04-12 00:19:29 +03:00
|
|
|
name VARCHAR(32) NOT NULL,
|
2022-04-12 00:02:43 +03:00
|
|
|
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
|
|
|
`));
|
|
|
|
}
|