fix(server): skip migrations on LiteFS replicas
LiteFS replicas are read-only, so migrations fail with "read only replica" error. Check LITEFS_CANDIDATE env var and skip migrations on replicas. The primary (pod-0) will run migrations and replicate the changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
1f1083773d
commit
e72018ae44
|
|
@ -9,17 +9,24 @@ const port = parseInt(process.env.PORT || '3000', 10)
|
|||
const app = next({ dev, hostname, port })
|
||||
const handle = app.getRequestHandler()
|
||||
|
||||
// Run migrations before starting server
|
||||
console.log('🔄 Running database migrations...')
|
||||
const { migrate } = require('drizzle-orm/better-sqlite3/migrator')
|
||||
const { db } = require('./dist/db/index')
|
||||
// Run migrations before starting server (only on primary/candidate nodes)
|
||||
// LiteFS replicas are read-only, so migrations must run on the primary
|
||||
const isLiteFSReplica = process.env.LITEFS_CANDIDATE === 'false'
|
||||
|
||||
try {
|
||||
migrate(db, { migrationsFolder: './drizzle' })
|
||||
console.log('✅ Migrations complete')
|
||||
} catch (error) {
|
||||
console.error('❌ Migration failed:', error)
|
||||
process.exit(1)
|
||||
if (isLiteFSReplica) {
|
||||
console.log('📖 Skipping migrations (LiteFS replica - read-only)')
|
||||
} else {
|
||||
console.log('🔄 Running database migrations...')
|
||||
const { migrate } = require('drizzle-orm/better-sqlite3/migrator')
|
||||
const { db } = require('./dist/db/index')
|
||||
|
||||
try {
|
||||
migrate(db, { migrationsFolder: './drizzle' })
|
||||
console.log('✅ Migrations complete')
|
||||
} catch (error) {
|
||||
console.error('❌ Migration failed:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
app.prepare().then(() => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue