Skip to content

Commit

Permalink
Update docker setup to include migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
mmerfort committed Mar 30, 2023
1 parent 73058b9 commit b44c84c
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.gitignore
node_modules
.github
.vscode
docs
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ dist
.tern-port

# Prisma
prisma/
!prisma/schema.prisma
prisma/generated
prisma/*.db*

# Generated "NFD" images
src/assets/NFD/images
24 changes: 20 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
111 changes: 111 additions & 0 deletions prisma/migrations/20230330024630_init/migration.sql
Original file line number Diff line number Diff line change
@@ -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");
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ generator client {

datasource db {
provider = "sqlite"
url = "file:./dev.db"
url = "file:./main.db"
}

model GuildOptions {
Expand Down

0 comments on commit b44c84c

Please sign in to comment.