feat(api): migrations on startup
This commit is contained in:
parent
626cf0ef70
commit
919f53ead5
@ -1,4 +1,3 @@
|
|||||||
import path from 'node:path'
|
|
||||||
import { migrateDatabase } from '@boring.tools/database'
|
import { migrateDatabase } from '@boring.tools/database'
|
||||||
|
|
||||||
declare module 'bun' {
|
declare module 'bun' {
|
||||||
@ -11,7 +10,6 @@ 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!')
|
||||||
@ -33,6 +31,6 @@ export const startup = async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (import.meta.env.NODE_ENV === 'production') {
|
if (import.meta.env.NODE_ENV === 'production') {
|
||||||
await migrateDatabase(path.join(__dirname, 'migrations'))
|
await migrateDatabase('migrations')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
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 (dir: string) => {
|
export const migrateDatabase = async (dir: string) => {
|
||||||
try {
|
try {
|
||||||
console.log(__dirname)
|
|
||||||
await migrate(db, { migrationsFolder: dir })
|
await migrate(db, { migrationsFolder: dir })
|
||||||
await client.end()
|
await client.end()
|
||||||
console.log('Migrations: Ok')
|
console.log('Migrations: Ok')
|
||||||
|
Loading…
Reference in New Issue
Block a user