Create database initialization scripts

This commit is contained in:
Steffo 2024-10-21 03:24:20 +02:00
parent c554cb5936
commit f490404fb6
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
8 changed files with 70 additions and 0 deletions

View file

@ -0,0 +1 @@
DROP SCHEMA public CASCADE;

View file

@ -0,0 +1 @@
CREATE SCHEMA public;

View file

@ -0,0 +1,3 @@
CREATE TABLE migration_applied (
code CHAR(4) PRIMARY KEY
);

View file

@ -0,0 +1,9 @@
CREATE TABLE actor (
handle VARCHAR PRIMARY KEY,
public_rsassa BYTEA NOT NULL,
private_rsassa BYTEA NOT NULL,
public_jwk BYTEA NOT NULL,
private_jwk BYTEA NOT NULL
);

View file

@ -0,0 +1,5 @@
CREATE TABLE actor_service (
service_id SERIAL UNIQUE NOT NULL
) INHERITS (
actor
);

View file

@ -0,0 +1,5 @@
CREATE TABLE actor_player (
steam_id BIGINT UNIQUE NOT NULL
) INHERITS (
actor
);

View file

@ -0,0 +1,5 @@
CREATE TABLE actor_guild (
guild_id INT UNIQUE NOT NULL
) INHERITS (
actor
);

View file

@ -0,0 +1,41 @@
import { getLogger } from "https://jsr.io/@logtape/logtape/0.6.3/logtape/logger.ts"
import { createPostgresFromEnv } from "../postgres.ts"
import { initLogging } from "../../deno/logging.ts"
const l = getLogger(["dotino-veloce", "database", "init"])
async function main() {
await initLogging()
l.debug`Creating Postgres instance...`
const postgres = createPostgresFromEnv()
l.info`01/XX Dropping public schema from database...`
await postgres.file("src/database/init/01-drop-schema.sql")
l.info`02/XX Recreating public schema...`
await postgres.file("src/database/init/02-create-schema.sql")
l.info`03/XX Creating applied migrations table...`
await postgres.file("src/database/init/03-create-migration_applied.sql")
l.info`04/XX Creating actor table...`
await postgres.file("src/database/init/04-create-actor.sql")
l.info`05/XX Creating service table...`
await postgres.file("src/database/init/05-create-actor_service.sql")
l.info`06/XX Creating player table...`
await postgres.file("src/database/init/06-create-actor_player.sql")
l.info`07/XX Creating guild table...`
await postgres.file("src/database/init/07-create-actor_guild.sql")
l.info("Done!")
Deno.exit(0)
}
await main()