From 95356840c3090d4e9f1d3e8d5c57f037e553ba00 Mon Sep 17 00:00:00 2001 From: Yunus <19399214+yunusefendi52@users.noreply.github.com> Date: Sun, 31 Mar 2024 05:21:50 +0700 Subject: [PATCH] Add migration db sqlite --- Dockerfile | 4 ++++ package.json | 1 + server/plugins/startup.ts | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 server/plugins/startup.ts diff --git a/Dockerfile b/Dockerfile index 7ffbc21..ebd0fdc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,10 +6,14 @@ RUN bun install --frozen-lockfile COPY . . RUN bun run prismaGenerate +RUN bun run prisma:migrate + RUN bun run build FROM oven/bun:1 WORKDIR /app COPY --from=builder /builder/.output . +RUN mkdir -p .temp +COPY --from=builder /builder/prisma/data .temp ENTRYPOINT [ "bun" "run" "server/index.mjs" ] diff --git a/package.json b/package.json index dc139ae..54de74f 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "generate": "nuxt generate", "preview": "nuxt preview", "prismaGenerate": "prisma generate", + "prisma:migrate": "prisma migrate dev", "postinstall": "nuxt prepare", "lint": "eslint --ext \".js,.vue\" --ignore-path .gitignore .", "lint:fix": "eslint --fix --ext \".js,.vue\" --ignore-path .gitignore .", diff --git a/server/plugins/startup.ts b/server/plugins/startup.ts new file mode 100644 index 0000000..f7a0641 --- /dev/null +++ b/server/plugins/startup.ts @@ -0,0 +1,20 @@ +import fs from 'fs'; +import path from 'path' + +export default defineNitroPlugin(async (nuxtApp) => { + tryMigrateSqliteDb() +}) + +function tryMigrateSqliteDb() { + console.log('Start tryMigrateSqliteDb') + const dir = process.cwd() + const appDbFile = path.join(dir, 'prisma', 'data', 'app.db') + if (fs.existsSync(appDbFile)) { + console.log('Ignoring copying migration db, already exists') + } else { + console.log('Copying migration db') + const dbMigrationFile = path.join(dir, '.temp', 'app.db') + fs.copyFileSync(dbMigrationFile, appDbFile) + } + console.log('Done tryMigrateSqliteDb') +}