From 7d0cb9d9bac39b85e9d4f5b8623cbd2b13d3af00 Mon Sep 17 00:00:00 2001 From: a Date: Sun, 2 Mar 2025 18:34:53 -0600 Subject: [PATCH] noot --- .gitea/workflows/dockerfiles.yml | 2 +- migrations/Dockerfile | 3 +- ts/src/cmd/worker.ts | 4 - ts/src/services/pg/migrations.ts | 124 ------------------------------- 4 files changed, 3 insertions(+), 130 deletions(-) delete mode 100644 ts/src/services/pg/migrations.ts diff --git a/.gitea/workflows/dockerfiles.yml b/.gitea/workflows/dockerfiles.yml index 04cafe3..dcb89e3 100644 --- a/.gitea/workflows/dockerfiles.yml +++ b/.gitea/workflows/dockerfiles.yml @@ -31,7 +31,7 @@ jobs: registry: https://tuxpa.in username: actions_token password: ${{ secrets.ACTIONS_TOKEN }} - - name: build and push typescript + - name: build and push docker images uses: docker/build-push-action@v6 with: context: ${{ matrix.args.context }} diff --git a/migrations/Dockerfile b/migrations/Dockerfile index bf6b4a1..0d8cd2c 100644 --- a/migrations/Dockerfile +++ b/migrations/Dockerfile @@ -1,6 +1,7 @@ FROM ghcr.io/jackc/tern:v2.3.2 - USER 1000:1000 WORKDIR /migrations COPY . . + +ENTRYPOINT ["/tern"] diff --git a/ts/src/cmd/worker.ts b/ts/src/cmd/worker.ts index f7b7625..a65bc60 100644 --- a/ts/src/cmd/worker.ts +++ b/ts/src/cmd/worker.ts @@ -1,7 +1,6 @@ import { Command } from 'clipanion'; import { c } from '#/di'; -import { runMigrations } from '#/services/pg/migrations'; // di import "#/services/temporal" @@ -90,7 +89,6 @@ const addSchedules = async (c: Client) => { try { const desc = await handle.describe(); console.log(desc) - }catch(e: any){ if(e instanceof ScheduleNotFoundError) { await c.schedule.create(o) @@ -107,8 +105,6 @@ export class WorkerCommand extends Command { async execute() { const { db } = await c.getAsync(PG); - await runMigrations(db); - const client = await c.getAsync(Client); // schedules await addSchedules(client); diff --git a/ts/src/services/pg/migrations.ts b/ts/src/services/pg/migrations.ts deleted file mode 100644 index b8d9e86..0000000 --- a/ts/src/services/pg/migrations.ts +++ /dev/null @@ -1,124 +0,0 @@ -import { Sql, TransactionSql } from "postgres"; - - -type MigrationFunc = (sql:TransactionSql)=>Promise - -interface Migration { - name: string - up: MigrationFunc - // TODO: implement down - down?: MigrationFunc -} - -const migration = (name:string, up:MigrationFunc, down?:MigrationFunc)=>{ - return {name, up, down} -} - -const migrations: Array = [ - migration("create-api-responses", async (sql)=>{ - await sql` -create table if not exists wynn_api_responses ( - path text not null, - content jsonb not null, - content_hash text not null, - received_time timestamptz not null -)` - await sql` -create index wynn_api_responses_received_time on wynn_api_responses (received_time, path) -` - }), - migration("guild-info", async (sql)=>{ - await sql` -create table if not exists wynn_guild_members ( - guild_id UUID not null, - member_id UUID not null, - rank text not null, - joined_at timestamptz not null, - contributed bigint not null, - primary key (guild_id, member_id), - unique(member_id) -)` - await sql` -create table if not exists wynn_guild_info ( - uid UUID not null, - name text not null, - prefix text not null, - level bigint, - xp_percent bigint, - territories bigint, - wars bigint, - created timestamptz, - primary key (uid) -)` - - await sql` -create table if not exists wynn_guild_season_results ( - guild_id UUID not null, - season text not null, - rating bigint not null, - territories bigint not null, - primary key (guild_id, season) -) -` - }), - migration("create-user-info", async (sql)=>{ - await sql` - create table if not exists minecraft_user ( - uid UUID not null, - name text not null, - server text, - primary key (uid) - ) - ` - }), - migration("create-guild-settings", async (sql)=>{ - await sql` - create table if not exists discord_guild_setting( - discord_guild text not null, - name text not null, - value jsonb not null, - primary key (discord_guild, name) - )` - }), - - migration("add-guild-xp", async (sql)=>{ - await sql`alter table wynn_guild_info add xp bigint not null default 0;` - }), -] - - -export const runMigrations = async (pg: Sql) => { - await pg.begin(async (sql)=>{ - await sql` -create table if not exists migration_version (version int) -` - await sql` -insert into migration_version - select 0 - where 0=(select count(*) from migration_version) -` - const [{version}] = await sql` -select version from migration_version limit 1 -` - - const targetVersion = migrations.length - - if(version == targetVersion) { - return - } - if (version > targetVersion) { - console.log(`version ${version} is greater than the latest migration ${targetVersion}, nothing to do`) - return - } - console.log(`running migrations from version ${version}`) - for (let i = version+1; i <= targetVersion; i++) { - const m = migrations[i-1] - console.log(`running migration ${i}_${m.name}`) - await m.up(sql) - await sql` -update migration_version set version=${i} -` - } - console.log(`done running db migrations`) - }); -}