@payloadcms/db-postgres 3.0.0-alpha.53 → 3.0.0-alpha.55
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +5 -2
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +5 -2
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +6 -3
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +12 -4
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.js +5 -2
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +5 -2
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +6 -2
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +24 -5
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +9 -5
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +5 -2
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +6 -2
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +8 -4
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +6 -2
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +27 -9
- package/dist/init.js.map +1 -1
- package/dist/migrate.js.map +1 -1
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +57 -13
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +6 -2
- package/dist/queryDrafts.js.map +1 -1
- package/dist/schema/build.d.ts +2 -1
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/build.js +18 -8
- package/dist/schema/build.js.map +1 -1
- package/dist/schema/getTableName.d.ts +32 -0
- package/dist/schema/getTableName.d.ts.map +1 -0
- package/dist/schema/getTableName.js +31 -0
- package/dist/schema/getTableName.js.map +1 -0
- package/dist/schema/traverseFields.d.ts +2 -1
- package/dist/schema/traverseFields.d.ts.map +1 -1
- package/dist/schema/traverseFields.js +52 -15
- package/dist/schema/traverseFields.js.map +1 -1
- package/dist/types.d.ts +13 -0
- 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 +6 -3
- package/dist/update.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +5 -2
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +6 -2
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +6 -2
- package/dist/updateVersion.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +6 -1
package/dist/schema/build.d.ts
CHANGED
@@ -17,12 +17,13 @@ type Args = {
|
|
17
17
|
rootTableName?: string;
|
18
18
|
tableName: string;
|
19
19
|
timestamps?: boolean;
|
20
|
+
versions: boolean;
|
20
21
|
};
|
21
22
|
type Result = {
|
22
23
|
hasManyNumberField: 'index' | boolean;
|
23
24
|
hasManyTextField: 'index' | boolean;
|
24
25
|
relationsToBuild: Map<string, string>;
|
25
26
|
};
|
26
|
-
export declare const buildTable: ({ adapter, baseColumns, baseExtraConfig, buildNumbers, buildRelationships, buildTexts, disableNotNull, disableUnique, fields, rootRelationsToBuild, rootRelationships, rootTableIDColType, rootTableName: incomingRootTableName, tableName, timestamps, }: Args) => Result;
|
27
|
+
export declare const buildTable: ({ adapter, baseColumns, baseExtraConfig, buildNumbers, buildRelationships, buildTexts, disableNotNull, disableUnique, fields, rootRelationsToBuild, rootRelationships, rootTableIDColType, rootTableName: incomingRootTableName, tableName, timestamps, versions, }: Args) => Result;
|
27
28
|
export {};
|
28
29
|
//# sourceMappingURL=build.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/schema/build.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EAEf,uBAAuB,EACxB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/schema/build.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EAEf,uBAAuB,EACxB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAM1C,OAAO,KAAK,EAAE,cAAc,EAAwB,eAAe,EAAE,MAAM,aAAa,CAAA;AAOxF,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAC7C,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,YAAY,GAAG,uBAAuB,CAAC,CAAA;IAClG,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,cAAc,EAAE,OAAO,CAAA;IACvB,aAAa,EAAE,OAAO,CAAA;IACtB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,oBAAoB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC1C,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC/B,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,kBAAkB,EAAE,OAAO,GAAG,OAAO,CAAA;IACrC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAA;IACnC,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACtC,CAAA;AAED,eAAO,MAAM,UAAU,wQAiBpB,IAAI,KAAG,MAyUT,CAAA"}
|
package/dist/schema/build.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
/* eslint-disable no-param-reassign */ import { relations } from 'drizzle-orm';
|
2
2
|
import { index, integer, numeric, serial, timestamp, unique, varchar } from 'drizzle-orm/pg-core';
|
3
3
|
import { fieldAffectsData } from 'payload/types';
|
4
|
-
import
|
4
|
+
import { getTableName } from './getTableName.js';
|
5
5
|
import { parentIDColumnMap } from './parentIDColumnMap.js';
|
6
6
|
import { setColumnID } from './setColumnID.js';
|
7
7
|
import { traverseFields } from './traverseFields.js';
|
8
|
-
export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, buildNumbers, buildRelationships, buildTexts, disableNotNull, disableUnique = false, fields, rootRelationsToBuild, rootRelationships, rootTableIDColType, rootTableName: incomingRootTableName, tableName, timestamps })=>{
|
8
|
+
export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, buildNumbers, buildRelationships, buildTexts, disableNotNull, disableUnique = false, fields, rootRelationsToBuild, rootRelationships, rootTableIDColType, rootTableName: incomingRootTableName, tableName, timestamps, versions })=>{
|
9
9
|
const rootTableName = incomingRootTableName || tableName;
|
10
10
|
const columns = baseColumns;
|
11
11
|
const indexes = {};
|
@@ -48,7 +48,8 @@ export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, bu
|
|
48
48
|
relationships,
|
49
49
|
rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,
|
50
50
|
rootTableIDColType: rootTableIDColType || idColType,
|
51
|
-
rootTableName
|
51
|
+
rootTableName,
|
52
|
+
versions
|
52
53
|
}));
|
53
54
|
if (timestamps) {
|
54
55
|
columns.createdAt = timestamp('created_at', {
|
@@ -74,7 +75,7 @@ export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, bu
|
|
74
75
|
});
|
75
76
|
adapter.tables[tableName] = table;
|
76
77
|
if (hasLocalizedField) {
|
77
|
-
const localeTableName = `${tableName}
|
78
|
+
const localeTableName = `${tableName}${adapter.localesSuffix}`;
|
78
79
|
localesColumns.id = serial('id').primaryKey();
|
79
80
|
localesColumns._locale = adapter.enums.enum__locales('_locale').notNull();
|
80
81
|
localesColumns._parentID = parentIDColumnMap[idColType]('_parent_id').references(()=>table.id, {
|
@@ -193,16 +194,21 @@ export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, bu
|
|
193
194
|
relationshipColumns.locale = adapter.enums.enum__locales('locale');
|
194
195
|
}
|
195
196
|
relationships.forEach((relationTo)=>{
|
196
|
-
const
|
197
|
+
const relationshipConfig = adapter.payload.collections[relationTo].config;
|
198
|
+
const formattedRelationTo = getTableName({
|
199
|
+
adapter,
|
200
|
+
config: relationshipConfig,
|
201
|
+
throwValidationError: true
|
202
|
+
});
|
197
203
|
let colType = adapter.idType === 'uuid' ? 'uuid' : 'integer';
|
198
|
-
const relatedCollectionCustomID =
|
204
|
+
const relatedCollectionCustomID = relationshipConfig.fields.find((field)=>fieldAffectsData(field) && field.name === 'id');
|
199
205
|
if (relatedCollectionCustomID?.type === 'number') colType = 'numeric';
|
200
206
|
if (relatedCollectionCustomID?.type === 'text') colType = 'varchar';
|
201
207
|
relationshipColumns[`${relationTo}ID`] = parentIDColumnMap[colType](`${formattedRelationTo}_id`).references(()=>adapter.tables[formattedRelationTo].id, {
|
202
208
|
onDelete: 'cascade'
|
203
209
|
});
|
204
210
|
});
|
205
|
-
const relationshipsTableName = `${tableName}
|
211
|
+
const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`;
|
206
212
|
relationshipsTable = adapter.pgSchema.table(relationshipsTableName, relationshipColumns, (cols)=>{
|
207
213
|
const result = {
|
208
214
|
order: index(`${relationshipsTableName}_order_idx`).on(cols.order),
|
@@ -228,7 +234,11 @@ export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, bu
|
|
228
234
|
})
|
229
235
|
};
|
230
236
|
relationships.forEach((relationTo)=>{
|
231
|
-
const relatedTableName =
|
237
|
+
const relatedTableName = getTableName({
|
238
|
+
adapter,
|
239
|
+
config: adapter.payload.collections[relationTo].config,
|
240
|
+
throwValidationError: true
|
241
|
+
});
|
232
242
|
const idColumnName = `${relationTo}ID`;
|
233
243
|
result[idColumnName] = one(adapter.tables[relatedTableName], {
|
234
244
|
fields: [
|
package/dist/schema/build.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/schema/build.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Relation } from 'drizzle-orm'\nimport type {\n IndexBuilder,\n PgColumnBuilder,\n PgTableWithColumns,\n UniqueConstraintBuilder,\n} from 'drizzle-orm/pg-core'\nimport type { Field } from 'payload/types'\n\nimport { relations } from 'drizzle-orm'\nimport { index, integer, numeric, serial, timestamp, unique, varchar } from 'drizzle-orm/pg-core'\nimport { fieldAffectsData } from 'payload/types'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { GenericColumns, GenericTable, IDType, PostgresAdapter } from '../types.js'\n\nimport { parentIDColumnMap } from './parentIDColumnMap.js'\nimport { setColumnID } from './setColumnID.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: PostgresAdapter\n baseColumns?: Record<string, PgColumnBuilder>\n baseExtraConfig?: Record<string, (cols: GenericColumns) => IndexBuilder | UniqueConstraintBuilder>\n buildNumbers?: boolean\n buildRelationships?: boolean\n buildTexts?: boolean\n disableNotNull: boolean\n disableUnique: boolean\n fields: Field[]\n rootRelationsToBuild?: Map<string, string>\n rootRelationships?: Set<string>\n rootTableIDColType?: string\n rootTableName?: string\n tableName: string\n timestamps?: boolean\n}\n\ntype Result = {\n hasManyNumberField: 'index' | boolean\n hasManyTextField: 'index' | boolean\n relationsToBuild: Map<string, string>\n}\n\nexport const buildTable = ({\n adapter,\n baseColumns = {},\n baseExtraConfig = {},\n buildNumbers,\n buildRelationships,\n buildTexts,\n disableNotNull,\n disableUnique = false,\n fields,\n rootRelationsToBuild,\n rootRelationships,\n rootTableIDColType,\n rootTableName: incomingRootTableName,\n tableName,\n timestamps,\n}: Args): Result => {\n const rootTableName = incomingRootTableName || tableName\n const columns: Record<string, PgColumnBuilder> = baseColumns\n const indexes: Record<string, (cols: GenericColumns) => IndexBuilder> = {}\n\n let hasLocalizedField = false\n let hasLocalizedRelationshipField = false\n let hasManyTextField: 'index' | boolean = false\n let hasManyNumberField: 'index' | boolean = false\n let hasLocalizedManyTextField = false\n let hasLocalizedManyNumberField = false\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: Map<string, string> = new Map()\n\n const idColType: IDType = setColumnID({ adapter, columns, fields })\n\n ;({\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n } = traverseFields({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\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 }))\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 return Object.entries(indexes).reduce((acc, [colName, func]) => {\n acc[colName] = func(cols)\n return acc\n }, extraConfig)\n })\n\n adapter.tables[tableName] = table\n\n if (hasLocalizedField) {\n const localeTableName = `${tableName}_locales`\n localesColumns.id = serial('id').primaryKey()\n localesColumns._locale = adapter.enums.enum__locales('_locale').notNull()\n localesColumns._parentID = parentIDColumnMap[idColType]('_parent_id')\n .references(() => table.id, { onDelete: 'cascade' })\n .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 },\n )\n })\n\n adapter.tables[localeTableName] = localesTable\n\n const localesTableRelations = relations(localesTable, ({ one }) => ({\n _parentID: one(table, {\n fields: [localesTable._parentID],\n references: [table.id],\n }),\n }))\n\n adapter.relations[`relations_${localeTableName}`] = localesTableRelations\n }\n\n if (hasManyTextField && buildTexts) {\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')\n .references(() => table.id, { onDelete: 'cascade' })\n .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 indexes: Record<string, IndexBuilder> = {\n orderParentIdx: index(`${textsTableName}_order_parent_idx`).on(cols.order, cols.parent),\n }\n\n if (hasManyTextField === 'index') {\n indexes.text_idx = index(`${textsTableName}_text_idx`).on(cols.text)\n }\n\n if (hasLocalizedManyTextField) {\n indexes.localeParent = index(`${textsTableName}_locale_parent`).on(cols.locale, cols.parent)\n }\n\n return indexes\n })\n\n adapter.tables[textsTableName] = textsTable\n\n const textsTableRelations = relations(textsTable, ({ one }) => ({\n parent: one(table, {\n fields: [textsTable.parent],\n references: [table.id],\n }),\n }))\n\n adapter.relations[`relations_${textsTableName}`] = textsTableRelations\n }\n\n if (hasManyNumberField && buildNumbers) {\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')\n .references(() => table.id, { onDelete: 'cascade' })\n .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 indexes: Record<string, IndexBuilder> = {\n orderParentIdx: index(`${numbersTableName}_order_parent_idx`).on(cols.order, cols.parent),\n }\n\n if (hasManyNumberField === 'index') {\n indexes.numberIdx = index(`${numbersTableName}_number_idx`).on(cols.number)\n }\n\n if (hasLocalizedManyNumberField) {\n indexes.localeParent = index(`${numbersTableName}_locale_parent`).on(\n cols.locale,\n cols.parent,\n )\n }\n\n return indexes\n })\n\n adapter.tables[numbersTableName] = numbersTable\n\n const numbersTableRelations = relations(numbersTable, ({ one }) => ({\n parent: one(table, {\n fields: [numbersTable.parent],\n references: [table.id],\n }),\n }))\n\n adapter.relations[`relations_${numbersTableName}`] = numbersTableRelations\n }\n\n if (buildRelationships) {\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')\n .references(() => table.id, { onDelete: 'cascade' })\n .notNull(),\n path: varchar('path').notNull(),\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipColumns.locale = adapter.enums.enum__locales('locale')\n }\n\n relationships.forEach((relationTo) => {\n const formattedRelationTo = toSnakeCase(relationTo)\n let colType = adapter.idType === 'uuid' ? 'uuid' : 'integer'\n const relatedCollectionCustomID = adapter.payload.collections[\n relationTo\n ].config.fields.find((field) => fieldAffectsData(field) && field.name === 'id')\n if (relatedCollectionCustomID?.type === 'number') colType = 'numeric'\n if (relatedCollectionCustomID?.type === 'text') colType = 'varchar'\n\n relationshipColumns[`${relationTo}ID`] = parentIDColumnMap[colType](\n `${formattedRelationTo}_id`,\n ).references(() => adapter.tables[formattedRelationTo].id, { onDelete: 'cascade' })\n })\n\n const relationshipsTableName = `${tableName}_rels`\n\n relationshipsTable = adapter.pgSchema.table(\n relationshipsTableName,\n relationshipColumns,\n (cols) => {\n const result: Record<string, unknown> = {\n order: index(`${relationshipsTableName}_order_idx`).on(cols.order),\n parentIdx: index(`${relationshipsTableName}_parent_idx`).on(cols.parent),\n pathIdx: index(`${relationshipsTableName}_path_idx`).on(cols.path),\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 const relationshipsTableRelations = relations(relationshipsTable, ({ 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 = toSnakeCase(relationTo)\n const idColumnName = `${relationTo}ID`\n result[idColumnName] = one(adapter.tables[relatedTableName], {\n fields: [relationshipsTable[idColumnName]],\n references: [adapter.tables[relatedTableName].id],\n })\n })\n\n return result\n })\n\n adapter.relations[`relations_${relationshipsTableName}`] = relationshipsTableRelations\n }\n }\n\n const tableRelations = relations(table, ({ many }) => {\n const result: Record<string, Relation<string>> = {}\n\n relationsToBuild.forEach((val, key) => {\n result[key] = many(adapter.tables[val])\n })\n\n if (hasLocalizedField) {\n result._locales = many(localesTable)\n }\n\n if (hasManyTextField) {\n result._texts = many(textsTable)\n }\n if (hasManyNumberField) {\n result._numbers = many(numbersTable)\n }\n\n if (relationships.size && relationshipsTable) {\n result._rels = many(relationshipsTable, {\n relationName: '_rels',\n })\n }\n\n return result\n })\n\n adapter.relations[`relations_${tableName}`] = tableRelations\n\n return { hasManyNumberField, hasManyTextField, relationsToBuild }\n}\n"],"names":["relations","index","integer","numeric","serial","timestamp","unique","varchar","fieldAffectsData","toSnakeCase","parentIDColumnMap","setColumnID","traverseFields","buildTable","adapter","baseColumns","baseExtraConfig","buildNumbers","buildRelationships","buildTexts","disableNotNull","disableUnique","fields","rootRelationsToBuild","rootRelationships","rootTableIDColType","rootTableName","incomingRootTableName","tableName","timestamps","columns","indexes","hasLocalizedField","hasLocalizedRelationshipField","hasManyTextField","hasManyNumberField","hasLocalizedManyTextField","hasLocalizedManyNumberField","localesColumns","localesIndexes","localesTable","textsTable","numbersTable","relationships","Set","relationshipsTable","relationsToBuild","Map","idColType","newTableName","parentTableName","createdAt","mode","precision","withTimezone","defaultNow","notNull","updatedAt","table","pgSchema","cols","extraConfig","Object","entries","reduce","config","key","func","acc","colName","tables","localeTableName","id","primaryKey","_locale","enums","enum__locales","_parentID","references","onDelete","_localeParent","on","localesTableRelations","one","textsTableName","order","parent","path","text","locale","orderParentIdx","text_idx","localeParent","textsTableRelations","numbersTableName","number","numberIdx","numbersTableRelations","size","relationshipColumns","forEach","relationTo","formattedRelationTo","colType","idType","relatedCollectionCustomID","payload","collections","find","field","name","type","relationshipsTableName","result","parentIdx","pathIdx","localeIdx","relationshipsTableRelations","relationName","relatedTableName","idColumnName","tableRelations","many","val","_locales","_texts","_numbers","_rels"],"mappings":"AAAA,oCAAoC,GAUpC,SAASA,SAAS,QAAQ,cAAa;AACvC,SAASC,KAAK,EAAEC,OAAO,EAAEC,OAAO,EAAEC,MAAM,EAAEC,SAAS,EAAEC,MAAM,EAAEC,OAAO,QAAQ,sBAAqB;AACjG,SAASC,gBAAgB,QAAQ,gBAAe;AAChD,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,cAAc,QAAQ,sBAAqB;AA0BpD,OAAO,MAAMC,aAAa,CAAC,EACzBC,OAAO,EACPC,cAAc,CAAC,CAAC,EAChBC,kBAAkB,CAAC,CAAC,EACpBC,YAAY,EACZC,kBAAkB,EAClBC,UAAU,EACVC,cAAc,EACdC,gBAAgB,KAAK,EACrBC,MAAM,EACNC,oBAAoB,EACpBC,iBAAiB,EACjBC,kBAAkB,EAClBC,eAAeC,qBAAqB,EACpCC,SAAS,EACTC,UAAU,EACL;IACL,MAAMH,gBAAgBC,yBAAyBC;IAC/C,MAAME,UAA2Cf;IACjD,MAAMgB,UAAkE,CAAC;IAEzE,IAAIC,oBAAoB;IACxB,IAAIC,gCAAgC;IACpC,IAAIC,mBAAsC;IAC1C,IAAIC,qBAAwC;IAC5C,IAAIC,4BAA4B;IAChC,IAAIC,8BAA8B;IAElC,MAAMC,iBAAkD,CAAC;IACzD,MAAMC,iBAAyE,CAAC;IAChF,IAAIC;IACJ,IAAIC;IACJ,IAAIC;I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A,MAAMI,iBAAiBzH,UAAU0D,OAAO,CAAC,EAAEgE,IAAI,EAAE;QAC/C,MAAMT,SAA2C,CAAC;QAElDnE,iBAAiBsD,OAAO,CAAC,CAACuB,KAAKzD;YAC7B+C,MAAM,CAAC/C,IAAI,GAAGwD,KAAK5G,QAAQwD,MAAM,CAACqD,IAAI;QACxC;QAEA,IAAI3F,mBAAmB;YACrBiF,OAAOW,QAAQ,GAAGF,KAAKlF;QACzB;QAEA,IAAIN,kBAAkB;YACpB+E,OAAOY,MAAM,GAAGH,KAAKjF;QACvB;QACA,IAAIN,oBAAoB;YACtB8E,OAAOa,QAAQ,GAAGJ,KAAKhF;QACzB;QAEA,IAAIC,cAAcuD,IAAI,IAAIrD,oBAAoB;YAC5CoE,OAAOc,KAAK,GAAGL,KAAK7E,oBAAoB;gBACtCyE,cAAc;YAChB;QACF;QAEA,OAAOL;IACT;IAEAnG,QAAQd,SAAS,CAAC,CAAC,UAAU,EAAE4B,UAAU,CAAC,CAAC,GAAG6F;IAE9C,OAAO;QAAEtF;QAAoBD;QAAkBY;IAAiB;AAClE,EAAC"}
|
1
|
+
{"version":3,"sources":["../../src/schema/build.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Relation } from 'drizzle-orm'\nimport type {\n IndexBuilder,\n PgColumnBuilder,\n PgTableWithColumns,\n UniqueConstraintBuilder,\n} from 'drizzle-orm/pg-core'\nimport type { Field } from 'payload/types'\n\nimport { relations } from 'drizzle-orm'\nimport { index, integer, numeric, serial, timestamp, unique, varchar } from 'drizzle-orm/pg-core'\nimport { fieldAffectsData } from 'payload/types'\n\nimport type { GenericColumns, GenericTable, IDType, PostgresAdapter } from '../types.js'\n\nimport { getTableName } from './getTableName.js'\nimport { parentIDColumnMap } from './parentIDColumnMap.js'\nimport { setColumnID } from './setColumnID.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: PostgresAdapter\n baseColumns?: Record<string, PgColumnBuilder>\n baseExtraConfig?: Record<string, (cols: GenericColumns) => IndexBuilder | UniqueConstraintBuilder>\n buildNumbers?: boolean\n buildRelationships?: boolean\n buildTexts?: boolean\n disableNotNull: boolean\n disableUnique: boolean\n fields: Field[]\n rootRelationsToBuild?: Map<string, string>\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: Map<string, string>\n}\n\nexport const buildTable = ({\n adapter,\n baseColumns = {},\n baseExtraConfig = {},\n buildNumbers,\n buildRelationships,\n buildTexts,\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 rootTableName = incomingRootTableName || tableName\n const columns: Record<string, PgColumnBuilder> = baseColumns\n const indexes: Record<string, (cols: GenericColumns) => IndexBuilder> = {}\n\n let hasLocalizedField = false\n let hasLocalizedRelationshipField = false\n let hasManyTextField: 'index' | boolean = false\n let hasManyNumberField: 'index' | boolean = false\n let hasLocalizedManyTextField = false\n let hasLocalizedManyNumberField = false\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: Map<string, string> = new Map()\n\n const idColType: IDType = setColumnID({ adapter, columns, fields })\n\n ;({\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n } = traverseFields({\n adapter,\n buildNumbers,\n buildRelationships,\n buildTexts,\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 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 return Object.entries(indexes).reduce((acc, [colName, func]) => {\n acc[colName] = func(cols)\n return acc\n }, extraConfig)\n })\n\n adapter.tables[tableName] = table\n\n if (hasLocalizedField) {\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')\n .references(() => table.id, { onDelete: 'cascade' })\n .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 },\n )\n })\n\n adapter.tables[localeTableName] = localesTable\n\n const localesTableRelations = relations(localesTable, ({ one }) => ({\n _parentID: one(table, {\n fields: [localesTable._parentID],\n references: [table.id],\n }),\n }))\n\n adapter.relations[`relations_${localeTableName}`] = localesTableRelations\n }\n\n if (hasManyTextField && buildTexts) {\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')\n .references(() => table.id, { onDelete: 'cascade' })\n .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 indexes: Record<string, IndexBuilder> = {\n orderParentIdx: index(`${textsTableName}_order_parent_idx`).on(cols.order, cols.parent),\n }\n\n if (hasManyTextField === 'index') {\n indexes.text_idx = index(`${textsTableName}_text_idx`).on(cols.text)\n }\n\n if (hasLocalizedManyTextField) {\n indexes.localeParent = index(`${textsTableName}_locale_parent`).on(cols.locale, cols.parent)\n }\n\n return indexes\n })\n\n adapter.tables[textsTableName] = textsTable\n\n const textsTableRelations = relations(textsTable, ({ one }) => ({\n parent: one(table, {\n fields: [textsTable.parent],\n references: [table.id],\n }),\n }))\n\n adapter.relations[`relations_${textsTableName}`] = textsTableRelations\n }\n\n if (hasManyNumberField && buildNumbers) {\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')\n .references(() => table.id, { onDelete: 'cascade' })\n .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 indexes: Record<string, IndexBuilder> = {\n orderParentIdx: index(`${numbersTableName}_order_parent_idx`).on(cols.order, cols.parent),\n }\n\n if (hasManyNumberField === 'index') {\n indexes.numberIdx = index(`${numbersTableName}_number_idx`).on(cols.number)\n }\n\n if (hasLocalizedManyNumberField) {\n indexes.localeParent = index(`${numbersTableName}_locale_parent`).on(\n cols.locale,\n cols.parent,\n )\n }\n\n return indexes\n })\n\n adapter.tables[numbersTableName] = numbersTable\n\n const numbersTableRelations = relations(numbersTable, ({ one }) => ({\n parent: one(table, {\n fields: [numbersTable.parent],\n references: [table.id],\n }),\n }))\n\n adapter.relations[`relations_${numbersTableName}`] = numbersTableRelations\n }\n\n if (buildRelationships) {\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')\n .references(() => table.id, { onDelete: 'cascade' })\n .notNull(),\n path: varchar('path').notNull(),\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipColumns.locale = adapter.enums.enum__locales('locale')\n }\n\n relationships.forEach((relationTo) => {\n const relationshipConfig = adapter.payload.collections[relationTo].config\n const formattedRelationTo = getTableName({\n adapter,\n config: relationshipConfig,\n throwValidationError: true,\n })\n let colType = adapter.idType === 'uuid' ? 'uuid' : 'integer'\n const relatedCollectionCustomID = relationshipConfig.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n if (relatedCollectionCustomID?.type === 'number') colType = 'numeric'\n if (relatedCollectionCustomID?.type === 'text') colType = 'varchar'\n\n relationshipColumns[`${relationTo}ID`] = parentIDColumnMap[colType](\n `${formattedRelationTo}_id`,\n ).references(() => adapter.tables[formattedRelationTo].id, { onDelete: 'cascade' })\n })\n\n const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`\n\n relationshipsTable = adapter.pgSchema.table(\n relationshipsTableName,\n relationshipColumns,\n (cols) => {\n const result: Record<string, unknown> = {\n order: index(`${relationshipsTableName}_order_idx`).on(cols.order),\n parentIdx: index(`${relationshipsTableName}_parent_idx`).on(cols.parent),\n pathIdx: index(`${relationshipsTableName}_path_idx`).on(cols.path),\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 const relationshipsTableRelations = relations(relationshipsTable, ({ 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 = getTableName({\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 })\n })\n\n return result\n })\n\n adapter.relations[`relations_${relationshipsTableName}`] = relationshipsTableRelations\n }\n }\n\n const tableRelations = relations(table, ({ many }) => {\n const result: Record<string, Relation<string>> = {}\n\n relationsToBuild.forEach((val, key) => {\n result[key] = many(adapter.tables[val])\n })\n\n if (hasLocalizedField) {\n result._locales = many(localesTable)\n }\n\n if (hasManyTextField) {\n result._texts = many(textsTable)\n }\n if (hasManyNumberField) {\n result._numbers = many(numbersTable)\n }\n\n if (relationships.size && relationshipsTable) {\n result._rels = many(relationshipsTable, {\n relationName: '_rels',\n })\n }\n\n return result\n })\n\n adapter.relations[`relations_${tableName}`] = tableRelations\n\n return { hasManyNumberField, hasManyTextField, relationsToBuild }\n}\n"],"names":["relations","index","integer","numeric","serial","timestamp","unique","varchar","fieldAffectsData","getTableName","parentIDColumnMap","setColumnID","traverseFields","buildTable","adapter","baseColumns","baseExtraConfig","buildNumbers","buildRelationships","buildTexts","disableNotNull","disableUnique","fields","rootRelationsToBuild","rootRelationships","rootTableIDColType","rootTableName","incomingRootTableName","tableName","timestamps","versions","columns","indexes","hasLocalizedField","hasLocalizedRelationshipField","hasManyTextField","hasManyNumberField","hasLocalizedManyTextField","hasLocalizedManyNumberField","localesColumns","localesIndexes","localesTable","textsTable","numbersTable","relationships","Set","relationshipsTable","relationsToBuild","Map","idColType","newTableName","parentTableName","createdAt","mode","precision","withTimezone","defaultNow","notNull","updatedAt","table","pgSchema","cols","extraConfig","Object","entries","reduce","config","key","func","acc","colName","tables","localeTableName","localesSuffix","id","primaryKey","_locale","enums","enum__locales","_parentID","references","onDelete","_localeParent","on","localesTableRelations","one","textsTableName","order","parent","path","text","locale","orderParentIdx","text_idx","localeParent","textsTableRelations","numbersTableName","number","numberIdx","numbersTableRelations","size","relationshipColumns","forEach","relationTo","relationshipConfig","payload","collections","formattedRelationTo","throwValidationError","colType","idType","relatedCollectionCustomID","find","field","name","type","relationshipsTableName","relationshipsSuffix","result","parentIdx","pathIdx","localeIdx","relationshipsTableRelations","relationName","relatedTableName","idColumnName","tableRelations","many","val","_locales","_texts","_numbers","_rels"],"mappings":"AAAA,oCAAoC,GAUpC,SAASA,SAAS,QAAQ,cAAa;AACvC,SAASC,KAAK,EAAEC,OAAO,EAAEC,OAAO,EAAEC,MAAM,EAAEC,SAAS,EAAEC,MAAM,EAAEC,OAAO,QAAQ,sBAAqB;AACjG,SAASC,gBAAgB,QAAQ,gBAAe;AAIhD,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,cAAc,QAAQ,sBAAqB;AA2BpD,OAAO,MAAMC,aAAa,CAAC,EACzBC,OAAO,EACPC,cAAc,CAAC,CAAC,EAChBC,kBAAkB,CAAC,CAAC,EACpBC,YAAY,EACZC,kBAAkB,EAClBC,UAAU,EACVC,cAAc,EACdC,gBAAgB,KAAK,EACrBC,MAAM,EACNC,oBAAoB,EACpBC,iBAAiB,EACjBC,kBAAkB,EAClBC,eAAeC,qBAAqB,EACpCC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACH;IACL,MAAMJ,gBAAgBC,yBAAyBC;IAC/C,MAAMG,UAA2ChB;IACjD,MAAMiB,UAAkE,CAAC;IAEzE,IAAIC,oBAAoB;IACxB,IAAIC,gCAAgC;IACpC,IAAIC,mBAAsC;IAC1C,IAAIC,qBAAwC;IAC5C,IAAIC,4BAA4B;IAChC,IAAIC,8BAA8B;IAElC,MAAMC,iBAAkD,CAAC;IACzD,MA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D,iBAAiB,EAAE;wBAC3DtG,QAAQ;4BAACwB,kBAAkB,CAAC+E,aAAa;yBAAC;wBAC1C7C,YAAY;4BAAClE,QAAQyD,MAAM,CAACqD,iBAAiB,CAAClD,EAAE;yBAAC;oBACnD;gBACF;gBAEA,OAAO4C;YACT;YAEAxG,QAAQd,SAAS,CAAC,CAAC,UAAU,EAAEoH,uBAAuB,CAAC,CAAC,GAAGM;QAC7D;IACF;IAEA,MAAMI,iBAAiB9H,UAAU2D,OAAO,CAAC,EAAEoE,IAAI,EAAE;QAC/C,MAAMT,SAA2C,CAAC;QAElDvE,iBAAiBuD,OAAO,CAAC,CAAC0B,KAAK7D;YAC7BmD,MAAM,CAACnD,IAAI,GAAG4D,KAAKjH,QAAQyD,MAAM,CAACyD,IAAI;QACxC;QAEA,IAAI/F,mBAAmB;YACrBqF,OAAOW,QAAQ,GAAGF,KAAKtF;QACzB;QAEA,IAAIN,kBAAkB;YACpBmF,OAAOY,MAAM,GAAGH,KAAKrF;QACvB;QACA,IAAIN,oBAAoB;YACtBkF,OAAOa,QAAQ,GAAGJ,KAAKpF;QACzB;QAEA,IAAIC,cAAcwD,IAAI,IAAItD,oBAAoB;YAC5CwE,OAAOc,KAAK,GAAGL,KAAKjF,oBAAoB;gBACtC6E,cAAc;YAChB;QACF;QAEA,OAAOL;IACT;IAEAxG,QAAQd,SAAS,CAAC,CAAC,UAAU,EAAE4B,UAAU,CAAC,CAAC,GAAGkG;IAE9C,OAAO;QAAE1F;QAAoBD;QAAkBY;IAAiB;AAClE,EAAC"}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import type { DBIdentifierName } from 'payload/database';
|
2
|
+
import type { PostgresAdapter } from '../types.js';
|
3
|
+
type Args = {
|
4
|
+
adapter: PostgresAdapter;
|
5
|
+
/** The collection, global or field config **/
|
6
|
+
config: {
|
7
|
+
dbName?: DBIdentifierName;
|
8
|
+
enumName?: DBIdentifierName;
|
9
|
+
name?: string;
|
10
|
+
slug?: string;
|
11
|
+
};
|
12
|
+
/** Localized tables need to be given the locales suffix */
|
13
|
+
locales?: boolean;
|
14
|
+
/** For nested tables passed for the user custom dbName functions to handle their own iterations */
|
15
|
+
parentTableName?: string;
|
16
|
+
/** For sub tables (array for example) this needs to include the parentTableName */
|
17
|
+
prefix?: string;
|
18
|
+
/** Adds the relationships suffix */
|
19
|
+
relationships?: boolean;
|
20
|
+
/** For tables based on fields that could have both enumName and dbName (ie: select with hasMany), default: 'dbName' */
|
21
|
+
target?: 'dbName' | 'enumName';
|
22
|
+
throwValidationError?: boolean;
|
23
|
+
/** Adds the versions suffix, should only be used on the base collection to duplicate suffixing */
|
24
|
+
versions?: boolean;
|
25
|
+
};
|
26
|
+
/**
|
27
|
+
* Used to name database enums and tables
|
28
|
+
* Returns the table or enum name for a given entity
|
29
|
+
*/
|
30
|
+
export declare const getTableName: ({ adapter, config: { name, slug }, config, locales, parentTableName, prefix, relationships, target, throwValidationError, versions, }: Args) => string;
|
31
|
+
export {};
|
32
|
+
//# sourceMappingURL=getTableName.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getTableName.d.ts","sourceRoot":"","sources":["../../src/schema/getTableName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAKxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,8CAA8C;IAC9C,MAAM,EAAE;QACN,MAAM,CAAC,EAAE,gBAAgB,CAAA;QACzB,QAAQ,CAAC,EAAE,gBAAgB,CAAA;QAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IACD,2DAA2D;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,mGAAmG;IACnG,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,mFAAmF;IACnF,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,oCAAoC;IACpC,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,uHAAuH;IACvH,MAAM,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC9B,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,kGAAkG;IAClG,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,0IAWtB,IAAI,KAAG,MA4BT,CAAA"}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { APIError } from 'payload/errors';
|
2
|
+
import toSnakeCase from 'to-snake-case';
|
3
|
+
/**
|
4
|
+
* Used to name database enums and tables
|
5
|
+
* Returns the table or enum name for a given entity
|
6
|
+
*/ export const getTableName = ({ adapter, config: { name, slug }, config, locales = false, parentTableName, prefix = '', relationships = false, target = 'dbName', throwValidationError = false, versions = false })=>{
|
7
|
+
let result;
|
8
|
+
let custom = config[target];
|
9
|
+
if (!custom && target === 'enumName') {
|
10
|
+
custom = config['dbName'];
|
11
|
+
}
|
12
|
+
if (custom) {
|
13
|
+
result = typeof custom === 'function' ? custom({
|
14
|
+
tableName: parentTableName
|
15
|
+
}) : custom;
|
16
|
+
} else {
|
17
|
+
result = `${prefix}${toSnakeCase(name ?? slug)}`;
|
18
|
+
}
|
19
|
+
if (locales) result = `${result}${adapter.localesSuffix}`;
|
20
|
+
if (versions) result = `_${result}${adapter.versionsSuffix}`;
|
21
|
+
if (relationships) result = `${result}${adapter.relationshipsSuffix}`;
|
22
|
+
if (!throwValidationError) {
|
23
|
+
return result;
|
24
|
+
}
|
25
|
+
if (result.length > 63) {
|
26
|
+
throw new APIError(`Exceeded max identifier length for table or enum name of 63 characters. Invalid name: ${result}`);
|
27
|
+
}
|
28
|
+
return result;
|
29
|
+
};
|
30
|
+
|
31
|
+
//# sourceMappingURL=getTableName.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/schema/getTableName.ts"],"sourcesContent":["import type { DBIdentifierName } from 'payload/database'\n\nimport { APIError } from 'payload/errors'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../types.js'\n\ntype Args = {\n adapter: PostgresAdapter\n /** The collection, global or field config **/\n config: {\n dbName?: DBIdentifierName\n enumName?: DBIdentifierName\n name?: string\n slug?: string\n }\n /** Localized tables need to be given the locales suffix */\n locales?: boolean\n /** For nested tables passed for the user custom dbName functions to handle their own iterations */\n parentTableName?: string\n /** For sub tables (array for example) this needs to include the parentTableName */\n prefix?: string\n /** Adds the relationships suffix */\n relationships?: boolean\n /** For tables based on fields that could have both enumName and dbName (ie: select with hasMany), default: 'dbName' */\n target?: 'dbName' | 'enumName'\n throwValidationError?: boolean\n /** Adds the versions suffix, should only be used on the base collection to duplicate suffixing */\n versions?: boolean\n}\n\n/**\n * Used to name database enums and tables\n * Returns the table or enum name for a given entity\n */\nexport const getTableName = ({\n adapter,\n config: { name, slug },\n config,\n locales = false,\n parentTableName,\n prefix = '',\n relationships = false,\n target = 'dbName',\n throwValidationError = false,\n versions = false,\n}: Args): string => {\n let result: string\n let custom = config[target]\n\n if (!custom && target === 'enumName') {\n custom = config['dbName']\n }\n\n if (custom) {\n result = typeof custom === 'function' ? custom({ tableName: parentTableName }) : custom\n } else {\n result = `${prefix}${toSnakeCase(name ?? slug)}`\n }\n\n if (locales) result = `${result}${adapter.localesSuffix}`\n if (versions) result = `_${result}${adapter.versionsSuffix}`\n if (relationships) result = `${result}${adapter.relationshipsSuffix}`\n\n if (!throwValidationError) {\n return result\n }\n\n if (result.length > 63) {\n throw new APIError(\n `Exceeded max identifier length for table or enum name of 63 characters. Invalid name: ${result}`,\n )\n }\n return result\n}\n"],"names":["APIError","toSnakeCase","getTableName","adapter","config","name","slug","locales","parentTableName","prefix","relationships","target","throwValidationError","versions","result","custom","tableName","localesSuffix","versionsSuffix","relationshipsSuffix","length"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,iBAAgB;AACzC,OAAOC,iBAAiB,gBAAe;AA4BvC;;;CAGC,GACD,OAAO,MAAMC,eAAe,CAAC,EAC3BC,OAAO,EACPC,QAAQ,EAAEC,IAAI,EAAEC,IAAI,EAAE,EACtBF,MAAM,EACNG,UAAU,KAAK,EACfC,eAAe,EACfC,SAAS,EAAE,EACXC,gBAAgB,KAAK,EACrBC,SAAS,QAAQ,EACjBC,uBAAuB,KAAK,EAC5BC,WAAW,KAAK,EACX;IACL,IAAIC;IACJ,IAAIC,SAASX,MAAM,CAACO,OAAO;IAE3B,IAAI,CAACI,UAAUJ,WAAW,YAAY;QACpCI,SAASX,MAAM,CAAC,SAAS;IAC3B;IAEA,IAAIW,QAAQ;QACVD,SAAS,OAAOC,WAAW,aAAaA,OAAO;YAAEC,WAAWR;QAAgB,KAAKO;IACnF,OAAO;QACLD,SAAS,CAAC,EAAEL,OAAO,EAAER,YAAYI,QAAQC,MAAM,CAAC;IAClD;IAEA,IAAIC,SAASO,SAAS,CAAC,EAAEA,OAAO,EAAEX,QAAQc,aAAa,CAAC,CAAC;IACzD,IAAIJ,UAAUC,SAAS,CAAC,CAAC,EAAEA,OAAO,EAAEX,QAAQe,cAAc,CAAC,CAAC;IAC5D,IAAIR,eAAeI,SAAS,CAAC,EAAEA,OAAO,EAAEX,QAAQgB,mBAAmB,CAAC,CAAC;IAErE,IAAI,CAACP,sBAAsB;QACzB,OAAOE;IACT;IAEA,IAAIA,OAAOM,MAAM,GAAG,IAAI;QACtB,MAAM,IAAIpB,SACR,CAAC,sFAAsF,EAAEc,OAAO,CAAC;IAErG;IACA,OAAOA;AACT,EAAC"}
|
@@ -23,6 +23,7 @@ type Args = {
|
|
23
23
|
rootRelationsToBuild?: Map<string, string>;
|
24
24
|
rootTableIDColType: string;
|
25
25
|
rootTableName: string;
|
26
|
+
versions: boolean;
|
26
27
|
};
|
27
28
|
type Result = {
|
28
29
|
hasLocalizedField: boolean;
|
@@ -32,6 +33,6 @@ type Result = {
|
|
32
33
|
hasManyNumberField: 'index' | boolean;
|
33
34
|
hasManyTextField: 'index' | boolean;
|
34
35
|
};
|
35
|
-
export declare const traverseFields: ({ adapter, buildNumbers, buildRelationships, buildTexts, columnPrefix, columns, disableNotNull, disableUnique, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationsToBuild, relationships, rootRelationsToBuild, rootTableIDColType, rootTableName, }: Args) => Result;
|
36
|
+
export declare const traverseFields: ({ adapter, buildNumbers, buildRelationships, buildTexts, columnPrefix, columns, disableNotNull, disableUnique, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationsToBuild, relationships, rootRelationsToBuild, rootTableIDColType, rootTableName, versions, }: Args) => Result;
|
36
37
|
export {};
|
37
38
|
//# sourceMappingURL=traverseFields.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/schema/traverseFields.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAA2B,MAAM,qBAAqB,CAAA;AACjG,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAqBtD,OAAO,KAAK,EAAE,cAAc,EAAU,eAAe,EAAE,MAAM,aAAa,CAAA;
|
1
|
+
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/schema/traverseFields.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAA2B,MAAM,qBAAqB,CAAA;AACjG,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAqBtD,OAAO,KAAK,EAAE,cAAc,EAAU,eAAe,EAAE,MAAM,aAAa,CAAA;AAU1E,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,YAAY,EAAE,OAAO,CAAA;IACrB,kBAAkB,EAAE,OAAO,CAAA;IAC3B,U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-6,10 +6,12 @@ import toSnakeCase from 'to-snake-case';
|
|
6
6
|
import { hasLocalesTable } from '../utilities/hasLocalesTable.js';
|
7
7
|
import { buildTable } from './build.js';
|
8
8
|
import { createIndex } from './createIndex.js';
|
9
|
+
import { getTableName } from './getTableName.js';
|
9
10
|
import { idToUUID } from './idToUUID.js';
|
10
11
|
import { parentIDColumnMap } from './parentIDColumnMap.js';
|
11
12
|
import { validateExistingBlockIsIdentical } from './validateExistingBlockIsIdentical.js';
|
12
|
-
export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buildTexts, columnPrefix, columns, disableNotNull, disableUnique = false, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationsToBuild, relationships, rootRelationsToBuild, rootTableIDColType, rootTableName })=>{
|
13
|
+
export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buildTexts, columnPrefix, columns, disableNotNull, disableUnique = false, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationsToBuild, relationships, rootRelationsToBuild, rootTableIDColType, rootTableName, versions })=>{
|
14
|
+
const throwValidationError = true;
|
13
15
|
let hasLocalizedField = false;
|
14
16
|
let hasLocalizedRelationshipField = false;
|
15
17
|
let hasManyTextField = false;
|
@@ -128,7 +130,15 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
128
130
|
case 'radio':
|
129
131
|
case 'select':
|
130
132
|
{
|
131
|
-
const enumName =
|
133
|
+
const enumName = getTableName({
|
134
|
+
adapter,
|
135
|
+
config: field,
|
136
|
+
parentTableName: newTableName,
|
137
|
+
prefix: `enum_${newTableName}_`,
|
138
|
+
target: 'enumName',
|
139
|
+
throwValidationError,
|
140
|
+
versions
|
141
|
+
});
|
132
142
|
adapter.enums[enumName] = pgEnum(enumName, field.options.map((option)=>{
|
133
143
|
if (optionIsObject(option)) {
|
134
144
|
return option.value;
|
@@ -136,7 +146,14 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
136
146
|
return option;
|
137
147
|
}));
|
138
148
|
if (field.type === 'select' && field.hasMany) {
|
139
|
-
const selectTableName =
|
149
|
+
const selectTableName = getTableName({
|
150
|
+
adapter,
|
151
|
+
config: field,
|
152
|
+
parentTableName: newTableName,
|
153
|
+
prefix: `${newTableName}_`,
|
154
|
+
throwValidationError,
|
155
|
+
versions
|
156
|
+
});
|
140
157
|
const baseColumns = {
|
141
158
|
order: integer('order').notNull(),
|
142
159
|
parent: parentIDColumnMap[parentIDColType]('parent_id').references(()=>adapter.tables[parentTableName].id, {
|
@@ -162,7 +179,8 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
162
179
|
disableNotNull,
|
163
180
|
disableUnique,
|
164
181
|
fields: [],
|
165
|
-
tableName: selectTableName
|
182
|
+
tableName: selectTableName,
|
183
|
+
versions
|
166
184
|
});
|
167
185
|
relationsToBuild.set(fieldName, selectTableName);
|
168
186
|
const selectTableRelations = relations(adapter.tables[selectTableName], ({ one })=>{
|
@@ -192,7 +210,13 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
192
210
|
case 'array':
|
193
211
|
{
|
194
212
|
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
195
|
-
const arrayTableName =
|
213
|
+
const arrayTableName = getTableName({
|
214
|
+
adapter,
|
215
|
+
config: field,
|
216
|
+
parentTableName: newTableName,
|
217
|
+
prefix: `${newTableName}_`,
|
218
|
+
throwValidationError
|
219
|
+
});
|
196
220
|
const baseColumns = {
|
197
221
|
_order: integer('_order').notNull(),
|
198
222
|
_parentID: parentIDColumnMap[parentIDColType]('_parent_id').references(()=>adapter.tables[parentTableName].id, {
|
@@ -218,7 +242,8 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
218
242
|
rootRelationships: relationships,
|
219
243
|
rootTableIDColType,
|
220
244
|
rootTableName,
|
221
|
-
tableName: arrayTableName
|
245
|
+
tableName: arrayTableName,
|
246
|
+
versions
|
222
247
|
});
|
223
248
|
if (subHasManyTextField) {
|
224
249
|
if (!hasManyTextField || subHasManyTextField === 'index') hasManyTextField = subHasManyTextField;
|
@@ -239,7 +264,7 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
239
264
|
})
|
240
265
|
};
|
241
266
|
if (hasLocalesTable(field.fields)) {
|
242
|
-
result._locales = many(adapter.tables[`${arrayTableName}
|
267
|
+
result._locales = many(adapter.tables[`${arrayTableName}${adapter.localesSuffix}`]);
|
243
268
|
}
|
244
269
|
subRelationsToBuild.forEach((val, key)=>{
|
245
270
|
result[key] = many(adapter.tables[val]);
|
@@ -253,7 +278,13 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
253
278
|
{
|
254
279
|
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
255
280
|
field.blocks.forEach((block)=>{
|
256
|
-
const blockTableName =
|
281
|
+
const blockTableName = getTableName({
|
282
|
+
adapter,
|
283
|
+
config: block,
|
284
|
+
parentTableName: rootTableName,
|
285
|
+
prefix: `${rootTableName}_blocks_`,
|
286
|
+
throwValidationError
|
287
|
+
});
|
257
288
|
if (!adapter.tables[blockTableName]) {
|
258
289
|
const baseColumns = {
|
259
290
|
_order: integer('_order').notNull(),
|
@@ -282,7 +313,8 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
282
313
|
rootRelationships: relationships,
|
283
314
|
rootTableIDColType,
|
284
315
|
rootTableName,
|
285
|
-
tableName: blockTableName
|
316
|
+
tableName: blockTableName,
|
317
|
+
versions
|
286
318
|
});
|
287
319
|
if (subHasManyTextField) {
|
288
320
|
if (!hasManyTextField || subHasManyTextField === 'index') hasManyTextField = subHasManyTextField;
|
@@ -302,7 +334,7 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
302
334
|
})
|
303
335
|
};
|
304
336
|
if (hasLocalesTable(block.fields)) {
|
305
|
-
result._locales = many(adapter.tables[`${blockTableName}
|
337
|
+
result._locales = many(adapter.tables[`${blockTableName}${adapter.localesSuffix}`]);
|
306
338
|
}
|
307
339
|
subRelationsToBuild.forEach((val, key)=>{
|
308
340
|
result[key] = many(adapter.tables[val]);
|
@@ -310,7 +342,7 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
310
342
|
return result;
|
311
343
|
});
|
312
344
|
adapter.relations[`relations_${blockTableName}`] = blockTableRelations;
|
313
|
-
} else if (process.env.NODE_ENV !== 'production') {
|
345
|
+
} else if (process.env.NODE_ENV !== 'production' && !versions) {
|
314
346
|
validateExistingBlockIsIdentical({
|
315
347
|
block,
|
316
348
|
localized: field.localized,
|
@@ -318,6 +350,7 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
318
350
|
table: adapter.tables[blockTableName]
|
319
351
|
});
|
320
352
|
}
|
353
|
+
adapter.blockTableNames[`${rootTableName}.${toSnakeCase(block.slug)}`] = blockTableName;
|
321
354
|
rootRelationsToBuild.set(`_blocks_${block.slug}`, blockTableName);
|
322
355
|
});
|
323
356
|
break;
|
@@ -347,7 +380,8 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
347
380
|
relationships,
|
348
381
|
rootRelationsToBuild,
|
349
382
|
rootTableIDColType,
|
350
|
-
rootTableName
|
383
|
+
rootTableName,
|
384
|
+
versions
|
351
385
|
});
|
352
386
|
if (groupHasLocalizedField) hasLocalizedField = true;
|
353
387
|
if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true;
|
@@ -379,7 +413,8 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
379
413
|
relationships,
|
380
414
|
rootRelationsToBuild,
|
381
415
|
rootTableIDColType,
|
382
|
-
rootTableName
|
416
|
+
rootTableName,
|
417
|
+
versions
|
383
418
|
});
|
384
419
|
if (groupHasLocalizedField) hasLocalizedField = true;
|
385
420
|
if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true;
|
@@ -416,7 +451,8 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
416
451
|
relationships,
|
417
452
|
rootRelationsToBuild,
|
418
453
|
rootTableIDColType,
|
419
|
-
rootTableName
|
454
|
+
rootTableName,
|
455
|
+
versions
|
420
456
|
});
|
421
457
|
if (tabHasLocalizedField) hasLocalizedField = true;
|
422
458
|
if (tabHasLocalizedRelationshipField) hasLocalizedRelationshipField = true;
|
@@ -451,7 +487,8 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
451
487
|
relationships,
|
452
488
|
rootRelationsToBuild,
|
453
489
|
rootTableIDColType,
|
454
|
-
rootTableName
|
490
|
+
rootTableName,
|
491
|
+
versions
|
455
492
|
});
|
456
493
|
if (rowHasLocalizedField) hasLocalizedField = true;
|
457
494
|
if (rowHasLocalizedRelationshipField) hasLocalizedRelationshipField = true;
|