@payloadcms/drizzle 4.0.0-canary.19 → 4.0.0-canary.20

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.
@@ -1 +1 @@
1
- {"version":3,"file":"createTableName.d.ts","sourceRoot":"","sources":["../src/createTableName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAK/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,cAAc,GAAG,gBAAgB,CAAC,CAAA;IAChE,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,mGAAmG;IACnG,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,mFAAmF;IACnF,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,uHAAuH;IACvH,MAAM,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC9B,uFAAuF;IACvF,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,mIAAmI;IACnI,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,mHAAmH;IACnH,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,sIAUzB,IAAI,KAAG,MA2CT,CAAA"}
1
+ {"version":3,"file":"createTableName.d.ts","sourceRoot":"","sources":["../src/createTableName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAI/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAIhD,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,cAAc,GAAG,gBAAgB,CAAC,CAAA;IAChE,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,mGAAmG;IACnG,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,mFAAmF;IACnF,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,uHAAuH;IACvH,MAAM,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC9B,uFAAuF;IACvF,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,mIAAmI;IACnI,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,mHAAmH;IACnH,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,sIAUzB,IAAI,KAAG,MAmCT,CAAA"}
@@ -1,5 +1,5 @@
1
- import { APIError } from 'payload';
2
1
  import toSnakeCase from 'to-snake-case';
2
+ import { validateIdentifierLength } from './utilities/validateIdentifierLength.js';
3
3
  /**
4
4
  * Used to name database enums and tables
5
5
  * Returns the table or enum name for a given entity
@@ -26,12 +26,7 @@ import toSnakeCase from 'to-snake-case';
26
26
  if (!throwValidationError) {
27
27
  return result;
28
28
  }
29
- if (result.length > 63) {
30
- throw new APIError(`Exceeded max identifier length for table or enum name of 63 characters. Invalid name: ${result}.
31
- Tip: You can use the dbName property to reduce the table name length.
32
- `);
33
- }
34
- return result;
29
+ return validateIdentifierLength(result);
35
30
  };
36
31
 
37
32
  //# sourceMappingURL=createTableName.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createTableName.ts"],"sourcesContent":["import type { DBIdentifierName } from 'payload'\n\nimport { APIError } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\ntype Args = {\n adapter: Pick<DrizzleAdapter, 'tableNameMap' | 'versionsSuffix'>\n /** The collection, global or field config **/\n config: {\n dbName?: DBIdentifierName\n enumName?: DBIdentifierName\n name?: string\n slug?: string\n }\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 /** For tables based on fields that could have both enumName and dbName (ie: select with hasMany), default: 'dbName' */\n target?: 'dbName' | 'enumName'\n /** Throws error if true for postgres when table and enum names exceed 63 characters */\n throwValidationError?: boolean\n /** Adds the versions suffix to the default table name - should only be used on the base collection to avoid duplicate suffixing */\n versions?: boolean\n /** Adds the versions suffix to custom dbName only - this is used while creating blocks / selects / arrays / etc */\n versionsCustomName?: 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 createTableName = ({\n adapter,\n config: { name, slug },\n config,\n parentTableName,\n prefix = '',\n target = 'dbName',\n throwValidationError = false,\n versions = false,\n versionsCustomName = false,\n}: Args): string => {\n let customNameDefinition = config[target]\n\n let defaultTableName = `${prefix}${toSnakeCase(name ?? slug)}`\n\n if (versions) {\n defaultTableName = `_${defaultTableName}${adapter.versionsSuffix}`\n }\n\n let customTableNameResult: string\n\n if (!customNameDefinition && target === 'enumName') {\n customNameDefinition = config['dbName']\n }\n\n if (customNameDefinition) {\n customTableNameResult =\n typeof customNameDefinition === 'function'\n ? customNameDefinition({ tableName: parentTableName })\n : customNameDefinition\n\n if (versionsCustomName) {\n customTableNameResult = `_${customTableNameResult}${adapter.versionsSuffix}`\n }\n }\n\n const result = customTableNameResult || defaultTableName\n\n adapter.tableNameMap.set(defaultTableName, result)\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}.\nTip: You can use the dbName property to reduce the table name length.\n `,\n )\n }\n\n return result\n}\n"],"names":["APIError","toSnakeCase","createTableName","adapter","config","name","slug","parentTableName","prefix","target","throwValidationError","versions","versionsCustomName","customNameDefinition","defaultTableName","versionsSuffix","customTableNameResult","tableName","result","tableNameMap","set","length"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAClC,OAAOC,iBAAiB,gBAAe;AA2BvC;;;CAGC,GACD,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,OAAO,EACPC,QAAQ,EAAEC,IAAI,EAAEC,IAAI,EAAE,EACtBF,MAAM,EACNG,eAAe,EACfC,SAAS,EAAE,EACXC,SAAS,QAAQ,EACjBC,uBAAuB,KAAK,EAC5BC,WAAW,KAAK,EAChBC,qBAAqB,KAAK,EACrB;IACL,IAAIC,uBAAuBT,MAAM,CAACK,OAAO;IAEzC,IAAIK,mBAAmB,GAAGN,SAASP,YAAYI,QAAQC,OAAO;IAE9D,IAAIK,UAAU;QACZG,mBAAmB,CAAC,CAAC,EAAEA,mBAAmBX,QAAQY,cAAc,EAAE;IACpE;IAEA,IAAIC;IAEJ,IAAI,CAACH,wBAAwBJ,WAAW,YAAY;QAClDI,uBAAuBT,MAAM,CAAC,SAAS;IACzC;IAEA,IAAIS,sBAAsB;QACxBG,wBACE,OAAOH,yBAAyB,aAC5BA,qBAAqB;YAAEI,WAAWV;QAAgB,KAClDM;QAEN,IAAID,oBAAoB;YACtBI,wBAAwB,CAAC,CAAC,EAAEA,wBAAwBb,QAAQY,cAAc,EAAE;QAC9E;IACF;IAEA,MAAMG,SAASF,yBAAyBF;IAExCX,QAAQgB,YAAY,CAACC,GAAG,CAACN,kBAAkBI;IAE3C,IAAI,CAACR,sBAAsB;QACzB,OAAOQ;IACT;IAEA,IAAIA,OAAOG,MAAM,GAAG,IAAI;QACtB,MAAM,IAAIrB,SACR,CAAC,sFAAsF,EAAEkB,OAAO;;MAEhG,CAAC;IAEL;IAEA,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/createTableName.ts"],"sourcesContent":["import type { DBIdentifierName } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { validateIdentifierLength } from './utilities/validateIdentifierLength.js'\n\ntype Args = {\n adapter: Pick<DrizzleAdapter, 'tableNameMap' | 'versionsSuffix'>\n /** The collection, global or field config **/\n config: {\n dbName?: DBIdentifierName\n enumName?: DBIdentifierName\n name?: string\n slug?: string\n }\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 /** For tables based on fields that could have both enumName and dbName (ie: select with hasMany), default: 'dbName' */\n target?: 'dbName' | 'enumName'\n /** Throws error if true for postgres when table and enum names exceed 63 characters */\n throwValidationError?: boolean\n /** Adds the versions suffix to the default table name - should only be used on the base collection to avoid duplicate suffixing */\n versions?: boolean\n /** Adds the versions suffix to custom dbName only - this is used while creating blocks / selects / arrays / etc */\n versionsCustomName?: 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 createTableName = ({\n adapter,\n config: { name, slug },\n config,\n parentTableName,\n prefix = '',\n target = 'dbName',\n throwValidationError = false,\n versions = false,\n versionsCustomName = false,\n}: Args): string => {\n let customNameDefinition = config[target]\n\n let defaultTableName = `${prefix}${toSnakeCase(name ?? slug)}`\n\n if (versions) {\n defaultTableName = `_${defaultTableName}${adapter.versionsSuffix}`\n }\n\n let customTableNameResult: string\n\n if (!customNameDefinition && target === 'enumName') {\n customNameDefinition = config['dbName']\n }\n\n if (customNameDefinition) {\n customTableNameResult =\n typeof customNameDefinition === 'function'\n ? customNameDefinition({ tableName: parentTableName })\n : customNameDefinition\n\n if (versionsCustomName) {\n customTableNameResult = `_${customTableNameResult}${adapter.versionsSuffix}`\n }\n }\n\n const result = customTableNameResult || defaultTableName\n\n adapter.tableNameMap.set(defaultTableName, result)\n\n if (!throwValidationError) {\n return result\n }\n\n return validateIdentifierLength(result)\n}\n"],"names":["toSnakeCase","validateIdentifierLength","createTableName","adapter","config","name","slug","parentTableName","prefix","target","throwValidationError","versions","versionsCustomName","customNameDefinition","defaultTableName","versionsSuffix","customTableNameResult","tableName","result","tableNameMap","set"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,wBAAwB,QAAQ,0CAAyC;AAyBlF;;;CAGC,GACD,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,OAAO,EACPC,QAAQ,EAAEC,IAAI,EAAEC,IAAI,EAAE,EACtBF,MAAM,EACNG,eAAe,EACfC,SAAS,EAAE,EACXC,SAAS,QAAQ,EACjBC,uBAAuB,KAAK,EAC5BC,WAAW,KAAK,EAChBC,qBAAqB,KAAK,EACrB;IACL,IAAIC,uBAAuBT,MAAM,CAACK,OAAO;IAEzC,IAAIK,mBAAmB,GAAGN,SAASR,YAAYK,QAAQC,OAAO;IAE9D,IAAIK,UAAU;QACZG,mBAAmB,CAAC,CAAC,EAAEA,mBAAmBX,QAAQY,cAAc,EAAE;IACpE;IAEA,IAAIC;IAEJ,IAAI,CAACH,wBAAwBJ,WAAW,YAAY;QAClDI,uBAAuBT,MAAM,CAAC,SAAS;IACzC;IAEA,IAAIS,sBAAsB;QACxBG,wBACE,OAAOH,yBAAyB,aAC5BA,qBAAqB;YAAEI,WAAWV;QAAgB,KAClDM;QAEN,IAAID,oBAAoB;YACtBI,wBAAwB,CAAC,CAAC,EAAEA,wBAAwBb,QAAQY,cAAc,EAAE;QAC9E;IACF;IAEA,MAAMG,SAASF,yBAAyBF;IAExCX,QAAQgB,YAAY,CAACC,GAAG,CAACN,kBAAkBI;IAE3C,IAAI,CAACR,sBAAsB;QACzB,OAAOQ;IACT;IAEA,OAAOjB,yBAAyBiB;AAClC,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/schema/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAK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E,WAAW,CAAA;IAClC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,uBAAuB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACrC,WAAW,EAAE,WAAW,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAA;CACtC,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,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;IACnC,gBAAgB,EAAE,WAAW,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,UAAU,0XAsBpB,IAAI,KAAG,MAmsBT,CAAA"}
@@ -4,6 +4,7 @@ import { createTableName } from '../createTableName.js';
4
4
  import { buildForeignKeyName } from '../utilities/buildForeignKeyName.js';
5
5
  import { buildIndexName } from '../utilities/buildIndexName.js';
6
6
  import { isUUIDType } from '../utilities/isUUIDType.js';
7
+ import { validateIdentifierLength } from '../utilities/validateIdentifierLength.js';
7
8
  import { traverseFields } from './traverseFields.js';
8
9
  export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, baseIndexes = {}, blocksTableNameMap, compoundIndexes, disableNotNull, disableRelsTableUnique = false, disableUnique = false, fields, parentIsLocalized, rootRelationships, rootRelationsToBuild, rootTableIDColType, rootTableName: incomingRootTableName, rootUniqueRelationships, setColumnID, tableName, timestamps, versions, withinLocalizedArrayOrBlock })=>{
9
10
  const isRoot = !incomingRootTableName;
@@ -90,7 +91,7 @@ export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, ba
90
91
  };
91
92
  adapter.rawTables[tableName] = table;
92
93
  if (hasLocalizedField || localizedRelations.size) {
93
- const localeTableName = `${tableName}${adapter.localesSuffix}`;
94
+ const localeTableName = validateIdentifierLength(`${tableName}${adapter.localesSuffix}`);
94
95
  adapter.rawTables[localeTableName] = localesTable;
95
96
  localesColumns.id = {
96
97
  name: 'id',
@@ -231,7 +232,7 @@ export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, ba
231
232
  }
232
233
  if (isRoot) {
233
234
  if (hasManyTextField) {
234
- const textsTableName = `${rootTableName}_texts`;
235
+ const textsTableName = validateIdentifierLength(`${rootTableName}_texts`);
235
236
  adapter.rawTables[textsTableName] = textsTable;
236
237
  const columns = {
237
238
  id: {
@@ -343,7 +344,7 @@ export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, ba
343
344
  };
344
345
  }
345
346
  if (hasManyNumberField) {
346
- const numbersTableName = `${rootTableName}_numbers`;
347
+ const numbersTableName = validateIdentifierLength(`${rootTableName}_numbers`);
347
348
  adapter.rawTables[numbersTableName] = numbersTable;
348
349
  const columns = {
349
350
  id: {
@@ -482,7 +483,7 @@ export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, ba
482
483
  locale: true
483
484
  };
484
485
  }
485
- const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`;
486
+ const relationshipsTableName = validateIdentifierLength(`${tableName}${adapter.relationshipsSuffix}`);
486
487
  const relationshipIndexes = {
487
488
  order: {
488
489
  name: buildIndexName({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/build.ts"],"sourcesContent":["import type { FlattenedField, SanitizedCompoundIndex } from 'payload'\n\nimport { InvalidConfiguration } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type {\n DrizzleAdapter,\n IDType,\n RawColumn,\n RawForeignKey,\n RawIndex,\n RawRelation,\n RawTable,\n RelationMap,\n SetColumnID,\n} from '../types.js'\n\nimport { createTableName } from '../createTableName.js'\nimport { buildForeignKeyName } from '../utilities/buildForeignKeyName.js'\nimport { buildIndexName } from '../utilities/buildIndexName.js'\nimport { isUUIDType } from '../utilities/isUUIDType.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n baseColumns?: Record<string, RawColumn>\n /**\n * After table is created, run these functions to add extra config to the table\n * ie. indexes, multiple columns, etc\n */\n baseForeignKeys?: Record<string, RawForeignKey>\n /**\n * After table is created, run these functions to add extra config to the table\n * ie. indexes, multiple columns, etc\n */\n baseIndexes?: Record<string, RawIndex>\n blocksTableNameMap: Record<string, number>\n buildNumbers?: boolean\n buildRelationships?: boolean\n compoundIndexes?: SanitizedCompoundIndex[]\n disableNotNull: boolean\n disableRelsTableUnique?: boolean\n disableUnique: boolean\n fields: FlattenedField[]\n parentIsLocalized: boolean\n rootRelationships?: Set<string>\n rootRelationsToBuild?: RelationMap\n rootTableIDColType?: IDType\n rootTableName?: string\n rootUniqueRelationships?: Set<string>\n setColumnID: SetColumnID\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 baseForeignKeys = {},\n baseIndexes = {},\n blocksTableNameMap,\n compoundIndexes,\n disableNotNull,\n disableRelsTableUnique = false,\n disableUnique = false,\n fields,\n parentIsLocalized,\n rootRelationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName: incomingRootTableName,\n rootUniqueRelationships,\n setColumnID,\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, RawColumn> = baseColumns\n const indexes: Record<string, RawIndex> = baseIndexes\n\n const localesColumns: Record<string, RawColumn> = {}\n const localesIndexes: Record<string, RawIndex> = {}\n let localesTable: RawTable\n let textsTable: RawTable\n let numbersTable: RawTable\n\n // Relationships to the base collection\n const relationships: Set<string> = rootRelationships || new Set()\n\n // Unique relationships to the base collection\n const uniqueRelationships: Set<string> = rootUniqueRelationships || new Set()\n\n let relationshipsTable: RawTable\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 blocksTableNameMap,\n columns,\n disableNotNull,\n disableRelsTableUnique,\n disableUnique,\n fields,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: tableName,\n parentIsLocalized,\n parentTableName: tableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,\n rootTableIDColType: rootTableIDColType || idColType,\n rootTableName,\n setColumnID,\n uniqueRelationships,\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 = {\n name: 'created_at',\n type: 'timestamp',\n defaultNow: true,\n mode: 'string',\n notNull: true,\n precision: 3,\n withTimezone: true,\n }\n\n columns.updatedAt = {\n name: 'updated_at',\n type: 'timestamp',\n defaultNow: true,\n mode: 'string',\n notNull: true,\n precision: 3,\n withTimezone: true,\n }\n }\n\n const table: RawTable = {\n name: tableName,\n columns,\n foreignKeys: baseForeignKeys,\n indexes,\n }\n\n adapter.rawTables[tableName] = table\n\n if (hasLocalizedField || localizedRelations.size) {\n const localeTableName = `${tableName}${adapter.localesSuffix}`\n adapter.rawTables[localeTableName] = localesTable\n\n localesColumns.id = {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n }\n\n localesColumns._locale = {\n name: '_locale',\n type: 'enum',\n locale: true,\n notNull: true,\n }\n\n localesColumns._parentID = {\n name: '_parent_id',\n type: idColType,\n notNull: true,\n }\n\n localesIndexes._localeParent = {\n name: buildIndexName({\n name: `${localeTableName}_locale_parent_id_unique`,\n adapter,\n appendSuffix: false,\n }),\n on: ['_locale', '_parentID'],\n unique: true,\n }\n\n localesTable = {\n name: localeTableName,\n columns: localesColumns,\n foreignKeys: {\n _parentIdFk: {\n name: buildForeignKeyName({ name: `${localeTableName}_parent_id`, adapter }),\n columns: ['_parentID'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n },\n indexes: localesIndexes,\n }\n\n adapter.rawTables[localeTableName] = localesTable\n\n const localeRelations: Record<string, RawRelation> = {\n _parentID: {\n type: 'one',\n fields: [\n {\n name: '_parentID',\n table: localeTableName,\n },\n ],\n references: ['id'],\n relationName: '_locales',\n to: tableName,\n },\n }\n\n localizedRelations.forEach(({ type, target }, key) => {\n if (type === 'one') {\n localeRelations[key] = {\n type: 'one',\n fields: [\n {\n name: key,\n table: localeTableName,\n },\n ],\n references: ['id'],\n relationName: key,\n to: target,\n }\n }\n if (type === 'many') {\n localeRelations[key] = {\n type: 'many',\n relationName: key,\n to: target,\n }\n }\n })\n adapter.rawRelations[localeTableName] = localeRelations\n }\n\n if (compoundIndexes) {\n for (const index of compoundIndexes) {\n let someLocalized: boolean | null = null\n const columns: string[] = []\n\n const getTableToUse = () => {\n if (someLocalized) {\n return localesTable\n }\n\n return table\n }\n\n for (const { path, pathHasLocalized } of index.fields) {\n if (someLocalized === null) {\n someLocalized = pathHasLocalized\n }\n\n if (someLocalized !== pathHasLocalized) {\n throw new InvalidConfiguration(\n `Compound indexes within localized and non localized fields are not supported in SQL. Expected ${path} to be ${someLocalized ? 'non' : ''} localized.`,\n )\n }\n\n const columnPath = path.replaceAll('.', '_')\n\n if (!getTableToUse().columns[columnPath]) {\n throw new InvalidConfiguration(\n `Column ${columnPath} for compound index on ${path} was not found in the ${getTableToUse().name} table.`,\n )\n }\n\n columns.push(columnPath)\n }\n\n if (someLocalized) {\n columns.push('_locale')\n }\n\n let name = columns.join('_')\n // truncate against the limit, buildIndexName will handle collisions\n if (name.length > 63) {\n name = 'compound_index'\n }\n\n const indexName = buildIndexName({ name, adapter })\n\n getTableToUse().indexes[indexName] = {\n name: indexName,\n on: columns,\n unique: disableUnique ? false : index.unique,\n }\n }\n }\n\n if (isRoot) {\n if (hasManyTextField) {\n const textsTableName = `${rootTableName}_texts`\n adapter.rawTables[textsTableName] = textsTable\n\n const columns: Record<string, RawColumn> = {\n id: {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n },\n order: {\n name: 'order',\n type: 'integer',\n notNull: true,\n },\n parent: {\n name: 'parent_id',\n type: idColType,\n notNull: true,\n },\n path: {\n name: 'path',\n type: 'varchar',\n\n notNull: true,\n },\n text: {\n name: 'text',\n type: 'varchar',\n },\n }\n\n if (hasLocalizedManyTextField) {\n columns.locale = {\n name: 'locale',\n type: 'enum',\n locale: true,\n }\n }\n\n const textsTableIndexes: Record<string, RawIndex> = {\n orderParentIdx: {\n name: buildIndexName({\n name: `${textsTableName}_order_parent`,\n adapter,\n appendSuffix: false,\n }),\n on: ['order', 'parent'],\n },\n }\n\n if (hasManyTextField === 'index') {\n textsTableIndexes.text_idx = {\n name: buildIndexName({ name: `${textsTableName}_text`, adapter }),\n on: 'text',\n }\n }\n\n if (hasLocalizedManyTextField) {\n textsTableIndexes.localeParent = {\n name: buildIndexName({\n name: `${textsTableName}_locale_parent`,\n adapter,\n appendSuffix: false,\n }),\n on: ['locale', 'parent'],\n }\n }\n\n textsTable = {\n name: textsTableName,\n columns,\n foreignKeys: {\n parentFk: {\n name: buildForeignKeyName({ name: `${textsTableName}_parent`, adapter }),\n columns: ['parent'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n },\n indexes: textsTableIndexes,\n }\n\n adapter.rawTables[textsTableName] = textsTable\n\n adapter.rawRelations[textsTableName] = {\n parent: {\n type: 'one',\n fields: [\n {\n name: 'parent',\n table: textsTableName,\n },\n ],\n references: ['id'],\n relationName: '_texts',\n to: tableName,\n },\n }\n }\n\n if (hasManyNumberField) {\n const numbersTableName = `${rootTableName}_numbers`\n adapter.rawTables[numbersTableName] = numbersTable\n const columns: Record<string, RawColumn> = {\n id: {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n },\n number: {\n name: 'number',\n type: 'numeric',\n },\n order: {\n name: 'order',\n type: 'integer',\n notNull: true,\n },\n parent: {\n name: 'parent_id',\n type: idColType,\n notNull: true,\n },\n path: {\n name: 'path',\n type: 'varchar',\n notNull: true,\n },\n }\n\n if (hasLocalizedManyNumberField) {\n columns.locale = {\n name: 'locale',\n type: 'enum',\n locale: true,\n }\n }\n\n const numbersTableIndexes: Record<string, RawIndex> = {\n orderParentIdx: {\n name: buildIndexName({ name: `${numbersTableName}_order_parent`, adapter }),\n on: ['order', 'parent'],\n },\n }\n\n if (hasManyNumberField === 'index') {\n numbersTableIndexes.numberIdx = {\n name: buildIndexName({ name: `${numbersTableName}_number`, adapter }),\n on: 'number',\n }\n }\n\n if (hasLocalizedManyNumberField) {\n numbersTableIndexes.localeParent = {\n name: buildIndexName({\n name: `${numbersTableName}_locale_parent`,\n adapter,\n appendSuffix: false,\n }),\n on: ['locale', 'parent'],\n }\n }\n\n numbersTable = {\n name: numbersTableName,\n columns,\n foreignKeys: {\n parentFk: {\n name: buildForeignKeyName({ name: `${numbersTableName}_parent`, adapter }),\n columns: ['parent'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n },\n indexes: numbersTableIndexes,\n }\n\n adapter.rawTables[numbersTableName] = numbersTable\n\n adapter.rawRelations[numbersTableName] = {\n parent: {\n type: 'one',\n fields: [\n {\n name: 'parent',\n table: numbersTableName,\n },\n ],\n references: ['id'],\n relationName: '_numbers',\n to: tableName,\n },\n }\n }\n\n if (relationships.size) {\n const relationshipColumns: Record<string, RawColumn> = {\n id: {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n },\n order: {\n name: 'order',\n type: 'integer',\n },\n parent: {\n name: 'parent_id',\n type: idColType,\n notNull: true,\n },\n path: {\n name: 'path',\n type: 'varchar',\n notNull: true,\n },\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipColumns.locale = {\n name: 'locale',\n type: 'enum',\n locale: true,\n }\n }\n\n const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`\n\n const relationshipIndexes: Record<string, RawIndex> = {\n order: {\n name: buildIndexName({ name: `${relationshipsTableName}_order`, adapter }),\n on: 'order',\n },\n parentIdx: {\n name: buildIndexName({ name: `${relationshipsTableName}_parent`, adapter }),\n on: 'parent',\n },\n pathIdx: {\n name: buildIndexName({ name: `${relationshipsTableName}_path`, adapter }),\n on: 'path',\n },\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipIndexes.localeIdx = {\n name: buildIndexName({ name: `${relationshipsTableName}_locale`, adapter }),\n on: 'locale',\n }\n }\n\n const relationshipForeignKeys: Record<string, RawForeignKey> = {\n parentFk: {\n name: buildForeignKeyName({ name: `${relationshipsTableName}_parent`, adapter }),\n columns: ['parent'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n }\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: 'integer' | 'numeric' | 'uuid' | 'varchar' = isUUIDType(adapter.idType)\n ? 'uuid'\n : '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 const colName = `${relationTo}ID`\n\n relationshipColumns[colName] = {\n name: `${formattedRelationTo}_id`,\n type: colType,\n }\n\n relationshipForeignKeys[`${relationTo}IdFk`] = {\n name: buildForeignKeyName({\n name: `${relationshipsTableName}_${toSnakeCase(relationTo)}`,\n adapter,\n }),\n columns: [colName],\n foreignColumns: [\n {\n name: 'id',\n table: formattedRelationTo,\n },\n ],\n onDelete: 'cascade',\n }\n\n const indexColumns = [colName]\n\n const unique = !disableUnique && uniqueRelationships.has(relationTo)\n\n if (unique) {\n indexColumns.push('path')\n }\n if (hasLocalizedRelationshipField) {\n indexColumns.push('locale')\n }\n\n const indexName = buildIndexName({\n name: `${relationshipsTableName}_${formattedRelationTo}_id`,\n adapter,\n })\n\n relationshipIndexes[indexName] = {\n name: indexName,\n on: indexColumns,\n unique,\n }\n })\n\n relationshipsTable = {\n name: relationshipsTableName,\n columns: relationshipColumns,\n foreignKeys: relationshipForeignKeys,\n indexes: relationshipIndexes,\n }\n\n adapter.rawTables[relationshipsTableName] = relationshipsTable\n\n const relationshipsTableRelations: Record<string, RawRelation> = {\n parent: {\n type: 'one',\n fields: [\n {\n name: 'parent',\n table: relationshipsTableName,\n },\n ],\n references: ['id'],\n relationName: '_rels',\n to: tableName,\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\n relationshipsTableRelations[idColumnName] = {\n type: 'one',\n fields: [\n {\n name: idColumnName,\n table: relationshipsTableName,\n },\n ],\n references: ['id'],\n relationName: relationTo,\n to: relatedTableName,\n }\n })\n adapter.rawRelations[relationshipsTableName] = relationshipsTableRelations\n }\n }\n\n const tableRelations: Record<string, RawRelation> = {}\n\n nonLocalizedRelations.forEach(({ type, relationName, target }, key) => {\n if (type === 'one') {\n tableRelations[key] = {\n type: 'one',\n fields: [\n {\n name: key,\n table: tableName,\n },\n ],\n references: ['id'],\n relationName: key,\n to: target,\n }\n }\n if (type === 'many') {\n tableRelations[key] = {\n type: 'many',\n relationName: relationName || key,\n to: target,\n }\n }\n })\n\n if (hasLocalizedField) {\n tableRelations._locales = {\n type: 'many',\n relationName: '_locales',\n to: localesTable.name,\n }\n }\n\n if (isRoot && textsTable) {\n tableRelations._texts = {\n type: 'many',\n relationName: '_texts',\n to: textsTable.name,\n }\n }\n\n if (isRoot && numbersTable) {\n tableRelations._numbers = {\n type: 'many',\n relationName: '_numbers',\n to: numbersTable.name,\n }\n }\n\n if (relationships.size && relationshipsTable) {\n tableRelations._rels = {\n type: 'many',\n relationName: '_rels',\n to: relationshipsTable.name,\n }\n }\n\n adapter.rawRelations[tableName] = tableRelations\n\n return {\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n relationsToBuild,\n }\n}\n"],"names":["InvalidConfiguration","toSnakeCase","createTableName","buildForeignKeyName","buildIndexName","isUUIDType","traverseFields","buildTable","adapter","baseColumns","baseForeignKeys","baseIndexes","blocksTableNameMap","compoundIndexes","disableNotNull","disableRelsTableUnique","disableUnique","fields","parentIsLocalized","rootRelationships","rootRelationsToBuild","rootTableIDColType","rootTableName","incomingRootTableName","rootUniqueRelationships","setColumnID","tableName","timestamps","versions","withinLocalizedArrayOrBlock","isRoot","columns","indexes","localesColumns","localesIndexes","localesTable","textsTable","numbersTable","relationships","Set","uniqueRelationships","relationshipsTable","relationsToBuild","Map","idColType","hasLocalizedField","hasLocalizedManyNumberField","hasLocalizedManyTextField","hasLocalizedRelationshipField","hasManyNumberField","hasManyTextField","newTableName","parentTableName","localizedRelations","nonLocalizedRelations","forEach","type","localized","relationName","target","key","map","set","createdAt","name","defaultNow","mode","notNull","precision","withTimezone","updatedAt","table","foreignKeys","rawTables","size","localeTableName","localesSuffix","id","primaryKey","_locale","locale","_parentID","_localeParent","appendSuffix","on","unique","_parentIdFk","foreignColumns","onDelete","localeRelations","references","to","rawRelations","index","someLocalized","getTableToUse","path","pathHasLocalized","columnPath","replaceAll","push","join","length","indexName","textsTableName","order","parent","text","textsTableIndexes","orderParentIdx","text_idx","localeParent","parentFk","numbersTableName","number","numbersTableIndexes","numberIdx","relationshipColumns","relationshipsTableName","relationshipsSuffix","relationshipIndexes","parentIdx","pathIdx","localeIdx","relationshipForeignKeys","relationTo","relationshipConfig","payload","collections","config","formattedRelationTo","throwValidationError","colType","idType","relatedCollectionCustomIDType","slug","customIDType","colName","indexColumns","has","relationshipsTableRelations","relatedTableName","idColumnName","tableRelations","_locales","_texts","_numbers","_rels"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,UAAS;AAC9C,OAAOC,iBAAiB,gBAAe;AAcvC,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,cAAc,QAAQ,sBAAqB;AAiDpD,OAAO,MAAMC,aAAa,CAAC,EACzBC,OAAO,EACPC,cAAc,CAAC,CAAC,EAChBC,kBAAkB,CAAC,CAAC,EACpBC,cAAc,CAAC,CAAC,EAChBC,kBAAkB,EAClBC,eAAe,EACfC,cAAc,EACdC,yBAAyB,KAAK,EAC9BC,gBAAgB,KAAK,EACrBC,MAAM,EACNC,iBAAiB,EACjBC,iBAAiB,EACjBC,oBAAoB,EACpBC,kBAAkB,EAClBC,eAAeC,qBAAqB,EACpCC,uBAAuB,EACvBC,WAAW,EACXC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACRC,2BAA2B,EACtB;IACL,MAAMC,SAAS,CAACP;IAChB,MAAMD,gBAAgBC,yBAAyBG;IAC/C,MAAMK,UAAqCtB;IAC3C,MAAMuB,UAAoCrB;IAE1C,MAAMsB,iBAA4C,CAAC;IACnD,MAAMC,iBAA2C,CAAC;I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;gBACpBJ,MAAM;gBACNE,cAAcA,gBAAgBE;gBAC9B+B,IAAIhC;YACN;QACF;IACF;IAEA,IAAId,mBAAmB;QACrBkG,eAAeC,QAAQ,GAAG;YACxBxF,MAAM;YACNE,cAAc;YACdiC,IAAIxD,aAAa6B,IAAI;QACvB;IACF;IAEA,IAAIlC,UAAUM,YAAY;QACxB2G,eAAeE,MAAM,GAAG;YACtBzF,MAAM;YACNE,cAAc;YACdiC,IAAIvD,WAAW4B,IAAI;QACrB;IACF;IAEA,IAAIlC,UAAUO,cAAc;QAC1B0G,eAAeG,QAAQ,GAAG;YACxB1F,MAAM;YACNE,cAAc;YACdiC,IAAItD,aAAa2B,IAAI;QACvB;IACF;IAEA,IAAI1B,cAAcoC,IAAI,IAAIjC,oBAAoB;QAC5CsG,eAAeI,KAAK,GAAG;YACrB3F,MAAM;YACNE,cAAc;YACdiC,IAAIlD,mBAAmBuB,IAAI;QAC7B;IACF;IAEAxD,QAAQoF,YAAY,CAAClE,UAAU,GAAGqH;IAElC,OAAO;QACLjG;QACAC;QACAC;QACAC;QACAC;QACAR;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/schema/build.ts"],"sourcesContent":["import type { FlattenedField, SanitizedCompoundIndex } from 'payload'\n\nimport { InvalidConfiguration } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type {\n DrizzleAdapter,\n IDType,\n RawColumn,\n RawForeignKey,\n RawIndex,\n RawRelation,\n RawTable,\n RelationMap,\n SetColumnID,\n} from '../types.js'\n\nimport { createTableName } from '../createTableName.js'\nimport { buildForeignKeyName } from '../utilities/buildForeignKeyName.js'\nimport { buildIndexName } from '../utilities/buildIndexName.js'\nimport { isUUIDType } from '../utilities/isUUIDType.js'\nimport { validateIdentifierLength } from '../utilities/validateIdentifierLength.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n baseColumns?: Record<string, RawColumn>\n /**\n * After table is created, run these functions to add extra config to the table\n * ie. indexes, multiple columns, etc\n */\n baseForeignKeys?: Record<string, RawForeignKey>\n /**\n * After table is created, run these functions to add extra config to the table\n * ie. indexes, multiple columns, etc\n */\n baseIndexes?: Record<string, RawIndex>\n blocksTableNameMap: Record<string, number>\n buildNumbers?: boolean\n buildRelationships?: boolean\n compoundIndexes?: SanitizedCompoundIndex[]\n disableNotNull: boolean\n disableRelsTableUnique?: boolean\n disableUnique: boolean\n fields: FlattenedField[]\n parentIsLocalized: boolean\n rootRelationships?: Set<string>\n rootRelationsToBuild?: RelationMap\n rootTableIDColType?: IDType\n rootTableName?: string\n rootUniqueRelationships?: Set<string>\n setColumnID: SetColumnID\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 baseForeignKeys = {},\n baseIndexes = {},\n blocksTableNameMap,\n compoundIndexes,\n disableNotNull,\n disableRelsTableUnique = false,\n disableUnique = false,\n fields,\n parentIsLocalized,\n rootRelationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName: incomingRootTableName,\n rootUniqueRelationships,\n setColumnID,\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, RawColumn> = baseColumns\n const indexes: Record<string, RawIndex> = baseIndexes\n\n const localesColumns: Record<string, RawColumn> = {}\n const localesIndexes: Record<string, RawIndex> = {}\n let localesTable: RawTable\n let textsTable: RawTable\n let numbersTable: RawTable\n\n // Relationships to the base collection\n const relationships: Set<string> = rootRelationships || new Set()\n\n // Unique relationships to the base collection\n const uniqueRelationships: Set<string> = rootUniqueRelationships || new Set()\n\n let relationshipsTable: RawTable\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 blocksTableNameMap,\n columns,\n disableNotNull,\n disableRelsTableUnique,\n disableUnique,\n fields,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: tableName,\n parentIsLocalized,\n parentTableName: tableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,\n rootTableIDColType: rootTableIDColType || idColType,\n rootTableName,\n setColumnID,\n uniqueRelationships,\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 = {\n name: 'created_at',\n type: 'timestamp',\n defaultNow: true,\n mode: 'string',\n notNull: true,\n precision: 3,\n withTimezone: true,\n }\n\n columns.updatedAt = {\n name: 'updated_at',\n type: 'timestamp',\n defaultNow: true,\n mode: 'string',\n notNull: true,\n precision: 3,\n withTimezone: true,\n }\n }\n\n const table: RawTable = {\n name: tableName,\n columns,\n foreignKeys: baseForeignKeys,\n indexes,\n }\n\n adapter.rawTables[tableName] = table\n\n if (hasLocalizedField || localizedRelations.size) {\n const localeTableName = validateIdentifierLength(`${tableName}${adapter.localesSuffix}`)\n adapter.rawTables[localeTableName] = localesTable\n\n localesColumns.id = {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n }\n\n localesColumns._locale = {\n name: '_locale',\n type: 'enum',\n locale: true,\n notNull: true,\n }\n\n localesColumns._parentID = {\n name: '_parent_id',\n type: idColType,\n notNull: true,\n }\n\n localesIndexes._localeParent = {\n name: buildIndexName({\n name: `${localeTableName}_locale_parent_id_unique`,\n adapter,\n appendSuffix: false,\n }),\n on: ['_locale', '_parentID'],\n unique: true,\n }\n\n localesTable = {\n name: localeTableName,\n columns: localesColumns,\n foreignKeys: {\n _parentIdFk: {\n name: buildForeignKeyName({ name: `${localeTableName}_parent_id`, adapter }),\n columns: ['_parentID'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n },\n indexes: localesIndexes,\n }\n\n adapter.rawTables[localeTableName] = localesTable\n\n const localeRelations: Record<string, RawRelation> = {\n _parentID: {\n type: 'one',\n fields: [\n {\n name: '_parentID',\n table: localeTableName,\n },\n ],\n references: ['id'],\n relationName: '_locales',\n to: tableName,\n },\n }\n\n localizedRelations.forEach(({ type, target }, key) => {\n if (type === 'one') {\n localeRelations[key] = {\n type: 'one',\n fields: [\n {\n name: key,\n table: localeTableName,\n },\n ],\n references: ['id'],\n relationName: key,\n to: target,\n }\n }\n if (type === 'many') {\n localeRelations[key] = {\n type: 'many',\n relationName: key,\n to: target,\n }\n }\n })\n adapter.rawRelations[localeTableName] = localeRelations\n }\n\n if (compoundIndexes) {\n for (const index of compoundIndexes) {\n let someLocalized: boolean | null = null\n const columns: string[] = []\n\n const getTableToUse = () => {\n if (someLocalized) {\n return localesTable\n }\n\n return table\n }\n\n for (const { path, pathHasLocalized } of index.fields) {\n if (someLocalized === null) {\n someLocalized = pathHasLocalized\n }\n\n if (someLocalized !== pathHasLocalized) {\n throw new InvalidConfiguration(\n `Compound indexes within localized and non localized fields are not supported in SQL. Expected ${path} to be ${someLocalized ? 'non' : ''} localized.`,\n )\n }\n\n const columnPath = path.replaceAll('.', '_')\n\n if (!getTableToUse().columns[columnPath]) {\n throw new InvalidConfiguration(\n `Column ${columnPath} for compound index on ${path} was not found in the ${getTableToUse().name} table.`,\n )\n }\n\n columns.push(columnPath)\n }\n\n if (someLocalized) {\n columns.push('_locale')\n }\n\n let name = columns.join('_')\n // truncate against the limit, buildIndexName will handle collisions\n if (name.length > 63) {\n name = 'compound_index'\n }\n\n const indexName = buildIndexName({ name, adapter })\n\n getTableToUse().indexes[indexName] = {\n name: indexName,\n on: columns,\n unique: disableUnique ? false : index.unique,\n }\n }\n }\n\n if (isRoot) {\n if (hasManyTextField) {\n const textsTableName = validateIdentifierLength(`${rootTableName}_texts`)\n adapter.rawTables[textsTableName] = textsTable\n\n const columns: Record<string, RawColumn> = {\n id: {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n },\n order: {\n name: 'order',\n type: 'integer',\n notNull: true,\n },\n parent: {\n name: 'parent_id',\n type: idColType,\n notNull: true,\n },\n path: {\n name: 'path',\n type: 'varchar',\n\n notNull: true,\n },\n text: {\n name: 'text',\n type: 'varchar',\n },\n }\n\n if (hasLocalizedManyTextField) {\n columns.locale = {\n name: 'locale',\n type: 'enum',\n locale: true,\n }\n }\n\n const textsTableIndexes: Record<string, RawIndex> = {\n orderParentIdx: {\n name: buildIndexName({\n name: `${textsTableName}_order_parent`,\n adapter,\n appendSuffix: false,\n }),\n on: ['order', 'parent'],\n },\n }\n\n if (hasManyTextField === 'index') {\n textsTableIndexes.text_idx = {\n name: buildIndexName({ name: `${textsTableName}_text`, adapter }),\n on: 'text',\n }\n }\n\n if (hasLocalizedManyTextField) {\n textsTableIndexes.localeParent = {\n name: buildIndexName({\n name: `${textsTableName}_locale_parent`,\n adapter,\n appendSuffix: false,\n }),\n on: ['locale', 'parent'],\n }\n }\n\n textsTable = {\n name: textsTableName,\n columns,\n foreignKeys: {\n parentFk: {\n name: buildForeignKeyName({ name: `${textsTableName}_parent`, adapter }),\n columns: ['parent'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n },\n indexes: textsTableIndexes,\n }\n\n adapter.rawTables[textsTableName] = textsTable\n\n adapter.rawRelations[textsTableName] = {\n parent: {\n type: 'one',\n fields: [\n {\n name: 'parent',\n table: textsTableName,\n },\n ],\n references: ['id'],\n relationName: '_texts',\n to: tableName,\n },\n }\n }\n\n if (hasManyNumberField) {\n const numbersTableName = validateIdentifierLength(`${rootTableName}_numbers`)\n adapter.rawTables[numbersTableName] = numbersTable\n const columns: Record<string, RawColumn> = {\n id: {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n },\n number: {\n name: 'number',\n type: 'numeric',\n },\n order: {\n name: 'order',\n type: 'integer',\n notNull: true,\n },\n parent: {\n name: 'parent_id',\n type: idColType,\n notNull: true,\n },\n path: {\n name: 'path',\n type: 'varchar',\n notNull: true,\n },\n }\n\n if (hasLocalizedManyNumberField) {\n columns.locale = {\n name: 'locale',\n type: 'enum',\n locale: true,\n }\n }\n\n const numbersTableIndexes: Record<string, RawIndex> = {\n orderParentIdx: {\n name: buildIndexName({ name: `${numbersTableName}_order_parent`, adapter }),\n on: ['order', 'parent'],\n },\n }\n\n if (hasManyNumberField === 'index') {\n numbersTableIndexes.numberIdx = {\n name: buildIndexName({ name: `${numbersTableName}_number`, adapter }),\n on: 'number',\n }\n }\n\n if (hasLocalizedManyNumberField) {\n numbersTableIndexes.localeParent = {\n name: buildIndexName({\n name: `${numbersTableName}_locale_parent`,\n adapter,\n appendSuffix: false,\n }),\n on: ['locale', 'parent'],\n }\n }\n\n numbersTable = {\n name: numbersTableName,\n columns,\n foreignKeys: {\n parentFk: {\n name: buildForeignKeyName({ name: `${numbersTableName}_parent`, adapter }),\n columns: ['parent'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n },\n indexes: numbersTableIndexes,\n }\n\n adapter.rawTables[numbersTableName] = numbersTable\n\n adapter.rawRelations[numbersTableName] = {\n parent: {\n type: 'one',\n fields: [\n {\n name: 'parent',\n table: numbersTableName,\n },\n ],\n references: ['id'],\n relationName: '_numbers',\n to: tableName,\n },\n }\n }\n\n if (relationships.size) {\n const relationshipColumns: Record<string, RawColumn> = {\n id: {\n name: 'id',\n type: 'serial',\n primaryKey: true,\n },\n order: {\n name: 'order',\n type: 'integer',\n },\n parent: {\n name: 'parent_id',\n type: idColType,\n notNull: true,\n },\n path: {\n name: 'path',\n type: 'varchar',\n notNull: true,\n },\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipColumns.locale = {\n name: 'locale',\n type: 'enum',\n locale: true,\n }\n }\n\n const relationshipsTableName = validateIdentifierLength(\n `${tableName}${adapter.relationshipsSuffix}`,\n )\n\n const relationshipIndexes: Record<string, RawIndex> = {\n order: {\n name: buildIndexName({ name: `${relationshipsTableName}_order`, adapter }),\n on: 'order',\n },\n parentIdx: {\n name: buildIndexName({ name: `${relationshipsTableName}_parent`, adapter }),\n on: 'parent',\n },\n pathIdx: {\n name: buildIndexName({ name: `${relationshipsTableName}_path`, adapter }),\n on: 'path',\n },\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipIndexes.localeIdx = {\n name: buildIndexName({ name: `${relationshipsTableName}_locale`, adapter }),\n on: 'locale',\n }\n }\n\n const relationshipForeignKeys: Record<string, RawForeignKey> = {\n parentFk: {\n name: buildForeignKeyName({ name: `${relationshipsTableName}_parent`, adapter }),\n columns: ['parent'],\n foreignColumns: [\n {\n name: 'id',\n table: tableName,\n },\n ],\n onDelete: 'cascade',\n },\n }\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: 'integer' | 'numeric' | 'uuid' | 'varchar' = isUUIDType(adapter.idType)\n ? 'uuid'\n : '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 const colName = `${relationTo}ID`\n\n relationshipColumns[colName] = {\n name: `${formattedRelationTo}_id`,\n type: colType,\n }\n\n relationshipForeignKeys[`${relationTo}IdFk`] = {\n name: buildForeignKeyName({\n name: `${relationshipsTableName}_${toSnakeCase(relationTo)}`,\n adapter,\n }),\n columns: [colName],\n foreignColumns: [\n {\n name: 'id',\n table: formattedRelationTo,\n },\n ],\n onDelete: 'cascade',\n }\n\n const indexColumns = [colName]\n\n const unique = !disableUnique && uniqueRelationships.has(relationTo)\n\n if (unique) {\n indexColumns.push('path')\n }\n if (hasLocalizedRelationshipField) {\n indexColumns.push('locale')\n }\n\n const indexName = buildIndexName({\n name: `${relationshipsTableName}_${formattedRelationTo}_id`,\n adapter,\n })\n\n relationshipIndexes[indexName] = {\n name: indexName,\n on: indexColumns,\n unique,\n }\n })\n\n relationshipsTable = {\n name: relationshipsTableName,\n columns: relationshipColumns,\n foreignKeys: relationshipForeignKeys,\n indexes: relationshipIndexes,\n }\n\n adapter.rawTables[relationshipsTableName] = relationshipsTable\n\n const relationshipsTableRelations: Record<string, RawRelation> = {\n parent: {\n type: 'one',\n fields: [\n {\n name: 'parent',\n table: relationshipsTableName,\n },\n ],\n references: ['id'],\n relationName: '_rels',\n to: tableName,\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\n relationshipsTableRelations[idColumnName] = {\n type: 'one',\n fields: [\n {\n name: idColumnName,\n table: relationshipsTableName,\n },\n ],\n references: ['id'],\n relationName: relationTo,\n to: relatedTableName,\n }\n })\n adapter.rawRelations[relationshipsTableName] = relationshipsTableRelations\n }\n }\n\n const tableRelations: Record<string, RawRelation> = {}\n\n nonLocalizedRelations.forEach(({ type, relationName, target }, key) => {\n if (type === 'one') {\n tableRelations[key] = {\n type: 'one',\n fields: [\n {\n name: key,\n table: tableName,\n },\n ],\n references: ['id'],\n relationName: key,\n to: target,\n }\n }\n if (type === 'many') {\n tableRelations[key] = {\n type: 'many',\n relationName: relationName || key,\n to: target,\n }\n }\n })\n\n if (hasLocalizedField) {\n tableRelations._locales = {\n type: 'many',\n relationName: '_locales',\n to: localesTable.name,\n }\n }\n\n if (isRoot && textsTable) {\n tableRelations._texts = {\n type: 'many',\n relationName: '_texts',\n to: textsTable.name,\n }\n }\n\n if (isRoot && numbersTable) {\n tableRelations._numbers = {\n type: 'many',\n relationName: '_numbers',\n to: numbersTable.name,\n }\n }\n\n if (relationships.size && relationshipsTable) {\n tableRelations._rels = {\n type: 'many',\n relationName: '_rels',\n to: relationshipsTable.name,\n }\n }\n\n adapter.rawRelations[tableName] = tableRelations\n\n return {\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n relationsToBuild,\n }\n}\n"],"names":["InvalidConfiguration","toSnakeCase","createTableName","buildForeignKeyName","buildIndexName","isUUIDType","validateIdentifierLength","traverseFields","buildTable","adapter","baseColumns","baseForeignKeys","baseIndexes","blocksTableNameMap","compoundIndexes","disableNotNull","disableRelsTableUnique","disableUnique","fields","parentIsLocalized","rootRelationships","rootRelationsToBuild","rootTableIDColType","rootTableName","incomingRootTableName","rootUniqueRelationships","setColumnID","tableName","timestamps","versions","withinLocalizedArrayOrBlock","isRoot","columns","indexes","localesColumns","localesIndexes","localesTable","textsTable","numbersTable","relationships","Set","uniqueRelationships","relationshipsTable","relationsToBuild","Map","idColType","hasLocalizedField","hasLocalizedManyNumberField","hasLocalizedManyTextField","hasLocalizedRelationshipField","hasManyNumberField","hasManyTextField","newTableName","parentTableName","localizedRelations","nonLocalizedRelations","forEach","type","localized","relationName","target","key","map","set","createdAt","name","defaultNow","mode","notNull","precision","withTimezone","updatedAt","table","foreignKeys","rawTables","size","localeTableName","localesSuffix","id","primaryKey","_locale","locale","_parentID","_localeParent","appendSuffix","on","unique","_parentIdFk","foreignColumns","onDelete","localeRelations","references","to","rawRelations","index","someLocalized","getTableToUse","path","pathHasLocalized","columnPath","replaceAll","push","join","length","indexName","textsTableName","order","parent","text","textsTableIndexes","orderParentIdx","text_idx","localeParent","parentFk","numbersTableName","number","numbersTableIndexes","numberIdx","relationshipColumns","relationshipsTableName","relationshipsSuffix","relationshipIndexes","parentIdx","pathIdx","localeIdx","relationshipForeignKeys","relationTo","relationshipConfig","payload","collections","config","formattedRelationTo","throwValidationError","colType","idType","relatedCollectionCustomIDType","slug","customIDType","colName","indexColumns","has","relationshipsTableRelations","relatedTableName","idColumnName","tableRelations","_locales","_texts","_numbers","_rels"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,UAAS;AAC9C,OAAOC,iBAAiB,gBAAe;AAcvC,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,wBAAwB,QAAQ,2CAA0C;AACnF,SAASC,cAAc,QAAQ,sBAAqB;AAiDpD,OAAO,MAAMC,aAAa,CAAC,EACzBC,OAAO,EACPC,cAAc,CAAC,CAAC,EAChBC,kBAAkB,CAAC,CAAC,EACpBC,cAAc,CAAC,CAAC,EAChBC,kBAAkB,EAClBC,eAAe,EACfC,cAAc,EACdC,yBAAyB,KAAK,EAC9BC,gBAAgB,KAAK,EACrBC,MAAM,EACNC,iBAAiB,EACjBC,iBAAiB,EACjBC,oBAAoB,EACpBC,kBAAkB,EAClBC,eAAeC,qBAAqB,EACpCC,uBAAuB,EACvBC,WAAW,EACXC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACRC,2BAA2B,EACtB;IACL,MAAMC,SAAS,CAACP;IAChB,MAAMD,gBAAgBC,yBAAyBG;IAC/C,MAAMK,UAAqCtB;IAC3C,MAAMuB,UAAoCrB;IAE1C,MAAMsB,iBAA4C,CAAC;IACnD,MAAMC,iBAA2C,CAAC;IAClD,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IAEJ,uCAAuC;IACvC,MAAMC,gBAA6BnB,qBAAqB,IAAIoB;IA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IhC;YACN;QACF;IACF;IAEA,IAAId,mBAAmB;QACrBkG,eAAeC,QAAQ,GAAG;YACxBxF,MAAM;YACNE,cAAc;YACdiC,IAAIxD,aAAa6B,IAAI;QACvB;IACF;IAEA,IAAIlC,UAAUM,YAAY;QACxB2G,eAAeE,MAAM,GAAG;YACtBzF,MAAM;YACNE,cAAc;YACdiC,IAAIvD,WAAW4B,IAAI;QACrB;IACF;IAEA,IAAIlC,UAAUO,cAAc;QAC1B0G,eAAeG,QAAQ,GAAG;YACxB1F,MAAM;YACNE,cAAc;YACdiC,IAAItD,aAAa2B,IAAI;QACvB;IACF;IAEA,IAAI1B,cAAcoC,IAAI,IAAIjC,oBAAoB;QAC5CsG,eAAeI,KAAK,GAAG;YACrB3F,MAAM;YACNE,cAAc;YACdiC,IAAIlD,mBAAmBuB,IAAI;QAC7B;IACF;IAEAxD,QAAQoF,YAAY,CAAClE,UAAU,GAAGqH;IAElC,OAAO;QACLjG;QACAC;QACAC;QACAC;QACAC;QACAR;IACF;AACF,EAAC"}
@@ -162,6 +162,69 @@ describe('buildRawSchema', ()=>{
162
162
  expect(adapter.rawTables.posts_blocks_headline_2).toBeUndefined();
163
163
  expect(adapter.rawTables.posts_blocks_headline_2_locales).toBeUndefined();
164
164
  });
165
+ it('should throw when a localized field pushes the _locales companion table past 63 chars', async ()=>{
166
+ // Base table name (61 chars) is under the limit, but `${base}_locales` (69) overflows it.
167
+ const longSlug = `localized_collection_${'x'.repeat(40)}`;
168
+ const config = await sanitizeConfig({
169
+ collections: [
170
+ {
171
+ slug: longSlug,
172
+ fields: [
173
+ {
174
+ name: 'title',
175
+ type: 'text',
176
+ localized: true
177
+ }
178
+ ],
179
+ timestamps: false,
180
+ versions: false
181
+ }
182
+ ],
183
+ localization: {
184
+ defaultLocale: 'en',
185
+ locales: [
186
+ 'en',
187
+ 'de'
188
+ ]
189
+ }
190
+ });
191
+ const adapter = createAdapter(config);
192
+ expect(()=>buildRawSchema({
193
+ adapter,
194
+ setColumnID
195
+ })).toThrow('Exceeded max identifier length');
196
+ });
197
+ it('should not throw for a localized field whose _locales companion table fits within 63 chars', async ()=>{
198
+ const config = await sanitizeConfig({
199
+ collections: [
200
+ {
201
+ slug: 'short_localized',
202
+ fields: [
203
+ {
204
+ name: 'title',
205
+ type: 'text',
206
+ localized: true
207
+ }
208
+ ],
209
+ timestamps: false,
210
+ versions: false
211
+ }
212
+ ],
213
+ localization: {
214
+ defaultLocale: 'en',
215
+ locales: [
216
+ 'en',
217
+ 'de'
218
+ ]
219
+ }
220
+ });
221
+ const adapter = createAdapter(config);
222
+ buildRawSchema({
223
+ adapter,
224
+ setColumnID
225
+ });
226
+ expect(adapter.rawTables.short_localized_locales).toBeDefined();
227
+ });
165
228
  });
166
229
 
167
230
  //# sourceMappingURL=buildRawSchema.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/buildRawSchema.spec.ts"],"sourcesContent":["import type { Block, Config, SanitizedConfig } from 'payload'\nimport { sanitizeConfig } from 'payload'\nimport { describe, expect, it } from 'vitest'\n\nimport { setColumnID } from '../postgres/schema/setColumnID.js'\nimport type { DrizzleAdapter } from '../types.js'\nimport { buildRawSchema } from './buildRawSchema.js'\n\nconst headlineBlock: Block = {\n slug: 'headline',\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n}\n\nconst createContainerBlock = (slug: string): Block => ({\n slug,\n fields: [\n {\n name: 'content',\n type: 'blocks',\n blocks: ['headline'],\n },\n ],\n})\n\nconst createAdapter = (config: SanitizedConfig): DrizzleAdapter =>\n ({\n blocksAsJSON: false,\n fieldConstraints: {},\n idType: 'serial',\n localesSuffix: '_locales',\n payload: {\n blocks: Object.fromEntries(config.blocks.map((block) => [block.slug, block])),\n collections: Object.fromEntries(\n config.collections.map((collection) => [\n collection.slug,\n {\n config: collection,\n customIDType: undefined,\n },\n ]),\n ),\n config,\n },\n rawRelations: {},\n rawTables: {},\n tableNameMap: new Map(),\n versionsSuffix: '_versions',\n }) as unknown as DrizzleAdapter\n\ndescribe('buildRawSchema', () => {\n it('should create suffixed block tables for different schemas with the same slug', async () => {\n const config = await sanitizeConfig({\n collections: [\n {\n slug: 'pages',\n fields: [\n {\n name: 'primaryContent',\n type: 'blocks',\n localized: true,\n blocks: [\n {\n slug: 'content',\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n },\n ],\n },\n {\n name: 'secondaryContent',\n type: 'blocks',\n localized: true,\n blocks: [\n {\n slug: 'content',\n fields: [\n {\n name: 'description',\n type: 'textarea',\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const adapter = createAdapter(config)\n\n buildRawSchema({\n adapter,\n setColumnID,\n })\n\n expect(adapter.rawTables.pages_blocks_content.columns.title).toBeDefined()\n expect(adapter.rawTables.pages_blocks_content.columns._locale).toBeDefined()\n expect(adapter.rawTables.pages_blocks_content_2.columns.description).toBeDefined()\n expect(adapter.rawTables.pages_blocks_content_2.columns._locale).toBeDefined()\n })\n\n it('should not create duplicate suffixed block tables for identical reused blocks under localized ancestors', async () => {\n const layoutBlocks = [createContainerBlock('container'), createContainerBlock('container50')]\n\n const config = await sanitizeConfig({\n blocks: [headlineBlock],\n collections: [\n {\n slug: 'pages',\n fields: [\n {\n name: 'layout',\n type: 'blocks',\n localized: true,\n blocks: layoutBlocks,\n },\n ],\n },\n {\n slug: 'posts',\n fields: [\n {\n name: 'layout',\n type: 'blocks',\n localized: true,\n blocks: layoutBlocks,\n },\n ],\n },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const adapter = createAdapter(config)\n\n buildRawSchema({\n adapter,\n setColumnID,\n })\n\n expect(adapter.rawTables.pages_blocks_headline).toBeDefined()\n expect(adapter.rawTables.pages_blocks_headline.columns._locale).toBeDefined()\n expect(adapter.rawTables.pages_blocks_headline_2).toBeUndefined()\n expect(adapter.rawTables.pages_blocks_headline_2_locales).toBeUndefined()\n expect(adapter.rawTables.posts_blocks_headline).toBeDefined()\n expect(adapter.rawTables.posts_blocks_headline.columns._locale).toBeDefined()\n expect(adapter.rawTables.posts_blocks_headline_2).toBeUndefined()\n expect(adapter.rawTables.posts_blocks_headline_2_locales).toBeUndefined()\n })\n})\n"],"names":["sanitizeConfig","describe","expect","it","setColumnID","buildRawSchema","headlineBlock","slug","fields","name","type","createContainerBlock","blocks","createAdapter","config","blocksAsJSON","fieldConstraints","idType","localesSuffix","payload","Object","fromEntries","map","block","collections","collection","customIDType","undefined","rawRelations","rawTables","tableNameMap","Map","versionsSuffix","localized","localization","defaultLocale","locales","adapter","pages_blocks_content","columns","title","toBeDefined","_locale","pages_blocks_content_2","description","layoutBlocks","pages_blocks_headline","pages_blocks_headline_2","toBeUndefined","pages_blocks_headline_2_locales","posts_blocks_headline","posts_blocks_headline_2","posts_blocks_headline_2_locales"],"mappings":"AACA,SAASA,cAAc,QAAQ,UAAS;AACxC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,WAAW,QAAQ,oCAAmC;AAE/D,SAASC,cAAc,QAAQ,sBAAqB;AAEpD,MAAMC,gBAAuB;IAC3BC,MAAM;IACNC,QAAQ;QACN;YACEC,MAAM;YACNC,MAAM;QACR;KACD;AACH;AAEA,MAAMC,uBAAuB,CAACJ,OAAyB,CAAA;QACrDA;QACAC,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;gBACNE,QAAQ;oBAAC;iBAAW;YACtB;SACD;IACH,CAAA;AAEA,MAAMC,gBAAgB,CAACC,SACpB,CAAA;QACCC,cAAc;QACdC,kBAAkB,CAAC;QACnBC,QAAQ;QACRC,eAAe;QACfC,SAAS;YACPP,QAAQQ,OAAOC,WAAW,CAACP,OAAOF,MAAM,CAACU,GAAG,CAAC,CAACC,QAAU;oBAACA,MAAMhB,IAAI;oBAAEgB;iBAAM;YAC3EC,aAAaJ,OAAOC,WAAW,CAC7BP,OAAOU,WA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AAMd,eAAe;YAClCY,QAAQ;gBAACN;aAAc;YACvBkB,aAAa;gBACX;oBACEjB,MAAM;oBACNC,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNuB,WAAW;4BACXrB,QAAQiC;wBACV;qBACD;gBACH;gBACA;oBACEtC,MAAM;oBACNC,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNuB,WAAW;4BACXrB,QAAQiC;wBACV;qBACD;gBACH;aACD;YACDX,cAAc;gBACZC,eAAe;gBACfC,SAAS;oBAAC;oBAAM;iBAAK;YACvB;QACF;QAEA,MAAMC,UAAUxB,cAAcC;QAE9BT,eAAe;YACbgC;YACAjC;QACF;QAEAF,OAAOmC,QAAQR,SAAS,CAACiB,qBAAqB,EAAEL,WAAW;QAC3DvC,OAAOmC,QAAQR,SAAS,CAACiB,qBAAqB,CAACP,OAAO,CAACG,OAAO,EAAED,WAAW;QAC3EvC,OAAOmC,QAAQR,SAAS,CAACkB,uBAAuB,EAAEC,aAAa;QAC/D9C,OAAOmC,QAAQR,SAAS,CAACoB,+BAA+B,EAAED,aAAa;QACvE9C,OAAOmC,QAAQR,SAAS,CAACqB,qBAAqB,EAAET,WAAW;QAC3DvC,OAAOmC,QAAQR,SAAS,CAACqB,qBAAqB,CAACX,OAAO,CAACG,OAAO,EAAED,WAAW;QAC3EvC,OAAOmC,QAAQR,SAAS,CAACsB,uBAAuB,EAAEH,aAAa;QAC/D9C,OAAOmC,QAAQR,SAAS,CAACuB,+BAA+B,EAAEJ,aAAa;IACzE;AACF"}
1
+ {"version":3,"sources":["../../src/schema/buildRawSchema.spec.ts"],"sourcesContent":["import type { Block, Config, SanitizedConfig } from 'payload'\nimport { sanitizeConfig } from 'payload'\nimport { describe, expect, it } from 'vitest'\n\nimport { setColumnID } from '../postgres/schema/setColumnID.js'\nimport type { DrizzleAdapter } from '../types.js'\nimport { buildRawSchema } from './buildRawSchema.js'\n\nconst headlineBlock: Block = {\n slug: 'headline',\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n}\n\nconst createContainerBlock = (slug: string): Block => ({\n slug,\n fields: [\n {\n name: 'content',\n type: 'blocks',\n blocks: ['headline'],\n },\n ],\n})\n\nconst createAdapter = (config: SanitizedConfig): DrizzleAdapter =>\n ({\n blocksAsJSON: false,\n fieldConstraints: {},\n idType: 'serial',\n localesSuffix: '_locales',\n payload: {\n blocks: Object.fromEntries(config.blocks.map((block) => [block.slug, block])),\n collections: Object.fromEntries(\n config.collections.map((collection) => [\n collection.slug,\n {\n config: collection,\n customIDType: undefined,\n },\n ]),\n ),\n config,\n },\n rawRelations: {},\n rawTables: {},\n tableNameMap: new Map(),\n versionsSuffix: '_versions',\n }) as unknown as DrizzleAdapter\n\ndescribe('buildRawSchema', () => {\n it('should create suffixed block tables for different schemas with the same slug', async () => {\n const config = await sanitizeConfig({\n collections: [\n {\n slug: 'pages',\n fields: [\n {\n name: 'primaryContent',\n type: 'blocks',\n localized: true,\n blocks: [\n {\n slug: 'content',\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n },\n ],\n },\n {\n name: 'secondaryContent',\n type: 'blocks',\n localized: true,\n blocks: [\n {\n slug: 'content',\n fields: [\n {\n name: 'description',\n type: 'textarea',\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const adapter = createAdapter(config)\n\n buildRawSchema({\n adapter,\n setColumnID,\n })\n\n expect(adapter.rawTables.pages_blocks_content.columns.title).toBeDefined()\n expect(adapter.rawTables.pages_blocks_content.columns._locale).toBeDefined()\n expect(adapter.rawTables.pages_blocks_content_2.columns.description).toBeDefined()\n expect(adapter.rawTables.pages_blocks_content_2.columns._locale).toBeDefined()\n })\n\n it('should not create duplicate suffixed block tables for identical reused blocks under localized ancestors', async () => {\n const layoutBlocks = [createContainerBlock('container'), createContainerBlock('container50')]\n\n const config = await sanitizeConfig({\n blocks: [headlineBlock],\n collections: [\n {\n slug: 'pages',\n fields: [\n {\n name: 'layout',\n type: 'blocks',\n localized: true,\n blocks: layoutBlocks,\n },\n ],\n },\n {\n slug: 'posts',\n fields: [\n {\n name: 'layout',\n type: 'blocks',\n localized: true,\n blocks: layoutBlocks,\n },\n ],\n },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const adapter = createAdapter(config)\n\n buildRawSchema({\n adapter,\n setColumnID,\n })\n\n expect(adapter.rawTables.pages_blocks_headline).toBeDefined()\n expect(adapter.rawTables.pages_blocks_headline.columns._locale).toBeDefined()\n expect(adapter.rawTables.pages_blocks_headline_2).toBeUndefined()\n expect(adapter.rawTables.pages_blocks_headline_2_locales).toBeUndefined()\n expect(adapter.rawTables.posts_blocks_headline).toBeDefined()\n expect(adapter.rawTables.posts_blocks_headline.columns._locale).toBeDefined()\n expect(adapter.rawTables.posts_blocks_headline_2).toBeUndefined()\n expect(adapter.rawTables.posts_blocks_headline_2_locales).toBeUndefined()\n })\n\n it('should throw when a localized field pushes the _locales companion table past 63 chars', async () => {\n // Base table name (61 chars) is under the limit, but `${base}_locales` (69) overflows it.\n const longSlug = `localized_collection_${'x'.repeat(40)}`\n\n const config = await sanitizeConfig({\n collections: [\n {\n slug: longSlug,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n timestamps: false,\n versions: false,\n },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const adapter = createAdapter(config)\n\n expect(() =>\n buildRawSchema({\n adapter,\n setColumnID,\n }),\n ).toThrow('Exceeded max identifier length')\n })\n\n it('should not throw for a localized field whose _locales companion table fits within 63 chars', async () => {\n const config = await sanitizeConfig({\n collections: [\n {\n slug: 'short_localized',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n timestamps: false,\n versions: false,\n },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const adapter = createAdapter(config)\n\n buildRawSchema({\n adapter,\n setColumnID,\n })\n\n expect(adapter.rawTables.short_localized_locales).toBeDefined()\n })\n})\n"],"names":["sanitizeConfig","describe","expect","it","setColumnID","buildRawSchema","headlineBlock","slug","fields","name","type","createContainerBlock","blocks","createAdapter","config","blocksAsJSON","fieldConstraints","idType","localesSuffix","payload","Object","fromEntries","map","block","collections","collection","customIDType","undefined","rawRelations","rawTables","tableNameMap","Map","versionsSuffix","localized","localization","defaultLocale","locales","adapter","pages_blocks_content","columns","title","toBeDefined","_locale","pages_blocks_content_2","description","layoutBlocks","pages_blocks_headline","pages_blocks_headline_2","toBeUndefined","pages_blocks_headline_2_locales","posts_blocks_headline","posts_blocks_headline_2","posts_blocks_headline_2_locales","longSlug","repeat","timestamps","versions","toThrow","short_localized_locales"],"mappings":"AACA,SAASA,cAAc,QAAQ,UAAS;AACxC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,WAAW,QAAQ,oCAAmC;AAE/D,SAASC,cAAc,QAAQ,sBAAqB;AAEpD,MAAMC,gBAAuB;IAC3BC,MAAM;IACNC,QAAQ;QACN;YACEC,MAAM;YACNC,MAAM;QACR;KACD;AACH;AAEA,MAAMC,uBAAuB,CAACJ,OAAyB,CAAA;QACrDA;QACAC,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;gBACNE,QAAQ;oBAAC;iBAAW;YACtB;SACD;IACH,CAAA;AAEA,MAAMC,gBAAgB,CAACC,SACpB,CAAA;QACCC,cAAc;QACdC,kBAAkB,CAAC;QACnBC,QAAQ;QACRC,eAAe;QACfC,SAAS;YACPP,QAAQQ,OAAOC,WAAW,CAACP,OAAOF,MAAM,CAACU,GAAG,CAAC,CAACC,QAAU;oBAACA,MAAMhB,IAAI;oBAAEgB;iBAAM;YAC3EC,aAAaJ,OAAOC,WAAW,CAC7BP,OAAOU,WAAW,CAACF,GAAG,CAAC,CAACG,aAAe;oBACrCA,WAAWlB,IAAI;oBACf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oBAAM;iBAAK;YACvB;QACF;QAEA,MAAMC,UAAUxB,cAAcC;QAE9BZ,OAAO,IACLG,eAAe;gBACbgC;gBACAjC;YACF,IACAqD,OAAO,CAAC;IACZ;IAEAtD,GAAG,8FAA8F;QAC/F,MAAMW,SAAS,MAAMd,eAAe;YAClCwB,aAAa;gBACX;oBACEjB,MAAM;oBACNC,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNuB,WAAW;wBACb;qBACD;oBACDsB,YAAY;oBACZC,UAAU;gBACZ;aACD;YACDtB,cAAc;gBACZC,eAAe;gBACfC,SAAS;oBAAC;oBAAM;iBAAK;YACvB;QACF;QAEA,MAAMC,UAAUxB,cAAcC;QAE9BT,eAAe;YACbgC;YACAjC;QACF;QAEAF,OAAOmC,QAAQR,SAAS,CAAC6B,uBAAuB,EAAEjB,WAAW;IAC/D;AACF"}
@@ -0,0 +1,7 @@
1
+ /** Postgres max identifier length (NAMEDATALEN - 1). */
2
+ export declare const maxIdentifierLength = 63;
3
+ /**
4
+ * Throws if a table or enum identifier exceeds the Postgres 63-char limit.
5
+ */
6
+ export declare const validateIdentifierLength: (name: string) => string;
7
+ //# sourceMappingURL=validateIdentifierLength.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateIdentifierLength.d.ts","sourceRoot":"","sources":["../../src/utilities/validateIdentifierLength.ts"],"names":[],"mappings":"AAEA,wDAAwD;AACxD,eAAO,MAAM,mBAAmB,KAAK,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,wBAAwB,SAAU,MAAM,KAAG,MAUvD,CAAA"}
@@ -0,0 +1,14 @@
1
+ import { APIError } from 'payload';
2
+ /** Postgres max identifier length (NAMEDATALEN - 1). */ export const maxIdentifierLength = 63;
3
+ /**
4
+ * Throws if a table or enum identifier exceeds the Postgres 63-char limit.
5
+ */ export const validateIdentifierLength = (name)=>{
6
+ if (name.length > maxIdentifierLength) {
7
+ throw new APIError(`Exceeded max identifier length for table or enum name of ${maxIdentifierLength} characters. Invalid name: ${name}.
8
+ Tip: You can use the dbName property to reduce the table name length.
9
+ `);
10
+ }
11
+ return name;
12
+ };
13
+
14
+ //# sourceMappingURL=validateIdentifierLength.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/validateIdentifierLength.ts"],"sourcesContent":["import { APIError } from 'payload'\n\n/** Postgres max identifier length (NAMEDATALEN - 1). */\nexport const maxIdentifierLength = 63\n\n/**\n * Throws if a table or enum identifier exceeds the Postgres 63-char limit.\n */\nexport const validateIdentifierLength = (name: string): string => {\n if (name.length > maxIdentifierLength) {\n throw new APIError(\n `Exceeded max identifier length for table or enum name of ${maxIdentifierLength} characters. Invalid name: ${name}.\nTip: You can use the dbName property to reduce the table name length.\n `,\n )\n }\n\n return name\n}\n"],"names":["APIError","maxIdentifierLength","validateIdentifierLength","name","length"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,UAAS;AAElC,sDAAsD,GACtD,OAAO,MAAMC,sBAAsB,GAAE;AAErC;;CAEC,GACD,OAAO,MAAMC,2BAA2B,CAACC;IACvC,IAAIA,KAAKC,MAAM,GAAGH,qBAAqB;QACrC,MAAM,IAAID,SACR,CAAC,yDAAyD,EAAEC,oBAAoB,2BAA2B,EAAEE,KAAK;;MAElH,CAAC;IAEL;IAEA,OAAOA;AACT,EAAC"}
@@ -0,0 +1,19 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { maxIdentifierLength, validateIdentifierLength } from './validateIdentifierLength.js';
3
+ describe('validateIdentifierLength', ()=>{
4
+ it('should return the name unchanged when at or under the 63-char limit', ()=>{
5
+ const name = 'a'.repeat(maxIdentifierLength);
6
+ expect(validateIdentifierLength(name)).toBe(name);
7
+ });
8
+ it('should throw when the name exceeds the 63-char limit', ()=>{
9
+ const name = 'a'.repeat(maxIdentifierLength + 1);
10
+ expect(()=>validateIdentifierLength(name)).toThrow('Exceeded max identifier length');
11
+ });
12
+ it('should include the invalid name and the dbName tip in the error', ()=>{
13
+ const name = `some_long_table_name${'x'.repeat(maxIdentifierLength)}_locales`;
14
+ expect(()=>validateIdentifierLength(name)).toThrow(name);
15
+ expect(()=>validateIdentifierLength(name)).toThrow('You can use the dbName property to reduce the table name length');
16
+ });
17
+ });
18
+
19
+ //# sourceMappingURL=validateIdentifierLength.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/validateIdentifierLength.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport { maxIdentifierLength, validateIdentifierLength } from './validateIdentifierLength.js'\n\ndescribe('validateIdentifierLength', () => {\n it('should return the name unchanged when at or under the 63-char limit', () => {\n const name = 'a'.repeat(maxIdentifierLength)\n\n expect(validateIdentifierLength(name)).toBe(name)\n })\n\n it('should throw when the name exceeds the 63-char limit', () => {\n const name = 'a'.repeat(maxIdentifierLength + 1)\n\n expect(() => validateIdentifierLength(name)).toThrow('Exceeded max identifier length')\n })\n\n it('should include the invalid name and the dbName tip in the error', () => {\n const name = `some_long_table_name${'x'.repeat(maxIdentifierLength)}_locales`\n\n expect(() => validateIdentifierLength(name)).toThrow(name)\n expect(() => validateIdentifierLength(name)).toThrow(\n 'You can use the dbName property to reduce the table name length',\n )\n })\n})\n"],"names":["describe","expect","it","maxIdentifierLength","validateIdentifierLength","name","repeat","toBe","toThrow"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,mBAAmB,EAAEC,wBAAwB,QAAQ,gCAA+B;AAE7FJ,SAAS,4BAA4B;IACnCE,GAAG,uEAAuE;QACxE,MAAMG,OAAO,IAAIC,MAAM,CAACH;QAExBF,OAAOG,yBAAyBC,OAAOE,IAAI,CAACF;IAC9C;IAEAH,GAAG,wDAAwD;QACzD,MAAMG,OAAO,IAAIC,MAAM,CAACH,sBAAsB;QAE9CF,OAAO,IAAMG,yBAAyBC,OAAOG,OAAO,CAAC;IACvD;IAEAN,GAAG,mEAAmE;QACpE,MAAMG,OAAO,CAAC,oBAAoB,EAAE,IAAIC,MAAM,CAACH,qBAAqB,QAAQ,CAAC;QAE7EF,OAAO,IAAMG,yBAAyBC,OAAOG,OAAO,CAACH;QACrDJ,OAAO,IAAMG,yBAAyBC,OAAOG,OAAO,CAClD;IAEJ;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/drizzle",
3
- "version": "4.0.0-canary.19",
3
+ "version": "4.0.0-canary.20",
4
4
  "description": "A library of shared functions used by different payload database adapters",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -55,10 +55,10 @@
55
55
  "@types/pg": "8.20.0",
56
56
  "@types/to-snake-case": "1.0.0",
57
57
  "@payloadcms/eslint-config": "3.28.0",
58
- "payload": "4.0.0-canary.19"
58
+ "payload": "4.0.0-canary.20"
59
59
  },
60
60
  "peerDependencies": {
61
- "payload": "4.0.0-canary.19"
61
+ "payload": "4.0.0-canary.20"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "pnpm build:swc && pnpm build:types",