Create database initialization scripts
This commit is contained in:
parent
c554cb5936
commit
f490404fb6
8 changed files with 70 additions and 0 deletions
1
src/database/init/01-drop-schema.sql
Normal file
1
src/database/init/01-drop-schema.sql
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DROP SCHEMA public CASCADE;
|
1
src/database/init/02-create-schema.sql
Normal file
1
src/database/init/02-create-schema.sql
Normal file
|
@ -0,0 +1 @@
|
||||||
|
CREATE SCHEMA public;
|
3
src/database/init/03-create-migration_applied.sql
Normal file
3
src/database/init/03-create-migration_applied.sql
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
CREATE TABLE migration_applied (
|
||||||
|
code CHAR(4) PRIMARY KEY
|
||||||
|
);
|
9
src/database/init/04-create-actor.sql
Normal file
9
src/database/init/04-create-actor.sql
Normal 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
|
||||||
|
);
|
5
src/database/init/05-create-actor_service.sql
Normal file
5
src/database/init/05-create-actor_service.sql
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
CREATE TABLE actor_service (
|
||||||
|
service_id SERIAL UNIQUE NOT NULL
|
||||||
|
) INHERITS (
|
||||||
|
actor
|
||||||
|
);
|
5
src/database/init/06-create-actor_player.sql
Normal file
5
src/database/init/06-create-actor_player.sql
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
CREATE TABLE actor_player (
|
||||||
|
steam_id BIGINT UNIQUE NOT NULL
|
||||||
|
) INHERITS (
|
||||||
|
actor
|
||||||
|
);
|
5
src/database/init/07-create-actor_guild.sql
Normal file
5
src/database/init/07-create-actor_guild.sql
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
CREATE TABLE actor_guild (
|
||||||
|
guild_id INT UNIQUE NOT NULL
|
||||||
|
) INHERITS (
|
||||||
|
actor
|
||||||
|
);
|
41
src/database/init/index.ts
Normal file
41
src/database/init/index.ts
Normal 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()
|
Loading…
Reference in a new issue