@payloadcms/drizzle 3.0.0-canary.23fcb9e → 3.0.0-canary.28c161d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +1 -1
- package/dist/count.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +4 -2
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createTableName.d.ts.map +1 -1
- package/dist/createTableName.js +6 -2
- package/dist/createTableName.js.map +1 -1
- package/dist/createVersion.d.ts +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +22 -14
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +5 -3
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.js +1 -1
- package/dist/deleteVersions.js.map +1 -1
- package/dist/destroy.d.ts.map +1 -1
- package/dist/destroy.js +3 -1
- package/dist/destroy.js.map +1 -1
- package/dist/find/buildFindManyArgs.d.ts +13 -7
- package/dist/find/buildFindManyArgs.d.ts.map +1 -1
- package/dist/find/buildFindManyArgs.js +5 -1
- package/dist/find/buildFindManyArgs.js.map +1 -1
- package/dist/find/findMany.d.ts +1 -1
- package/dist/find/findMany.d.ts.map +1 -1
- package/dist/find/findMany.js +6 -3
- package/dist/find/findMany.js.map +1 -1
- package/dist/find/traverseFields.d.ts +7 -3
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +91 -16
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +2 -1
- package/dist/find.js.map +1 -1
- package/dist/findGlobalVersions.js +1 -1
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findMigrationDir.d.ts.map +1 -1
- package/dist/findMigrationDir.js +3 -1
- package/dist/findMigrationDir.js.map +1 -1
- package/dist/findOne.d.ts +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +2 -1
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.js +1 -1
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/migrate.js +1 -0
- package/dist/migrate.js.map +1 -1
- package/dist/migrateDown.d.ts.map +1 -1
- package/dist/migrateDown.js +1 -1
- package/dist/migrateDown.js.map +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +1 -0
- package/dist/migrateFresh.js.map +1 -1
- package/dist/migrateRefresh.d.ts.map +1 -1
- package/dist/migrateRefresh.js +2 -1
- package/dist/migrateRefresh.js.map +1 -1
- package/dist/migrateReset.d.ts.map +1 -1
- package/dist/migrateReset.js +4 -2
- package/dist/migrateReset.js.map +1 -1
- package/dist/migrateStatus.js +0 -1
- package/dist/migrateStatus.js.map +1 -1
- package/dist/postgres/countDistinct.d.ts.map +1 -1
- package/dist/postgres/countDistinct.js +3 -3
- package/dist/postgres/countDistinct.js.map +1 -1
- package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -1
- package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.js +3 -1
- package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.js.map +1 -1
- package/dist/postgres/createMigration.d.ts.map +1 -1
- package/dist/postgres/createMigration.js +1 -0
- package/dist/postgres/createMigration.js.map +1 -1
- package/dist/postgres/getMigrationTemplate.d.ts +1 -1
- package/dist/postgres/getMigrationTemplate.d.ts.map +1 -1
- package/dist/postgres/getMigrationTemplate.js +1 -1
- package/dist/postgres/getMigrationTemplate.js.map +1 -1
- package/dist/postgres/init.d.ts.map +1 -1
- package/dist/postgres/init.js +12 -3
- package/dist/postgres/init.js.map +1 -1
- package/dist/postgres/schema/build.d.ts +10 -2
- package/dist/postgres/schema/build.d.ts.map +1 -1
- package/dist/postgres/schema/build.js +17 -8
- package/dist/postgres/schema/build.js.map +1 -1
- package/dist/postgres/schema/createIndex.d.ts.map +1 -1
- package/dist/postgres/schema/createIndex.js +3 -1
- package/dist/postgres/schema/createIndex.js.map +1 -1
- package/dist/postgres/schema/traverseFields.d.ts +7 -2
- package/dist/postgres/schema/traverseFields.d.ts.map +1 -1
- package/dist/postgres/schema/traverseFields.js +179 -61
- package/dist/postgres/schema/traverseFields.js.map +1 -1
- package/dist/postgres/schema/withDefault.d.ts.map +1 -1
- package/dist/postgres/schema/withDefault.js +3 -1
- package/dist/postgres/schema/withDefault.js.map +1 -1
- package/dist/postgres/types.d.ts +18 -4
- package/dist/postgres/types.d.ts.map +1 -1
- package/dist/postgres/types.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +1 -1
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +2 -4
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildOrderBy.d.ts +18 -0
- package/dist/queries/buildOrderBy.d.ts.map +1 -0
- package/dist/queries/buildOrderBy.js +52 -0
- package/dist/queries/buildOrderBy.js.map +1 -0
- package/dist/queries/buildQuery.d.ts +4 -4
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +12 -47
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/getTableColumnFromPath.d.ts +8 -3
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +73 -23
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queries/operatorMap.d.ts.map +1 -1
- package/dist/queries/operatorMap.js.map +1 -1
- package/dist/queries/parseParams.d.ts +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +52 -6
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +12 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +77 -21
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queries/selectDistinct.d.ts +3 -4
- package/dist/queries/selectDistinct.d.ts.map +1 -1
- package/dist/queries/selectDistinct.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +1 -2
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +5 -1
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +3 -1
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transform/read/hasManyNumber.d.ts +2 -1
- package/dist/transform/read/hasManyNumber.d.ts.map +1 -1
- package/dist/transform/read/hasManyNumber.js +12 -2
- package/dist/transform/read/hasManyNumber.js.map +1 -1
- package/dist/transform/read/hasManyText.d.ts +2 -1
- package/dist/transform/read/hasManyText.d.ts.map +1 -1
- package/dist/transform/read/hasManyText.js +12 -2
- package/dist/transform/read/hasManyText.js.map +1 -1
- package/dist/transform/read/index.d.ts +3 -2
- package/dist/transform/read/index.d.ts.map +1 -1
- package/dist/transform/read/index.js +3 -2
- package/dist/transform/read/index.js.map +1 -1
- package/dist/transform/read/relationship.d.ts +2 -1
- package/dist/transform/read/relationship.d.ts.map +1 -1
- package/dist/transform/read/relationship.js +15 -6
- package/dist/transform/read/relationship.js.map +1 -1
- package/dist/transform/read/traverseFields.d.ts +10 -2
- package/dist/transform/read/traverseFields.d.ts.map +1 -1
- package/dist/transform/read/traverseFields.js +163 -55
- package/dist/transform/read/traverseFields.js.map +1 -1
- package/dist/transform/write/array.d.ts +6 -1
- package/dist/transform/write/array.d.ts.map +1 -1
- package/dist/transform/write/array.js +7 -3
- package/dist/transform/write/array.js.map +1 -1
- package/dist/transform/write/blocks.d.ts +8 -3
- package/dist/transform/write/blocks.d.ts.map +1 -1
- package/dist/transform/write/blocks.js +19 -7
- package/dist/transform/write/blocks.js.map +1 -1
- package/dist/transform/write/index.d.ts.map +1 -1
- package/dist/transform/write/index.js +1 -1
- package/dist/transform/write/index.js.map +1 -1
- package/dist/transform/write/relationships.d.ts.map +1 -1
- package/dist/transform/write/relationships.js +6 -2
- package/dist/transform/write/relationships.js.map +1 -1
- package/dist/transform/write/selects.d.ts.map +1 -1
- package/dist/transform/write/selects.js +1 -1
- package/dist/transform/write/selects.js.map +1 -1
- package/dist/transform/write/traverseFields.d.ts +6 -1
- package/dist/transform/write/traverseFields.d.ts.map +1 -1
- package/dist/transform/write/traverseFields.js +46 -17
- package/dist/transform/write/traverseFields.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/update.d.ts.map +1 -1
- package/dist/update.js +3 -2
- package/dist/update.js.map +1 -1
- package/dist/updateGlobalVersion.js +2 -2
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateVersion.js +2 -2
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
- package/dist/upsertRow/deleteExistingRowsByPath.js +6 -2
- package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
- package/dist/upsertRow/index.d.ts +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/index.js +50 -13
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/upsertRow/insertArrays.d.ts.map +1 -1
- package/dist/upsertRow/insertArrays.js +5 -2
- package/dist/upsertRow/insertArrays.js.map +1 -1
- package/dist/upsertRow/types.d.ts +8 -5
- package/dist/upsertRow/types.d.ts.map +1 -1
- package/dist/upsertRow/types.js.map +1 -1
- package/dist/utilities/createBlocksMap.d.ts.map +1 -1
- package/dist/utilities/createBlocksMap.js +4 -2
- package/dist/utilities/createBlocksMap.js.map +1 -1
- package/dist/utilities/createRelationshipMap.d.ts.map +1 -1
- package/dist/utilities/createRelationshipMap.js +3 -1
- package/dist/utilities/createRelationshipMap.js.map +1 -1
- package/dist/utilities/executeSchemaHooks.d.ts +24 -0
- package/dist/utilities/executeSchemaHooks.d.ts.map +1 -0
- package/dist/utilities/executeSchemaHooks.js +21 -0
- package/dist/utilities/executeSchemaHooks.js.map +1 -0
- package/dist/utilities/extendDrizzleTable.d.ts +19 -0
- package/dist/utilities/extendDrizzleTable.d.ts.map +1 -0
- package/dist/utilities/extendDrizzleTable.js +38 -0
- package/dist/utilities/extendDrizzleTable.js.map +1 -0
- package/dist/utilities/getCollectionIdType.d.ts +7 -0
- package/dist/utilities/getCollectionIdType.d.ts.map +1 -0
- package/dist/utilities/getCollectionIdType.js +11 -0
- package/dist/utilities/getCollectionIdType.js.map +1 -0
- package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
- package/dist/utilities/hasLocalesTable.js +12 -4
- package/dist/utilities/hasLocalesTable.js.map +1 -1
- package/dist/utilities/isPolymorphicRelationship.d.ts +6 -0
- package/dist/utilities/isPolymorphicRelationship.d.ts.map +1 -0
- package/dist/utilities/isPolymorphicRelationship.js +5 -0
- package/dist/utilities/isPolymorphicRelationship.js.map +1 -0
- package/package.json +7 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/postgres/schema/build.ts"],"sourcesContent":["import type { Relation } from 'drizzle-orm'\nimport type {\n ForeignKeyBuilder,\n IndexBuilder,\n PgColumnBuilder,\n PgTableWithColumns,\n} from 'drizzle-orm/pg-core'\nimport type { Field } from 'payload'\n\nimport { relations } from 'drizzle-orm'\nimport {\n foreignKey,\n index,\n integer,\n numeric,\n serial,\n timestamp,\n unique,\n varchar,\n} from 'drizzle-orm/pg-core'\nimport toSnakeCase from 'to-snake-case'\n\nimport type {\n BaseExtraConfig,\n BasePostgresAdapter,\n GenericColumns,\n GenericTable,\n IDType,\n RelationMap,\n} from '../types.js'\n\nimport { createTableName } from '../../createTableName.js'\nimport { parentIDColumnMap } from './parentIDColumnMap.js'\nimport { setColumnID } from './setColumnID.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: BasePostgresAdapter\n baseColumns?: Record<string, PgColumnBuilder>\n /**\n * After table is created, run these functions to add extra config to the table\n * ie. indexes, multiple columns, etc\n */\n baseExtraConfig?: BaseExtraConfig\n buildNumbers?: boolean\n buildRelationships?: boolean\n disableNotNull: boolean\n disableUnique: boolean\n fields: Field[]\n rootRelationsToBuild?: RelationMap\n rootRelationships?: Set<string>\n rootTableIDColType?: string\n rootTableName?: string\n tableName: string\n timestamps?: boolean\n versions: boolean\n}\n\ntype Result = {\n hasManyNumberField: 'index' | boolean\n hasManyTextField: 'index' | boolean\n relationsToBuild: RelationMap\n}\n\nexport const buildTable = ({\n adapter,\n baseColumns = {},\n baseExtraConfig = {},\n disableNotNull,\n disableUnique = false,\n fields,\n rootRelationsToBuild,\n rootRelationships,\n rootTableIDColType,\n rootTableName: incomingRootTableName,\n tableName,\n timestamps,\n versions,\n}: Args): Result => {\n const isRoot = !incomingRootTableName\n const rootTableName = incomingRootTableName || tableName\n const columns: Record<string, PgColumnBuilder> = baseColumns\n const indexes: Record<string, (cols: GenericColumns) => IndexBuilder> = {}\n\n const localesColumns: Record<string, PgColumnBuilder> = {}\n const localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder> = {}\n let localesTable: GenericTable | PgTableWithColumns<any>\n let textsTable: GenericTable | PgTableWithColumns<any>\n let numbersTable: GenericTable | PgTableWithColumns<any>\n\n // Relationships to the base collection\n const relationships: Set<string> = rootRelationships || new Set()\n\n let relationshipsTable: GenericTable | PgTableWithColumns<any>\n\n // Drizzle relations\n const relationsToBuild: RelationMap = new Map()\n\n const idColType: IDType = setColumnID({ adapter, columns, fields })\n\n const {\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n } = traverseFields({\n adapter,\n columns,\n disableNotNull,\n disableUnique,\n fields,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: tableName,\n parentTableName: tableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,\n rootTableIDColType: rootTableIDColType || idColType,\n rootTableName,\n versions,\n })\n\n // split the relationsToBuild by localized and non-localized\n const localizedRelations = new Map()\n const nonLocalizedRelations = new Map()\n\n relationsToBuild.forEach(({ type, localized, target }, key) => {\n const map = localized ? localizedRelations : nonLocalizedRelations\n map.set(key, { type, target })\n })\n\n if (timestamps) {\n columns.createdAt = timestamp('created_at', {\n mode: 'string',\n precision: 3,\n withTimezone: true,\n })\n .defaultNow()\n .notNull()\n columns.updatedAt = timestamp('updated_at', {\n mode: 'string',\n precision: 3,\n withTimezone: true,\n })\n .defaultNow()\n .notNull()\n }\n\n const table = adapter.pgSchema.table(tableName, columns, (cols) => {\n const extraConfig = Object.entries(baseExtraConfig).reduce((config, [key, func]) => {\n config[key] = func(cols)\n return config\n }, {})\n\n const result = Object.entries(indexes).reduce((acc, [colName, func]) => {\n acc[colName] = func(cols)\n return acc\n }, extraConfig)\n\n return result\n })\n\n adapter.tables[tableName] = table\n\n if (hasLocalizedField || localizedRelations.size) {\n const localeTableName = `${tableName}${adapter.localesSuffix}`\n localesColumns.id = serial('id').primaryKey()\n localesColumns._locale = adapter.enums.enum__locales('_locale').notNull()\n localesColumns._parentID = parentIDColumnMap[idColType]('_parent_id').notNull()\n\n localesTable = adapter.pgSchema.table(localeTableName, localesColumns, (cols) => {\n return Object.entries(localesIndexes).reduce(\n (acc, [colName, func]) => {\n acc[colName] = func(cols)\n return acc\n },\n {\n _localeParent: unique(`${localeTableName}_locale_parent_id_unique`).on(\n cols._locale,\n cols._parentID,\n ),\n _parentIdFk: foreignKey({\n name: `${localeTableName}_parent_id_fk`,\n columns: [cols._parentID],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n },\n )\n })\n\n adapter.tables[localeTableName] = localesTable\n\n adapter.relations[`relations_${localeTableName}`] = relations(localesTable, ({ many, one }) => {\n const result: Record<string, Relation<string>> = {}\n\n result._parentID = one(table, {\n fields: [localesTable._parentID],\n references: [table.id],\n // name the relationship by what the many() relationName is\n relationName: '_locales',\n })\n\n localizedRelations.forEach(({ type, target }, key) => {\n if (type === 'one') {\n result[key] = one(adapter.tables[target], {\n fields: [localesTable[key]],\n references: [adapter.tables[target].id],\n relationName: key,\n })\n }\n if (type === 'many') {\n result[key] = many(adapter.tables[target], {\n relationName: key,\n })\n }\n })\n\n return result\n })\n }\n\n if (isRoot) {\n if (hasManyTextField) {\n const textsTableName = `${rootTableName}_texts`\n const columns: Record<string, PgColumnBuilder> = {\n id: serial('id').primaryKey(),\n order: integer('order').notNull(),\n parent: parentIDColumnMap[idColType]('parent_id').notNull(),\n path: varchar('path').notNull(),\n text: varchar('text'),\n }\n\n if (hasLocalizedManyTextField) {\n columns.locale = adapter.enums.enum__locales('locale')\n }\n\n textsTable = adapter.pgSchema.table(textsTableName, columns, (cols) => {\n const config: Record<string, ForeignKeyBuilder | IndexBuilder> = {\n orderParentIdx: index(`${textsTableName}_order_parent_idx`).on(cols.order, cols.parent),\n parentFk: foreignKey({\n name: `${textsTableName}_parent_fk`,\n columns: [cols.parent],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n }\n\n if (hasManyTextField === 'index') {\n config.text_idx = index(`${textsTableName}_text_idx`).on(cols.text)\n }\n\n if (hasLocalizedManyTextField) {\n config.localeParent = index(`${textsTableName}_locale_parent`).on(\n cols.locale,\n cols.parent,\n )\n }\n\n return config\n })\n\n adapter.tables[textsTableName] = textsTable\n\n adapter.relations[`relations_${textsTableName}`] = relations(textsTable, ({ one }) => ({\n parent: one(table, {\n fields: [textsTable.parent],\n references: [table.id],\n relationName: '_texts',\n }),\n }))\n }\n\n if (hasManyNumberField) {\n const numbersTableName = `${rootTableName}_numbers`\n const columns: Record<string, PgColumnBuilder> = {\n id: serial('id').primaryKey(),\n number: numeric('number'),\n order: integer('order').notNull(),\n parent: parentIDColumnMap[idColType]('parent_id').notNull(),\n path: varchar('path').notNull(),\n }\n\n if (hasLocalizedManyNumberField) {\n columns.locale = adapter.enums.enum__locales('locale')\n }\n\n numbersTable = adapter.pgSchema.table(numbersTableName, columns, (cols) => {\n const config: Record<string, ForeignKeyBuilder | IndexBuilder> = {\n orderParentIdx: index(`${numbersTableName}_order_parent_idx`).on(cols.order, cols.parent),\n parentFk: foreignKey({\n name: `${numbersTableName}_parent_fk`,\n columns: [cols.parent],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n }\n\n if (hasManyNumberField === 'index') {\n config.numberIdx = index(`${numbersTableName}_number_idx`).on(cols.number)\n }\n\n if (hasLocalizedManyNumberField) {\n config.localeParent = index(`${numbersTableName}_locale_parent`).on(\n cols.locale,\n cols.parent,\n )\n }\n\n return config\n })\n\n adapter.tables[numbersTableName] = numbersTable\n\n adapter.relations[`relations_${numbersTableName}`] = relations(numbersTable, ({ one }) => ({\n parent: one(table, {\n fields: [numbersTable.parent],\n references: [table.id],\n relationName: '_numbers',\n }),\n }))\n }\n\n if (relationships.size) {\n const relationshipColumns: Record<string, PgColumnBuilder> = {\n id: serial('id').primaryKey(),\n order: integer('order'),\n parent: parentIDColumnMap[idColType]('parent_id').notNull(),\n path: varchar('path').notNull(),\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipColumns.locale = adapter.enums.enum__locales('locale')\n }\n\n const relationExtraConfig: BaseExtraConfig = {}\n const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`\n\n relationships.forEach((relationTo) => {\n const relationshipConfig = adapter.payload.collections[relationTo].config\n const formattedRelationTo = createTableName({\n adapter,\n config: relationshipConfig,\n throwValidationError: true,\n })\n let colType = adapter.idType === 'uuid' ? 'uuid' : 'integer'\n const relatedCollectionCustomIDType =\n adapter.payload.collections[relationshipConfig.slug]?.customIDType\n\n if (relatedCollectionCustomIDType === 'number') colType = 'numeric'\n if (relatedCollectionCustomIDType === 'text') colType = 'varchar'\n\n relationshipColumns[`${relationTo}ID`] = parentIDColumnMap[colType](\n `${formattedRelationTo}_id`,\n )\n\n relationExtraConfig[`${relationTo}IdFk`] = (cols) =>\n foreignKey({\n name: `${relationshipsTableName}_${toSnakeCase(relationTo)}_fk`,\n columns: [cols[`${relationTo}ID`]],\n foreignColumns: [adapter.tables[formattedRelationTo].id],\n }).onDelete('cascade')\n })\n\n relationshipsTable = adapter.pgSchema.table(\n relationshipsTableName,\n relationshipColumns,\n (cols) => {\n const result: Record<string, ForeignKeyBuilder | IndexBuilder> = Object.entries(\n relationExtraConfig,\n ).reduce(\n (config, [key, func]) => {\n config[key] = func(cols)\n return config\n },\n {\n order: index(`${relationshipsTableName}_order_idx`).on(cols.order),\n parentFk: foreignKey({\n name: `${relationshipsTableName}_parent_fk`,\n columns: [cols.parent],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n parentIdx: index(`${relationshipsTableName}_parent_idx`).on(cols.parent),\n pathIdx: index(`${relationshipsTableName}_path_idx`).on(cols.path),\n },\n )\n\n if (hasLocalizedRelationshipField) {\n result.localeIdx = index(`${relationshipsTableName}_locale_idx`).on(cols.locale)\n }\n\n return result\n },\n )\n\n adapter.tables[relationshipsTableName] = relationshipsTable\n\n adapter.relations[`relations_${relationshipsTableName}`] = relations(\n relationshipsTable,\n ({ one }) => {\n const result: Record<string, Relation<string>> = {\n parent: one(table, {\n fields: [relationshipsTable.parent],\n references: [table.id],\n relationName: '_rels',\n }),\n }\n\n relationships.forEach((relationTo) => {\n const relatedTableName = createTableName({\n adapter,\n config: adapter.payload.collections[relationTo].config,\n throwValidationError: true,\n })\n const idColumnName = `${relationTo}ID`\n result[idColumnName] = one(adapter.tables[relatedTableName], {\n fields: [relationshipsTable[idColumnName]],\n references: [adapter.tables[relatedTableName].id],\n relationName: relationTo,\n })\n })\n\n return result\n },\n )\n }\n }\n\n adapter.relations[`relations_${tableName}`] = relations(table, ({ many, one }) => {\n const result: Record<string, Relation<string>> = {}\n\n nonLocalizedRelations.forEach(({ type, target }, key) => {\n if (type === 'one') {\n result[key] = one(adapter.tables[target], {\n fields: [table[key]],\n references: [adapter.tables[target].id],\n relationName: key,\n })\n }\n if (type === 'many') {\n result[key] = many(adapter.tables[target], { relationName: key })\n }\n })\n\n if (hasLocalizedField) {\n result._locales = many(localesTable, { relationName: '_locales' })\n }\n\n if (hasManyTextField) {\n result._texts = many(textsTable, { relationName: '_texts' })\n }\n\n if (hasManyNumberField) {\n result._numbers = many(numbersTable, { relationName: '_numbers' })\n }\n\n if (relationships.size && relationshipsTable) {\n result._rels = many(relationshipsTable, {\n relationName: '_rels',\n })\n }\n\n return result\n })\n\n return { hasManyNumberField, hasManyTextField, relationsToBuild }\n}\n"],"names":["relations","foreignKey","index","integer","numeric","serial","timestamp","unique","varchar","toSnakeCase","createTableName","parentIDColumnMap","setColumnID","traverseFields","buildTable","adapter","baseColumns","baseExtraConfig","disableNotNull","disableUnique","fields","rootRelationsToBuild","rootRelationships","rootTableIDColType","rootTableName","incomingRootTableName","tableName","timestamps","versions","isRoot","columns","indexes","localesColumns","localesIndexes","localesTable","textsTable","numbersTable","relationships","Set","relationshipsTable","relationsToBuild","Map","idColType","hasLocalizedField","hasLocalizedManyNumberField","hasLocalizedManyTextField","hasLocalizedRelationshipField","hasManyNumberField","hasManyTextField","newTableName","parentTableName","localizedRelations","nonLocalizedRelations","forEach","type","localized","target","key","map","set","createdAt","mode","precision","withTimezone","defaultNow","notNull","updatedAt","table","pgSchema","cols","extraConfig","Object","entries","reduce","config","func","result","acc","colName","tables","size","localeTableName","localesSuffix","id","primaryKey","_locale","enums","enum__locales","_parentID","_localeParent","on","_parentIdFk","name","foreignColumns","onDelete","many","one","references","relationName","textsTableName","order","parent","path","text","locale","orderParentIdx","parentFk","text_idx","localeParent","numbersTableName","number","numberIdx","relationshipColumns","relationExtraConfig","relationshipsTableName","relationshipsSuffix","relationTo","relationshipConfig","payload","collections","formattedRelationTo","throwValidationError","colType","idType","relatedCollectionCustomIDType","slug","customIDType","parentIdx","pathIdx","localeIdx","relatedTableName","idColumnName","_locales","_texts","_numbers","_rels"],"mappings":"AASA,SAASA,SAAS,QAAQ,cAAa;AACvC,SACEC,UAAU,EACVC,KAAK,EACLC,OAAO,EACPC,OAAO,EACPC,MAAM,EACNC,SAAS,EACTC,MAAM,EACNC,OAAO,QACF,sBAAqB;AAC5B,OAAOC,iBAAiB,gBAAe;AAWvC,SAASC,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,cAAc,QAAQ,sBAAqB;AA8BpD,OAAO,MAAMC,aAAa,CAAC,EACzBC,OAAO,EACPC,cAAc,CAAC,CAAC,EAChBC,kBAAkB,CAAC,CAAC,EACpBC,cAAc,EACdC,gBAAgB,KAAK,EACrBC,MAAM,EACNC,oBAAoB,EACpBC,iBAAiB,EACjBC,kBAAkB,EAClBC,eAAeC,qBAAqB,EACpCC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACH;IACL,MAAMC,SAAS,CAACJ;IAChB,MAAMD,gBAAgBC,yBAAyBC;IAC/C,MAAMI,UAA2Cd;IACjD,MAAMe,UAAkE,CAAC;IAEzE,MAAMC,iBAAkD,CAAC;IACzD,MAAMC,iBAAyE,CAAC;IAChF,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IAEJ,uCAAuC;IACvC,MAAMC,gBAA6Bf,qBAAqB,IAAIgB;IAE5D,IAAIC;IAEJ,oBAAoB;IACpB,MAAMC,mBAAgC,IAAIC;IAE1C,MAAMC,YAAoB9B,YAAY;QAAEG;QAASe;QAASV;IAAO;IAEjE,MAAM,EACJuB,iBAAiB,EACjBC,2BAA2B,EAC3BC,yBAAyB,EACzBC,6BAA6B,EAC7BC,kBAAkB,EAClBC,gBAAgB,EACjB,GAAGnC,eAAe;QACjBE;QACAe;QACAZ;QACAC;QACAC;QACAW;QACAC;QACAC;QACAgB,cAAcvB;QACdwB,iBAA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ClE;QAEA,IAAI7D,cAAc2C,IAAI,IAAIzC,oBAAoB;YAC5CqC,OAAO2D,KAAK,GAAGxC,KAAKxD,oBAAoB;gBACtC2D,cAAc;YAChB;QACF;QAEA,OAAOtB;IACT;IAEA,OAAO;QAAE7B;QAAoBC;QAAkBR;IAAiB;AAClE,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/postgres/schema/build.ts"],"sourcesContent":["import type { Relation } from 'drizzle-orm'\nimport type {\n ForeignKeyBuilder,\n IndexBuilder,\n PgColumnBuilder,\n PgTableWithColumns,\n} from 'drizzle-orm/pg-core'\nimport type { Field } from 'payload'\n\nimport { relations } from 'drizzle-orm'\nimport {\n foreignKey,\n index,\n integer,\n numeric,\n serial,\n timestamp,\n unique,\n varchar,\n} from 'drizzle-orm/pg-core'\nimport toSnakeCase from 'to-snake-case'\n\nimport type {\n BaseExtraConfig,\n BasePostgresAdapter,\n GenericColumns,\n GenericTable,\n IDType,\n RelationMap,\n} from '../types.js'\n\nimport { createTableName } from '../../createTableName.js'\nimport { parentIDColumnMap } from './parentIDColumnMap.js'\nimport { setColumnID } from './setColumnID.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: BasePostgresAdapter\n baseColumns?: Record<string, PgColumnBuilder>\n /**\n * After table is created, run these functions to add extra config to the table\n * ie. indexes, multiple columns, etc\n */\n baseExtraConfig?: BaseExtraConfig\n buildNumbers?: boolean\n buildRelationships?: boolean\n disableNotNull: boolean\n disableUnique: boolean\n fields: Field[]\n rootRelationships?: Set<string>\n rootRelationsToBuild?: RelationMap\n rootTableIDColType?: string\n rootTableName?: string\n tableName: string\n timestamps?: boolean\n versions: boolean\n /**\n * Tracks whether or not this table is built\n * from the result of a localized array or block field at some point\n */\n withinLocalizedArrayOrBlock?: boolean\n}\n\ntype Result = {\n hasLocalizedManyNumberField: boolean\n hasLocalizedManyTextField: boolean\n hasLocalizedRelationshipField: boolean\n hasManyNumberField: 'index' | boolean\n hasManyTextField: 'index' | boolean\n relationsToBuild: RelationMap\n}\n\nexport const buildTable = ({\n adapter,\n baseColumns = {},\n baseExtraConfig = {},\n disableNotNull,\n disableUnique = false,\n fields,\n rootRelationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName: incomingRootTableName,\n tableName,\n timestamps,\n versions,\n withinLocalizedArrayOrBlock,\n}: Args): Result => {\n const isRoot = !incomingRootTableName\n const rootTableName = incomingRootTableName || tableName\n const columns: Record<string, PgColumnBuilder> = baseColumns\n const indexes: Record<string, (cols: GenericColumns) => IndexBuilder> = {}\n\n const localesColumns: Record<string, PgColumnBuilder> = {}\n const localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder> = {}\n let localesTable: GenericTable | PgTableWithColumns<any>\n let textsTable: GenericTable | PgTableWithColumns<any>\n let numbersTable: GenericTable | PgTableWithColumns<any>\n\n // Relationships to the base collection\n const relationships: Set<string> = rootRelationships || new Set()\n\n let relationshipsTable: GenericTable | PgTableWithColumns<any>\n\n // Drizzle relations\n const relationsToBuild: RelationMap = new Map()\n\n const idColType: IDType = setColumnID({ adapter, columns, fields })\n\n const {\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n } = traverseFields({\n adapter,\n columns,\n disableNotNull,\n disableUnique,\n fields,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: tableName,\n parentTableName: tableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,\n rootTableIDColType: rootTableIDColType || idColType,\n rootTableName,\n versions,\n withinLocalizedArrayOrBlock,\n })\n\n // split the relationsToBuild by localized and non-localized\n const localizedRelations = new Map()\n const nonLocalizedRelations = new Map()\n\n relationsToBuild.forEach(({ type, localized, relationName, target }, key) => {\n const map = localized ? localizedRelations : nonLocalizedRelations\n map.set(key, { type, relationName, target })\n })\n\n if (timestamps) {\n columns.createdAt = timestamp('created_at', {\n mode: 'string',\n precision: 3,\n withTimezone: true,\n })\n .defaultNow()\n .notNull()\n columns.updatedAt = timestamp('updated_at', {\n mode: 'string',\n precision: 3,\n withTimezone: true,\n })\n .defaultNow()\n .notNull()\n }\n\n const table = adapter.pgSchema.table(tableName, columns, (cols) => {\n const extraConfig = Object.entries(baseExtraConfig).reduce((config, [key, func]) => {\n config[key] = func(cols)\n return config\n }, {})\n\n const result = Object.entries(indexes).reduce((acc, [colName, func]) => {\n acc[colName] = func(cols)\n return acc\n }, extraConfig)\n\n return result\n })\n\n adapter.tables[tableName] = table\n\n if (hasLocalizedField || localizedRelations.size) {\n const localeTableName = `${tableName}${adapter.localesSuffix}`\n localesColumns.id = serial('id').primaryKey()\n localesColumns._locale = adapter.enums.enum__locales('_locale').notNull()\n localesColumns._parentID = parentIDColumnMap[idColType]('_parent_id').notNull()\n\n localesTable = adapter.pgSchema.table(localeTableName, localesColumns, (cols) => {\n return Object.entries(localesIndexes).reduce(\n (acc, [colName, func]) => {\n acc[colName] = func(cols)\n return acc\n },\n {\n _localeParent: unique(`${localeTableName}_locale_parent_id_unique`).on(\n cols._locale,\n cols._parentID,\n ),\n _parentIdFk: foreignKey({\n name: `${localeTableName}_parent_id_fk`,\n columns: [cols._parentID],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n },\n )\n })\n\n adapter.tables[localeTableName] = localesTable\n\n adapter.relations[`relations_${localeTableName}`] = relations(localesTable, ({ many, one }) => {\n const result: Record<string, Relation<string>> = {}\n\n result._parentID = one(table, {\n fields: [localesTable._parentID],\n references: [table.id],\n // name the relationship by what the many() relationName is\n relationName: '_locales',\n })\n\n localizedRelations.forEach(({ type, target }, key) => {\n if (type === 'one') {\n result[key] = one(adapter.tables[target], {\n fields: [localesTable[key]],\n references: [adapter.tables[target].id],\n relationName: key,\n })\n }\n if (type === 'many') {\n result[key] = many(adapter.tables[target], {\n relationName: key,\n })\n }\n })\n\n return result\n })\n }\n\n if (isRoot) {\n if (hasManyTextField) {\n const textsTableName = `${rootTableName}_texts`\n const columns: Record<string, PgColumnBuilder> = {\n id: serial('id').primaryKey(),\n order: integer('order').notNull(),\n parent: parentIDColumnMap[idColType]('parent_id').notNull(),\n path: varchar('path').notNull(),\n text: varchar('text'),\n }\n\n if (hasLocalizedManyTextField) {\n columns.locale = adapter.enums.enum__locales('locale')\n }\n\n textsTable = adapter.pgSchema.table(textsTableName, columns, (cols) => {\n const config: Record<string, ForeignKeyBuilder | IndexBuilder> = {\n orderParentIdx: index(`${textsTableName}_order_parent_idx`).on(cols.order, cols.parent),\n parentFk: foreignKey({\n name: `${textsTableName}_parent_fk`,\n columns: [cols.parent],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n }\n\n if (hasManyTextField === 'index') {\n config.text_idx = index(`${textsTableName}_text_idx`).on(cols.text)\n }\n\n if (hasLocalizedManyTextField) {\n config.localeParent = index(`${textsTableName}_locale_parent`).on(\n cols.locale,\n cols.parent,\n )\n }\n\n return config\n })\n\n adapter.tables[textsTableName] = textsTable\n\n adapter.relations[`relations_${textsTableName}`] = relations(textsTable, ({ one }) => ({\n parent: one(table, {\n fields: [textsTable.parent],\n references: [table.id],\n relationName: '_texts',\n }),\n }))\n }\n\n if (hasManyNumberField) {\n const numbersTableName = `${rootTableName}_numbers`\n const columns: Record<string, PgColumnBuilder> = {\n id: serial('id').primaryKey(),\n number: numeric('number'),\n order: integer('order').notNull(),\n parent: parentIDColumnMap[idColType]('parent_id').notNull(),\n path: varchar('path').notNull(),\n }\n\n if (hasLocalizedManyNumberField) {\n columns.locale = adapter.enums.enum__locales('locale')\n }\n\n numbersTable = adapter.pgSchema.table(numbersTableName, columns, (cols) => {\n const config: Record<string, ForeignKeyBuilder | IndexBuilder> = {\n orderParentIdx: index(`${numbersTableName}_order_parent_idx`).on(cols.order, cols.parent),\n parentFk: foreignKey({\n name: `${numbersTableName}_parent_fk`,\n columns: [cols.parent],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n }\n\n if (hasManyNumberField === 'index') {\n config.numberIdx = index(`${numbersTableName}_number_idx`).on(cols.number)\n }\n\n if (hasLocalizedManyNumberField) {\n config.localeParent = index(`${numbersTableName}_locale_parent`).on(\n cols.locale,\n cols.parent,\n )\n }\n\n return config\n })\n\n adapter.tables[numbersTableName] = numbersTable\n\n adapter.relations[`relations_${numbersTableName}`] = relations(numbersTable, ({ one }) => ({\n parent: one(table, {\n fields: [numbersTable.parent],\n references: [table.id],\n relationName: '_numbers',\n }),\n }))\n }\n\n if (relationships.size) {\n const relationshipColumns: Record<string, PgColumnBuilder> = {\n id: serial('id').primaryKey(),\n order: integer('order'),\n parent: parentIDColumnMap[idColType]('parent_id').notNull(),\n path: varchar('path').notNull(),\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipColumns.locale = adapter.enums.enum__locales('locale')\n }\n\n const relationExtraConfig: BaseExtraConfig = {}\n const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`\n\n relationships.forEach((relationTo) => {\n const relationshipConfig = adapter.payload.collections[relationTo].config\n const formattedRelationTo = createTableName({\n adapter,\n config: relationshipConfig,\n throwValidationError: true,\n })\n let colType = adapter.idType === 'uuid' ? 'uuid' : 'integer'\n const relatedCollectionCustomIDType =\n adapter.payload.collections[relationshipConfig.slug]?.customIDType\n\n if (relatedCollectionCustomIDType === 'number') {\n colType = 'numeric'\n }\n if (relatedCollectionCustomIDType === 'text') {\n colType = 'varchar'\n }\n\n relationshipColumns[`${relationTo}ID`] = parentIDColumnMap[colType](\n `${formattedRelationTo}_id`,\n )\n\n relationExtraConfig[`${relationTo}IdFk`] = (cols) =>\n foreignKey({\n name: `${relationshipsTableName}_${toSnakeCase(relationTo)}_fk`,\n columns: [cols[`${relationTo}ID`]],\n foreignColumns: [adapter.tables[formattedRelationTo].id],\n }).onDelete('cascade')\n })\n\n relationshipsTable = adapter.pgSchema.table(\n relationshipsTableName,\n relationshipColumns,\n (cols) => {\n const result: Record<string, ForeignKeyBuilder | IndexBuilder> = Object.entries(\n relationExtraConfig,\n ).reduce(\n (config, [key, func]) => {\n config[key] = func(cols)\n return config\n },\n {\n order: index(`${relationshipsTableName}_order_idx`).on(cols.order),\n parentFk: foreignKey({\n name: `${relationshipsTableName}_parent_fk`,\n columns: [cols.parent],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n parentIdx: index(`${relationshipsTableName}_parent_idx`).on(cols.parent),\n pathIdx: index(`${relationshipsTableName}_path_idx`).on(cols.path),\n },\n )\n\n if (hasLocalizedRelationshipField) {\n result.localeIdx = index(`${relationshipsTableName}_locale_idx`).on(cols.locale)\n }\n\n return result\n },\n )\n\n adapter.tables[relationshipsTableName] = relationshipsTable\n\n adapter.relations[`relations_${relationshipsTableName}`] = relations(\n relationshipsTable,\n ({ one }) => {\n const result: Record<string, Relation<string>> = {\n parent: one(table, {\n fields: [relationshipsTable.parent],\n references: [table.id],\n relationName: '_rels',\n }),\n }\n\n relationships.forEach((relationTo) => {\n const relatedTableName = createTableName({\n adapter,\n config: adapter.payload.collections[relationTo].config,\n throwValidationError: true,\n })\n const idColumnName = `${relationTo}ID`\n result[idColumnName] = one(adapter.tables[relatedTableName], {\n fields: [relationshipsTable[idColumnName]],\n references: [adapter.tables[relatedTableName].id],\n relationName: relationTo,\n })\n })\n\n return result\n },\n )\n }\n }\n\n adapter.relations[`relations_${tableName}`] = relations(table, ({ many, one }) => {\n const result: Record<string, Relation<string>> = {}\n\n nonLocalizedRelations.forEach(({ type, relationName, target }, key) => {\n if (type === 'one') {\n result[key] = one(adapter.tables[target], {\n fields: [table[key]],\n references: [adapter.tables[target].id],\n relationName: key,\n })\n }\n if (type === 'many') {\n result[key] = many(adapter.tables[target], { relationName: relationName || key })\n }\n })\n\n if (hasLocalizedField) {\n result._locales = many(localesTable, { relationName: '_locales' })\n }\n\n if (hasManyTextField) {\n result._texts = many(textsTable, { relationName: '_texts' })\n }\n\n if (hasManyNumberField) {\n result._numbers = many(numbersTable, { relationName: '_numbers' })\n }\n\n if (relationships.size && relationshipsTable) {\n result._rels = many(relationshipsTable, {\n relationName: '_rels',\n })\n }\n\n return result\n })\n\n return {\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n relationsToBuild,\n }\n}\n"],"names":["relations","foreignKey","index","integer","numeric","serial","timestamp","unique","varchar","toSnakeCase","createTableName","parentIDColumnMap","setColumnID","traverseFields","buildTable","adapter","baseColumns","baseExtraConfig","disableNotNull","disableUnique","fields","rootRelationships","rootRelationsToBuild","rootTableIDColType","rootTableName","incomingRootTableName","tableName","timestamps","versions","withinLocalizedArrayOrBlock","isRoot","columns","indexes","localesColumns","localesIndexes","localesTable","textsTable","numbersTable","relationships","Set","relationshipsTable","relationsToBuild","Map","idColType","hasLocalizedField","hasLocalizedManyNumberField","hasLocalizedManyTextField","hasLocalizedRelationshipField","hasManyNumberField","hasManyTextField","newTableName","parentTableName","localizedRelations","nonLocalizedRelations","forEach","type","localized","relationName","target","key","map","set","createdAt","mode","precision","withTimezone","defaultNow","notNull","updatedAt","table","pgSchema","cols","extraConfig","Object","entries","reduce","config","func","result","acc","colName","tables","size","localeTableName","localesSuffix","id","primaryKey","_locale","enums","enum__locales","_parentID","_localeParent","on","_parentIdFk","name","foreignColumns","onDelete","many","one","references","textsTableName","order","parent","path","text","locale","orderParentIdx","parentFk","text_idx","localeParent","numbersTableName","number","numberIdx","relationshipColumns","relationExtraConfig","relationshipsTableName","relationshipsSuffix","relationTo","relationshipConfig","payload","collections","formattedRelationTo","throwValidationError","colType","idType","relatedCollectionCustomIDType","slug","customIDType","parentIdx","pathIdx","localeIdx","relatedTableName","idColumnName","_locales","_texts","_numbers","_rels"],"mappings":"AASA,SAASA,SAAS,QAAQ,cAAa;AACvC,SACEC,UAAU,EACVC,KAAK,EACLC,OAAO,EACPC,OAAO,EACPC,MAAM,EACNC,SAAS,EACTC,MAAM,EACNC,OAAO,QACF,sBAAqB;AAC5B,OAAOC,iBAAiB,gBAAe;AAWvC,SAASC,eAAe,QAAQ,2BAA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AC;QACAR;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createIndex.d.ts","sourceRoot":"","sources":["../../../src/postgres/schema/createIndex.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,eAAe,GAAG;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,WAAW,4CAA6C,eAAe,aACnE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,aAAa,CAAA;CAAE,+
|
|
1
|
+
{"version":3,"file":"createIndex.d.ts","sourceRoot":"","sources":["../../../src/postgres/schema/createIndex.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,eAAe,GAAG;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,WAAW,4CAA6C,eAAe,aACnE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,aAAa,CAAA;CAAE,+CAe9C,CAAA"}
|
|
@@ -10,7 +10,9 @@ export const createIndex = ({ name, columnName, tableName, unique })=>{
|
|
|
10
10
|
table[name]
|
|
11
11
|
];
|
|
12
12
|
}
|
|
13
|
-
if (unique)
|
|
13
|
+
if (unique) {
|
|
14
|
+
return uniqueIndex(`${tableName}_${columnName}_idx`).on(columns[0], ...columns.slice(1));
|
|
15
|
+
}
|
|
14
16
|
return index(`${tableName}_${columnName}_idx`).on(columns[0], ...columns.slice(1));
|
|
15
17
|
};
|
|
16
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/postgres/schema/createIndex.ts"],"sourcesContent":["import { index, uniqueIndex } from 'drizzle-orm/pg-core'\n\nimport type { GenericColumn } from '../types.js'\n\ntype CreateIndexArgs = {\n columnName: string\n name: string | string[]\n tableName: string\n unique?: boolean\n}\n\nexport const createIndex = ({ name, columnName, tableName, unique }: CreateIndexArgs) => {\n return (table: { [x: string]: GenericColumn }) => {\n let columns\n if (Array.isArray(name)) {\n columns = name\n .map((columnName) => table[columnName])\n // exclude fields were included in compound indexes but do not exist on the table\n .filter((col) => typeof col !== 'undefined')\n } else {\n columns = [table[name]]\n }\n if (unique)\n return uniqueIndex(`${tableName}_${columnName}_idx`).on(columns[0], ...columns.slice(1))\n return index(`${tableName}_${columnName}_idx`).on(columns[0], ...columns.slice(1))\n }\n}\n"],"names":["index","uniqueIndex","createIndex","name","columnName","tableName","unique","table","columns","Array","isArray","map","filter","col","on","slice"],"mappings":"AAAA,SAASA,KAAK,EAAEC,WAAW,QAAQ,sBAAqB;AAWxD,OAAO,MAAMC,cAAc,CAAC,EAAEC,IAAI,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAmB;IAClF,OAAO,CAACC;QACN,IAAIC;QACJ,IAAIC,MAAMC,OAAO,CAACP,OAAO;YACvBK,UAAUL,KACPQ,GAAG,CAAC,CAACP,aAAeG,KAAK,CAACH,WAAW,CACtC,iFAAiF;aAChFQ,MAAM,CAAC,CAACC,MAAQ,OAAOA,QAAQ;QACpC,OAAO;YACLL,UAAU;gBAACD,KAAK,CAACJ,KAAK;aAAC;QACzB;QACA,IAAIG,
|
|
1
|
+
{"version":3,"sources":["../../../src/postgres/schema/createIndex.ts"],"sourcesContent":["import { index, uniqueIndex } from 'drizzle-orm/pg-core'\n\nimport type { GenericColumn } from '../types.js'\n\ntype CreateIndexArgs = {\n columnName: string\n name: string | string[]\n tableName: string\n unique?: boolean\n}\n\nexport const createIndex = ({ name, columnName, tableName, unique }: CreateIndexArgs) => {\n return (table: { [x: string]: GenericColumn }) => {\n let columns\n if (Array.isArray(name)) {\n columns = name\n .map((columnName) => table[columnName])\n // exclude fields were included in compound indexes but do not exist on the table\n .filter((col) => typeof col !== 'undefined')\n } else {\n columns = [table[name]]\n }\n if (unique) {\n return uniqueIndex(`${tableName}_${columnName}_idx`).on(columns[0], ...columns.slice(1))\n }\n return index(`${tableName}_${columnName}_idx`).on(columns[0], ...columns.slice(1))\n }\n}\n"],"names":["index","uniqueIndex","createIndex","name","columnName","tableName","unique","table","columns","Array","isArray","map","filter","col","on","slice"],"mappings":"AAAA,SAASA,KAAK,EAAEC,WAAW,QAAQ,sBAAqB;AAWxD,OAAO,MAAMC,cAAc,CAAC,EAAEC,IAAI,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAmB;IAClF,OAAO,CAACC;QACN,IAAIC;QACJ,IAAIC,MAAMC,OAAO,CAACP,OAAO;YACvBK,UAAUL,KACPQ,GAAG,CAAC,CAACP,aAAeG,KAAK,CAACH,WAAW,CACtC,iFAAiF;aAChFQ,MAAM,CAAC,CAACC,MAAQ,OAAOA,QAAQ;QACpC,OAAO;YACLL,UAAU;gBAACD,KAAK,CAACJ,KAAK;aAAC;QACzB;QACA,IAAIG,QAAQ;YACV,OAAOL,YAAY,CAAC,EAAEI,UAAU,CAAC,EAAED,WAAW,IAAI,CAAC,EAAEU,EAAE,CAACN,OAAO,CAAC,EAAE,KAAKA,QAAQO,KAAK,CAAC;QACvF;QACA,OAAOf,MAAM,CAAC,EAAEK,UAAU,CAAC,EAAED,WAAW,IAAI,CAAC,EAAEU,EAAE,CAACN,OAAO,CAAC,EAAE,KAAKA,QAAQO,KAAK,CAAC;IACjF;AACF,EAAC"}
|
|
@@ -15,12 +15,17 @@ type Args = {
|
|
|
15
15
|
localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder>;
|
|
16
16
|
newTableName: string;
|
|
17
17
|
parentTableName: string;
|
|
18
|
-
relationsToBuild: RelationMap;
|
|
19
18
|
relationships: Set<string>;
|
|
19
|
+
relationsToBuild: RelationMap;
|
|
20
20
|
rootRelationsToBuild?: RelationMap;
|
|
21
21
|
rootTableIDColType: string;
|
|
22
22
|
rootTableName: string;
|
|
23
23
|
versions: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Tracks whether or not this table is built
|
|
26
|
+
* from the result of a localized array or block field at some point
|
|
27
|
+
*/
|
|
28
|
+
withinLocalizedArrayOrBlock?: boolean;
|
|
24
29
|
};
|
|
25
30
|
type Result = {
|
|
26
31
|
hasLocalizedField: boolean;
|
|
@@ -30,6 +35,6 @@ type Result = {
|
|
|
30
35
|
hasManyNumberField: 'index' | boolean;
|
|
31
36
|
hasManyTextField: 'index' | boolean;
|
|
32
37
|
};
|
|
33
|
-
export declare const traverseFields: ({ adapter, columnPrefix, columns, disableNotNull, disableUnique, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName,
|
|
38
|
+
export declare const traverseFields: ({ adapter, columnPrefix, columns, disableNotNull, disableUnique, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationships, relationsToBuild, rootRelationsToBuild, rootTableIDColType, rootTableName, versions, withinLocalizedArrayOrBlock, }: Args) => Result;
|
|
34
39
|
export {};
|
|
35
40
|
//# sourceMappingURL=traverseFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../src/postgres/schema/traverseFields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACxE,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAqBhD,OAAO,KAAK,EAEV,mBAAmB,EACnB,cAAc,EAEd,WAAW,EACZ,MAAM,aAAa,CAAA;AAWpB,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,mBAAmB,CA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AAA;IAC9B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,YAAY,CAAC,CAAA;IAC/D,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAC/C,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,YAAY,CAAC,CAAA;IACtE,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC1B,gBAAgB,EAAE,WAAW,CAAA;IAC7B,oBAAoB,CAAC,EAAE,WAAW,CAAA;IAClC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAA;CACtC,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,iBAAiB,EAAE,OAAO,CAAA;IAC1B,2BAA2B,EAAE,OAAO,CAAA;IACpC,yBAAyB,EAAE,OAAO,CAAA;IAClC,6BAA6B,EAAE,OAAO,CAAA;IACtC,kBAAkB,EAAE,OAAO,GAAG,OAAO,CAAA;IACrC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,cAAc,qTAqBxB,IAAI,KAAG,MAm1BT,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { relations } from 'drizzle-orm';
|
|
2
|
-
import {
|
|
2
|
+
import { boolean, foreignKey, index, integer, jsonb, numeric, PgNumericBuilder, PgUUIDBuilder, PgVarcharBuilder, text, timestamp, varchar } from 'drizzle-orm/pg-core';
|
|
3
3
|
import { InvalidConfiguration } from 'payload';
|
|
4
|
-
import { fieldAffectsData, optionIsObject } from 'payload/shared';
|
|
4
|
+
import { fieldAffectsData, fieldIsVirtual, optionIsObject } from 'payload/shared';
|
|
5
5
|
import toSnakeCase from 'to-snake-case';
|
|
6
6
|
import { createTableName } from '../../createTableName.js';
|
|
7
7
|
import { hasLocalesTable } from '../../utilities/hasLocalesTable.js';
|
|
@@ -11,7 +11,7 @@ import { createIndex } from './createIndex.js';
|
|
|
11
11
|
import { idToUUID } from './idToUUID.js';
|
|
12
12
|
import { parentIDColumnMap } from './parentIDColumnMap.js';
|
|
13
13
|
import { withDefault } from './withDefault.js';
|
|
14
|
-
export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull, disableUnique = false, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName,
|
|
14
|
+
export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull, disableUnique = false, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationships, relationsToBuild, rootRelationsToBuild, rootTableIDColType, rootTableName, versions, withinLocalizedArrayOrBlock })=>{
|
|
15
15
|
const throwValidationError = true;
|
|
16
16
|
let hasLocalizedField = false;
|
|
17
17
|
let hasLocalizedRelationshipField = false;
|
|
@@ -20,11 +20,22 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
20
20
|
let hasManyNumberField = false;
|
|
21
21
|
let hasLocalizedManyNumberField = false;
|
|
22
22
|
let parentIDColType = 'integer';
|
|
23
|
-
if (columns.id instanceof PgUUIDBuilder)
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if (columns.id instanceof PgUUIDBuilder) {
|
|
24
|
+
parentIDColType = 'uuid';
|
|
25
|
+
}
|
|
26
|
+
if (columns.id instanceof PgNumericBuilder) {
|
|
27
|
+
parentIDColType = 'numeric';
|
|
28
|
+
}
|
|
29
|
+
if (columns.id instanceof PgVarcharBuilder) {
|
|
30
|
+
parentIDColType = 'varchar';
|
|
31
|
+
}
|
|
26
32
|
fields.forEach((field)=>{
|
|
27
|
-
if ('name' in field && field.name === 'id')
|
|
33
|
+
if ('name' in field && field.name === 'id') {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (fieldIsVirtual(field)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
28
39
|
let columnName;
|
|
29
40
|
let fieldName;
|
|
30
41
|
let targetTable = columns;
|
|
@@ -56,7 +67,10 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
56
67
|
adapter.fieldConstraints[rootTableName][`${columnName}_idx`] = constraintValue;
|
|
57
68
|
}
|
|
58
69
|
targetIndexes[`${newTableName}_${field.name}Idx`] = createIndex({
|
|
59
|
-
name:
|
|
70
|
+
name: field.localized ? [
|
|
71
|
+
fieldName,
|
|
72
|
+
'_locale'
|
|
73
|
+
] : fieldName,
|
|
60
74
|
columnName,
|
|
61
75
|
tableName: newTableName,
|
|
62
76
|
unique
|
|
@@ -67,7 +81,8 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
67
81
|
case 'text':
|
|
68
82
|
{
|
|
69
83
|
if (field.hasMany) {
|
|
70
|
-
|
|
84
|
+
const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
85
|
+
if (isLocalized) {
|
|
71
86
|
hasLocalizedManyTextField = true;
|
|
72
87
|
}
|
|
73
88
|
if (field.index) {
|
|
@@ -93,7 +108,8 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
93
108
|
case 'number':
|
|
94
109
|
{
|
|
95
110
|
if (field.hasMany) {
|
|
96
|
-
|
|
111
|
+
const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
112
|
+
if (isLocalized) {
|
|
97
113
|
hasLocalizedManyNumberField = true;
|
|
98
114
|
}
|
|
99
115
|
if (field.index) {
|
|
@@ -172,7 +188,8 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
172
188
|
}).onDelete('cascade'),
|
|
173
189
|
parentIdx: (cols)=>index(`${selectTableName}_parent_idx`).on(cols.parent)
|
|
174
190
|
};
|
|
175
|
-
|
|
191
|
+
const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
192
|
+
if (isLocalized) {
|
|
176
193
|
baseColumns.locale = adapter.enums.enum__locales('locale').notNull();
|
|
177
194
|
baseExtraConfig.localeIdx = (cols)=>index(`${selectTableName}_locale_idx`).on(cols.locale);
|
|
178
195
|
}
|
|
@@ -245,29 +262,44 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
245
262
|
}).onDelete('cascade'),
|
|
246
263
|
_parentIDIdx: (cols)=>index(`${arrayTableName}_parent_id_idx`).on(cols._parentID)
|
|
247
264
|
};
|
|
248
|
-
|
|
265
|
+
const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
266
|
+
if (isLocalized) {
|
|
249
267
|
baseColumns._locale = adapter.enums.enum__locales('_locale').notNull();
|
|
250
268
|
baseExtraConfig._localeIdx = (cols)=>index(`${arrayTableName}_locale_idx`).on(cols._locale);
|
|
251
269
|
}
|
|
252
|
-
const { hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
|
|
270
|
+
const { hasLocalizedManyNumberField: subHasLocalizedManyNumberField, hasLocalizedManyTextField: subHasLocalizedManyTextField, hasLocalizedRelationshipField: subHasLocalizedRelationshipField, hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
|
|
253
271
|
adapter,
|
|
254
272
|
baseColumns,
|
|
255
273
|
baseExtraConfig,
|
|
256
274
|
disableNotNull: disableNotNullFromHere,
|
|
257
275
|
disableUnique,
|
|
258
276
|
fields: disableUnique ? idToUUID(field.fields) : field.fields,
|
|
259
|
-
rootRelationsToBuild,
|
|
260
277
|
rootRelationships: relationships,
|
|
278
|
+
rootRelationsToBuild,
|
|
261
279
|
rootTableIDColType,
|
|
262
280
|
rootTableName,
|
|
263
281
|
tableName: arrayTableName,
|
|
264
|
-
versions
|
|
282
|
+
versions,
|
|
283
|
+
withinLocalizedArrayOrBlock: isLocalized
|
|
265
284
|
});
|
|
285
|
+
if (subHasLocalizedManyNumberField) {
|
|
286
|
+
hasLocalizedManyNumberField = subHasLocalizedManyNumberField;
|
|
287
|
+
}
|
|
288
|
+
if (subHasLocalizedRelationshipField) {
|
|
289
|
+
hasLocalizedRelationshipField = subHasLocalizedRelationshipField;
|
|
290
|
+
}
|
|
291
|
+
if (subHasLocalizedManyTextField) {
|
|
292
|
+
hasLocalizedManyTextField = subHasLocalizedManyTextField;
|
|
293
|
+
}
|
|
266
294
|
if (subHasManyTextField) {
|
|
267
|
-
if (!hasManyTextField || subHasManyTextField === 'index')
|
|
295
|
+
if (!hasManyTextField || subHasManyTextField === 'index') {
|
|
296
|
+
hasManyTextField = subHasManyTextField;
|
|
297
|
+
}
|
|
268
298
|
}
|
|
269
299
|
if (subHasManyNumberField) {
|
|
270
|
-
if (!hasManyNumberField || subHasManyNumberField === 'index')
|
|
300
|
+
if (!hasManyNumberField || subHasManyNumberField === 'index') {
|
|
301
|
+
hasManyNumberField = subHasManyNumberField;
|
|
302
|
+
}
|
|
271
303
|
}
|
|
272
304
|
relationsToBuild.set(fieldName, {
|
|
273
305
|
type: 'many',
|
|
@@ -335,7 +367,6 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
335
367
|
};
|
|
336
368
|
const baseExtraConfig = {
|
|
337
369
|
_orderIdx: (cols)=>index(`${blockTableName}_order_idx`).on(cols._order),
|
|
338
|
-
_parentIDIdx: (cols)=>index(`${blockTableName}_parent_id_idx`).on(cols._parentID),
|
|
339
370
|
_parentIdFk: (cols)=>foreignKey({
|
|
340
371
|
name: `${blockTableName}_parent_id_fk`,
|
|
341
372
|
columns: [
|
|
@@ -345,31 +376,47 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
345
376
|
adapter.tables[rootTableName].id
|
|
346
377
|
]
|
|
347
378
|
}).onDelete('cascade'),
|
|
379
|
+
_parentIDIdx: (cols)=>index(`${blockTableName}_parent_id_idx`).on(cols._parentID),
|
|
348
380
|
_pathIdx: (cols)=>index(`${blockTableName}_path_idx`).on(cols._path)
|
|
349
381
|
};
|
|
350
|
-
|
|
382
|
+
const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
383
|
+
if (isLocalized) {
|
|
351
384
|
baseColumns._locale = adapter.enums.enum__locales('_locale').notNull();
|
|
352
385
|
baseExtraConfig._localeIdx = (cols)=>index(`${blockTableName}_locale_idx`).on(cols._locale);
|
|
353
386
|
}
|
|
354
|
-
const { hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
|
|
387
|
+
const { hasLocalizedManyNumberField: subHasLocalizedManyNumberField, hasLocalizedManyTextField: subHasLocalizedManyTextField, hasLocalizedRelationshipField: subHasLocalizedRelationshipField, hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
|
|
355
388
|
adapter,
|
|
356
389
|
baseColumns,
|
|
357
390
|
baseExtraConfig,
|
|
358
391
|
disableNotNull: disableNotNullFromHere,
|
|
359
392
|
disableUnique,
|
|
360
393
|
fields: disableUnique ? idToUUID(block.fields) : block.fields,
|
|
361
|
-
rootRelationsToBuild,
|
|
362
394
|
rootRelationships: relationships,
|
|
395
|
+
rootRelationsToBuild,
|
|
363
396
|
rootTableIDColType,
|
|
364
397
|
rootTableName,
|
|
365
398
|
tableName: blockTableName,
|
|
366
|
-
versions
|
|
399
|
+
versions,
|
|
400
|
+
withinLocalizedArrayOrBlock: isLocalized
|
|
367
401
|
});
|
|
402
|
+
if (subHasLocalizedManyNumberField) {
|
|
403
|
+
hasLocalizedManyNumberField = subHasLocalizedManyNumberField;
|
|
404
|
+
}
|
|
405
|
+
if (subHasLocalizedRelationshipField) {
|
|
406
|
+
hasLocalizedRelationshipField = subHasLocalizedRelationshipField;
|
|
407
|
+
}
|
|
408
|
+
if (subHasLocalizedManyTextField) {
|
|
409
|
+
hasLocalizedManyTextField = subHasLocalizedManyTextField;
|
|
410
|
+
}
|
|
368
411
|
if (subHasManyTextField) {
|
|
369
|
-
if (!hasManyTextField || subHasManyTextField === 'index')
|
|
412
|
+
if (!hasManyTextField || subHasManyTextField === 'index') {
|
|
413
|
+
hasManyTextField = subHasManyTextField;
|
|
414
|
+
}
|
|
370
415
|
}
|
|
371
416
|
if (subHasManyNumberField) {
|
|
372
|
-
if (!hasManyNumberField || subHasManyNumberField === 'index')
|
|
417
|
+
if (!hasManyNumberField || subHasManyNumberField === 'index') {
|
|
418
|
+
hasManyNumberField = subHasManyNumberField;
|
|
419
|
+
}
|
|
373
420
|
}
|
|
374
421
|
adapter.relations[`relations_${blockTableName}`] = relations(adapter.tables[blockTableName], ({ many, one })=>{
|
|
375
422
|
const result = {
|
|
@@ -446,19 +493,32 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
446
493
|
localesIndexes,
|
|
447
494
|
newTableName,
|
|
448
495
|
parentTableName,
|
|
449
|
-
relationsToBuild,
|
|
450
496
|
relationships,
|
|
497
|
+
relationsToBuild,
|
|
451
498
|
rootRelationsToBuild,
|
|
452
499
|
rootTableIDColType,
|
|
453
500
|
rootTableName,
|
|
454
|
-
versions
|
|
501
|
+
versions,
|
|
502
|
+
withinLocalizedArrayOrBlock
|
|
455
503
|
});
|
|
456
|
-
if (groupHasLocalizedField)
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
if (
|
|
460
|
-
|
|
461
|
-
|
|
504
|
+
if (groupHasLocalizedField) {
|
|
505
|
+
hasLocalizedField = true;
|
|
506
|
+
}
|
|
507
|
+
if (groupHasLocalizedRelationshipField) {
|
|
508
|
+
hasLocalizedRelationshipField = true;
|
|
509
|
+
}
|
|
510
|
+
if (groupHasManyTextField) {
|
|
511
|
+
hasManyTextField = true;
|
|
512
|
+
}
|
|
513
|
+
if (groupHasLocalizedManyTextField) {
|
|
514
|
+
hasLocalizedManyTextField = true;
|
|
515
|
+
}
|
|
516
|
+
if (groupHasManyNumberField) {
|
|
517
|
+
hasManyNumberField = true;
|
|
518
|
+
}
|
|
519
|
+
if (groupHasLocalizedManyNumberField) {
|
|
520
|
+
hasLocalizedManyNumberField = true;
|
|
521
|
+
}
|
|
462
522
|
break;
|
|
463
523
|
}
|
|
464
524
|
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
|
@@ -476,19 +536,32 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
476
536
|
localesIndexes,
|
|
477
537
|
newTableName: `${parentTableName}_${columnName}`,
|
|
478
538
|
parentTableName,
|
|
479
|
-
relationsToBuild,
|
|
480
539
|
relationships,
|
|
540
|
+
relationsToBuild,
|
|
481
541
|
rootRelationsToBuild,
|
|
482
542
|
rootTableIDColType,
|
|
483
543
|
rootTableName,
|
|
484
|
-
versions
|
|
544
|
+
versions,
|
|
545
|
+
withinLocalizedArrayOrBlock: withinLocalizedArrayOrBlock || field.localized
|
|
485
546
|
});
|
|
486
|
-
if (groupHasLocalizedField)
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
if (
|
|
490
|
-
|
|
491
|
-
|
|
547
|
+
if (groupHasLocalizedField) {
|
|
548
|
+
hasLocalizedField = true;
|
|
549
|
+
}
|
|
550
|
+
if (groupHasLocalizedRelationshipField) {
|
|
551
|
+
hasLocalizedRelationshipField = true;
|
|
552
|
+
}
|
|
553
|
+
if (groupHasManyTextField) {
|
|
554
|
+
hasManyTextField = true;
|
|
555
|
+
}
|
|
556
|
+
if (groupHasLocalizedManyTextField) {
|
|
557
|
+
hasLocalizedManyTextField = true;
|
|
558
|
+
}
|
|
559
|
+
if (groupHasManyNumberField) {
|
|
560
|
+
hasManyNumberField = true;
|
|
561
|
+
}
|
|
562
|
+
if (groupHasLocalizedManyNumberField) {
|
|
563
|
+
hasLocalizedManyNumberField = true;
|
|
564
|
+
}
|
|
492
565
|
break;
|
|
493
566
|
}
|
|
494
567
|
case 'tabs':
|
|
@@ -511,19 +584,32 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
511
584
|
localesIndexes,
|
|
512
585
|
newTableName,
|
|
513
586
|
parentTableName,
|
|
514
|
-
relationsToBuild,
|
|
515
587
|
relationships,
|
|
588
|
+
relationsToBuild,
|
|
516
589
|
rootRelationsToBuild,
|
|
517
590
|
rootTableIDColType,
|
|
518
591
|
rootTableName,
|
|
519
|
-
versions
|
|
592
|
+
versions,
|
|
593
|
+
withinLocalizedArrayOrBlock
|
|
520
594
|
});
|
|
521
|
-
if (tabHasLocalizedField)
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
if (
|
|
525
|
-
|
|
526
|
-
|
|
595
|
+
if (tabHasLocalizedField) {
|
|
596
|
+
hasLocalizedField = true;
|
|
597
|
+
}
|
|
598
|
+
if (tabHasLocalizedRelationshipField) {
|
|
599
|
+
hasLocalizedRelationshipField = true;
|
|
600
|
+
}
|
|
601
|
+
if (tabHasManyTextField) {
|
|
602
|
+
hasManyTextField = true;
|
|
603
|
+
}
|
|
604
|
+
if (tabHasLocalizedManyTextField) {
|
|
605
|
+
hasLocalizedManyTextField = true;
|
|
606
|
+
}
|
|
607
|
+
if (tabHasManyNumberField) {
|
|
608
|
+
hasManyNumberField = true;
|
|
609
|
+
}
|
|
610
|
+
if (tabHasLocalizedManyNumberField) {
|
|
611
|
+
hasLocalizedManyNumberField = true;
|
|
612
|
+
}
|
|
527
613
|
break;
|
|
528
614
|
}
|
|
529
615
|
case 'row':
|
|
@@ -544,26 +630,39 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
544
630
|
localesIndexes,
|
|
545
631
|
newTableName,
|
|
546
632
|
parentTableName,
|
|
547
|
-
relationsToBuild,
|
|
548
633
|
relationships,
|
|
634
|
+
relationsToBuild,
|
|
549
635
|
rootRelationsToBuild,
|
|
550
636
|
rootTableIDColType,
|
|
551
637
|
rootTableName,
|
|
552
|
-
versions
|
|
638
|
+
versions,
|
|
639
|
+
withinLocalizedArrayOrBlock
|
|
553
640
|
});
|
|
554
|
-
if (rowHasLocalizedField)
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
if (
|
|
558
|
-
|
|
559
|
-
|
|
641
|
+
if (rowHasLocalizedField) {
|
|
642
|
+
hasLocalizedField = true;
|
|
643
|
+
}
|
|
644
|
+
if (rowHasLocalizedRelationshipField) {
|
|
645
|
+
hasLocalizedRelationshipField = true;
|
|
646
|
+
}
|
|
647
|
+
if (rowHasManyTextField) {
|
|
648
|
+
hasManyTextField = true;
|
|
649
|
+
}
|
|
650
|
+
if (rowHasLocalizedManyTextField) {
|
|
651
|
+
hasLocalizedManyTextField = true;
|
|
652
|
+
}
|
|
653
|
+
if (rowHasManyNumberField) {
|
|
654
|
+
hasManyNumberField = true;
|
|
655
|
+
}
|
|
656
|
+
if (rowHasLocalizedManyNumberField) {
|
|
657
|
+
hasLocalizedManyNumberField = true;
|
|
658
|
+
}
|
|
560
659
|
break;
|
|
561
660
|
}
|
|
562
661
|
case 'relationship':
|
|
563
662
|
case 'upload':
|
|
564
663
|
if (Array.isArray(field.relationTo)) {
|
|
565
664
|
field.relationTo.forEach((relation)=>relationships.add(relation));
|
|
566
|
-
} else if (field.
|
|
665
|
+
} else if (field.hasMany) {
|
|
567
666
|
relationships.add(field.relationTo);
|
|
568
667
|
} else {
|
|
569
668
|
// simple relationships get a column on the targetTable with a foreign key to the relationTo table
|
|
@@ -572,8 +671,12 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
572
671
|
// get the id type of the related collection
|
|
573
672
|
let colType = adapter.idType === 'uuid' ? 'uuid' : 'integer';
|
|
574
673
|
const relatedCollectionCustomID = relationshipConfig.fields.find((field)=>fieldAffectsData(field) && field.name === 'id');
|
|
575
|
-
if (relatedCollectionCustomID?.type === 'number')
|
|
576
|
-
|
|
674
|
+
if (relatedCollectionCustomID?.type === 'number') {
|
|
675
|
+
colType = 'numeric';
|
|
676
|
+
}
|
|
677
|
+
if (relatedCollectionCustomID?.type === 'text') {
|
|
678
|
+
colType = 'varchar';
|
|
679
|
+
}
|
|
577
680
|
// make the foreign key column for relationship using the correct id column type
|
|
578
681
|
targetTable[fieldName] = parentIDColumnMap[colType](`${columnName}_id`).references(()=>adapter.tables[tableName].id, {
|
|
579
682
|
onDelete: 'set null'
|
|
@@ -581,7 +684,7 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
581
684
|
// add relationship to table
|
|
582
685
|
relationsToBuild.set(fieldName, {
|
|
583
686
|
type: 'one',
|
|
584
|
-
localized: adapter.payload.config.localization && field.localized,
|
|
687
|
+
localized: adapter.payload.config.localization && (field.localized || forceLocalized),
|
|
585
688
|
target: tableName
|
|
586
689
|
});
|
|
587
690
|
// add notNull when not required
|
|
@@ -590,10 +693,25 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
590
693
|
}
|
|
591
694
|
break;
|
|
592
695
|
}
|
|
593
|
-
if (adapter.payload.config.localization
|
|
696
|
+
if (Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock) {
|
|
594
697
|
hasLocalizedRelationshipField = true;
|
|
595
698
|
}
|
|
596
699
|
break;
|
|
700
|
+
case 'join':
|
|
701
|
+
{
|
|
702
|
+
// fieldName could be 'posts' or 'group_posts'
|
|
703
|
+
// using on as the key for the relation
|
|
704
|
+
const localized = adapter.payload.config.localization && field.localized;
|
|
705
|
+
const target = `${adapter.tableNameMap.get(toSnakeCase(field.collection))}${localized ? adapter.localesSuffix : ''}`;
|
|
706
|
+
relationsToBuild.set(fieldName, {
|
|
707
|
+
type: 'many',
|
|
708
|
+
// joins are not localized on the parent table
|
|
709
|
+
localized: false,
|
|
710
|
+
relationName: field.on.replaceAll('.', '_'),
|
|
711
|
+
target
|
|
712
|
+
});
|
|
713
|
+
break;
|
|
714
|
+
}
|
|
597
715
|
default:
|
|
598
716
|
break;
|
|
599
717
|
}
|