Skip to content

Commit

Permalink
Add migration db sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
yunusefendi52 committed Mar 30, 2024
1 parent 1e00374 commit 9535684
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down
20 changes: 20 additions & 0 deletions server/plugins/startup.ts
Original file line number Diff line number Diff line change
@@ -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')
}

0 comments on commit 9535684

Please sign in to comment.