fix: sqlite import
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { postgresAdapter } from '@payloadcms/db-postgres'
|
||||
import { sqliteAdapter } from '@payloadcms/db-sqlite'
|
||||
import { lexicalEditor } from '@payloadcms/richtext-lexical'
|
||||
import path from 'path'
|
||||
import { buildConfig } from 'payload'
|
||||
@@ -21,22 +20,17 @@ import { seed } from './seed'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
// Conditionally import migrations only when using PostgreSQL
|
||||
let migrations: any
|
||||
if (process.env.DATABASE_URI || process.env.NODE_ENV === 'production') {
|
||||
const migrationsModule = await import('./migrations')
|
||||
migrations = migrationsModule.migrations
|
||||
}
|
||||
|
||||
// Use PostgreSQL by default, SQLite only for local development
|
||||
// Use PostgreSQL when DATABASE_URI is set, SQLite only for local development
|
||||
// Migration commands:
|
||||
// pnpm payload migrate:create - Create migration file
|
||||
// pnpm payload migrate - Run pending migrations
|
||||
// pnpm payload migrate:fresh - Drop all & re-run migrations
|
||||
// pnpm payload migrate:reset - Rollback all migrations
|
||||
// pnpm payload migrate:status - Check migration status
|
||||
const getDatabaseAdapter = () => {
|
||||
const getDatabaseAdapter = async () => {
|
||||
if (process.env.DATABASE_URI) {
|
||||
// Conditionally import migrations only when using PostgreSQL
|
||||
const { migrations } = await import('./migrations')
|
||||
return postgresAdapter({
|
||||
pool: {
|
||||
connectionString: process.env.DATABASE_URI,
|
||||
@@ -49,6 +43,8 @@ const getDatabaseAdapter = () => {
|
||||
}
|
||||
|
||||
// Only load SQLite in development (no DATABASE_URI set)
|
||||
// Dynamic import to avoid loading libsql in production/Docker
|
||||
const { sqliteAdapter } = await import('@payloadcms/db-sqlite')
|
||||
return sqliteAdapter({
|
||||
client: {
|
||||
url: 'file:./meal-planner.db',
|
||||
@@ -74,7 +70,7 @@ export default buildConfig({
|
||||
},
|
||||
},
|
||||
collections: [Users, Tenants, Residents, MealOrders, Meals, Media],
|
||||
db: getDatabaseAdapter(),
|
||||
db: await getDatabaseAdapter(),
|
||||
onInit: async (payload) => {
|
||||
// Run migrations automatically on startup (for Docker/production)
|
||||
payload.logger.info('Running database migrations...')
|
||||
|
||||
Reference in New Issue
Block a user