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>
This commit is contained in:
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@@ -152,6 +152,8 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
database:
|
database:
|
||||||
- mongodb
|
- mongodb
|
||||||
|
- documentdb
|
||||||
|
- cosmosdb
|
||||||
- firestore
|
- firestore
|
||||||
- postgres
|
- postgres
|
||||||
- postgres-custom-schema
|
- postgres-custom-schema
|
||||||
|
|||||||
@@ -204,6 +204,11 @@ export function getLocalizedPaths({
|
|||||||
case 'json':
|
case 'json':
|
||||||
case 'richText': {
|
case 'richText': {
|
||||||
const upcomingSegments = pathSegments.slice(i + 1).join('.')
|
const upcomingSegments = pathSegments.slice(i + 1).join('.')
|
||||||
|
pathSegments.forEach((path) => {
|
||||||
|
if (!/^\w+(?:\.\w+)*$/.test(path)) {
|
||||||
|
lastIncompletePath.invalid = true
|
||||||
|
}
|
||||||
|
})
|
||||||
lastIncompletePath.complete = true
|
lastIncompletePath.complete = true
|
||||||
lastIncompletePath.path = upcomingSegments
|
lastIncompletePath.path = upcomingSegments
|
||||||
? `${currentPath}.${upcomingSegments}`
|
? `${currentPath}.${upcomingSegments}`
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ describe('Custom GraphQL', () => {
|
|||||||
await payload.destroy()
|
await payload.destroy()
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!['sqlite', 'sqlite-uuid'].includes(process.env.PAYLOAD_DATABASE || '')) {
|
if (
|
||||||
|
!['cosmosdb', 'firestore', 'sqlite', 'sqlite-uuid'].includes(process.env.PAYLOAD_DATABASE || '')
|
||||||
|
) {
|
||||||
describe('Isolated Transaction ID', () => {
|
describe('Isolated Transaction ID', () => {
|
||||||
it('should isolate transaction IDs between queries in the same request', async () => {
|
it('should isolate transaction IDs between queries in the same request', async () => {
|
||||||
const query = `query {
|
const query = `query {
|
||||||
@@ -58,7 +60,7 @@ describe('Custom GraphQL', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
it('should not run isolated transaction ID tests for sqlite', () => {
|
it('should not run isolated transaction ID tests for sqlite/firestore/cosmosdb', () => {
|
||||||
expect(true).toBe(true)
|
expect(true).toBe(true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1748,7 +1748,9 @@ describe('database', () => {
|
|||||||
describe('transactions', () => {
|
describe('transactions', () => {
|
||||||
describe('local api', () => {
|
describe('local api', () => {
|
||||||
// sqlite cannot handle concurrent write transactions
|
// sqlite cannot handle concurrent write transactions
|
||||||
if (!['sqlite', 'sqlite-uuid'].includes(process.env.PAYLOAD_DATABASE)) {
|
if (
|
||||||
|
!['cosmosdb', 'firestore', 'sqlite', 'sqlite-uuid'].includes(process.env.PAYLOAD_DATABASE)
|
||||||
|
) {
|
||||||
it('should commit multiple operations in isolation', async () => {
|
it('should commit multiple operations in isolation', async () => {
|
||||||
const req = {
|
const req = {
|
||||||
payload,
|
payload,
|
||||||
|
|||||||
@@ -5,11 +5,7 @@ import { fileURLToPath } from 'node:url'
|
|||||||
const filename = fileURLToPath(import.meta.url)
|
const filename = fileURLToPath(import.meta.url)
|
||||||
const dirname = path.dirname(filename)
|
const dirname = path.dirname(filename)
|
||||||
|
|
||||||
export const allDatabaseAdapters = {
|
const mongooseAdapterArgs = `
|
||||||
mongodb: `
|
|
||||||
import { mongooseAdapter } from '@payloadcms/db-mongodb'
|
|
||||||
|
|
||||||
export const databaseAdapter = mongooseAdapter({
|
|
||||||
ensureIndexes: true,
|
ensureIndexes: true,
|
||||||
// required for connect to detect that we are using a memory server
|
// required for connect to detect that we are using a memory server
|
||||||
mongoMemoryServer: global._mongoMemoryServer,
|
mongoMemoryServer: global._mongoMemoryServer,
|
||||||
@@ -20,23 +16,38 @@ export const allDatabaseAdapters = {
|
|||||||
collation: {
|
collation: {
|
||||||
strength: 1,
|
strength: 1,
|
||||||
},
|
},
|
||||||
|
`
|
||||||
|
|
||||||
|
export const allDatabaseAdapters = {
|
||||||
|
mongodb: `
|
||||||
|
import { mongooseAdapter } from '@payloadcms/db-mongodb'
|
||||||
|
|
||||||
|
export const databaseAdapter = mongooseAdapter({
|
||||||
|
${mongooseAdapterArgs}
|
||||||
|
})`,
|
||||||
|
cosmosdb: `
|
||||||
|
import { mongooseAdapter, compatibilityOptions } from '@payloadcms/db-mongodb'
|
||||||
|
|
||||||
|
export const databaseAdapter = mongooseAdapter({
|
||||||
|
...compatibilityOptions.cosmosdb,
|
||||||
|
${mongooseAdapterArgs}
|
||||||
|
})`,
|
||||||
|
documentdb: `
|
||||||
|
import { mongooseAdapter, compatibilityOptions } from '@payloadcms/db-mongodb'
|
||||||
|
|
||||||
|
export const databaseAdapter = mongooseAdapter({
|
||||||
|
...compatibilityOptions.documentdb,
|
||||||
|
${mongooseAdapterArgs}
|
||||||
})`,
|
})`,
|
||||||
firestore: `
|
firestore: `
|
||||||
import { mongooseAdapter, compatibilityOptions } from '@payloadcms/db-mongodb'
|
import { mongooseAdapter, compatibilityOptions } from '@payloadcms/db-mongodb'
|
||||||
|
|
||||||
export const databaseAdapter = mongooseAdapter({
|
export const databaseAdapter = mongooseAdapter({
|
||||||
...compatibilityOptions.firestore,
|
...compatibilityOptions.firestore,
|
||||||
url:
|
${mongooseAdapterArgs}
|
||||||
process.env.DATABASE_URI ||
|
|
||||||
process.env.MONGODB_MEMORY_SERVER_URI ||
|
|
||||||
'mongodb://127.0.0.1/payloadtests',
|
|
||||||
collation: {
|
|
||||||
strength: 1,
|
|
||||||
},
|
|
||||||
// The following options prevent some tests from failing.
|
// The following options prevent some tests from failing.
|
||||||
// More work needed to get tests succeeding without these options.
|
// More work needed to get tests succeeding without these options.
|
||||||
ensureIndexes: true,
|
ensureIndexes: true,
|
||||||
transactionOptions: {},
|
|
||||||
disableIndexHints: false,
|
disableIndexHints: false,
|
||||||
useAlternativeDropDatabase: false,
|
useAlternativeDropDatabase: false,
|
||||||
})`,
|
})`,
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
|
export const mongooseList = ['cosmosdb', 'documentdb', 'firestore', 'mongodb']
|
||||||
|
|
||||||
export function isMongoose(_payload?: Payload) {
|
export function isMongoose(_payload?: Payload) {
|
||||||
return (
|
return _payload?.db?.name === 'mongoose' || mongooseList.includes(process.env.PAYLOAD_DATABASE)
|
||||||
_payload?.db?.name === 'mongoose' ||
|
|
||||||
['firestore', 'mongodb'].includes(process.env.PAYLOAD_DATABASE)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { D1DatabaseAPI } from '@miniflare/d1'
|
|||||||
import { createSQLiteDB } from '@miniflare/shared'
|
import { createSQLiteDB } from '@miniflare/shared'
|
||||||
import dotenv from 'dotenv'
|
import dotenv from 'dotenv'
|
||||||
import { MongoMemoryReplSet } from 'mongodb-memory-server'
|
import { MongoMemoryReplSet } from 'mongodb-memory-server'
|
||||||
|
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@@ -31,7 +32,7 @@ export default async () => {
|
|||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
(!process.env.PAYLOAD_DATABASE ||
|
(!process.env.PAYLOAD_DATABASE ||
|
||||||
['firestore', 'mongodb'].includes(process.env.PAYLOAD_DATABASE)) &&
|
['cosmosdb', 'documentdb', 'firestore', 'mongodb'].includes(process.env.PAYLOAD_DATABASE)) &&
|
||||||
!global._mongoMemoryServer
|
!global._mongoMemoryServer
|
||||||
) {
|
) {
|
||||||
console.log('Starting memory db...')
|
console.log('Starting memory db...')
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import type {
|
|||||||
} from './payload-types.js'
|
} from './payload-types.js'
|
||||||
|
|
||||||
import { devUser } from '../credentials.js'
|
import { devUser } from '../credentials.js'
|
||||||
|
import { isMongoose, mongooseList } from '../helpers/isMongoose.js'
|
||||||
|
|
||||||
// eslint-disable-next-line payload/no-relative-monorepo-imports
|
// eslint-disable-next-line payload/no-relative-monorepo-imports
|
||||||
import { copyDataFromLocaleHandler } from '../../packages/ui/src/utilities/copyDataFromLocale.js'
|
import { copyDataFromLocaleHandler } from '../../packages/ui/src/utilities/copyDataFromLocale.js'
|
||||||
@@ -398,7 +399,7 @@ describe('Localization', () => {
|
|||||||
expect(docs[2].id).toBe(doc_3.id)
|
expect(docs[2].id).toBe(doc_3.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (['mongodb'].includes(process.env.PAYLOAD_DATABASE)) {
|
if (mongooseList.includes(process.env.PAYLOAD_DATABASE)) {
|
||||||
describe('Localized sorting', () => {
|
describe('Localized sorting', () => {
|
||||||
let localizedAccentPostOne: LocalizedPost
|
let localizedAccentPostOne: LocalizedPost
|
||||||
let localizedAccentPostTwo: LocalizedPost
|
let localizedAccentPostTwo: LocalizedPost
|
||||||
@@ -1249,7 +1250,7 @@ describe('Localization', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// eslint-disable-next-line jest/no-conditional-in-test
|
// eslint-disable-next-line jest/no-conditional-in-test
|
||||||
if (['firestore', 'mongodb'].includes(process.env.PAYLOAD_DATABASE!)) {
|
if (isMongoose(payload)) {
|
||||||
expect(docWithoutFallback.items).toStrictEqual(null)
|
expect(docWithoutFallback.items).toStrictEqual(null)
|
||||||
} else {
|
} else {
|
||||||
// TODO: build out compatability with SQL databases
|
// TODO: build out compatability with SQL databases
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import type {
|
|||||||
} from './payload-types.js'
|
} from './payload-types.js'
|
||||||
|
|
||||||
import { initPayloadInt } from '../helpers/initPayloadInt.js'
|
import { initPayloadInt } from '../helpers/initPayloadInt.js'
|
||||||
|
import { mongooseList } from '../helpers/isMongoose.js'
|
||||||
import {
|
import {
|
||||||
chainedRelSlug,
|
chainedRelSlug,
|
||||||
customIdNumberSlug,
|
customIdNumberSlug,
|
||||||
@@ -38,7 +39,7 @@ const dirname = path.dirname(filename)
|
|||||||
|
|
||||||
type EasierChained = { id: string; relation: EasierChained }
|
type EasierChained = { id: string; relation: EasierChained }
|
||||||
|
|
||||||
const mongoIt = ['firestore', 'mongodb'].includes(process.env.PAYLOAD_DATABASE || '') ? it : it.skip
|
const mongoIt = mongooseList.includes(process.env.PAYLOAD_DATABASE || '') ? it : it.skip
|
||||||
|
|
||||||
describe('Relationships', () => {
|
describe('Relationships', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user