Compare commits
3 commits
2f54d41625
...
f490404fb6
Author | SHA1 | Date | |
---|---|---|---|
f490404fb6 | |||
c554cb5936 | |||
4ebacf6753 |
11 changed files with 122 additions and 2 deletions
50
.vscode/launch.json
vendored
Normal file
50
.vscode/launch.json
vendored
Normal 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
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
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()
|
|
@ -3,7 +3,7 @@ import { getLogger } from "@logtape/logtape"
|
||||||
import Postgres from "@@npm/postgres"
|
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 {
|
export function createPostgresKvStore(postgres: Postgres.Sql): PostgresKvStore {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import Postgres from "@@npm/postgres"
|
||||||
import { getLogger } from "@logtape/logtape"
|
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 {
|
export function createPostgres(connString: string): Postgres.Sql {
|
||||||
|
|
Loading…
Reference in a new issue