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