diff --git a/src/database/init/01-drop-schema.sql b/src/database/init/01-drop-schema.sql new file mode 100644 index 0000000..cae5c3d --- /dev/null +++ b/src/database/init/01-drop-schema.sql @@ -0,0 +1 @@ +DROP SCHEMA public CASCADE; diff --git a/src/database/init/02-create-schema.sql b/src/database/init/02-create-schema.sql new file mode 100644 index 0000000..32e23a6 --- /dev/null +++ b/src/database/init/02-create-schema.sql @@ -0,0 +1 @@ +CREATE SCHEMA public; diff --git a/src/database/init/03-create-migration_applied.sql b/src/database/init/03-create-migration_applied.sql new file mode 100644 index 0000000..7aac154 --- /dev/null +++ b/src/database/init/03-create-migration_applied.sql @@ -0,0 +1,3 @@ +CREATE TABLE migration_applied ( + code CHAR(4) PRIMARY KEY +); diff --git a/src/database/init/04-create-actor.sql b/src/database/init/04-create-actor.sql new file mode 100644 index 0000000..cf073bc --- /dev/null +++ b/src/database/init/04-create-actor.sql @@ -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 +); diff --git a/src/database/init/05-create-actor_service.sql b/src/database/init/05-create-actor_service.sql new file mode 100644 index 0000000..e4318d7 --- /dev/null +++ b/src/database/init/05-create-actor_service.sql @@ -0,0 +1,5 @@ +CREATE TABLE actor_service ( + service_id SERIAL UNIQUE NOT NULL +) INHERITS ( + actor +); diff --git a/src/database/init/06-create-actor_player.sql b/src/database/init/06-create-actor_player.sql new file mode 100644 index 0000000..8ff5637 --- /dev/null +++ b/src/database/init/06-create-actor_player.sql @@ -0,0 +1,5 @@ +CREATE TABLE actor_player ( + steam_id BIGINT UNIQUE NOT NULL +) INHERITS ( + actor +); diff --git a/src/database/init/07-create-actor_guild.sql b/src/database/init/07-create-actor_guild.sql new file mode 100644 index 0000000..62910d6 --- /dev/null +++ b/src/database/init/07-create-actor_guild.sql @@ -0,0 +1,5 @@ +CREATE TABLE actor_guild ( + guild_id INT UNIQUE NOT NULL +) INHERITS ( + actor +); diff --git a/src/database/init/index.ts b/src/database/init/index.ts new file mode 100644 index 0000000..a41c07a --- /dev/null +++ b/src/database/init/index.ts @@ -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()