mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 22:04:03 +00:00
feat(db): add rent_payment_destinations column and multi-schema support
- Add migration 0020 for rent_payment_destinations jsonb column - Add DB_SCHEMA env var support for multi-schema deployments - Create custom migrate.ts script with proper search_path handling - Update drizzle.config.ts and client.ts to use DB_SCHEMA - Add db_schema variable to Terraform with dev=test/prod=public defaults - Update CD workflow to set DB_SCHEMA based on branch
This commit is contained in:
35
packages/db/src/migrate.ts
Normal file
35
packages/db/src/migrate.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import postgres from 'postgres'
|
||||
import { drizzle } from 'drizzle-orm/postgres-js'
|
||||
import { migrate } from 'drizzle-orm/postgres-js/migrator'
|
||||
import path from 'path'
|
||||
|
||||
const databaseUrl = process.env.DATABASE_URL
|
||||
if (!databaseUrl) {
|
||||
throw new Error('DATABASE_URL is not set')
|
||||
}
|
||||
|
||||
const dbSchema = process.env.DB_SCHEMA || 'public'
|
||||
|
||||
console.log(`Running migrations for schema: ${dbSchema}...`)
|
||||
|
||||
const migrationClient = postgres(databaseUrl, {
|
||||
max: 1,
|
||||
onnotice: () => {}
|
||||
})
|
||||
|
||||
// Explicitly set search_path to the target schema
|
||||
// This ensures that 'CREATE TABLE "x"' goes into the right schema
|
||||
await migrationClient.unsafe(`SET search_path TO ${dbSchema}`)
|
||||
|
||||
const db = drizzle(migrationClient)
|
||||
|
||||
// This runs migrations from the 'drizzle' folder
|
||||
await migrate(db, {
|
||||
migrationsFolder: path.resolve(__dirname, '../drizzle'),
|
||||
migrationsSchema: dbSchema,
|
||||
migrationsTable: '__drizzle_migrations'
|
||||
})
|
||||
|
||||
console.log('Migrations applied successfully!')
|
||||
await migrationClient.end()
|
||||
process.exit(0)
|
||||
Reference in New Issue
Block a user