From b44c84cdd24aaa194988d01dcdcaa689cb98fa62 Mon Sep 17 00:00:00 2001 From: Martin Merfort <395822+mmerfort@users.noreply.github.com> Date: Thu, 30 Mar 2023 03:03:21 +0000 Subject: [PATCH] Update docker setup to include migrations --- .dockerignore | 5 +- .gitignore | 4 +- Dockerfile | 24 +++- package.json | 2 +- .../20230330024630_init/migration.sql | 111 ++++++++++++++++++ prisma/migrations/migration_lock.toml | 3 + prisma/schema.prisma | 2 +- 7 files changed, 142 insertions(+), 9 deletions(-) create mode 100644 prisma/migrations/20230330024630_init/migration.sql create mode 100644 prisma/migrations/migration_lock.toml diff --git a/.dockerignore b/.dockerignore index 3e4e48b..79928e7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,4 @@ -.gitignore \ No newline at end of file +node_modules +.github +.vscode +docs \ No newline at end of file diff --git a/.gitignore b/.gitignore index 98ce808..beadc9c 100644 --- a/.gitignore +++ b/.gitignore @@ -112,8 +112,8 @@ dist .tern-port # Prisma -prisma/ -!prisma/schema.prisma +prisma/generated +prisma/*.db* # Generated "NFD" images src/assets/NFD/images \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 6c1958c..3ecf179 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,27 @@ -FROM node:16.13.1-alpine3.15 +# syntax=docker/dockerfile:1 +FROM node:lts-alpine3.17 as builder -WORKDIR /usr/src/app +WORKDIR /app COPY package*.json ./ +COPY prisma ./prisma + RUN npm install COPY . . -RUN npx prisma generate && npx prisma migrate dev --name init && npm run build -CMD ["npm", "run", "serve"] +RUN npm run build && npx prisma generate + +FROM node:lts-alpine3.17 + +WORKDIR /app + +RUN addgroup -S twiggy && adduser -S twiggy -G twiggy +USER twiggy + +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/package*.json ./ +COPY --from=builder /app/build ./build +COPY --from=builder /app/prisma ./prisma + +CMD ["npm", "run", "migrate:serve"] diff --git a/package.json b/package.json index e60ef71..9e36bf1 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "serve": "node build/main.js", "lint": "eslint -c .eslintrc.cjs src .eslintrc.cjs", "lint:fix": "eslint -c .eslintrc.cjs src .eslintrc.cjs --fix", - "eloDecay": " node ./build/standalones/eloDecay.js" + "migrate:serve": "prisma migrate deploy && npm run serve" }, "repository": { "type": "git", diff --git a/prisma/migrations/20230330024630_init/migration.sql b/prisma/migrations/20230330024630_init/migration.sql new file mode 100644 index 0000000..4e1ab0f --- /dev/null +++ b/prisma/migrations/20230330024630_init/migration.sql @@ -0,0 +1,111 @@ +-- CreateTable +CREATE TABLE "GuildOptions" ( + "guildId" TEXT NOT NULL PRIMARY KEY, + "gambleChance" DECIMAL NOT NULL DEFAULT 33.33, + "globalDuelCD" INTEGER NOT NULL DEFAULT 60000, + "lastDuel" DATETIME NOT NULL DEFAULT 0, + "lastRPG" DATETIME NOT NULL DEFAULT 0 +); + +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL PRIMARY KEY, + "favColor" TEXT, + "lastRandom" DATETIME NOT NULL DEFAULT 0, + "lastLoss" DATETIME NOT NULL DEFAULT 0 +); + +-- CreateTable +CREATE TABLE "Duels" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "userId" TEXT NOT NULL, + "losses" INTEGER NOT NULL DEFAULT 0, + "wins" INTEGER NOT NULL DEFAULT 0, + "draws" INTEGER NOT NULL DEFAULT 0, + "winStreak" INTEGER NOT NULL DEFAULT 0, + "lossStreak" INTEGER NOT NULL DEFAULT 0, + "winStreakMax" INTEGER NOT NULL DEFAULT 0, + "lossStreakMax" INTEGER NOT NULL DEFAULT 0, + CONSTRAINT "Duels_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "BestMixu" ( + "id" TEXT NOT NULL DEFAULT '1', + "owner" TEXT NOT NULL DEFAULT '', + "tiles" TEXT NOT NULL DEFAULT '', + "score" INTEGER NOT NULL DEFAULT 0 +); + +-- CreateTable +CREATE TABLE "RPGCharacter" ( + "id" TEXT NOT NULL PRIMARY KEY, + "wins" INTEGER NOT NULL DEFAULT 0, + "losses" INTEGER NOT NULL DEFAULT 0, + "draws" INTEGER NOT NULL DEFAULT 0, + "lastLoss" DATETIME NOT NULL DEFAULT 0, + "eloRank" INTEGER NOT NULL DEFAULT 1000, + "peakElo" INTEGER NOT NULL DEFAULT 1000, + "floorElo" INTEGER NOT NULL DEFAULT 1000 +); + +-- CreateTable +CREATE TABLE "NFDItem" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "name" TEXT NOT NULL, + "code" TEXT NOT NULL, + "filename" TEXT NOT NULL, + "owner" TEXT NOT NULL, + "discordUrl" TEXT NOT NULL DEFAULT '', + "mintDate" DATETIME NOT NULL DEFAULT 0, + "previousOwners" TEXT NOT NULL DEFAULT '', + "coveters" TEXT NOT NULL DEFAULT '', + "shunners" TEXT NOT NULL DEFAULT '', + "hotness" INTEGER NOT NULL DEFAULT 0 +); + +-- CreateTable +CREATE TABLE "NFDEnjoyer" ( + "id" TEXT NOT NULL PRIMARY KEY, + "mintCount" INTEGER NOT NULL DEFAULT 0, + "lastMint" DATETIME NOT NULL DEFAULT 0, + "lastGiftGiven" DATETIME NOT NULL DEFAULT 0, + "lastSlurp" DATETIME NOT NULL DEFAULT 0, + "consecutiveFails" INTEGER NOT NULL DEFAULT 4, + "successfulMints" INTEGER NOT NULL DEFAULT 0, + "failedMints" INTEGER NOT NULL DEFAULT 0 +); + +-- CreateTable +CREATE TABLE "NFDEnthusiasts" ( + "dinoId" INTEGER NOT NULL, + "enjoyerId" TEXT NOT NULL, + + PRIMARY KEY ("dinoId", "enjoyerId"), + CONSTRAINT "NFDEnthusiasts_dinoId_fkey" FOREIGN KEY ("dinoId") REFERENCES "NFDItem" ("id") ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "NFDEnthusiasts_enjoyerId_fkey" FOREIGN KEY ("enjoyerId") REFERENCES "NFDEnjoyer" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- CreateIndex +CREATE UNIQUE INDEX "GuildOptions_guildId_key" ON "GuildOptions"("guildId"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_id_key" ON "User"("id"); + +-- CreateIndex +CREATE UNIQUE INDEX "BestMixu_id_key" ON "BestMixu"("id"); + +-- CreateIndex +CREATE UNIQUE INDEX "RPGCharacter_id_key" ON "RPGCharacter"("id"); + +-- CreateIndex +CREATE UNIQUE INDEX "NFDItem_name_key" ON "NFDItem"("name"); + +-- CreateIndex +CREATE UNIQUE INDEX "NFDItem_code_key" ON "NFDItem"("code"); + +-- CreateIndex +CREATE UNIQUE INDEX "NFDItem_filename_key" ON "NFDItem"("filename"); + +-- CreateIndex +CREATE UNIQUE INDEX "NFDEnjoyer_id_key" ON "NFDEnjoyer"("id"); diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..e5e5c47 --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "sqlite" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 42f6ead..eb3ddaa 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -9,7 +9,7 @@ generator client { datasource db { provider = "sqlite" - url = "file:./dev.db" + url = "file:./main.db" } model GuildOptions {