@payloadcms/drizzle 4.0.0-internal.cc18726 → 4.0.0-internal.cd47d20
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/find/buildPolymorphicJoinQuery.d.ts +38 -0
- package/dist/find/buildPolymorphicJoinQuery.d.ts.map +1 -0
- package/dist/find/buildPolymorphicJoinQuery.js +135 -0
- package/dist/find/buildPolymorphicJoinQuery.js.map +1 -0
- package/dist/find/buildPolymorphicJoinWhere.d.ts +20 -0
- package/dist/find/buildPolymorphicJoinWhere.d.ts.map +1 -0
- package/dist/find/buildPolymorphicJoinWhere.js +301 -0
- package/dist/find/buildPolymorphicJoinWhere.js.map +1 -0
- package/dist/find/createPolymorphicJoinWherePlan.d.ts +37 -0
- package/dist/find/createPolymorphicJoinWherePlan.d.ts.map +1 -0
- package/dist/find/createPolymorphicJoinWherePlan.js +191 -0
- package/dist/find/createPolymorphicJoinWherePlan.js.map +1 -0
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +19 -191
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +6 -2
- package/dist/migrate.js.map +1 -1
- package/dist/migrateDown.d.ts.map +1 -1
- package/dist/migrateDown.js +5 -2
- package/dist/migrateDown.js.map +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +5 -2
- package/dist/migrateFresh.js.map +1 -1
- package/dist/migrateRefresh.d.ts.map +1 -1
- package/dist/migrateRefresh.js +6 -2
- package/dist/migrateRefresh.js.map +1 -1
- package/dist/migrateReset.d.ts.map +1 -1
- package/dist/migrateReset.js +6 -2
- package/dist/migrateReset.js.map +1 -1
- package/dist/postgres/createJSONQuery/index.js +3 -3
- package/dist/postgres/createJSONQuery/index.js.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js +8 -4
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +9 -0
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +59 -2
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.js +3 -2
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.js.map +1 -1
- package/dist/sqlite/createJSONQuery/index.d.ts.map +1 -1
- package/dist/sqlite/createJSONQuery/index.js +6 -5
- package/dist/sqlite/createJSONQuery/index.js.map +1 -1
- package/dist/sqlite/insert.d.ts.map +1 -1
- package/dist/sqlite/insert.js +4 -1
- package/dist/sqlite/insert.js.map +1 -1
- package/dist/transform/write/traverseFields.d.ts.map +1 -1
- package/dist/transform/write/traverseFields.js +8 -14
- package/dist/transform/write/traverseFields.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +41 -1
- package/dist/updateOne.js.map +1 -1
- package/dist/upsertRow/index.d.ts +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/index.js +25 -5
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/utilities/parseJSONPathSegment.d.ts +9 -0
- package/dist/utilities/parseJSONPathSegment.d.ts.map +1 -0
- package/dist/utilities/parseJSONPathSegment.js +17 -0
- package/dist/utilities/parseJSONPathSegment.js.map +1 -0
- package/package.json +3 -3
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.spec.js +0 -91
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.spec.js.map +0 -1
- package/dist/postgres/query/postgresUnaccent.spec.js +0 -71
- package/dist/postgres/query/postgresUnaccent.spec.js.map +0 -1
- package/dist/queries/buildOperatorConstraint.spec.js +0 -348
- package/dist/queries/buildOperatorConstraint.spec.js.map +0 -1
- package/dist/queries/validateOperatorHandlers.spec.js +0 -142
- package/dist/queries/validateOperatorHandlers.spec.js.map +0 -1
- package/dist/schema/buildRawSchema.spec.js +0 -290
- package/dist/schema/buildRawSchema.spec.js.map +0 -1
- package/dist/upsertRow/handleUpsertError.spec.js +0 -42
- package/dist/upsertRow/handleUpsertError.spec.js.map +0 -1
- package/dist/utilities/checkTruncatedIdentifiers.spec.js +0 -301
- package/dist/utilities/checkTruncatedIdentifiers.spec.js.map +0 -1
- package/dist/utilities/isValidStringID.spec.js +0 -15
- package/dist/utilities/isValidStringID.spec.js.map +0 -1
- package/dist/utilities/validateIdentifierLength.spec.js +0 -19
- package/dist/utilities/validateIdentifierLength.spec.js.map +0 -1
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import { sanitizeConfig } from 'payload';
|
|
2
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
-
import { setColumnID } from '../postgres/schema/setColumnID.js';
|
|
4
|
-
import { checkTruncatedIdentifiers } from '../utilities/checkTruncatedIdentifiers.js';
|
|
5
|
-
import { buildRawSchema } from './buildRawSchema.js';
|
|
6
|
-
const headlineBlock = {
|
|
7
|
-
slug: 'headline',
|
|
8
|
-
fields: [
|
|
9
|
-
{
|
|
10
|
-
name: 'title',
|
|
11
|
-
type: 'text'
|
|
12
|
-
}
|
|
13
|
-
]
|
|
14
|
-
};
|
|
15
|
-
const createContainerBlock = (slug)=>({
|
|
16
|
-
slug,
|
|
17
|
-
fields: [
|
|
18
|
-
{
|
|
19
|
-
name: 'content',
|
|
20
|
-
type: 'blocks',
|
|
21
|
-
blocks: [
|
|
22
|
-
'headline'
|
|
23
|
-
]
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
});
|
|
27
|
-
const createAdapter = (config, warn = ()=>{})=>({
|
|
28
|
-
blocksAsJSON: false,
|
|
29
|
-
fieldConstraints: {},
|
|
30
|
-
idType: 'serial',
|
|
31
|
-
localesSuffix: '_locales',
|
|
32
|
-
payload: {
|
|
33
|
-
blocks: Object.fromEntries(config.blocks.map((block)=>[
|
|
34
|
-
block.slug,
|
|
35
|
-
block
|
|
36
|
-
])),
|
|
37
|
-
collections: Object.fromEntries(config.collections.map((collection)=>[
|
|
38
|
-
collection.slug,
|
|
39
|
-
{
|
|
40
|
-
config: collection,
|
|
41
|
-
customIDType: undefined
|
|
42
|
-
}
|
|
43
|
-
])),
|
|
44
|
-
config,
|
|
45
|
-
logger: {
|
|
46
|
-
warn
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
rawRelations: {},
|
|
50
|
-
rawTables: {},
|
|
51
|
-
tableNameMap: new Map(),
|
|
52
|
-
versionsSuffix: '_versions'
|
|
53
|
-
});
|
|
54
|
-
describe('buildRawSchema', ()=>{
|
|
55
|
-
it('should create suffixed block tables for different schemas with the same slug', async ()=>{
|
|
56
|
-
const config = sanitizeConfig({
|
|
57
|
-
collections: [
|
|
58
|
-
{
|
|
59
|
-
slug: 'pages',
|
|
60
|
-
fields: [
|
|
61
|
-
{
|
|
62
|
-
name: 'primaryContent',
|
|
63
|
-
type: 'blocks',
|
|
64
|
-
localized: true,
|
|
65
|
-
blocks: [
|
|
66
|
-
{
|
|
67
|
-
slug: 'content',
|
|
68
|
-
fields: [
|
|
69
|
-
{
|
|
70
|
-
name: 'title',
|
|
71
|
-
type: 'text'
|
|
72
|
-
}
|
|
73
|
-
]
|
|
74
|
-
}
|
|
75
|
-
]
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
name: 'secondaryContent',
|
|
79
|
-
type: 'blocks',
|
|
80
|
-
localized: true,
|
|
81
|
-
blocks: [
|
|
82
|
-
{
|
|
83
|
-
slug: 'content',
|
|
84
|
-
fields: [
|
|
85
|
-
{
|
|
86
|
-
name: 'description',
|
|
87
|
-
type: 'textarea'
|
|
88
|
-
}
|
|
89
|
-
]
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
}
|
|
93
|
-
]
|
|
94
|
-
}
|
|
95
|
-
],
|
|
96
|
-
localization: {
|
|
97
|
-
defaultLocale: 'en',
|
|
98
|
-
locales: [
|
|
99
|
-
'en',
|
|
100
|
-
'de'
|
|
101
|
-
]
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
const adapter = createAdapter(config);
|
|
105
|
-
buildRawSchema({
|
|
106
|
-
adapter,
|
|
107
|
-
setColumnID
|
|
108
|
-
});
|
|
109
|
-
expect(adapter.rawTables.pages_blocks_content.columns.title).toBeDefined();
|
|
110
|
-
expect(adapter.rawTables.pages_blocks_content.columns._locale).toBeDefined();
|
|
111
|
-
expect(adapter.rawTables.pages_blocks_content_2.columns.description).toBeDefined();
|
|
112
|
-
expect(adapter.rawTables.pages_blocks_content_2.columns._locale).toBeDefined();
|
|
113
|
-
});
|
|
114
|
-
it('should not create duplicate suffixed block tables for identical reused blocks under localized ancestors', async ()=>{
|
|
115
|
-
const layoutBlocks = [
|
|
116
|
-
createContainerBlock('container'),
|
|
117
|
-
createContainerBlock('container50')
|
|
118
|
-
];
|
|
119
|
-
const config = sanitizeConfig({
|
|
120
|
-
blocks: [
|
|
121
|
-
headlineBlock
|
|
122
|
-
],
|
|
123
|
-
collections: [
|
|
124
|
-
{
|
|
125
|
-
slug: 'pages',
|
|
126
|
-
fields: [
|
|
127
|
-
{
|
|
128
|
-
name: 'layout',
|
|
129
|
-
type: 'blocks',
|
|
130
|
-
localized: true,
|
|
131
|
-
blocks: layoutBlocks
|
|
132
|
-
}
|
|
133
|
-
]
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
slug: 'posts',
|
|
137
|
-
fields: [
|
|
138
|
-
{
|
|
139
|
-
name: 'layout',
|
|
140
|
-
type: 'blocks',
|
|
141
|
-
localized: true,
|
|
142
|
-
blocks: layoutBlocks
|
|
143
|
-
}
|
|
144
|
-
]
|
|
145
|
-
}
|
|
146
|
-
],
|
|
147
|
-
localization: {
|
|
148
|
-
defaultLocale: 'en',
|
|
149
|
-
locales: [
|
|
150
|
-
'en',
|
|
151
|
-
'de'
|
|
152
|
-
]
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
const adapter = createAdapter(config);
|
|
156
|
-
buildRawSchema({
|
|
157
|
-
adapter,
|
|
158
|
-
setColumnID
|
|
159
|
-
});
|
|
160
|
-
expect(adapter.rawTables.pages_blocks_headline).toBeDefined();
|
|
161
|
-
expect(adapter.rawTables.pages_blocks_headline.columns._locale).toBeDefined();
|
|
162
|
-
expect(adapter.rawTables.pages_blocks_headline_2).toBeUndefined();
|
|
163
|
-
expect(adapter.rawTables.pages_blocks_headline_2_locales).toBeUndefined();
|
|
164
|
-
expect(adapter.rawTables.posts_blocks_headline).toBeDefined();
|
|
165
|
-
expect(adapter.rawTables.posts_blocks_headline.columns._locale).toBeDefined();
|
|
166
|
-
expect(adapter.rawTables.posts_blocks_headline_2).toBeUndefined();
|
|
167
|
-
expect(adapter.rawTables.posts_blocks_headline_2_locales).toBeUndefined();
|
|
168
|
-
});
|
|
169
|
-
it('should warn when a localized field pushes the _locales companion table past 63 chars', async ()=>{
|
|
170
|
-
// Base table name (61 chars) is under the limit, but `${base}_locales` (69) overflows it.
|
|
171
|
-
const longSlug = `localized_collection_${'x'.repeat(40)}`;
|
|
172
|
-
const config = sanitizeConfig({
|
|
173
|
-
collections: [
|
|
174
|
-
{
|
|
175
|
-
slug: longSlug,
|
|
176
|
-
fields: [
|
|
177
|
-
{
|
|
178
|
-
name: 'title',
|
|
179
|
-
type: 'text',
|
|
180
|
-
localized: true
|
|
181
|
-
}
|
|
182
|
-
],
|
|
183
|
-
timestamps: false,
|
|
184
|
-
versions: false
|
|
185
|
-
}
|
|
186
|
-
],
|
|
187
|
-
localization: {
|
|
188
|
-
defaultLocale: 'en',
|
|
189
|
-
locales: [
|
|
190
|
-
'en',
|
|
191
|
-
'de'
|
|
192
|
-
]
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
const warn = vi.fn();
|
|
196
|
-
const adapter = createAdapter(config, warn);
|
|
197
|
-
buildRawSchema({
|
|
198
|
-
adapter,
|
|
199
|
-
setColumnID
|
|
200
|
-
});
|
|
201
|
-
expect(adapter.rawTables[`${longSlug}_locales`]).toBeDefined();
|
|
202
|
-
expect(()=>checkTruncatedIdentifiers({
|
|
203
|
-
adapter,
|
|
204
|
-
logWarnings: true
|
|
205
|
-
})).not.toThrow();
|
|
206
|
-
expect(warn).toHaveBeenCalledTimes(1);
|
|
207
|
-
expect(warn.mock.calls[0][0]).toContain(`${longSlug}_locales`);
|
|
208
|
-
});
|
|
209
|
-
it('should not warn when the _locales companion table fits within 63 chars', async ()=>{
|
|
210
|
-
const config = sanitizeConfig({
|
|
211
|
-
collections: [
|
|
212
|
-
{
|
|
213
|
-
slug: 'short_localized',
|
|
214
|
-
fields: [
|
|
215
|
-
{
|
|
216
|
-
name: 'title',
|
|
217
|
-
type: 'text',
|
|
218
|
-
localized: true
|
|
219
|
-
}
|
|
220
|
-
],
|
|
221
|
-
timestamps: false,
|
|
222
|
-
versions: false
|
|
223
|
-
}
|
|
224
|
-
],
|
|
225
|
-
localization: {
|
|
226
|
-
defaultLocale: 'en',
|
|
227
|
-
locales: [
|
|
228
|
-
'en',
|
|
229
|
-
'de'
|
|
230
|
-
]
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
const warn = vi.fn();
|
|
234
|
-
const adapter = createAdapter(config, warn);
|
|
235
|
-
buildRawSchema({
|
|
236
|
-
adapter,
|
|
237
|
-
setColumnID
|
|
238
|
-
});
|
|
239
|
-
expect(adapter.rawTables.short_localized_locales).toBeDefined();
|
|
240
|
-
checkTruncatedIdentifiers({
|
|
241
|
-
adapter,
|
|
242
|
-
logWarnings: true
|
|
243
|
-
});
|
|
244
|
-
expect(warn).not.toHaveBeenCalled();
|
|
245
|
-
});
|
|
246
|
-
it('should warn about raw inline sub-table index and foreign key names that exceed 63 chars', async ()=>{
|
|
247
|
-
// Array sub-tables assign structural index/FK names inline (not via buildIndexName/
|
|
248
|
-
// buildForeignKeyName), so a long-but-valid array table name still overflows them.
|
|
249
|
-
const arrayFieldName = 'a'.repeat(58);
|
|
250
|
-
const config = sanitizeConfig({
|
|
251
|
-
collections: [
|
|
252
|
-
{
|
|
253
|
-
slug: 'p',
|
|
254
|
-
fields: [
|
|
255
|
-
{
|
|
256
|
-
name: arrayFieldName,
|
|
257
|
-
type: 'array',
|
|
258
|
-
fields: [
|
|
259
|
-
{
|
|
260
|
-
name: 'title',
|
|
261
|
-
type: 'text'
|
|
262
|
-
}
|
|
263
|
-
]
|
|
264
|
-
}
|
|
265
|
-
],
|
|
266
|
-
timestamps: false,
|
|
267
|
-
versions: false
|
|
268
|
-
}
|
|
269
|
-
]
|
|
270
|
-
});
|
|
271
|
-
const warn = vi.fn();
|
|
272
|
-
const adapter = createAdapter(config, warn);
|
|
273
|
-
buildRawSchema({
|
|
274
|
-
adapter,
|
|
275
|
-
setColumnID
|
|
276
|
-
});
|
|
277
|
-
const arrayTable = `p_${arrayFieldName}`;
|
|
278
|
-
checkTruncatedIdentifiers({
|
|
279
|
-
adapter,
|
|
280
|
-
logWarnings: true
|
|
281
|
-
});
|
|
282
|
-
expect(arrayTable.length).toBeLessThanOrEqual(63);
|
|
283
|
-
expect(warn).toHaveBeenCalledTimes(1);
|
|
284
|
-
const message = warn.mock.calls[0][0];
|
|
285
|
-
expect(message).toContain(`${arrayTable}_order_idx`);
|
|
286
|
-
expect(message).toContain(`${arrayTable}_parent_id_fk`);
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
//# sourceMappingURL=buildRawSchema.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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 blocks: ['headline'],\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 create suffixed block tables for different schemas with the same slug', async () => {\n const config = sanitizeConfig({\n collections: [\n {\n slug: 'pages',\n fields: [\n {\n name: 'primaryContent',\n type: 'blocks',\n localized: true,\n blocks: [\n {\n slug: 'content',\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n },\n ],\n },\n {\n name: 'secondaryContent',\n type: 'blocks',\n localized: true,\n blocks: [\n {\n slug: 'content',\n fields: [\n {\n name: 'description',\n type: 'textarea',\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const adapter = createAdapter(config)\n\n buildRawSchema({\n adapter,\n setColumnID,\n })\n\n expect(adapter.rawTables.pages_blocks_content.columns.title).toBeDefined()\n expect(adapter.rawTables.pages_blocks_content.columns._locale).toBeDefined()\n expect(adapter.rawTables.pages_blocks_content_2.columns.description).toBeDefined()\n expect(adapter.rawTables.pages_blocks_content_2.columns._locale).toBeDefined()\n })\n\n it('should not create duplicate suffixed block tables for identical reused blocks under localized ancestors', async () => {\n const layoutBlocks = [createContainerBlock('container'), createContainerBlock('container50')]\n\n const config = sanitizeConfig({\n blocks: [headlineBlock],\n collections: [\n {\n slug: 'pages',\n fields: [\n {\n name: 'layout',\n type: 'blocks',\n localized: true,\n blocks: layoutBlocks,\n },\n ],\n },\n {\n slug: 'posts',\n fields: [\n {\n name: 'layout',\n type: 'blocks',\n localized: true,\n blocks: layoutBlocks,\n },\n ],\n },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const adapter = createAdapter(config)\n\n buildRawSchema({\n adapter,\n setColumnID,\n })\n\n expect(adapter.rawTables.pages_blocks_headline).toBeDefined()\n expect(adapter.rawTables.pages_blocks_headline.columns._locale).toBeDefined()\n expect(adapter.rawTables.pages_blocks_headline_2).toBeUndefined()\n expect(adapter.rawTables.pages_blocks_headline_2_locales).toBeUndefined()\n expect(adapter.rawTables.posts_blocks_headline).toBeDefined()\n expect(adapter.rawTables.posts_blocks_headline.columns._locale).toBeDefined()\n expect(adapter.rawTables.posts_blocks_headline_2).toBeUndefined()\n expect(adapter.rawTables.posts_blocks_headline_2_locales).toBeUndefined()\n })\n\n it('should 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 = sanitizeConfig({\n collections: [\n {\n slug: longSlug,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n timestamps: false,\n versions: false,\n },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const 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 = sanitizeConfig({\n collections: [\n {\n slug: 'short_localized',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n timestamps: false,\n versions: false,\n },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const 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 = 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 versions: 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","blocks","createAdapter","config","warn","blocksAsJSON","fieldConstraints","idType","localesSuffix","payload","Object","fromEntries","map","block","collections","collection","customIDType","undefined","logger","rawRelations","rawTables","tableNameMap","Map","versionsSuffix","localized","localization","defaultLocale","locales","adapter","pages_blocks_content","columns","title","toBeDefined","_locale","pages_blocks_content_2","description","layoutBlocks","pages_blocks_headline","pages_blocks_headline_2","toBeUndefined","pages_blocks_headline_2_locales","posts_blocks_headline","posts_blocks_headline_2","posts_blocks_headline_2_locales","longSlug","repeat","timestamps","versions","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,QAAQ;oBAAC;iBAAW;YACtB;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,MAAMjB,IAAI;oBAAEiB;iBAAM;YAC3EC,aAAaJ,OAAOC,WAAW,CAC7BR,OAAOW,WAAW,CAACF,GAAG,CAAC,CAACG,aAAe;oBACrCA,WAAWnB,IAAI;oBACf;wBACEO,QAAQY;wBACRC,cAAcC;oBAChB;iBACD;YAEHd;YACAe,QAAQ;gBAAEd;YAAK;QACjB;QACA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gBACZ;aACD;QACH;QAEA,MAAM3C,OAAOb,GAAGyD,EAAE;QAClB,MAAMpB,UAAU1B,cAAcC,QAAQC;QAEtCV,eAAe;YAAEkC;YAASpC;QAAY;QAEtC,MAAMmE,aAAa,CAAC,EAAE,EAAED,gBAAgB;QAExCjE,0BAA0B;YAAEmC;YAASqB,aAAa;QAAK;QAEvD5D,OAAOsE,WAAWC,MAAM,EAAEC,mBAAmB,CAAC;QAC9CxE,OAAOe,MAAMgD,qBAAqB,CAAC;QAEnC,MAAMU,UAAkB1D,KAAKiD,IAAI,CAACC,KAAK,CAAC,EAAE,CAAC,EAAE;QAE7CjE,OAAOyE,SAASP,SAAS,CAAC,GAAGI,WAAW,UAAU,CAAC;QACnDtE,OAAOyE,SAASP,SAAS,CAAC,GAAGI,WAAW,aAAa,CAAC;IACxD;AACF"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { ValidationError } from 'payload';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { handleUpsertError } from './handleUpsertError.js';
|
|
4
|
-
const adapter = {
|
|
5
|
-
fieldConstraints: {}
|
|
6
|
-
};
|
|
7
|
-
describe('handleUpsertError', ()=>{
|
|
8
|
-
it('preserves the failing sub-table name on the ValidationError', ()=>{
|
|
9
|
-
const pgError = {
|
|
10
|
-
code: '23505',
|
|
11
|
-
constraint: 'ultrasonic_avail_country_pkey',
|
|
12
|
-
detail: 'Key (id)=(6a27e2a63f4b64567370f595) already exists.'
|
|
13
|
-
};
|
|
14
|
-
let thrown;
|
|
15
|
-
try {
|
|
16
|
-
handleUpsertError({
|
|
17
|
-
adapter,
|
|
18
|
-
collectionSlug: 'ultrasonic',
|
|
19
|
-
error: pgError,
|
|
20
|
-
tableName: 'ultrasonic_avail_country'
|
|
21
|
-
});
|
|
22
|
-
} catch (error) {
|
|
23
|
-
thrown = error;
|
|
24
|
-
}
|
|
25
|
-
expect(thrown).toBeInstanceOf(ValidationError);
|
|
26
|
-
const validationError = thrown;
|
|
27
|
-
const fieldError = validationError.data.errors[0];
|
|
28
|
-
expect(fieldError.path).toBe('id');
|
|
29
|
-
expect(fieldError.tableName).toBe('ultrasonic_avail_country');
|
|
30
|
-
});
|
|
31
|
-
it('re-throws non unique-constraint errors unchanged', ()=>{
|
|
32
|
-
const otherError = new Error('some other db error');
|
|
33
|
-
expect(()=>handleUpsertError({
|
|
34
|
-
adapter,
|
|
35
|
-
collectionSlug: 'ultrasonic',
|
|
36
|
-
error: otherError,
|
|
37
|
-
tableName: 'ultrasonic_avail_country'
|
|
38
|
-
})).toThrow(otherError);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
//# sourceMappingURL=handleUpsertError.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/upsertRow/handleUpsertError.spec.ts"],"sourcesContent":["import { ValidationError } from 'payload'\nimport { describe, expect, it } from 'vitest'\n\nimport type { DrizzleAdapter } from '../types.js'\n\nimport { handleUpsertError } from './handleUpsertError.js'\n\nconst adapter = { fieldConstraints: {} } as unknown as DrizzleAdapter\n\ndescribe('handleUpsertError', () => {\n it('preserves the failing sub-table name on the ValidationError', () => {\n const pgError = {\n code: '23505',\n constraint: 'ultrasonic_avail_country_pkey',\n detail: 'Key (id)=(6a27e2a63f4b64567370f595) already exists.',\n }\n\n let thrown: unknown\n try {\n handleUpsertError({\n adapter,\n collectionSlug: 'ultrasonic',\n error: pgError,\n tableName: 'ultrasonic_avail_country',\n })\n } catch (error) {\n thrown = error\n }\n\n expect(thrown).toBeInstanceOf(ValidationError)\n const validationError = thrown as ValidationError\n const fieldError = validationError.data.errors[0]!\n expect(fieldError.path).toBe('id')\n expect(fieldError.tableName).toBe('ultrasonic_avail_country')\n })\n\n it('re-throws non unique-constraint errors unchanged', () => {\n const otherError = new Error('some other db error')\n\n expect(() =>\n handleUpsertError({\n adapter,\n collectionSlug: 'ultrasonic',\n error: otherError,\n tableName: 'ultrasonic_avail_country',\n }),\n ).toThrow(otherError)\n })\n})\n"],"names":["ValidationError","describe","expect","it","handleUpsertError","adapter","fieldConstraints","pgError","code","constraint","detail","thrown","collectionSlug","error","tableName","toBeInstanceOf","validationError","fieldError","data","errors","path","toBe","otherError","Error","toThrow"],"mappings":"AAAA,SAASA,eAAe,QAAQ,UAAS;AACzC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAI7C,SAASC,iBAAiB,QAAQ,yBAAwB;AAE1D,MAAMC,UAAU;IAAEC,kBAAkB,CAAC;AAAE;AAEvCL,SAAS,qBAAqB;IAC5BE,GAAG,+DAA+D;QAChE,MAAMI,UAAU;YACdC,MAAM;YACNC,YAAY;YACZC,QAAQ;QACV;QAEA,IAAIC;QACJ,IAAI;YACFP,kBAAkB;gBAChBC;gBACAO,gBAAgB;gBAChBC,OAAON;gBACPO,WAAW;YACb;QACF,EAAE,OAAOD,OAAO;YACdF,SAASE;QACX;QAEAX,OAAOS,QAAQI,cAAc,CAACf;QAC9B,MAAMgB,kBAAkBL;QACxB,MAAMM,aAAaD,gBAAgBE,IAAI,CAACC,MAAM,CAAC,EAAE;QACjDjB,OAAOe,WAAWG,IAAI,EAAEC,IAAI,CAAC;QAC7BnB,OAAOe,WAAWH,SAAS,EAAEO,IAAI,CAAC;IACpC;IAEAlB,GAAG,oDAAoD;QACrD,MAAMmB,aAAa,IAAIC,MAAM;QAE7BrB,OAAO,IACLE,kBAAkB;gBAChBC;gBACAO,gBAAgB;gBAChBC,OAAOS;gBACPR,WAAW;YACb,IACAU,OAAO,CAACF;IACZ;AACF"}
|
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { checkTruncatedIdentifiers } from './checkTruncatedIdentifiers.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
|