From b0a5939eec5fc3cf42b62e6c758f31aa2c628f9d Mon Sep 17 00:00:00 2001 From: a Date: Sun, 2 Mar 2025 18:18:02 -0600 Subject: [PATCH] noot --- .gitea/workflows/dockerfiles.yml | 23 ++++++++------ Makefile | 9 ++++++ migrations/001_original.sql | 53 ++++++++++++++++++++++++++++++++ migrations/Dockerfile | 6 ++++ migrations/tern.conf | 34 ++++++++++++++++++++ 5 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 Makefile create mode 100644 migrations/001_original.sql create mode 100644 migrations/Dockerfile create mode 100644 migrations/tern.conf diff --git a/.gitea/workflows/dockerfiles.yml b/.gitea/workflows/dockerfiles.yml index 37c98d0..04cafe3 100644 --- a/.gitea/workflows/dockerfiles.yml +++ b/.gitea/workflows/dockerfiles.yml @@ -13,10 +13,13 @@ jobs: IMAGE_ROOT: a/wynn strategy: matrix: - options: - name: ts - context: ./ts - file: ./ts/Dockerfile + args: + - name: ts + context: ./ts + file: ./ts/Dockerfile + - name: "migrations" + context: ./migrations + file: ./migrations/Dockerfile steps: - name: Checkout uses: actions/checkout@v4 @@ -31,13 +34,13 @@ jobs: - name: build and push typescript uses: docker/build-push-action@v6 with: - context: ${{ matrix.options.context }} - file: ${{ matrix.options.file }} + context: ${{ matrix.args.context }} + file: ${{ matrix.args.file }} platforms: linux/amd64 push: true - cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_ROOT }}/${{matrix.options.name}}:cache - cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_ROOT }}/${{matrix.options.name}}:cache,mode=max,image-manifest=true,oci-mediatypes=true,type=registry + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_ROOT }}/${{matrix.args.name}}:cache + cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_ROOT }}/${{matrix.args.name}}:cache,mode=max,image-manifest=true,oci-mediatypes=true,type=registry tags: | - ${{env.REGISTRY}}/${{env.IMAGE_ROOT}}/${{matrix.options.name}}:${{ gitea.ref_name }}, - ${{env.REGISTRY}}/${{env.IMAGE_ROOT}}/${{matrix.options.name}}:${{ gitea.head_ref || gitea.ref_name }} + ${{env.REGISTRY}}/${{env.IMAGE_ROOT}}/${{matrix.args.name}}:${{ gitea.ref_name }}, + ${{env.REGISTRY}}/${{env.IMAGE_ROOT}}/${{matrix.args.name}}:${{ gitea.head_ref || gitea.ref_name }} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cdceab9 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +.PHONY: migrate tern + + +tern: + @echo "running tern $(ARGS)" + @cd migrations && PGUSER=postgres PGPASSWORD=postgres PGHOST=127.0.0.1 PGPORT=54327 PGDATABASE=postgres tern $(ARGS) + +migrate: $(shell find migrations -type f -name "*.sql") + $(MAKE) tern ARGS="migrate" diff --git a/migrations/001_original.sql b/migrations/001_original.sql new file mode 100644 index 0000000..2f5da55 --- /dev/null +++ b/migrations/001_original.sql @@ -0,0 +1,53 @@ +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) +); +create table if not exists wynn_guild_info ( + uid UUID not null, + name text not null, + prefix text not null, + xp bigint not null default 0, + level bigint, + xp_percent bigint, + territories bigint, + wars bigint, + created timestamptz, + primary key (uid) +); + +create index if not exists wynn_guild_info_xp on wynn_guild_info (xp); + +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) +); +create table if not exists minecraft_user ( + uid UUID not null, + name text not null, + server text, + primary key (uid) +); +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) +); + +---- create above / drop below ---- + +drop table if exists wynn_guild_members; +drop table if exists wynn_guild_info; +drop table if exists wynn_guild_season_results; +drop table if exists minecraft_user; +drop table if exists discord_guild_setting; + + diff --git a/migrations/Dockerfile b/migrations/Dockerfile new file mode 100644 index 0000000..bf6b4a1 --- /dev/null +++ b/migrations/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/jackc/tern:v2.3.2 + + +USER 1000:1000 +WORKDIR /migrations +COPY . . diff --git a/migrations/tern.conf b/migrations/tern.conf new file mode 100644 index 0000000..b049539 --- /dev/null +++ b/migrations/tern.conf @@ -0,0 +1,34 @@ +[database] +# host is required (network host or path to Unix domain socket) +# host = +# port = 5432 +# database is required +# database = +# user defaults to OS user +# user = +# password = +# version_table = public.schema_version +# +# sslmode generally matches the behavior described in: +# http://www.postgresql.org/docs/9.4/static/libpq-ssl.html#LIBPQ-SSL-PROTECTION +# +# There are only two modes that most users should use: +# prefer - on trusted networks where security is not required +# verify-full - require SSL connection +# sslmode = prefer +# +# sslrootcert is generally used with sslmode=verify-full +# sslrootcert = /path/to/root/ca + +# Proxy the above database connection via SSH +# [ssh-tunnel] +# host = +# port = 22 +# user defaults to OS user +# user = +# password is not required if using SSH agent authentication +# password = + +[data] +# Any fields in the data section are available in migration templates +# prefix = foo