Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/db/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export async function resolveDatabaseConfig(nuxt: Nuxt, hub: HubConfig): Promise
}
break
}
// Cloudflare D1 (production only - dev uses local libsql)
if (hub.hosting.includes('cloudflare') && !nuxt.options.dev) {
// Cloudflare D1 (production only - dev/prepare uses local libsql)
if (hub.hosting.includes('cloudflare') && !nuxt.options.dev && !nuxt.options._prepare) {
config.driver = 'd1'
break
}
Expand Down
36 changes: 33 additions & 3 deletions test/database.config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ describe('resolveDatabaseConfig', () => {
process.env = originalEnv
})

const createMockNuxt = (layers: any[] = []) => ({
const createMockNuxt = (layers: any[] = [], opts: { dev?: boolean, _prepare?: boolean } = {}) => ({
options: {
rootDir: '/',
srcDir: '/app/',
dev: opts.dev ?? false,
_prepare: opts._prepare ?? false,
_layers: layers
}
}) as any
Expand Down Expand Up @@ -104,8 +106,8 @@ describe('resolveDatabaseConfig', () => {
})
})

it('should use D1 driver when hosting is cloudflare', async () => {
const nuxt = createMockNuxt()
it('should use D1 driver when hosting is cloudflare (production mode)', async () => {
const nuxt = createMockNuxt([], { dev: false, _prepare: false })
const hub = createBaseHubConfig('sqlite')
hub.hosting = 'cloudflare'

Expand All @@ -118,6 +120,34 @@ describe('resolveDatabaseConfig', () => {
})
})

it('should use libsql when hosting is cloudflare in dev mode', async () => {
const nuxt = createMockNuxt([], { dev: true })
const hub = createBaseHubConfig('sqlite')
hub.hosting = 'cloudflare'

const result = await resolveDatabaseConfig(nuxt, hub)

expect(result).toMatchObject({
dialect: 'sqlite',
driver: 'libsql',
connection: { url: 'file:/tmp/test-hub/db/sqlite.db' }
})
})

it('should use libsql when hosting is cloudflare in prepare mode', async () => {
const nuxt = createMockNuxt([], { dev: false, _prepare: true })
const hub = createBaseHubConfig('sqlite')
hub.hosting = 'cloudflare'

const result = await resolveDatabaseConfig(nuxt, hub)

expect(result).toMatchObject({
dialect: 'sqlite',
driver: 'libsql',
connection: { url: 'file:/tmp/test-hub/db/sqlite.db' }
})
})

it('should preserve custom driver when specified', async () => {
const nuxt = createMockNuxt()
const hub = createBaseHubConfig({
Expand Down
Loading