Compare commits

..

3 commits

11 changed files with 122 additions and 2 deletions

50
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,50 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"request": "launch",
"name": "Dev Server",
"type": "node",
"program": "${workspaceFolder}/main.ts",
"cwd": "${workspaceFolder}",
"envFile": "${workspaceFolder}/local.env",
"runtimeExecutable": "/usr/bin/deno",
"runtimeArgs": [
"run",
"--watch",
"--no-prompt",
"--allow-read='.,$HOME/.cache/deno,$HOME/.cache/node_modules'",
"--allow-env=DOTINO_POSTGRES_STRING,DOTINO_STRATZ_URL,DOTINO_STRATZ_KEY",
"--allow-sys=uid,gid",
"--allow-net=0.0.0.0:8080",
"--inspect-wait",
"src/main.ts"
],
"attachSimplePort": 9229
},
{
"request": "launch",
"name": "Init database",
"type": "node",
"program": "${workspaceFolder}/main.ts",
"cwd": "${workspaceFolder}",
"envFile": "${workspaceFolder}/local.env",
"runtimeExecutable": "/usr/bin/deno",
"runtimeArgs": [
"run",
"--no-prompt",
"--allow-read='.'",
"--allow-env=DOTINO_POSTGRES_STRING",
"--allow-sys=uid,gid",
"--allow-net=0.0.0.0:8080",
"--inspect-wait",
"src/database/init/index.ts"
],
"attachSimplePort": 9229
},
]
}

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()

View file

@ -3,7 +3,7 @@ import { getLogger } from "@logtape/logtape"
import Postgres from "@@npm/postgres"
const l = getLogger(["dotino-veloce", "fedify", "kv"])
const l = getLogger(["dotino-veloce", "database", "kv"])
export function createPostgresKvStore(postgres: Postgres.Sql): PostgresKvStore {

View file

@ -2,7 +2,7 @@ import Postgres from "@@npm/postgres"
import { getLogger } from "@logtape/logtape"
const l = getLogger(["dotino-veloce", "fedify", "postgres"])
const l = getLogger(["dotino-veloce", "database", "postgres"])
export function createPostgres(connString: string): Postgres.Sql {