@payloadcms/drizzle 3.88.0 → 3.89.0-internal.4b0e9b6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/postgres/init.d.ts.map +1 -1
- package/dist/postgres/init.js +6 -0
- package/dist/postgres/init.js.map +1 -1
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/build.js +4 -5
- package/dist/schema/build.js.map +1 -1
- package/dist/schema/buildRawSchema.spec.js +69 -10
- package/dist/schema/buildRawSchema.spec.js.map +1 -1
- package/dist/utilities/buildForeignKeyName.d.ts.map +1 -1
- package/dist/utilities/buildForeignKeyName.js +3 -2
- package/dist/utilities/buildForeignKeyName.js.map +1 -1
- package/dist/utilities/buildIndexName.d.ts.map +1 -1
- package/dist/utilities/buildIndexName.js +3 -2
- package/dist/utilities/buildIndexName.js.map +1 -1
- package/dist/utilities/checkTruncatedIdentifiers.d.ts +13 -0
- package/dist/utilities/checkTruncatedIdentifiers.d.ts.map +1 -0
- package/dist/utilities/checkTruncatedIdentifiers.js +56 -0
- package/dist/utilities/checkTruncatedIdentifiers.js.map +1 -0
- package/dist/utilities/checkTruncatedIdentifiers.spec.js +301 -0
- package/dist/utilities/checkTruncatedIdentifiers.spec.js.map +1 -0
- package/dist/utilities/validateIdentifierLength.d.ts +5 -0
- package/dist/utilities/validateIdentifierLength.d.ts.map +1 -1
- package/dist/utilities/validateIdentifierLength.js +4 -0
- package/dist/utilities/validateIdentifierLength.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/postgres/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/postgres/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAWnC,eAAO,MAAM,IAAI,EAAE,IAqClB,CAAA"}
|
package/dist/postgres/init.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { buildDrizzleRelations } from '../schema/buildDrizzleRelations.js';
|
|
2
2
|
import { buildRawSchema } from '../schema/buildRawSchema.js';
|
|
3
|
+
import { checkTruncatedIdentifiers } from '../utilities/checkTruncatedIdentifiers.js';
|
|
3
4
|
import { executeSchemaHooks } from '../utilities/executeSchemaHooks.js';
|
|
4
5
|
import { buildDrizzleTable } from './schema/buildDrizzleTable.js';
|
|
5
6
|
import { setColumnID } from './schema/setColumnID.js';
|
|
@@ -14,6 +15,11 @@ export const init = async function init() {
|
|
|
14
15
|
type: 'beforeSchemaInit',
|
|
15
16
|
adapter: this
|
|
16
17
|
});
|
|
18
|
+
// Warn on identifiers Postgres will truncate past 63 chars; throw only when two collide.
|
|
19
|
+
checkTruncatedIdentifiers({
|
|
20
|
+
adapter: this,
|
|
21
|
+
logWarnings: process.env.NODE_ENV !== 'production'
|
|
22
|
+
});
|
|
17
23
|
if (this.payload.config.localization) {
|
|
18
24
|
this.enums.enum__locales = this.pgSchema.enum('_locales', this.payload.config.localization.locales.map(({ code })=>code));
|
|
19
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/postgres/init.ts"],"sourcesContent":["import type { Init } from 'payload'\n\nimport type { BasePostgresAdapter } from './types.js'\n\nimport { buildDrizzleRelations } from '../schema/buildDrizzleRelations.js'\nimport { buildRawSchema } from '../schema/buildRawSchema.js'\nimport { executeSchemaHooks } from '../utilities/executeSchemaHooks.js'\nimport { buildDrizzleTable } from './schema/buildDrizzleTable.js'\nimport { setColumnID } from './schema/setColumnID.js'\n\nexport const init: Init = async function init(this: BasePostgresAdapter) {\n this.rawRelations = {}\n this.rawTables = {}\n\n buildRawSchema({\n adapter: this,\n setColumnID,\n })\n\n await executeSchemaHooks({ type: 'beforeSchemaInit', adapter: this })\n\n if (this.payload.config.localization) {\n this.enums.enum__locales = this.pgSchema.enum(\n '_locales',\n this.payload.config.localization.locales.map(({ code }) => code) as [string, ...string[]],\n )\n }\n\n for (const tableName in this.rawTables) {\n buildDrizzleTable({ adapter: this, rawTable: this.rawTables[tableName] })\n }\n\n buildDrizzleRelations({\n adapter: this,\n })\n\n await executeSchemaHooks({ type: 'afterSchemaInit', adapter: this })\n\n this.schema = {\n pgSchema: this.pgSchema,\n ...this.tables,\n ...this.relations,\n ...this.enums,\n }\n}\n"],"names":["buildDrizzleRelations","buildRawSchema","executeSchemaHooks","buildDrizzleTable","setColumnID","init","rawRelations","rawTables","adapter","type","payload","config","localization","enums","enum__locales","pgSchema","enum","locales","map","code","tableName","rawTable","schema","tables","relations"],"mappings":"AAIA,SAASA,qBAAqB,QAAQ,qCAAoC;AAC1E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,iBAAiB,QAAQ,gCAA+B;AACjE,SAASC,WAAW,QAAQ,0BAAyB;AAErD,OAAO,MAAMC,OAAa,eAAeA;IACvC,IAAI,CAACC,YAAY,GAAG,CAAC;IACrB,IAAI,CAACC,SAAS,GAAG,CAAC;
|
|
1
|
+
{"version":3,"sources":["../../src/postgres/init.ts"],"sourcesContent":["import type { Init } from 'payload'\n\nimport type { BasePostgresAdapter } from './types.js'\n\nimport { buildDrizzleRelations } from '../schema/buildDrizzleRelations.js'\nimport { buildRawSchema } from '../schema/buildRawSchema.js'\nimport { checkTruncatedIdentifiers } from '../utilities/checkTruncatedIdentifiers.js'\nimport { executeSchemaHooks } from '../utilities/executeSchemaHooks.js'\nimport { buildDrizzleTable } from './schema/buildDrizzleTable.js'\nimport { setColumnID } from './schema/setColumnID.js'\n\nexport const init: Init = async function init(this: BasePostgresAdapter) {\n this.rawRelations = {}\n this.rawTables = {}\n\n buildRawSchema({\n adapter: this,\n setColumnID,\n })\n\n await executeSchemaHooks({ type: 'beforeSchemaInit', adapter: this })\n\n // Warn on identifiers Postgres will truncate past 63 chars; throw only when two collide.\n checkTruncatedIdentifiers({ adapter: this, logWarnings: process.env.NODE_ENV !== 'production' })\n\n if (this.payload.config.localization) {\n this.enums.enum__locales = this.pgSchema.enum(\n '_locales',\n this.payload.config.localization.locales.map(({ code }) => code) as [string, ...string[]],\n )\n }\n\n for (const tableName in this.rawTables) {\n buildDrizzleTable({ adapter: this, rawTable: this.rawTables[tableName] })\n }\n\n buildDrizzleRelations({\n adapter: this,\n })\n\n await executeSchemaHooks({ type: 'afterSchemaInit', adapter: this })\n\n this.schema = {\n pgSchema: this.pgSchema,\n ...this.tables,\n ...this.relations,\n ...this.enums,\n }\n}\n"],"names":["buildDrizzleRelations","buildRawSchema","checkTruncatedIdentifiers","executeSchemaHooks","buildDrizzleTable","setColumnID","init","rawRelations","rawTables","adapter","type","logWarnings","process","env","NODE_ENV","payload","config","localization","enums","enum__locales","pgSchema","enum","locales","map","code","tableName","rawTable","schema","tables","relations"],"mappings":"AAIA,SAASA,qBAAqB,QAAQ,qCAAoC;AAC1E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,4CAA2C;AACrF,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,iBAAiB,QAAQ,gCAA+B;AACjE,SAASC,WAAW,QAAQ,0BAAyB;AAErD,OAAO,MAAMC,OAAa,eAAeA;IACvC,IAAI,CAACC,YAAY,GAAG,CAAC;IACrB,IAAI,CAACC,SAAS,GAAG,CAAC;IAElBP,eAAe;QACbQ,SAAS,IAAI;QACbJ;IACF;IAEA,MAAMF,mBAAmB;QAAEO,MAAM;QAAoBD,SAAS,IAAI;IAAC;IAEnE,yFAAyF;IACzFP,0BAA0B;QAAEO,SAAS,IAAI;QAAEE,aAAaC,QAAQC,GAAG,CAACC,QAAQ,KAAK;IAAa;IAE9F,IAAI,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;QACpC,IAAI,CAACC,KAAK,CAACC,aAAa,GAAG,IAAI,CAACC,QAAQ,CAACC,IAAI,CAC3C,YACA,IAAI,CAACN,OAAO,CAACC,MAAM,CAACC,YAAY,CAACK,OAAO,CAACC,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA;IAE/D;IAEA,IAAK,MAAMC,aAAa,IAAI,CAACjB,SAAS,CAAE;QACtCJ,kBAAkB;YAAEK,SAAS,IAAI;YAAEiB,UAAU,IAAI,CAAClB,SAAS,CAACiB,UAAU;QAAC;IACzE;IAEAzB,sBAAsB;QACpBS,SAAS,IAAI;IACf;IAEA,MAAMN,mBAAmB;QAAEO,MAAM;QAAmBD,SAAS,IAAI;IAAC;IAElE,IAAI,CAACkB,MAAM,GAAG;QACZP,UAAU,IAAI,CAACA,QAAQ;QACvB,GAAG,IAAI,CAACQ,MAAM;QACd,GAAG,IAAI,CAACC,SAAS;QACjB,GAAG,IAAI,CAACX,KAAK;IACf;AACF,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;AAKrE,OAAO,KAAK,EACV,cAAc,EACd,MAAM,EACN,SAAS,EACT,aAAa,EACb,QAAQ,EAGR,WAAW,EACX,WAAW,EACZ,MAAM,aAAa,CAAA;
|
|
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;AAKrE,OAAO,KAAK,EACV,cAAc,EACd,MAAM,EACN,SAAS,EACT,aAAa,EACb,QAAQ,EAGR,WAAW,EACX,WAAW,EACZ,MAAM,aAAa,CAAA;AAQpB,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC,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AAM,UAAU,0XAsBpB,IAAI,KAAG,MAisBT,CAAA"}
|
package/dist/schema/build.js
CHANGED
|
@@ -4,7 +4,6 @@ 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';
|
|
8
7
|
import { traverseFields } from './traverseFields.js';
|
|
9
8
|
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 })=>{
|
|
10
9
|
const isRoot = !incomingRootTableName;
|
|
@@ -91,7 +90,7 @@ export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, ba
|
|
|
91
90
|
};
|
|
92
91
|
adapter.rawTables[tableName] = table;
|
|
93
92
|
if (hasLocalizedField || localizedRelations.size) {
|
|
94
|
-
const localeTableName =
|
|
93
|
+
const localeTableName = `${tableName}${adapter.localesSuffix}`;
|
|
95
94
|
adapter.rawTables[localeTableName] = localesTable;
|
|
96
95
|
localesColumns.id = {
|
|
97
96
|
name: 'id',
|
|
@@ -232,7 +231,7 @@ export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, ba
|
|
|
232
231
|
}
|
|
233
232
|
if (isRoot) {
|
|
234
233
|
if (hasManyTextField) {
|
|
235
|
-
const textsTableName =
|
|
234
|
+
const textsTableName = `${rootTableName}_texts`;
|
|
236
235
|
adapter.rawTables[textsTableName] = textsTable;
|
|
237
236
|
const columns = {
|
|
238
237
|
id: {
|
|
@@ -344,7 +343,7 @@ export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, ba
|
|
|
344
343
|
};
|
|
345
344
|
}
|
|
346
345
|
if (hasManyNumberField) {
|
|
347
|
-
const numbersTableName =
|
|
346
|
+
const numbersTableName = `${rootTableName}_numbers`;
|
|
348
347
|
adapter.rawTables[numbersTableName] = numbersTable;
|
|
349
348
|
const columns = {
|
|
350
349
|
id: {
|
|
@@ -483,7 +482,7 @@ export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, ba
|
|
|
483
482
|
locale: true
|
|
484
483
|
};
|
|
485
484
|
}
|
|
486
|
-
const relationshipsTableName =
|
|
485
|
+
const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`;
|
|
487
486
|
const relationshipIndexes = {
|
|
488
487
|
order: {
|
|
489
488
|
name: buildIndexName({
|
package/dist/schema/build.js.map
CHANGED
|
@@ -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 { 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;IAE5D,8CAA8C;IAC9C,MAAMC,sBAAmChB,2BAA2B,IAAIe;IAExE,IAAIE;IAEJ,oBAAoB;IACpB,MAAMC,mBAAgC,IAAIC;IAE1C,MAAMC,YAAoBnB,YAAY;QAAE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IlC,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 { 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":"A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AEA,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,6 +1,7 @@
|
|
|
1
1
|
import { sanitizeConfig } from 'payload';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
3
|
import { setColumnID } from '../postgres/schema/setColumnID.js';
|
|
4
|
+
import { checkTruncatedIdentifiers } from '../utilities/checkTruncatedIdentifiers.js';
|
|
4
5
|
import { buildRawSchema } from './buildRawSchema.js';
|
|
5
6
|
const headlineBlock = {
|
|
6
7
|
slug: 'headline',
|
|
@@ -24,7 +25,7 @@ const createContainerBlock = (slug)=>({
|
|
|
24
25
|
}
|
|
25
26
|
]
|
|
26
27
|
});
|
|
27
|
-
const createAdapter = (config)=>({
|
|
28
|
+
const createAdapter = (config, warn = ()=>{})=>({
|
|
28
29
|
blocksAsJSON: false,
|
|
29
30
|
fieldConstraints: {},
|
|
30
31
|
idType: 'serial',
|
|
@@ -41,7 +42,10 @@ const createAdapter = (config)=>({
|
|
|
41
42
|
customIDType: undefined
|
|
42
43
|
}
|
|
43
44
|
])),
|
|
44
|
-
config
|
|
45
|
+
config,
|
|
46
|
+
logger: {
|
|
47
|
+
warn
|
|
48
|
+
}
|
|
45
49
|
},
|
|
46
50
|
rawRelations: {},
|
|
47
51
|
rawTables: {},
|
|
@@ -106,7 +110,7 @@ describe('buildRawSchema', ()=>{
|
|
|
106
110
|
expect(adapter.rawTables.posts_blocks_headline_2).toBeUndefined();
|
|
107
111
|
expect(adapter.rawTables.posts_blocks_headline_2_locales).toBeUndefined();
|
|
108
112
|
});
|
|
109
|
-
it('should
|
|
113
|
+
it('should warn when a localized field pushes the _locales companion table past 63 chars', async ()=>{
|
|
110
114
|
// Base table name (61 chars) is under the limit, but `${base}_locales` (69) overflows it.
|
|
111
115
|
const longSlug = `localized_collection_${'x'.repeat(40)}`;
|
|
112
116
|
const config = await sanitizeConfig({
|
|
@@ -131,13 +135,21 @@ describe('buildRawSchema', ()=>{
|
|
|
131
135
|
]
|
|
132
136
|
}
|
|
133
137
|
});
|
|
134
|
-
const
|
|
135
|
-
|
|
138
|
+
const warn = vi.fn();
|
|
139
|
+
const adapter = createAdapter(config, warn);
|
|
140
|
+
buildRawSchema({
|
|
141
|
+
adapter,
|
|
142
|
+
setColumnID
|
|
143
|
+
});
|
|
144
|
+
expect(adapter.rawTables[`${longSlug}_locales`]).toBeDefined();
|
|
145
|
+
expect(()=>checkTruncatedIdentifiers({
|
|
136
146
|
adapter,
|
|
137
|
-
|
|
138
|
-
})).toThrow(
|
|
147
|
+
logWarnings: true
|
|
148
|
+
})).not.toThrow();
|
|
149
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
150
|
+
expect(warn.mock.calls[0][0]).toContain(`${longSlug}_locales`);
|
|
139
151
|
});
|
|
140
|
-
it('should not
|
|
152
|
+
it('should not warn when the _locales companion table fits within 63 chars', async ()=>{
|
|
141
153
|
const config = await sanitizeConfig({
|
|
142
154
|
collections: [
|
|
143
155
|
{
|
|
@@ -160,12 +172,59 @@ describe('buildRawSchema', ()=>{
|
|
|
160
172
|
]
|
|
161
173
|
}
|
|
162
174
|
});
|
|
163
|
-
const
|
|
175
|
+
const warn = vi.fn();
|
|
176
|
+
const adapter = createAdapter(config, warn);
|
|
164
177
|
buildRawSchema({
|
|
165
178
|
adapter,
|
|
166
179
|
setColumnID
|
|
167
180
|
});
|
|
168
181
|
expect(adapter.rawTables.short_localized_locales).toBeDefined();
|
|
182
|
+
checkTruncatedIdentifiers({
|
|
183
|
+
adapter,
|
|
184
|
+
logWarnings: true
|
|
185
|
+
});
|
|
186
|
+
expect(warn).not.toHaveBeenCalled();
|
|
187
|
+
});
|
|
188
|
+
it('should warn about raw inline sub-table index and foreign key names that exceed 63 chars', async ()=>{
|
|
189
|
+
// Array sub-tables assign structural index/FK names inline (not via buildIndexName/
|
|
190
|
+
// buildForeignKeyName), so a long-but-valid array table name still overflows them.
|
|
191
|
+
const arrayFieldName = 'a'.repeat(58);
|
|
192
|
+
const config = await sanitizeConfig({
|
|
193
|
+
collections: [
|
|
194
|
+
{
|
|
195
|
+
slug: 'p',
|
|
196
|
+
fields: [
|
|
197
|
+
{
|
|
198
|
+
name: arrayFieldName,
|
|
199
|
+
type: 'array',
|
|
200
|
+
fields: [
|
|
201
|
+
{
|
|
202
|
+
name: 'title',
|
|
203
|
+
type: 'text'
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
}
|
|
207
|
+
],
|
|
208
|
+
timestamps: false
|
|
209
|
+
}
|
|
210
|
+
]
|
|
211
|
+
});
|
|
212
|
+
const warn = vi.fn();
|
|
213
|
+
const adapter = createAdapter(config, warn);
|
|
214
|
+
buildRawSchema({
|
|
215
|
+
adapter,
|
|
216
|
+
setColumnID
|
|
217
|
+
});
|
|
218
|
+
const arrayTable = `p_${arrayFieldName}`;
|
|
219
|
+
checkTruncatedIdentifiers({
|
|
220
|
+
adapter,
|
|
221
|
+
logWarnings: true
|
|
222
|
+
});
|
|
223
|
+
expect(arrayTable.length).toBeLessThanOrEqual(63);
|
|
224
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
225
|
+
const message = warn.mock.calls[0][0];
|
|
226
|
+
expect(message).toContain(`${arrayTable}_order_idx`);
|
|
227
|
+
expect(message).toContain(`${arrayTable}_parent_id_fk`);
|
|
169
228
|
});
|
|
170
229
|
});
|
|
171
230
|
|
|
@@ -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 blockReferences: ['headline'],\n blocks: [],\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 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 timestamps: false,\n },\n {\n slug: 'posts',\n fields: [\n {\n name: 'layout',\n type: 'blocks',\n localized: true,\n blocks: layoutBlocks,\n },\n ],\n timestamps: 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.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 },\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 },\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","blockReferences","blocks","createAdapter","config","blocksAsJSON","fieldConstraints","idType","localesSuffix","payload","Object","fromEntries","map","block","collections","collection","customIDType","undefined","rawRelations","rawTables","tableNameMap","Map","versionsSuffix","layoutBlocks","localized","timestamps","localization","defaultLocale","locales","adapter","pages_blocks_headline","toBeDefined","columns","_locale","pages_blocks_headline_2","toBeUndefined","pages_blocks_headline_2_locales","posts_blocks_headline","posts_blocks_headline_2","posts_blocks_headline_2_locales","longSlug","repe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CAAC;IACZ;IAEAlD,GAAG,8FAA8F;QAC/F,MAAMY,SAAS,MAAMf,eAAe;YAClCyB,aAAa;gBACX;oBACElB,MAAM;oBACNC,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNyB,WAAW;wBACb;qBACD;oBACDC,YAAY;gBACd;aACD;YACDC,cAAc;gBACZC,eAAe;gBACfC,SAAS;oBAAC;oBAAM;iBAAK;YACvB;QACF;QAEA,MAAMC,UAAU1B,cAAcC;QAE9BV,eAAe;YACbmC;YACApC;QACF;QAEAF,OAAOsC,QAAQV,SAAS,CAACwB,uBAAuB,EAAEZ,WAAW;IAC/D;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, vi } from 'vitest'\n\nimport { setColumnID } from '../postgres/schema/setColumnID.js'\nimport type { DrizzleAdapter } from '../types.js'\nimport { checkTruncatedIdentifiers } from '../utilities/checkTruncatedIdentifiers.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 blockReferences: ['headline'],\n blocks: [],\n },\n ],\n})\n\nconst createAdapter = (\n config: SanitizedConfig,\n warn: (...args: any[]) => void = () => {},\n): 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 logger: { warn },\n },\n rawRelations: {},\n rawTables: {},\n tableNameMap: new Map(),\n versionsSuffix: '_versions',\n }) as unknown as DrizzleAdapter\n\ndescribe('buildRawSchema', () => {\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 timestamps: false,\n },\n {\n slug: 'posts',\n fields: [\n {\n name: 'layout',\n type: 'blocks',\n localized: true,\n blocks: layoutBlocks,\n },\n ],\n timestamps: 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.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 warn 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 },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const warn = vi.fn()\n const adapter = createAdapter(config, warn)\n\n buildRawSchema({ adapter, setColumnID })\n\n expect(adapter.rawTables[`${longSlug}_locales`]).toBeDefined()\n\n expect(() => checkTruncatedIdentifiers({ adapter, logWarnings: true })).not.toThrow()\n expect(warn).toHaveBeenCalledTimes(1)\n expect(warn.mock.calls[0][0]).toContain(`${longSlug}_locales`)\n })\n\n it('should not warn when the _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 },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const warn = vi.fn()\n const adapter = createAdapter(config, warn)\n\n buildRawSchema({ adapter, setColumnID })\n\n expect(adapter.rawTables.short_localized_locales).toBeDefined()\n\n checkTruncatedIdentifiers({ adapter, logWarnings: true })\n\n expect(warn).not.toHaveBeenCalled()\n })\n\n it('should warn about raw inline sub-table index and foreign key names that exceed 63 chars', async () => {\n // Array sub-tables assign structural index/FK names inline (not via buildIndexName/\n // buildForeignKeyName), so a long-but-valid array table name still overflows them.\n const arrayFieldName = 'a'.repeat(58)\n\n const config = await sanitizeConfig({\n collections: [\n {\n slug: 'p',\n fields: [\n {\n name: arrayFieldName,\n type: 'array',\n fields: [{ name: 'title', type: 'text' }],\n },\n ],\n timestamps: false,\n },\n ],\n } as Config)\n\n const warn = vi.fn()\n const adapter = createAdapter(config, warn)\n\n buildRawSchema({ adapter, setColumnID })\n\n const arrayTable = `p_${arrayFieldName}`\n\n checkTruncatedIdentifiers({ adapter, logWarnings: true })\n\n expect(arrayTable.length).toBeLessThanOrEqual(63)\n expect(warn).toHaveBeenCalledTimes(1)\n\n const message: string = warn.mock.calls[0][0]\n\n expect(message).toContain(`${arrayTable}_order_idx`)\n expect(message).toContain(`${arrayTable}_parent_id_fk`)\n })\n})\n"],"names":["sanitizeConfig","describe","expect","it","vi","setColumnID","checkTruncatedIdentifiers","buildRawSchema","headlineBlock","slug","fields","name","type","createContainerBlock","blockReferences","blocks","createAdapter","config","warn","blocksAsJSON","fieldConstraints","idType","localesSuffix","payload","Object","fromEntries","map","block","collections","collection","customIDType","undefined","logger","rawRelations","rawTables","tableNameMap","Map","versionsSuffix","layoutBlocks","localized","timestamps","localization","defaultLocale","locales","adapter","pages_blocks_headline","toBeDefined","columns","_locale","pages_blocks_headline_2","toBeUndefined","pages_blocks_headline_2_locales","posts_blocks_headline","posts_blocks_headline_2","posts_blocks_headline_2_locales","longSlug","repeat","fn","logWarnings","not","toThrow","toHaveBeenCalledTimes","mock","calls","toContain","short_localized_locales","toHaveBeenCalled","arrayFieldName","arrayTable","length","toBeLessThanOrEqual","message"],"mappings":"AACA,SAASA,cAAc,QAAQ,UAAS;AACxC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAEjD,SAASC,WAAW,QAAQ,oCAAmC;AAE/D,SAASC,yBAAyB,QAAQ,4CAA2C;AACrF,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,iBAAiB;oBAAC;iBAAW;gBAC7BC,QAAQ,EAAE;YACZ;SACD;IACH,CAAA;AAEA,MAAMC,gBAAgB,CACpBC,QACAC,OAAiC,KAAO,CAAC,GAExC,CAAA;QACCC,cAAc;QACdC,kBAAkB,CAAC;QACnBC,QAAQ;QACRC,eAAe;QACfC,SAAS;YACPR,QAAQS,OAAOC,WAAW,CAACR,OAAOF,MAAM,CAACW,GAAG,CAAC,CAACC,QAAU;oBAACA,MAAMlB,IAAI;oBAAEkB;iBAAM;YAC3EC,aAAaJ,OAAOC,WAAW,CAC7BR,OAAOW,WAAW,CAACF,GAAG,CAAC,CAACG,aAAe;oBACrCA,WAAWpB,IAAI;oBACf;wBACEQ,QAAQY;wBACRC,cAAcC;oBAChB;iBACD;YAEHd;YACAe,QAA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;QAAK;QAEvDxD,OAAOgB,MAAMyC,GAAG,CAACO,gBAAgB;IACnC;IAEA/D,GAAG,2FAA2F;QAC5F,oFAAoF;QACpF,mFAAmF;QACnF,MAAMgE,iBAAiB,IAAIX,MAAM,CAAC;QAElC,MAAMvC,SAAS,MAAMjB,eAAe;YAClC4B,aAAa;gBACX;oBACEnB,MAAM;oBACNC,QAAQ;wBACN;4BACEC,MAAMwD;4BACNvD,MAAM;4BACNF,QAAQ;gCAAC;oCAAEC,MAAM;oCAASC,MAAM;gCAAO;6BAAE;wBAC3C;qBACD;oBACD4B,YAAY;gBACd;aACD;QACH;QAEA,MAAMtB,OAAOd,GAAGqD,EAAE;QAClB,MAAMb,UAAU5B,cAAcC,QAAQC;QAEtCX,eAAe;YAAEqC;YAASvC;QAAY;QAEtC,MAAM+D,aAAa,CAAC,EAAE,EAAED,gBAAgB;QAExC7D,0BAA0B;YAAEsC;YAASc,aAAa;QAAK;QAEvDxD,OAAOkE,WAAWC,MAAM,EAAEC,mBAAmB,CAAC;QAC9CpE,OAAOgB,MAAM2C,qBAAqB,CAAC;QAEnC,MAAMU,UAAkBrD,KAAK4C,IAAI,CAACC,KAAK,CAAC,EAAE,CAAC,EAAE;QAE7C7D,OAAOqE,SAASP,SAAS,CAAC,GAAGI,WAAW,UAAU,CAAC;QACnDlE,OAAOqE,SAASP,SAAS,CAAC,GAAGI,WAAW,aAAa,CAAC;IACxD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildForeignKeyName.d.ts","sourceRoot":"","sources":["../../src/utilities/buildForeignKeyName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"buildForeignKeyName.d.ts","sourceRoot":"","sources":["../../src/utilities/buildForeignKeyName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,eAAO,MAAM,mBAAmB,+BAI7B;IACD,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,KAAG,MAkBH,CAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { maxGeneratedIdentifierLength } from './validateIdentifierLength.js';
|
|
1
2
|
export const buildForeignKeyName = ({ name, adapter, number = 0 })=>{
|
|
2
3
|
let foreignKeyName = `${name}${number ? `_${number}` : ''}_fk`;
|
|
3
|
-
if (foreignKeyName.length >
|
|
4
|
+
if (foreignKeyName.length > maxGeneratedIdentifierLength) {
|
|
4
5
|
const suffix = `${number ? `_${number}` : ''}_fk`;
|
|
5
|
-
foreignKeyName = `${name.slice(0,
|
|
6
|
+
foreignKeyName = `${name.slice(0, maxGeneratedIdentifierLength - suffix.length)}${suffix}`;
|
|
6
7
|
}
|
|
7
8
|
if (!adapter.foreignKeys.has(foreignKeyName)) {
|
|
8
9
|
adapter.foreignKeys.add(foreignKeyName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/buildForeignKeyName.ts"],"sourcesContent":["import type { DrizzleAdapter } from '../types.js'\n\nexport const buildForeignKeyName = ({\n name,\n adapter,\n number = 0,\n}: {\n adapter: DrizzleAdapter\n name: string\n number?: number\n}): string => {\n let foreignKeyName = `${name}${number ? `_${number}` : ''}_fk`\n\n if (foreignKeyName.length >
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/buildForeignKeyName.ts"],"sourcesContent":["import type { DrizzleAdapter } from '../types.js'\n\nimport { maxGeneratedIdentifierLength } from './validateIdentifierLength.js'\n\nexport const buildForeignKeyName = ({\n name,\n adapter,\n number = 0,\n}: {\n adapter: DrizzleAdapter\n name: string\n number?: number\n}): string => {\n let foreignKeyName = `${name}${number ? `_${number}` : ''}_fk`\n\n if (foreignKeyName.length > maxGeneratedIdentifierLength) {\n const suffix = `${number ? `_${number}` : ''}_fk`\n foreignKeyName = `${name.slice(0, maxGeneratedIdentifierLength - suffix.length)}${suffix}`\n }\n\n if (!adapter.foreignKeys.has(foreignKeyName)) {\n adapter.foreignKeys.add(foreignKeyName)\n return foreignKeyName\n }\n\n return buildForeignKeyName({\n name,\n adapter,\n number: number + 1,\n })\n}\n"],"names":["maxGeneratedIdentifierLength","buildForeignKeyName","name","adapter","number","foreignKeyName","length","suffix","slice","foreignKeys","has","add"],"mappings":"AAEA,SAASA,4BAA4B,QAAQ,gCAA+B;AAE5E,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,IAAI,EACJC,OAAO,EACPC,SAAS,CAAC,EAKX;IACC,IAAIC,iBAAiB,GAAGH,OAAOE,SAAS,CAAC,CAAC,EAAEA,QAAQ,GAAG,GAAG,GAAG,CAAC;IAE9D,IAAIC,eAAeC,MAAM,GAAGN,8BAA8B;QACxD,MAAMO,SAAS,GAAGH,SAAS,CAAC,CAAC,EAAEA,QAAQ,GAAG,GAAG,GAAG,CAAC;QACjDC,iBAAiB,GAAGH,KAAKM,KAAK,CAAC,GAAGR,+BAA+BO,OAAOD,MAAM,IAAIC,QAAQ;IAC5F;IAEA,IAAI,CAACJ,QAAQM,WAAW,CAACC,GAAG,CAACL,iBAAiB;QAC5CF,QAAQM,WAAW,CAACE,GAAG,CAACN;QACxB,OAAOA;IACT;IAEA,OAAOJ,oBAAoB;QACzBC;QACAC;QACAC,QAAQA,SAAS;IACnB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildIndexName.d.ts","sourceRoot":"","sources":["../../src/utilities/buildIndexName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"buildIndexName.d.ts","sourceRoot":"","sources":["../../src/utilities/buildIndexName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,eAAO,MAAM,cAAc,6CAKxB;IACD,OAAO,EAAE,cAAc,CAAA;IACvB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,KAAG,MAmBH,CAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { maxGeneratedIdentifierLength } from './validateIdentifierLength.js';
|
|
1
2
|
export const buildIndexName = ({ name, adapter, appendSuffix = true, number = 0 })=>{
|
|
2
3
|
let indexName = `${name}${number ? `_${number}` : ''}${appendSuffix ? '_idx' : ''}`;
|
|
3
|
-
if (indexName.length >
|
|
4
|
+
if (indexName.length > maxGeneratedIdentifierLength) {
|
|
4
5
|
const suffix = `${number ? `_${number}` : ''}${appendSuffix ? '_idx' : ''}`;
|
|
5
|
-
indexName = `${name.slice(0,
|
|
6
|
+
indexName = `${name.slice(0, maxGeneratedIdentifierLength - suffix.length)}${suffix}`;
|
|
6
7
|
}
|
|
7
8
|
if (!adapter.indexes.has(indexName) && !(indexName in adapter.rawTables)) {
|
|
8
9
|
adapter.indexes.add(indexName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/buildIndexName.ts"],"sourcesContent":["import type { DrizzleAdapter } from '../types.js'\n\nexport const buildIndexName = ({\n name,\n adapter,\n appendSuffix = true,\n number = 0,\n}: {\n adapter: DrizzleAdapter\n appendSuffix?: boolean\n name: string\n number?: number\n}): string => {\n let indexName = `${name}${number ? `_${number}` : ''}${appendSuffix ? '_idx' : ''}`\n\n if (indexName.length >
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/buildIndexName.ts"],"sourcesContent":["import type { DrizzleAdapter } from '../types.js'\n\nimport { maxGeneratedIdentifierLength } from './validateIdentifierLength.js'\n\nexport const buildIndexName = ({\n name,\n adapter,\n appendSuffix = true,\n number = 0,\n}: {\n adapter: DrizzleAdapter\n appendSuffix?: boolean\n name: string\n number?: number\n}): string => {\n let indexName = `${name}${number ? `_${number}` : ''}${appendSuffix ? '_idx' : ''}`\n\n if (indexName.length > maxGeneratedIdentifierLength) {\n const suffix = `${number ? `_${number}` : ''}${appendSuffix ? '_idx' : ''}`\n indexName = `${name.slice(0, maxGeneratedIdentifierLength - suffix.length)}${suffix}`\n }\n\n if (!adapter.indexes.has(indexName) && !(indexName in adapter.rawTables)) {\n adapter.indexes.add(indexName)\n return indexName\n }\n\n return buildIndexName({\n name,\n adapter,\n appendSuffix,\n number: number + 1,\n })\n}\n"],"names":["maxGeneratedIdentifierLength","buildIndexName","name","adapter","appendSuffix","number","indexName","length","suffix","slice","indexes","has","rawTables","add"],"mappings":"AAEA,SAASA,4BAA4B,QAAQ,gCAA+B;AAE5E,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,IAAI,EACJC,OAAO,EACPC,eAAe,IAAI,EACnBC,SAAS,CAAC,EAMX;IACC,IAAIC,YAAY,GAAGJ,OAAOG,SAAS,CAAC,CAAC,EAAEA,QAAQ,GAAG,KAAKD,eAAe,SAAS,IAAI;IAEnF,IAAIE,UAAUC,MAAM,GAAGP,8BAA8B;QACnD,MAAMQ,SAAS,GAAGH,SAAS,CAAC,CAAC,EAAEA,QAAQ,GAAG,KAAKD,eAAe,SAAS,IAAI;QAC3EE,YAAY,GAAGJ,KAAKO,KAAK,CAAC,GAAGT,+BAA+BQ,OAAOD,MAAM,IAAIC,QAAQ;IACvF;IAEA,IAAI,CAACL,QAAQO,OAAO,CAACC,GAAG,CAACL,cAAc,CAAEA,CAAAA,aAAaH,QAAQS,SAAS,AAAD,GAAI;QACxET,QAAQO,OAAO,CAACG,GAAG,CAACP;QACpB,OAAOA;IACT;IAEA,OAAOL,eAAe;QACpBC;QACAC;QACAC;QACAC,QAAQA,SAAS;IACnB;AACF,EAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DrizzleAdapter } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Warns about identifiers Postgres will silently truncate past 63 chars, and throws
|
|
4
|
+
* when two of them truncate to the same name (a schema Postgres can't create anyway).
|
|
5
|
+
*
|
|
6
|
+
* Base table/enum names throw during construction, so this only covers concatenated
|
|
7
|
+
* identifiers: companion tables, columns, and inline index/foreign key names.
|
|
8
|
+
*/
|
|
9
|
+
export declare const checkTruncatedIdentifiers: ({ adapter, logWarnings, }: {
|
|
10
|
+
adapter: Pick<DrizzleAdapter, "payload" | "rawTables">;
|
|
11
|
+
logWarnings: boolean;
|
|
12
|
+
}) => void;
|
|
13
|
+
//# sourceMappingURL=checkTruncatedIdentifiers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkTruncatedIdentifiers.d.ts","sourceRoot":"","sources":["../../src/utilities/checkTruncatedIdentifiers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAOjD;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,8BAGnC;IACD,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,WAAW,CAAC,CAAA;IACtD,WAAW,EAAE,OAAO,CAAA;CACrB,KAAG,IAgEH,CAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { APIError } from 'payload';
|
|
2
|
+
import { maxIdentifierLength } from './validateIdentifierLength.js';
|
|
3
|
+
const truncate = (name)=>name.length > maxIdentifierLength ? name.slice(0, maxIdentifierLength) : name;
|
|
4
|
+
/**
|
|
5
|
+
* Warns about identifiers Postgres will silently truncate past 63 chars, and throws
|
|
6
|
+
* when two of them truncate to the same name (a schema Postgres can't create anyway).
|
|
7
|
+
*
|
|
8
|
+
* Base table/enum names throw during construction, so this only covers concatenated
|
|
9
|
+
* identifiers: companion tables, columns, and inline index/foreign key names.
|
|
10
|
+
*/ export const checkTruncatedIdentifiers = ({ adapter, logWarnings })=>{
|
|
11
|
+
const truncatedNames = new Set();
|
|
12
|
+
const collisions = new Set();
|
|
13
|
+
// finalName -> originalName, per namespace, to detect post-truncation collisions
|
|
14
|
+
const tableNames = new Map();
|
|
15
|
+
const indexNames = new Map();
|
|
16
|
+
const foreignKeyNames = new Map();
|
|
17
|
+
const check = (original, seen)=>{
|
|
18
|
+
const final = truncate(original);
|
|
19
|
+
const existing = seen.get(final);
|
|
20
|
+
if (existing !== undefined && existing !== original) {
|
|
21
|
+
collisions.add(`"${existing}" and "${original}" both become "${final}"`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
seen.set(final, original);
|
|
25
|
+
if (final !== original) {
|
|
26
|
+
truncatedNames.add(original);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
for(const tableName in adapter.rawTables){
|
|
30
|
+
const table = adapter.rawTables[tableName];
|
|
31
|
+
check(table.name, tableNames);
|
|
32
|
+
// Columns only collide with other columns in the same table.
|
|
33
|
+
const columnNames = new Map();
|
|
34
|
+
for(const columnKey in table.columns){
|
|
35
|
+
check(table.columns[columnKey].name, columnNames);
|
|
36
|
+
}
|
|
37
|
+
if (table.indexes) {
|
|
38
|
+
for(const indexKey in table.indexes){
|
|
39
|
+
check(table.indexes[indexKey].name, indexNames);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (table.foreignKeys) {
|
|
43
|
+
for(const foreignKeyKey in table.foreignKeys){
|
|
44
|
+
check(table.foreignKeys[foreignKeyKey].name, foreignKeyNames);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (collisions.size > 0) {
|
|
49
|
+
throw new APIError(`Multiple identifiers exceed Postgres's ${maxIdentifierLength}-character limit and truncate to the same name, which Postgres cannot create: ${Array.from(collisions).join('; ')}. Use the dbName property to give them shorter, distinct names.`);
|
|
50
|
+
}
|
|
51
|
+
if (logWarnings && truncatedNames.size > 0) {
|
|
52
|
+
adapter.payload.logger.warn(`The following identifiers exceed Postgres's ${maxIdentifierLength}-character limit and will be silently truncated, which can leave the database out of sync with your Payload schema: ${Array.from(truncatedNames).join(', ')}. Use the dbName property to shorten them.`);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=checkTruncatedIdentifiers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/checkTruncatedIdentifiers.ts"],"sourcesContent":["import { APIError } from 'payload'\n\nimport type { DrizzleAdapter } from '../types.js'\n\nimport { maxIdentifierLength } from './validateIdentifierLength.js'\n\nconst truncate = (name: string): string =>\n name.length > maxIdentifierLength ? name.slice(0, maxIdentifierLength) : name\n\n/**\n * Warns about identifiers Postgres will silently truncate past 63 chars, and throws\n * when two of them truncate to the same name (a schema Postgres can't create anyway).\n *\n * Base table/enum names throw during construction, so this only covers concatenated\n * identifiers: companion tables, columns, and inline index/foreign key names.\n */\nexport const checkTruncatedIdentifiers = ({\n adapter,\n logWarnings,\n}: {\n adapter: Pick<DrizzleAdapter, 'payload' | 'rawTables'>\n logWarnings: boolean\n}): void => {\n const truncatedNames = new Set<string>()\n const collisions = new Set<string>()\n\n // finalName -> originalName, per namespace, to detect post-truncation collisions\n const tableNames = new Map<string, string>()\n const indexNames = new Map<string, string>()\n const foreignKeyNames = new Map<string, string>()\n\n const check = (original: string, seen: Map<string, string>) => {\n const final = truncate(original)\n\n const existing = seen.get(final)\n if (existing !== undefined && existing !== original) {\n collisions.add(`\"${existing}\" and \"${original}\" both become \"${final}\"`)\n return\n }\n\n seen.set(final, original)\n\n if (final !== original) {\n truncatedNames.add(original)\n }\n }\n\n for (const tableName in adapter.rawTables) {\n const table = adapter.rawTables[tableName]\n\n check(table.name, tableNames)\n\n // Columns only collide with other columns in the same table.\n const columnNames = new Map<string, string>()\n for (const columnKey in table.columns) {\n check(table.columns[columnKey].name, columnNames)\n }\n\n if (table.indexes) {\n for (const indexKey in table.indexes) {\n check(table.indexes[indexKey].name, indexNames)\n }\n }\n\n if (table.foreignKeys) {\n for (const foreignKeyKey in table.foreignKeys) {\n check(table.foreignKeys[foreignKeyKey].name, foreignKeyNames)\n }\n }\n }\n\n if (collisions.size > 0) {\n throw new APIError(\n `Multiple identifiers exceed Postgres's ${maxIdentifierLength}-character limit and truncate to the same name, which Postgres cannot create: ${Array.from(\n collisions,\n ).join('; ')}. Use the dbName property to give them shorter, distinct names.`,\n )\n }\n\n if (logWarnings && truncatedNames.size > 0) {\n adapter.payload.logger.warn(\n `The following identifiers exceed Postgres's ${maxIdentifierLength}-character limit and will be silently truncated, which can leave the database out of sync with your Payload schema: ${Array.from(\n truncatedNames,\n ).join(', ')}. Use the dbName property to shorten them.`,\n )\n }\n}\n"],"names":["APIError","maxIdentifierLength","truncate","name","length","slice","checkTruncatedIdentifiers","adapter","logWarnings","truncatedNames","Set","collisions","tableNames","Map","indexNames","foreignKeyNames","check","original","seen","final","existing","get","undefined","add","set","tableName","rawTables","table","columnNames","columnKey","columns","indexes","indexKey","foreignKeys","foreignKeyKey","size","Array","from","join","payload","logger","warn"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,UAAS;AAIlC,SAASC,mBAAmB,QAAQ,gCAA+B;AAEnE,MAAMC,WAAW,CAACC,OAChBA,KAAKC,MAAM,GAAGH,sBAAsBE,KAAKE,KAAK,CAAC,GAAGJ,uBAAuBE;AAE3E;;;;;;CAMC,GACD,OAAO,MAAMG,4BAA4B,CAAC,EACxCC,OAAO,EACPC,WAAW,EAIZ;IACC,MAAMC,iBAAiB,IAAIC;IAC3B,MAAMC,aAAa,IAAID;IAEvB,iFAAiF;IACjF,MAAME,aAAa,IAAIC;IACvB,MAAMC,aAAa,IAAID;IACvB,MAAME,kBAAkB,IAAIF;IAE5B,MAAMG,QAAQ,CAACC,UAAkBC;QAC/B,MAAMC,QAAQjB,SAASe;QAEvB,MAAMG,WAAWF,KAAKG,GAAG,CAACF;QAC1B,IAAIC,aAAaE,aAAaF,aAAaH,UAAU;YACnDN,WAAWY,GAAG,CAAC,CAAC,CAAC,EAAEH,SAAS,OAAO,EAAEH,SAAS,eAAe,EAAEE,MAAM,CAAC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kTruncatedIdentifiers.js';
|
|
3
|
+
import { maxIdentifierLength } from './validateIdentifierLength.js';
|
|
4
|
+
const buildAdapter = (rawTables, warn = ()=>{})=>({
|
|
5
|
+
payload: {
|
|
6
|
+
logger: {
|
|
7
|
+
warn
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
rawTables
|
|
11
|
+
});
|
|
12
|
+
const longName = (char)=>char.repeat(maxIdentifierLength + 1);
|
|
13
|
+
describe('checkTruncatedIdentifiers', ()=>{
|
|
14
|
+
it('should neither warn nor throw when all identifiers fit within the limit', ()=>{
|
|
15
|
+
const warn = vi.fn();
|
|
16
|
+
const adapter = buildAdapter({
|
|
17
|
+
posts: {
|
|
18
|
+
name: 'posts',
|
|
19
|
+
columns: {
|
|
20
|
+
id: {
|
|
21
|
+
name: 'id',
|
|
22
|
+
type: 'serial'
|
|
23
|
+
},
|
|
24
|
+
title: {
|
|
25
|
+
name: 'title',
|
|
26
|
+
type: 'text'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}, warn);
|
|
31
|
+
expect(()=>checkTruncatedIdentifiers({
|
|
32
|
+
adapter,
|
|
33
|
+
logWarnings: true
|
|
34
|
+
})).not.toThrow();
|
|
35
|
+
expect(warn).not.toHaveBeenCalled();
|
|
36
|
+
});
|
|
37
|
+
it('should warn (not throw) for a single over-long column name', ()=>{
|
|
38
|
+
const columnName = longName('a');
|
|
39
|
+
const warn = vi.fn();
|
|
40
|
+
const adapter = buildAdapter({
|
|
41
|
+
posts: {
|
|
42
|
+
name: 'posts',
|
|
43
|
+
columns: {
|
|
44
|
+
overflow: {
|
|
45
|
+
name: columnName,
|
|
46
|
+
type: 'text'
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}, warn);
|
|
51
|
+
expect(()=>checkTruncatedIdentifiers({
|
|
52
|
+
adapter,
|
|
53
|
+
logWarnings: true
|
|
54
|
+
})).not.toThrow();
|
|
55
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
56
|
+
expect(warn.mock.calls[0][0]).toContain(columnName);
|
|
57
|
+
});
|
|
58
|
+
it('should not warn when logWarnings is false', ()=>{
|
|
59
|
+
const warn = vi.fn();
|
|
60
|
+
const adapter = buildAdapter({
|
|
61
|
+
posts: {
|
|
62
|
+
name: 'posts',
|
|
63
|
+
columns: {
|
|
64
|
+
overflow: {
|
|
65
|
+
name: longName('a'),
|
|
66
|
+
type: 'text'
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}, warn);
|
|
71
|
+
expect(()=>checkTruncatedIdentifiers({
|
|
72
|
+
adapter,
|
|
73
|
+
logWarnings: false
|
|
74
|
+
})).not.toThrow();
|
|
75
|
+
expect(warn).not.toHaveBeenCalled();
|
|
76
|
+
});
|
|
77
|
+
it('should throw when two columns in the same table truncate to the same name', ()=>{
|
|
78
|
+
// Differ only past the 63rd character, so both truncate to the same identifier.
|
|
79
|
+
const shared = 'a'.repeat(maxIdentifierLength);
|
|
80
|
+
const adapter = buildAdapter({
|
|
81
|
+
posts: {
|
|
82
|
+
name: 'posts',
|
|
83
|
+
columns: {
|
|
84
|
+
first: {
|
|
85
|
+
name: `${shared}_one`,
|
|
86
|
+
type: 'text'
|
|
87
|
+
},
|
|
88
|
+
second: {
|
|
89
|
+
name: `${shared}_two`,
|
|
90
|
+
type: 'text'
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
expect(()=>checkTruncatedIdentifiers({
|
|
96
|
+
adapter,
|
|
97
|
+
logWarnings: true
|
|
98
|
+
})).toThrow('truncate to the same name');
|
|
99
|
+
});
|
|
100
|
+
it('should throw on a collision even when logWarnings is false', ()=>{
|
|
101
|
+
const shared = 'a'.repeat(maxIdentifierLength);
|
|
102
|
+
const adapter = buildAdapter({
|
|
103
|
+
posts: {
|
|
104
|
+
name: 'posts',
|
|
105
|
+
columns: {
|
|
106
|
+
first: {
|
|
107
|
+
name: `${shared}_one`,
|
|
108
|
+
type: 'text'
|
|
109
|
+
},
|
|
110
|
+
second: {
|
|
111
|
+
name: `${shared}_two`,
|
|
112
|
+
type: 'text'
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
expect(()=>checkTruncatedIdentifiers({
|
|
118
|
+
adapter,
|
|
119
|
+
logWarnings: false
|
|
120
|
+
})).toThrow();
|
|
121
|
+
});
|
|
122
|
+
it('should not treat same-named columns in different tables as a collision', ()=>{
|
|
123
|
+
const shared = 'a'.repeat(maxIdentifierLength);
|
|
124
|
+
const warn = vi.fn();
|
|
125
|
+
const adapter = buildAdapter({
|
|
126
|
+
posts: {
|
|
127
|
+
name: 'posts',
|
|
128
|
+
columns: {
|
|
129
|
+
overflow: {
|
|
130
|
+
name: `${shared}_one`,
|
|
131
|
+
type: 'text'
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
pages: {
|
|
136
|
+
name: 'pages',
|
|
137
|
+
columns: {
|
|
138
|
+
overflow: {
|
|
139
|
+
name: `${shared}_two`,
|
|
140
|
+
type: 'text'
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}, warn);
|
|
145
|
+
expect(()=>checkTruncatedIdentifiers({
|
|
146
|
+
adapter,
|
|
147
|
+
logWarnings: true
|
|
148
|
+
})).not.toThrow();
|
|
149
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
150
|
+
});
|
|
151
|
+
it('should throw when two table names truncate to the same name', ()=>{
|
|
152
|
+
const shared = 'a'.repeat(maxIdentifierLength);
|
|
153
|
+
const adapter = buildAdapter({
|
|
154
|
+
[`${shared}_one`]: {
|
|
155
|
+
name: `${shared}_one`,
|
|
156
|
+
columns: {
|
|
157
|
+
id: {
|
|
158
|
+
name: 'id',
|
|
159
|
+
type: 'serial'
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
[`${shared}_two`]: {
|
|
164
|
+
name: `${shared}_two`,
|
|
165
|
+
columns: {
|
|
166
|
+
id: {
|
|
167
|
+
name: 'id',
|
|
168
|
+
type: 'serial'
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
expect(()=>checkTruncatedIdentifiers({
|
|
174
|
+
adapter,
|
|
175
|
+
logWarnings: true
|
|
176
|
+
})).toThrow('truncate to the same name');
|
|
177
|
+
});
|
|
178
|
+
it('should warn about a single over-long inline index name', ()=>{
|
|
179
|
+
const indexName = `${'a'.repeat(maxIdentifierLength)}_idx`;
|
|
180
|
+
const warn = vi.fn();
|
|
181
|
+
const adapter = buildAdapter({
|
|
182
|
+
posts: {
|
|
183
|
+
name: 'posts',
|
|
184
|
+
columns: {
|
|
185
|
+
id: {
|
|
186
|
+
name: 'id',
|
|
187
|
+
type: 'serial'
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
indexes: {
|
|
191
|
+
a: {
|
|
192
|
+
name: indexName,
|
|
193
|
+
on: 'id'
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}, warn);
|
|
198
|
+
checkTruncatedIdentifiers({
|
|
199
|
+
adapter,
|
|
200
|
+
logWarnings: true
|
|
201
|
+
});
|
|
202
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
203
|
+
expect(warn.mock.calls[0][0]).toContain(indexName);
|
|
204
|
+
});
|
|
205
|
+
it('should throw when two inline index names truncate to the same name', ()=>{
|
|
206
|
+
const shared = 'a'.repeat(maxIdentifierLength);
|
|
207
|
+
const adapter = buildAdapter({
|
|
208
|
+
posts: {
|
|
209
|
+
name: 'posts',
|
|
210
|
+
columns: {
|
|
211
|
+
id: {
|
|
212
|
+
name: 'id',
|
|
213
|
+
type: 'serial'
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
indexes: {
|
|
217
|
+
a: {
|
|
218
|
+
name: `${shared}_one`,
|
|
219
|
+
on: 'id'
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
pages: {
|
|
224
|
+
name: 'pages',
|
|
225
|
+
columns: {
|
|
226
|
+
id: {
|
|
227
|
+
name: 'id',
|
|
228
|
+
type: 'serial'
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
indexes: {
|
|
232
|
+
b: {
|
|
233
|
+
name: `${shared}_two`,
|
|
234
|
+
on: 'id'
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
expect(()=>checkTruncatedIdentifiers({
|
|
240
|
+
adapter,
|
|
241
|
+
logWarnings: true
|
|
242
|
+
})).toThrow('truncate to the same name');
|
|
243
|
+
});
|
|
244
|
+
it('should throw when two inline foreign key names truncate to the same name', ()=>{
|
|
245
|
+
const shared = 'a'.repeat(maxIdentifierLength);
|
|
246
|
+
const adapter = buildAdapter({
|
|
247
|
+
posts: {
|
|
248
|
+
name: 'posts',
|
|
249
|
+
columns: {
|
|
250
|
+
author_id: {
|
|
251
|
+
name: 'author_id',
|
|
252
|
+
type: 'integer'
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
foreignKeys: {
|
|
256
|
+
a: {
|
|
257
|
+
name: `${shared}_one`,
|
|
258
|
+
columns: [
|
|
259
|
+
'author_id'
|
|
260
|
+
],
|
|
261
|
+
foreignColumns: [
|
|
262
|
+
{
|
|
263
|
+
name: 'id',
|
|
264
|
+
table: 'authors'
|
|
265
|
+
}
|
|
266
|
+
]
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
pages: {
|
|
271
|
+
name: 'pages',
|
|
272
|
+
columns: {
|
|
273
|
+
author_id: {
|
|
274
|
+
name: 'author_id',
|
|
275
|
+
type: 'integer'
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
foreignKeys: {
|
|
279
|
+
b: {
|
|
280
|
+
name: `${shared}_two`,
|
|
281
|
+
columns: [
|
|
282
|
+
'author_id'
|
|
283
|
+
],
|
|
284
|
+
foreignColumns: [
|
|
285
|
+
{
|
|
286
|
+
name: 'id',
|
|
287
|
+
table: 'authors'
|
|
288
|
+
}
|
|
289
|
+
]
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
expect(()=>checkTruncatedIdentifiers({
|
|
295
|
+
adapter,
|
|
296
|
+
logWarnings: true
|
|
297
|
+
})).toThrow('truncate to the same name');
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
//# sourceMappingURL=checkTruncatedIdentifiers.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/checkTruncatedIdentifiers.spec.ts"],"sourcesContent":["import { describe, expect, it, vi } from 'vitest'\n\nimport type { DrizzleAdapter } from '../types.js'\n\nimport { checkTruncatedIdentifiers } from './checkTruncatedIdentifiers.js'\nimport { maxIdentifierLength } from './validateIdentifierLength.js'\n\nconst buildAdapter = (\n rawTables: DrizzleAdapter['rawTables'],\n warn: (...args: any[]) => void = () => {},\n): Pick<DrizzleAdapter, 'payload' | 'rawTables'> =>\n ({\n payload: { logger: { warn } },\n rawTables,\n }) as unknown as Pick<DrizzleAdapter, 'payload' | 'rawTables'>\n\nconst longName = (char: string) => char.repeat(maxIdentifierLength + 1)\n\ndescribe('checkTruncatedIdentifiers', () => {\n it('should neither warn nor throw when all identifiers fit within the limit', () => {\n const warn = vi.fn()\n\n const adapter = buildAdapter(\n {\n posts: {\n name: 'posts',\n columns: {\n id: { name: 'id', type: 'serial' },\n title: { name: 'title', type: 'text' },\n },\n },\n },\n warn,\n )\n\n expect(() => checkTruncatedIdentifiers({ adapter, logWarnings: true })).not.toThrow()\n expect(warn).not.toHaveBeenCalled()\n })\n\n it('should warn (not throw) for a single over-long column name', () => {\n const columnName = longName('a')\n const warn = vi.fn()\n\n const adapter = buildAdapter(\n {\n posts: {\n name: 'posts',\n columns: {\n overflow: { name: columnName, type: 'text' },\n },\n },\n },\n warn,\n )\n\n expect(() => checkTruncatedIdentifiers({ adapter, logWarnings: true })).not.toThrow()\n expect(warn).toHaveBeenCalledTimes(1)\n expect(warn.mock.calls[0][0]).toContain(columnName)\n })\n\n it('should not warn when logWarnings is false', () => {\n const warn = vi.fn()\n\n const adapter = buildAdapter(\n {\n posts: {\n name: 'posts',\n columns: {\n overflow: { name: longName('a'), type: 'text' },\n },\n },\n },\n warn,\n )\n\n expect(() => checkTruncatedIdentifiers({ adapter, logWarnings: false })).not.toThrow()\n expect(warn).not.toHaveBeenCalled()\n })\n\n it('should throw when two columns in the same table truncate to the same name', () => {\n // Differ only past the 63rd character, so both truncate to the same identifier.\n const shared = 'a'.repeat(maxIdentifierLength)\n\n const adapter = buildAdapter({\n posts: {\n name: 'posts',\n columns: {\n first: { name: `${shared}_one`, type: 'text' },\n second: { name: `${shared}_two`, type: 'text' },\n },\n },\n })\n\n expect(() => checkTruncatedIdentifiers({ adapter, logWarnings: true })).toThrow(\n 'truncate to the same name',\n )\n })\n\n it('should throw on a collision even when logWarnings is false', () => {\n const shared = 'a'.repeat(maxIdentifierLength)\n\n const adapter = buildAdapter({\n posts: {\n name: 'posts',\n columns: {\n first: { name: `${shared}_one`, type: 'text' },\n second: { name: `${shared}_two`, type: 'text' },\n },\n },\n })\n\n expect(() => checkTruncatedIdentifiers({ adapter, logWarnings: false })).toThrow()\n })\n\n it('should not treat same-named columns in different tables as a collision', () => {\n const shared = 'a'.repeat(maxIdentifierLength)\n const warn = vi.fn()\n\n const adapter = buildAdapter(\n {\n posts: {\n name: 'posts',\n columns: {\n overflow: { name: `${shared}_one`, type: 'text' },\n },\n },\n pages: {\n name: 'pages',\n columns: {\n overflow: { name: `${shared}_two`, type: 'text' },\n },\n },\n },\n warn,\n )\n\n expect(() => checkTruncatedIdentifiers({ adapter, logWarnings: true })).not.toThrow()\n expect(warn).toHaveBeenCalledTimes(1)\n })\n\n it('should throw when two table names truncate to the same name', () => {\n const shared = 'a'.repeat(maxIdentifierLength)\n\n const adapter = buildAdapter({\n [`${shared}_one`]: {\n name: `${shared}_one`,\n columns: { id: { name: 'id', type: 'serial' } },\n },\n [`${shared}_two`]: {\n name: `${shared}_two`,\n columns: { id: { name: 'id', type: 'serial' } },\n },\n })\n\n expect(() => checkTruncatedIdentifiers({ adapter, logWarnings: true })).toThrow(\n 'truncate to the same name',\n )\n })\n\n it('should warn about a single over-long inline index name', () => {\n const indexName = `${'a'.repeat(maxIdentifierLength)}_idx`\n const warn = vi.fn()\n\n const adapter = buildAdapter(\n {\n posts: {\n name: 'posts',\n columns: { id: { name: 'id', type: 'serial' } },\n indexes: { a: { name: indexName, on: 'id' } },\n },\n },\n warn,\n )\n\n checkTruncatedIdentifiers({ adapter, logWarnings: true })\n\n expect(warn).toHaveBeenCalledTimes(1)\n expect(warn.mock.calls[0][0]).toContain(indexName)\n })\n\n it('should throw when two inline index names truncate to the same name', () => {\n const shared = 'a'.repeat(maxIdentifierLength)\n\n const adapter = buildAdapter({\n posts: {\n name: 'posts',\n columns: { id: { name: 'id', type: 'serial' } },\n indexes: { a: { name: `${shared}_one`, on: 'id' } },\n },\n pages: {\n name: 'pages',\n columns: { id: { name: 'id', type: 'serial' } },\n indexes: { b: { name: `${shared}_two`, on: 'id' } },\n },\n })\n\n expect(() => checkTruncatedIdentifiers({ adapter, logWarnings: true })).toThrow(\n 'truncate to the same name',\n )\n })\n\n it('should throw when two inline foreign key names truncate to the same name', () => {\n const shared = 'a'.repeat(maxIdentifierLength)\n\n const adapter = buildAdapter({\n posts: {\n name: 'posts',\n columns: { author_id: { name: 'author_id', type: 'integer' } },\n foreignKeys: {\n a: {\n name: `${shared}_one`,\n columns: ['author_id'],\n foreignColumns: [{ name: 'id', table: 'authors' }],\n },\n },\n },\n pages: {\n name: 'pages',\n columns: { author_id: { name: 'author_id', type: 'integer' } },\n foreignKeys: {\n b: {\n name: `${shared}_two`,\n columns: ['author_id'],\n foreignColumns: [{ name: 'id', table: 'authors' }],\n },\n },\n },\n })\n\n expect(() => checkTruncatedIdentifiers({ adapter, logWarnings: true })).toThrow(\n 'truncate to the same name',\n )\n })\n})\n"],"names":["describe","expect","it","vi","checkTruncatedIdentifiers","maxIdentifierLength","buildAdapter","rawTables","warn","payload","logger","longName","char","repeat","fn","adapter","posts","name","columns","id","type","title","logWarnings","not","toThrow","toHaveBeenCalled","columnName","overflow","toHaveBeenCalledTimes","mock","calls","toContain","shared","first","second","pages","indexName","indexes","a","on","b","author_id","foreignKeys","foreignColumns","table"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAIjD,SAASC,yBAAyB,QAAQ,iCAAgC;AAC1E,SAASC,mBAAmB,QAAQ,gCAA+B;AAEnE,MAAMC,eAAe,CACnBC,WACAC,OAAiC,KAAO,CAAC,GAExC,CAAA;QACCC,SAAS;YAAEC,QAAQ;gBAAEF;YAAK;QAAE;QAC5BD;IACF,CAAA;AAEF,MAAMI,WAAW,CAACC,OAAiBA,KAAKC,MAAM,CAACR,sBAAsB;AAErEL,SAAS,6BAA6B;IACpCE,GAAG,2EAA2E;QAC5E,MAAMM,OAAOL,GAAGW,EAAE;QAElB,MAAMC,UAAUT,aACd;YACEU,OAAO;gBACLC,MAAM;gBACNC,SAAS;oBACPC,IAAI;wBAAEF,MAAM;wBAAMG,MAAM;oBAAS;oBACjCC,OAAO;wBAAEJ,MAAM;wBAASG,MAAM;oBAAO;gBACvC;YACF;QACF,GACAZ;QAGFP,OAAO,IAAMG,0BAA0B;gBAAEW;gBAASO,aAAa;YAAK,IAAIC,GAAG,CAACC,OAAO;QACnFvB,OAAOO,MAAMe,GAAG,CAACE,gBAAgB;IACnC;IAEAvB,GAAG,8DAA8D;QAC/D,MAAMwB,aAAaf,SAAS;QAC5B,MAAMH,OAAOL,GAAGW,EAAE;QAElB,MAAMC,UAAUT,aACd;YACEU,OAAO;gBACLC,MAAM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,SAAS;oBAAEuB,WAAW;wBAAExB,MAAM;wBAAaG,MAAM;oBAAU;gBAAE;gBAC7DsB,aAAa;oBACXJ,GAAG;wBACDrB,MAAM,GAAGe,OAAO,IAAI,CAAC;wBACrBd,SAAS;4BAAC;yBAAY;wBACtByB,gBAAgB;4BAAC;gCAAE1B,MAAM;gCAAM2B,OAAO;4BAAU;yBAAE;oBACpD;gBACF;YACF;YACAT,OAAO;gBACLlB,MAAM;gBACNC,SAAS;oBAAEuB,WAAW;wBAAExB,MAAM;wBAAaG,MAAM;oBAAU;gBAAE;gBAC7DsB,aAAa;oBACXF,GAAG;wBACDvB,MAAM,GAAGe,OAAO,IAAI,CAAC;wBACrBd,SAAS;4BAAC;yBAAY;wBACtByB,gBAAgB;4BAAC;gCAAE1B,MAAM;gCAAM2B,OAAO;4BAAU;yBAAE;oBACpD;gBACF;YACF;QACF;QAEA3C,OAAO,IAAMG,0BAA0B;gBAAEW;gBAASO,aAAa;YAAK,IAAIE,OAAO,CAC7E;IAEJ;AACF"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/** Postgres max identifier length (NAMEDATALEN - 1). */
|
|
2
2
|
export declare const maxIdentifierLength = 63;
|
|
3
|
+
/**
|
|
4
|
+
* Cap for builder-generated identifiers (`buildIndexName`/`buildForeignKeyName`). Sits
|
|
5
|
+
* below `maxIdentifierLength` to leave headroom for the appended `_idx`/`_fk`/`_N` suffixes.
|
|
6
|
+
*/
|
|
7
|
+
export declare const maxGeneratedIdentifierLength: number;
|
|
3
8
|
/**
|
|
4
9
|
* Throws if a table or enum identifier exceeds the Postgres 63-char limit.
|
|
5
10
|
*/
|
|
@@ -1 +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"}
|
|
1
|
+
{"version":3,"file":"validateIdentifierLength.d.ts","sourceRoot":"","sources":["../../src/utilities/validateIdentifierLength.ts"],"names":[],"mappings":"AAEA,wDAAwD;AACxD,eAAO,MAAM,mBAAmB,KAAK,CAAA;AAErC;;;GAGG;AACH,eAAO,MAAM,4BAA4B,QAA0B,CAAA;AAEnE;;GAEG;AACH,eAAO,MAAM,wBAAwB,SAAU,MAAM,KAAG,MAUvD,CAAA"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { APIError } from 'payload';
|
|
2
2
|
/** Postgres max identifier length (NAMEDATALEN - 1). */ export const maxIdentifierLength = 63;
|
|
3
|
+
/**
|
|
4
|
+
* Cap for builder-generated identifiers (`buildIndexName`/`buildForeignKeyName`). Sits
|
|
5
|
+
* below `maxIdentifierLength` to leave headroom for the appended `_idx`/`_fk`/`_N` suffixes.
|
|
6
|
+
*/ export const maxGeneratedIdentifierLength = maxIdentifierLength - 3;
|
|
3
7
|
/**
|
|
4
8
|
* Throws if a table or enum identifier exceeds the Postgres 63-char limit.
|
|
5
9
|
*/ export const validateIdentifierLength = (name)=>{
|
|
@@ -1 +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,
|
|
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 * Cap for builder-generated identifiers (`buildIndexName`/`buildForeignKeyName`). Sits\n * below `maxIdentifierLength` to leave headroom for the appended `_idx`/`_fk`/`_N` suffixes.\n */\nexport const maxGeneratedIdentifierLength = maxIdentifierLength - 3\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","maxGeneratedIdentifierLength","validateIdentifierLength","name","length"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,UAAS;AAElC,sDAAsD,GACtD,OAAO,MAAMC,sBAAsB,GAAE;AAErC;;;CAGC,GACD,OAAO,MAAMC,+BAA+BD,sBAAsB,EAAC;AAEnE;;CAEC,GACD,OAAO,MAAME,2BAA2B,CAACC;IACvC,IAAIA,KAAKC,MAAM,GAAGJ,qBAAqB;QACrC,MAAM,IAAID,SACR,CAAC,yDAAyD,EAAEC,oBAAoB,2BAA2B,EAAEG,KAAK;;MAElH,CAAC;IAEL;IAEA,OAAOA;AACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/drizzle",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.89.0-internal.4b0e9b6",
|
|
4
4
|
"description": "A library of shared functions used by different payload database adapters",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"@types/pg": "8.20.0",
|
|
61
61
|
"@types/to-snake-case": "1.0.0",
|
|
62
62
|
"@payloadcms/eslint-config": "3.28.0",
|
|
63
|
-
"payload": "3.
|
|
63
|
+
"payload": "3.89.0-internal.4b0e9b6"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"payload": "3.
|
|
66
|
+
"payload": "3.89.0-internal.4b0e9b6"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"build": "pnpm build:swc && pnpm build:types",
|