feat(api): run migrations only on production
This commit is contained in:
parent
3bb5a4999d
commit
626cf0ef70
@ -1,3 +1,4 @@
|
|||||||
|
import path from 'node:path'
|
||||||
import { migrateDatabase } from '@boring.tools/database'
|
import { migrateDatabase } from '@boring.tools/database'
|
||||||
|
|
||||||
declare module 'bun' {
|
declare module 'bun' {
|
||||||
@ -10,6 +11,7 @@ declare module 'bun' {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const startup = async () => {
|
export const startup = async () => {
|
||||||
|
console.log(__dirname)
|
||||||
if (import.meta.env.NODE_ENV === 'test') {
|
if (import.meta.env.NODE_ENV === 'test') {
|
||||||
if (!import.meta.env.POSTGRES_URL) {
|
if (!import.meta.env.POSTGRES_URL) {
|
||||||
console.error('Env Var POSTGRES_URL is missing!')
|
console.error('Env Var POSTGRES_URL is missing!')
|
||||||
@ -30,5 +32,7 @@ export const startup = async () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await migrateDatabase()
|
if (import.meta.env.NODE_ENV === 'production') {
|
||||||
|
await migrateDatabase(path.join(__dirname, 'migrations'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,10 @@ import path from 'node:path'
|
|||||||
import { migrate } from 'drizzle-orm/postgres-js/migrator'
|
import { migrate } from 'drizzle-orm/postgres-js/migrator'
|
||||||
import { client, db } from './'
|
import { client, db } from './'
|
||||||
|
|
||||||
export const migrateDatabase = async () => {
|
export const migrateDatabase = async (dir: string) => {
|
||||||
try {
|
try {
|
||||||
console.log(__dirname)
|
console.log(__dirname)
|
||||||
await migrate(db, { migrationsFolder: path.join(__dirname, 'migrations') })
|
await migrate(db, { migrationsFolder: dir })
|
||||||
await client.end()
|
await client.end()
|
||||||
console.log('Migrations: Ok')
|
console.log('Migrations: Ok')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user