Files
template-showcase/migrate.mjs
T

17 lines
588 B
JavaScript

// Applies the SQL migrations in drizzle/ before the app starts (plan D15).
// `npm start` runs it first, so a deploy never serves against an old schema.
import { drizzle } from 'drizzle-orm/postgres-js'
import { migrate } from 'drizzle-orm/postgres-js/migrator'
import postgres from 'postgres'
const url = process.env.POSTGRES_URL
if (!url) {
console.error('POSTGRES_URL is required to apply migrations')
process.exit(1)
}
const client = postgres(url, { max: 1 })
await migrate(drizzle(client), { migrationsFolder: 'drizzle' })
await client.end()
console.log('migrations applied')