Skip to content

Commit

Permalink
fix: only run migration after generate schema
Browse files Browse the repository at this point in the history
  • Loading branch information
tfkhdyt committed Sep 27, 2023
1 parent a7d0907 commit ebdca5d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
14 changes: 6 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
FROM node

FROM node:lts-alpine3.18
WORKDIR /app

COPY . .

RUN npm i && \
npm run generate && \
rm -rf node_modules && \
npm ci --omit=dev
RUN npm i
RUN npm run generate
RUN npx tsx ./src/db/postgres/migrate.ts
RUN rm -rf node_modules
RUN npm ci --omit=dev

ENTRYPOINT [ "npx", "tsx", "./src/main.ts" ]
5 changes: 3 additions & 2 deletions src/db/postgres/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type DB = typeof db

export async function startMigration() {
console.log('Running migration...')
await migrate(db, { migrationsFolder: 'drizzle' })
await migrate(db, { migrationsFolder: './drizzle' })
console.log('Migrations is done')
}
}

6 changes: 6 additions & 0 deletions src/db/postgres/migrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { migrate } from 'drizzle-orm/libsql/migrator'
import { db } from '.'

console.log('Running migration...')
await migrate(db, { migrationsFolder: './drizzle' })
console.log('Migrations is done')
2 changes: 0 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { message } from 'telegraf/filters'
import Bot from './Bot.js'
import config from './config/config.js'
import { startCron } from './cron.js'
import { startMigration } from './db/postgres/index.js'
import { saldoHandler } from './handlers/saldoHandler.js'
import { checkUserMiddleware } from './middlewares/user.middleware.js'

startMigration()
startCron()

const app = new Bot(config.botToken)
Expand Down

0 comments on commit ebdca5d

Please sign in to comment.