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,7 +9,13 @@ const port = parseInt(process.env.PORT || '3000', 10)
|
||||||
const app = next({ dev, hostname, port })
|
const app = next({ dev, hostname, port })
|
||||||
const handle = app.getRequestHandler()
|
const handle = app.getRequestHandler()
|
||||||
|
|
||||||
// Run migrations before starting server
|
// 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'
|
||||||
|
|
||||||
|
if (isLiteFSReplica) {
|
||||||
|
console.log('📖 Skipping migrations (LiteFS replica - read-only)')
|
||||||
|
} else {
|
||||||
console.log('🔄 Running database migrations...')
|
console.log('🔄 Running database migrations...')
|
||||||
const { migrate } = require('drizzle-orm/better-sqlite3/migrator')
|
const { migrate } = require('drizzle-orm/better-sqlite3/migrator')
|
||||||
const { db } = require('./dist/db/index')
|
const { db } = require('./dist/db/index')
|
||||||
|
|
@ -21,6 +27,7 @@ try {
|
||||||
console.error('❌ Migration failed:', error)
|
console.error('❌ Migration failed:', error)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app.prepare().then(() => {
|
app.prepare().then(() => {
|
||||||
const server = createServer(async (req, res) => {
|
const server = createServer(async (req, res) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue