Skip to content

Commit 9ceee8e

Browse files
DanRibbensr1tsuu
andauthored
chore: ci changes to add compatibility for mongodb alternates (#13898)
- Adds documentdb and cosmosdb to CI test matrix - Adds missing generateDatabaseAdapter configs - Adjust generateDatabaseAdapter firestore config to make it pure to the compatibilityOptions we provide as an export Creating as draft because I expect a few tests to fail based on previous comments. --------- Co-authored-by: Sasha <64744993+r1tsuu@users.noreply.github.com>
1 parent e4f8478 commit 9ceee8e

File tree

9 files changed

+48
-24
lines changed

9 files changed

+48
-24
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ jobs:
152152
matrix:
153153
database:
154154
- mongodb
155+
- documentdb
156+
- cosmosdb
155157
- firestore
156158
- postgres
157159
- postgres-custom-schema

packages/payload/src/database/getLocalizedPaths.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ export function getLocalizedPaths({
204204
case 'json':
205205
case 'richText': {
206206
const upcomingSegments = pathSegments.slice(i + 1).join('.')
207+
pathSegments.forEach((path) => {
208+
if (!/^\w+(?:\.\w+)*$/.test(path)) {
209+
lastIncompletePath.invalid = true
210+
}
211+
})
207212
lastIncompletePath.complete = true
208213
lastIncompletePath.path = upcomingSegments
209214
? `${currentPath}.${upcomingSegments}`

test/custom-graphql/int.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ describe('Custom GraphQL', () => {
2222
await payload.destroy()
2323
})
2424

25-
if (!['sqlite', 'sqlite-uuid'].includes(process.env.PAYLOAD_DATABASE || '')) {
25+
if (
26+
!['cosmosdb', 'firestore', 'sqlite', 'sqlite-uuid'].includes(process.env.PAYLOAD_DATABASE || '')
27+
) {
2628
describe('Isolated Transaction ID', () => {
2729
it('should isolate transaction IDs between queries in the same request', async () => {
2830
const query = `query {
@@ -58,7 +60,7 @@ describe('Custom GraphQL', () => {
5860
})
5961
})
6062
} else {
61-
it('should not run isolated transaction ID tests for sqlite', () => {
63+
it('should not run isolated transaction ID tests for sqlite/firestore/cosmosdb', () => {
6264
expect(true).toBe(true)
6365
})
6466
}

test/database/int.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,9 @@ describe('database', () => {
17481748
describe('transactions', () => {
17491749
describe('local api', () => {
17501750
// sqlite cannot handle concurrent write transactions
1751-
if (!['sqlite', 'sqlite-uuid'].includes(process.env.PAYLOAD_DATABASE)) {
1751+
if (
1752+
!['cosmosdb', 'firestore', 'sqlite', 'sqlite-uuid'].includes(process.env.PAYLOAD_DATABASE)
1753+
) {
17521754
it('should commit multiple operations in isolation', async () => {
17531755
const req = {
17541756
payload,

test/generateDatabaseAdapter.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import { fileURLToPath } from 'node:url'
55
const filename = fileURLToPath(import.meta.url)
66
const dirname = path.dirname(filename)
77

8-
export const allDatabaseAdapters = {
9-
mongodb: `
10-
import { mongooseAdapter } from '@payloadcms/db-mongodb'
11-
12-
export const databaseAdapter = mongooseAdapter({
8+
const mongooseAdapterArgs = `
139
ensureIndexes: true,
1410
// required for connect to detect that we are using a memory server
1511
mongoMemoryServer: global._mongoMemoryServer,
@@ -20,23 +16,38 @@ export const allDatabaseAdapters = {
2016
collation: {
2117
strength: 1,
2218
},
19+
`
20+
21+
export const allDatabaseAdapters = {
22+
mongodb: `
23+
import { mongooseAdapter } from '@payloadcms/db-mongodb'
24+
25+
export const databaseAdapter = mongooseAdapter({
26+
${mongooseAdapterArgs}
27+
})`,
28+
cosmosdb: `
29+
import { mongooseAdapter, compatibilityOptions } from '@payloadcms/db-mongodb'
30+
31+
export const databaseAdapter = mongooseAdapter({
32+
...compatibilityOptions.cosmosdb,
33+
${mongooseAdapterArgs}
34+
})`,
35+
documentdb: `
36+
import { mongooseAdapter, compatibilityOptions } from '@payloadcms/db-mongodb'
37+
38+
export const databaseAdapter = mongooseAdapter({
39+
...compatibilityOptions.documentdb,
40+
${mongooseAdapterArgs}
2341
})`,
2442
firestore: `
2543
import { mongooseAdapter, compatibilityOptions } from '@payloadcms/db-mongodb'
2644
2745
export const databaseAdapter = mongooseAdapter({
2846
...compatibilityOptions.firestore,
29-
url:
30-
process.env.DATABASE_URI ||
31-
process.env.MONGODB_MEMORY_SERVER_URI ||
32-
'mongodb://127.0.0.1/payloadtests',
33-
collation: {
34-
strength: 1,
35-
},
47+
${mongooseAdapterArgs}
3648
// The following options prevent some tests from failing.
3749
// More work needed to get tests succeeding without these options.
3850
ensureIndexes: true,
39-
transactionOptions: {},
4051
disableIndexHints: false,
4152
useAlternativeDropDatabase: false,
4253
})`,

test/helpers/isMongoose.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import type { Payload } from 'payload'
22

3+
export const mongooseList = ['cosmosdb', 'documentdb', 'firestore', 'mongodb']
4+
35
export function isMongoose(_payload?: Payload) {
4-
return (
5-
_payload?.db?.name === 'mongoose' ||
6-
['firestore', 'mongodb'].includes(process.env.PAYLOAD_DATABASE)
7-
)
6+
return _payload?.db?.name === 'mongoose' || mongooseList.includes(process.env.PAYLOAD_DATABASE)
87
}

test/helpers/startMemoryDB.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { D1DatabaseAPI } from '@miniflare/d1'
22
import { createSQLiteDB } from '@miniflare/shared'
33
import dotenv from 'dotenv'
44
import { MongoMemoryReplSet } from 'mongodb-memory-server'
5+
56
dotenv.config()
67

78
declare global {
@@ -31,7 +32,7 @@ export default async () => {
3132
}
3233
if (
3334
(!process.env.PAYLOAD_DATABASE ||
34-
['firestore', 'mongodb'].includes(process.env.PAYLOAD_DATABASE)) &&
35+
['cosmosdb', 'documentdb', 'firestore', 'mongodb'].includes(process.env.PAYLOAD_DATABASE)) &&
3536
!global._mongoMemoryServer
3637
) {
3738
console.log('Starting memory db...')

test/localization/int.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
} from './payload-types.js'
1515

1616
import { devUser } from '../credentials.js'
17+
import { isMongoose, mongooseList } from '../helpers/isMongoose.js'
1718

1819
// eslint-disable-next-line payload/no-relative-monorepo-imports
1920
import { copyDataFromLocaleHandler } from '../../packages/ui/src/utilities/copyDataFromLocale.js'
@@ -398,7 +399,7 @@ describe('Localization', () => {
398399
expect(docs[2].id).toBe(doc_3.id)
399400
})
400401

401-
if (['mongodb'].includes(process.env.PAYLOAD_DATABASE)) {
402+
if (mongooseList.includes(process.env.PAYLOAD_DATABASE)) {
402403
describe('Localized sorting', () => {
403404
let localizedAccentPostOne: LocalizedPost
404405
let localizedAccentPostTwo: LocalizedPost
@@ -1249,7 +1250,7 @@ describe('Localization', () => {
12491250
})
12501251

12511252
// eslint-disable-next-line jest/no-conditional-in-test
1252-
if (['firestore', 'mongodb'].includes(process.env.PAYLOAD_DATABASE!)) {
1253+
if (isMongoose(payload)) {
12531254
expect(docWithoutFallback.items).toStrictEqual(null)
12541255
} else {
12551256
// TODO: build out compatability with SQL databases

test/relationships/int.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
} from './payload-types.js'
1818

1919
import { initPayloadInt } from '../helpers/initPayloadInt.js'
20+
import { mongooseList } from '../helpers/isMongoose.js'
2021
import {
2122
chainedRelSlug,
2223
customIdNumberSlug,
@@ -38,7 +39,7 @@ const dirname = path.dirname(filename)
3839

3940
type EasierChained = { id: string; relation: EasierChained }
4041

41-
const mongoIt = ['firestore', 'mongodb'].includes(process.env.PAYLOAD_DATABASE || '') ? it : it.skip
42+
const mongoIt = mongooseList.includes(process.env.PAYLOAD_DATABASE || '') ? it : it.skip
4243

4344
describe('Relationships', () => {
4445
beforeAll(async () => {

0 commit comments

Comments
 (0)