@payloadcms/db-sqlite 3.7.0 → 3.7.1-canary.6b01088

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.
Files changed (42) hide show
  1. package/dist/index.d.ts.map +1 -1
  2. package/dist/index.js +2 -0
  3. package/dist/index.js.map +1 -1
  4. package/dist/init.d.ts.map +1 -1
  5. package/dist/init.js +19 -101
  6. package/dist/init.js.map +1 -1
  7. package/dist/schema/buildDrizzleTable.d.ts +3 -0
  8. package/dist/schema/buildDrizzleTable.d.ts.map +1 -0
  9. package/dist/schema/buildDrizzleTable.js +135 -0
  10. package/dist/schema/buildDrizzleTable.js.map +1 -0
  11. package/dist/schema/setColumnID.d.ts +2 -9
  12. package/dist/schema/setColumnID.d.ts.map +1 -1
  13. package/dist/schema/setColumnID.js +15 -4
  14. package/dist/schema/setColumnID.js.map +1 -1
  15. package/dist/types.d.ts +13 -6
  16. package/dist/types.d.ts.map +1 -1
  17. package/dist/types.js.map +1 -1
  18. package/package.json +4 -4
  19. package/dist/schema/build.d.ts +0 -52
  20. package/dist/schema/build.d.ts.map +0 -1
  21. package/dist/schema/build.js +0 -440
  22. package/dist/schema/build.js.map +0 -1
  23. package/dist/schema/createIndex.d.ts +0 -11
  24. package/dist/schema/createIndex.d.ts.map +0 -1
  25. package/dist/schema/createIndex.js +0 -20
  26. package/dist/schema/createIndex.js.map +0 -1
  27. package/dist/schema/getIDColumn.d.ts +0 -8
  28. package/dist/schema/getIDColumn.d.ts.map +0 -1
  29. package/dist/schema/getIDColumn.js +0 -24
  30. package/dist/schema/getIDColumn.js.map +0 -1
  31. package/dist/schema/idToUUID.d.ts +0 -3
  32. package/dist/schema/idToUUID.d.ts.map +0 -1
  33. package/dist/schema/idToUUID.js +0 -11
  34. package/dist/schema/idToUUID.js.map +0 -1
  35. package/dist/schema/traverseFields.d.ts +0 -44
  36. package/dist/schema/traverseFields.d.ts.map +0 -1
  37. package/dist/schema/traverseFields.js +0 -610
  38. package/dist/schema/traverseFields.js.map +0 -1
  39. package/dist/schema/withDefault.d.ts +0 -4
  40. package/dist/schema/withDefault.d.ts.map +0 -1
  41. package/dist/schema/withDefault.js +0 -12
  42. package/dist/schema/withDefault.js.map +0 -1
@@ -1,610 +0,0 @@
1
- import { buildIndexName, createTableName, hasLocalesTable, validateExistingBlockIsIdentical } from '@payloadcms/drizzle';
2
- import { relations } from 'drizzle-orm';
3
- import { foreignKey, index, integer, numeric, SQLiteIntegerBuilder, SQLiteNumericBuilder, SQLiteTextBuilder, text } from 'drizzle-orm/sqlite-core';
4
- import { InvalidConfiguration } from 'payload';
5
- import { fieldAffectsData, fieldIsVirtual, optionIsObject } from 'payload/shared';
6
- import toSnakeCase from 'to-snake-case';
7
- import { buildTable } from './build.js';
8
- import { createIndex } from './createIndex.js';
9
- import { getIDColumn } from './getIDColumn.js';
10
- import { idToUUID } from './idToUUID.js';
11
- import { withDefault } from './withDefault.js';
12
- export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull, disableRelsTableUnique, disableUnique = false, fieldPrefix, fields, forceLocalized, indexes, locales, localesColumns, localesIndexes, newTableName, parentTableName, relationships, relationsToBuild, rootRelationsToBuild, rootTableIDColType, rootTableName, uniqueRelationships, versions, withinLocalizedArrayOrBlock })=>{
13
- let hasLocalizedField = false;
14
- let hasLocalizedRelationshipField = false;
15
- let hasManyTextField = false;
16
- let hasLocalizedManyTextField = false;
17
- let hasManyNumberField = false;
18
- let hasLocalizedManyNumberField = false;
19
- let parentIDColType = 'integer';
20
- if (columns.id instanceof SQLiteIntegerBuilder) {
21
- parentIDColType = 'integer';
22
- }
23
- if (columns.id instanceof SQLiteNumericBuilder) {
24
- parentIDColType = 'numeric';
25
- }
26
- if (columns.id instanceof SQLiteTextBuilder) {
27
- parentIDColType = 'text';
28
- }
29
- fields.forEach((field)=>{
30
- if ('name' in field && field.name === 'id') {
31
- return;
32
- }
33
- if (fieldIsVirtual(field)) {
34
- return;
35
- }
36
- let targetTable = columns;
37
- let targetIndexes = indexes;
38
- const columnName = `${columnPrefix || ''}${field.name[0] === '_' ? '_' : ''}${toSnakeCase(field.name)}`;
39
- const fieldName = `${fieldPrefix?.replace('.', '_') || ''}${field.name}`;
40
- // If field is localized,
41
- // add the column to the locale table instead of main table
42
- if (adapter.payload.config.localization && (field.localized || forceLocalized) && field.type !== 'array' && field.type !== 'blocks' && ('hasMany' in field && field.hasMany !== true || !('hasMany' in field))) {
43
- hasLocalizedField = true;
44
- targetTable = localesColumns;
45
- targetIndexes = localesIndexes;
46
- }
47
- if ((field.unique || field.index || [
48
- 'relationship',
49
- 'upload'
50
- ].includes(field.type)) && ![
51
- 'array',
52
- 'blocks',
53
- 'group',
54
- 'point'
55
- ].includes(field.type) && !('hasMany' in field && field.hasMany === true) && !('relationTo' in field && Array.isArray(field.relationTo))) {
56
- const unique = disableUnique !== true && field.unique;
57
- if (unique) {
58
- const constraintValue = `${fieldPrefix || ''}${field.name}`;
59
- if (!adapter.fieldConstraints?.[rootTableName]) {
60
- adapter.fieldConstraints[rootTableName] = {};
61
- }
62
- adapter.fieldConstraints[rootTableName][`${columnName}_idx`] = constraintValue;
63
- }
64
- const indexName = buildIndexName({
65
- name: `${newTableName}_${columnName}`,
66
- adapter: adapter
67
- });
68
- targetIndexes[indexName] = createIndex({
69
- name: field.localized ? [
70
- fieldName,
71
- '_locale'
72
- ] : fieldName,
73
- indexName,
74
- unique
75
- });
76
- }
77
- switch(field.type){
78
- case 'array':
79
- {
80
- const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
81
- const arrayTableName = createTableName({
82
- adapter,
83
- config: field,
84
- parentTableName: newTableName,
85
- prefix: `${newTableName}_`,
86
- versionsCustomName: versions
87
- });
88
- const baseColumns = {
89
- _order: integer('_order').notNull(),
90
- _parentID: getIDColumn({
91
- name: '_parent_id',
92
- type: parentIDColType,
93
- notNull: true,
94
- primaryKey: false
95
- })
96
- };
97
- const baseExtraConfig = {
98
- _orderIdx: (cols)=>index(`${arrayTableName}_order_idx`).on(cols._order),
99
- _parentIDFk: (cols)=>foreignKey({
100
- name: `${arrayTableName}_parent_id_fk`,
101
- columns: [
102
- cols['_parentID']
103
- ],
104
- foreignColumns: [
105
- adapter.tables[parentTableName].id
106
- ]
107
- }).onDelete('cascade'),
108
- _parentIDIdx: (cols)=>index(`${arrayTableName}_parent_id_idx`).on(cols._parentID)
109
- };
110
- const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
111
- if (isLocalized) {
112
- baseColumns._locale = text('_locale', {
113
- enum: locales
114
- }).notNull();
115
- baseExtraConfig._localeIdx = (cols)=>index(`${arrayTableName}_locale_idx`).on(cols._locale);
116
- }
117
- const { hasLocalizedManyNumberField: subHasLocalizedManyNumberField, hasLocalizedManyTextField: subHasLocalizedManyTextField, hasLocalizedRelationshipField: subHasLocalizedRelationshipField, hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
118
- adapter,
119
- baseColumns,
120
- baseExtraConfig,
121
- disableNotNull: disableNotNullFromHere,
122
- disableRelsTableUnique: true,
123
- disableUnique,
124
- fields: disableUnique ? idToUUID(field.flattenedFields) : field.flattenedFields,
125
- rootRelationships: relationships,
126
- rootRelationsToBuild,
127
- rootTableIDColType,
128
- rootTableName,
129
- rootUniqueRelationships: uniqueRelationships,
130
- tableName: arrayTableName,
131
- versions,
132
- withinLocalizedArrayOrBlock: isLocalized
133
- });
134
- if (subHasLocalizedManyNumberField) {
135
- hasLocalizedManyNumberField = subHasLocalizedManyNumberField;
136
- }
137
- if (subHasLocalizedRelationshipField) {
138
- hasLocalizedRelationshipField = subHasLocalizedRelationshipField;
139
- }
140
- if (subHasLocalizedManyTextField) {
141
- hasLocalizedManyTextField = subHasLocalizedManyTextField;
142
- }
143
- if (subHasManyTextField) {
144
- if (!hasManyTextField || subHasManyTextField === 'index') {
145
- hasManyTextField = subHasManyTextField;
146
- }
147
- }
148
- if (subHasManyNumberField) {
149
- if (!hasManyNumberField || subHasManyNumberField === 'index') {
150
- hasManyNumberField = subHasManyNumberField;
151
- }
152
- }
153
- relationsToBuild.set(fieldName, {
154
- type: 'many',
155
- // arrays have their own localized table, independent of the base table.
156
- localized: false,
157
- target: arrayTableName
158
- });
159
- adapter.relations[`relations_${arrayTableName}`] = relations(adapter.tables[arrayTableName], ({ many, one })=>{
160
- const result = {
161
- _parentID: one(adapter.tables[parentTableName], {
162
- fields: [
163
- adapter.tables[arrayTableName]._parentID
164
- ],
165
- references: [
166
- adapter.tables[parentTableName].id
167
- ],
168
- relationName: fieldName
169
- })
170
- };
171
- if (hasLocalesTable(field.fields)) {
172
- result._locales = many(adapter.tables[`${arrayTableName}${adapter.localesSuffix}`], {
173
- relationName: '_locales'
174
- });
175
- }
176
- subRelationsToBuild.forEach(({ type, localized, target }, key)=>{
177
- if (type === 'one') {
178
- const arrayWithLocalized = localized ? `${arrayTableName}${adapter.localesSuffix}` : arrayTableName;
179
- result[key] = one(adapter.tables[target], {
180
- fields: [
181
- adapter.tables[arrayWithLocalized][key]
182
- ],
183
- references: [
184
- adapter.tables[target].id
185
- ],
186
- relationName: key
187
- });
188
- }
189
- if (type === 'many') {
190
- result[key] = many(adapter.tables[target], {
191
- relationName: key
192
- });
193
- }
194
- });
195
- return result;
196
- });
197
- break;
198
- }
199
- case 'blocks':
200
- {
201
- const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
202
- field.blocks.forEach((block)=>{
203
- const blockTableName = createTableName({
204
- adapter,
205
- config: block,
206
- parentTableName: rootTableName,
207
- prefix: `${rootTableName}_blocks_`,
208
- versionsCustomName: versions
209
- });
210
- if (!adapter.tables[blockTableName]) {
211
- const baseColumns = {
212
- _order: integer('_order').notNull(),
213
- _parentID: getIDColumn({
214
- name: '_parent_id',
215
- type: rootTableIDColType,
216
- notNull: true,
217
- primaryKey: false
218
- }),
219
- _path: text('_path').notNull()
220
- };
221
- const baseExtraConfig = {
222
- _orderIdx: (cols)=>index(`${blockTableName}_order_idx`).on(cols._order),
223
- _parentIdFk: (cols)=>foreignKey({
224
- name: `${blockTableName}_parent_id_fk`,
225
- columns: [
226
- cols._parentID
227
- ],
228
- foreignColumns: [
229
- adapter.tables[rootTableName].id
230
- ]
231
- }).onDelete('cascade'),
232
- _parentIDIdx: (cols)=>index(`${blockTableName}_parent_id_idx`).on(cols._parentID),
233
- _pathIdx: (cols)=>index(`${blockTableName}_path_idx`).on(cols._path)
234
- };
235
- const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
236
- if (isLocalized) {
237
- baseColumns._locale = text('_locale', {
238
- enum: locales
239
- }).notNull();
240
- baseExtraConfig._localeIdx = (cols)=>index(`${blockTableName}_locale_idx`).on(cols._locale);
241
- }
242
- const { hasLocalizedManyNumberField: subHasLocalizedManyNumberField, hasLocalizedManyTextField: subHasLocalizedManyTextField, hasLocalizedRelationshipField: subHasLocalizedRelationshipField, hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
243
- adapter,
244
- baseColumns,
245
- baseExtraConfig,
246
- disableNotNull: disableNotNullFromHere,
247
- disableRelsTableUnique: true,
248
- disableUnique,
249
- fields: disableUnique ? idToUUID(block.flattenedFields) : block.flattenedFields,
250
- rootRelationships: relationships,
251
- rootRelationsToBuild,
252
- rootTableIDColType,
253
- rootTableName,
254
- rootUniqueRelationships: uniqueRelationships,
255
- tableName: blockTableName,
256
- versions,
257
- withinLocalizedArrayOrBlock: isLocalized
258
- });
259
- if (subHasLocalizedManyNumberField) {
260
- hasLocalizedManyNumberField = subHasLocalizedManyNumberField;
261
- }
262
- if (subHasLocalizedRelationshipField) {
263
- hasLocalizedRelationshipField = subHasLocalizedRelationshipField;
264
- }
265
- if (subHasLocalizedManyTextField) {
266
- hasLocalizedManyTextField = subHasLocalizedManyTextField;
267
- }
268
- if (subHasManyTextField) {
269
- if (!hasManyTextField || subHasManyTextField === 'index') {
270
- hasManyTextField = subHasManyTextField;
271
- }
272
- }
273
- if (subHasManyNumberField) {
274
- if (!hasManyNumberField || subHasManyNumberField === 'index') {
275
- hasManyNumberField = subHasManyNumberField;
276
- }
277
- }
278
- adapter.relations[`relations_${blockTableName}`] = relations(adapter.tables[blockTableName], ({ many, one })=>{
279
- const result = {
280
- _parentID: one(adapter.tables[rootTableName], {
281
- fields: [
282
- adapter.tables[blockTableName]._parentID
283
- ],
284
- references: [
285
- adapter.tables[rootTableName].id
286
- ],
287
- relationName: `_blocks_${block.slug}`
288
- })
289
- };
290
- if (hasLocalesTable(block.fields)) {
291
- result._locales = many(adapter.tables[`${blockTableName}${adapter.localesSuffix}`], {
292
- relationName: '_locales'
293
- });
294
- }
295
- subRelationsToBuild.forEach(({ type, localized, target }, key)=>{
296
- if (type === 'one') {
297
- const blockWithLocalized = localized ? `${blockTableName}${adapter.localesSuffix}` : blockTableName;
298
- result[key] = one(adapter.tables[target], {
299
- fields: [
300
- adapter.tables[blockWithLocalized][key]
301
- ],
302
- references: [
303
- adapter.tables[target].id
304
- ],
305
- relationName: key
306
- });
307
- }
308
- if (type === 'many') {
309
- result[key] = many(adapter.tables[target], {
310
- relationName: key
311
- });
312
- }
313
- });
314
- return result;
315
- });
316
- } else if (process.env.NODE_ENV !== 'production' && !versions) {
317
- validateExistingBlockIsIdentical({
318
- block,
319
- localized: field.localized,
320
- rootTableName,
321
- table: adapter.tables[blockTableName],
322
- tableLocales: adapter.tables[`${blockTableName}${adapter.localesSuffix}`]
323
- });
324
- }
325
- // blocks relationships are defined from the collection or globals table down to the block, bypassing any subBlocks
326
- rootRelationsToBuild.set(`_blocks_${block.slug}`, {
327
- type: 'many',
328
- // blocks are not localized on the parent table
329
- localized: false,
330
- target: blockTableName
331
- });
332
- });
333
- break;
334
- }
335
- case 'checkbox':
336
- {
337
- targetTable[fieldName] = withDefault(integer(columnName, {
338
- mode: 'boolean'
339
- }), field);
340
- break;
341
- }
342
- case 'code':
343
- case 'email':
344
- case 'textarea':
345
- {
346
- targetTable[fieldName] = withDefault(text(columnName), field);
347
- break;
348
- }
349
- case 'date':
350
- {
351
- targetTable[fieldName] = withDefault(text(columnName), field);
352
- break;
353
- }
354
- case 'group':
355
- case 'tab':
356
- {
357
- const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
358
- const { hasLocalizedField: groupHasLocalizedField, hasLocalizedManyNumberField: groupHasLocalizedManyNumberField, hasLocalizedManyTextField: groupHasLocalizedManyTextField, hasLocalizedRelationshipField: groupHasLocalizedRelationshipField, hasManyNumberField: groupHasManyNumberField, hasManyTextField: groupHasManyTextField } = traverseFields({
359
- adapter,
360
- columnPrefix: `${columnName}_`,
361
- columns,
362
- disableNotNull: disableNotNullFromHere,
363
- disableUnique,
364
- fieldPrefix: `${fieldName}.`,
365
- fields: field.flattenedFields,
366
- forceLocalized: field.localized,
367
- indexes,
368
- locales,
369
- localesColumns,
370
- localesIndexes,
371
- newTableName: `${parentTableName}_${columnName}`,
372
- parentTableName,
373
- relationships,
374
- relationsToBuild,
375
- rootRelationsToBuild,
376
- rootTableIDColType,
377
- rootTableName,
378
- uniqueRelationships,
379
- versions,
380
- withinLocalizedArrayOrBlock: withinLocalizedArrayOrBlock || field.localized
381
- });
382
- if (groupHasLocalizedField) {
383
- hasLocalizedField = true;
384
- }
385
- if (groupHasLocalizedRelationshipField) {
386
- hasLocalizedRelationshipField = true;
387
- }
388
- if (groupHasManyTextField) {
389
- hasManyTextField = true;
390
- }
391
- if (groupHasLocalizedManyTextField) {
392
- hasLocalizedManyTextField = true;
393
- }
394
- if (groupHasManyNumberField) {
395
- hasManyNumberField = true;
396
- }
397
- if (groupHasLocalizedManyNumberField) {
398
- hasLocalizedManyNumberField = true;
399
- }
400
- break;
401
- }
402
- case 'json':
403
- case 'richText':
404
- {
405
- targetTable[fieldName] = withDefault(text(columnName, {
406
- mode: 'json'
407
- }), field);
408
- break;
409
- }
410
- case 'number':
411
- {
412
- if (field.hasMany) {
413
- const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
414
- if (isLocalized) {
415
- hasLocalizedManyNumberField = true;
416
- }
417
- if (field.index) {
418
- hasManyNumberField = 'index';
419
- } else if (!hasManyNumberField) {
420
- hasManyNumberField = true;
421
- }
422
- if (field.unique) {
423
- throw new InvalidConfiguration('Unique is not supported in Postgres for hasMany number fields.');
424
- }
425
- } else {
426
- targetTable[fieldName] = withDefault(numeric(columnName), field);
427
- }
428
- break;
429
- }
430
- case 'point':
431
- {
432
- break;
433
- }
434
- case 'radio':
435
- case 'select':
436
- {
437
- const options = field.options.map((option)=>{
438
- if (optionIsObject(option)) {
439
- return option.value;
440
- }
441
- return option;
442
- });
443
- if (field.type === 'select' && field.hasMany) {
444
- const selectTableName = createTableName({
445
- adapter,
446
- config: field,
447
- parentTableName: newTableName,
448
- prefix: `${newTableName}_`,
449
- versionsCustomName: versions
450
- });
451
- const baseColumns = {
452
- order: integer('order').notNull(),
453
- parent: getIDColumn({
454
- name: 'parent_id',
455
- type: parentIDColType,
456
- notNull: true,
457
- primaryKey: false
458
- }),
459
- value: text('value', {
460
- enum: options
461
- })
462
- };
463
- const baseExtraConfig = {
464
- orderIdx: (cols)=>index(`${selectTableName}_order_idx`).on(cols.order),
465
- parentFk: (cols)=>foreignKey({
466
- name: `${selectTableName}_parent_fk`,
467
- columns: [
468
- cols.parent
469
- ],
470
- foreignColumns: [
471
- adapter.tables[parentTableName].id
472
- ]
473
- }).onDelete('cascade'),
474
- parentIdx: (cols)=>index(`${selectTableName}_parent_idx`).on(cols.parent)
475
- };
476
- const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
477
- if (isLocalized) {
478
- baseColumns.locale = text('locale', {
479
- enum: locales
480
- }).notNull();
481
- baseExtraConfig.localeIdx = (cols)=>index(`${selectTableName}_locale_idx`).on(cols.locale);
482
- }
483
- if (field.index) {
484
- baseExtraConfig.value = (cols)=>index(`${selectTableName}_value_idx`).on(cols.value);
485
- }
486
- buildTable({
487
- adapter,
488
- baseColumns,
489
- baseExtraConfig,
490
- disableNotNull,
491
- disableUnique,
492
- fields: [],
493
- rootTableName,
494
- tableName: selectTableName,
495
- versions
496
- });
497
- relationsToBuild.set(fieldName, {
498
- type: 'many',
499
- // selects have their own localized table, independent of the base table.
500
- localized: false,
501
- target: selectTableName
502
- });
503
- adapter.relations[`relations_${selectTableName}`] = relations(adapter.tables[selectTableName], ({ one })=>({
504
- parent: one(adapter.tables[parentTableName], {
505
- fields: [
506
- adapter.tables[selectTableName].parent
507
- ],
508
- references: [
509
- adapter.tables[parentTableName].id
510
- ],
511
- relationName: fieldName
512
- })
513
- }));
514
- } else {
515
- targetTable[fieldName] = withDefault(text(columnName, {
516
- enum: options
517
- }), field);
518
- }
519
- break;
520
- }
521
- case 'relationship':
522
- case 'upload':
523
- if (Array.isArray(field.relationTo)) {
524
- field.relationTo.forEach((relation)=>{
525
- relationships.add(relation);
526
- if (field.unique && !disableUnique && !disableRelsTableUnique) {
527
- uniqueRelationships.add(relation);
528
- }
529
- });
530
- } else if (field.hasMany) {
531
- relationships.add(field.relationTo);
532
- if (field.unique && !disableUnique && !disableRelsTableUnique) {
533
- uniqueRelationships.add(field.relationTo);
534
- }
535
- } else {
536
- // simple relationships get a column on the targetTable with a foreign key to the relationTo table
537
- const relationshipConfig = adapter.payload.collections[field.relationTo].config;
538
- const tableName = adapter.tableNameMap.get(toSnakeCase(field.relationTo));
539
- // get the id type of the related collection
540
- let colType = 'integer';
541
- const relatedCollectionCustomID = relationshipConfig.fields.find((field)=>fieldAffectsData(field) && field.name === 'id');
542
- if (relatedCollectionCustomID?.type === 'number') {
543
- colType = 'numeric';
544
- }
545
- if (relatedCollectionCustomID?.type === 'text') {
546
- colType = 'text';
547
- }
548
- // make the foreign key column for relationship using the correct id column type
549
- targetTable[fieldName] = getIDColumn({
550
- name: `${columnName}_id`,
551
- type: colType,
552
- primaryKey: false
553
- }).references(()=>adapter.tables[tableName].id, {
554
- onDelete: 'set null'
555
- });
556
- // add relationship to table
557
- relationsToBuild.set(fieldName, {
558
- type: 'one',
559
- localized: adapter.payload.config.localization && (field.localized || forceLocalized),
560
- target: tableName
561
- });
562
- // add notNull when not required
563
- if (!disableNotNull && field.required && !field.admin?.condition) {
564
- targetTable[fieldName].notNull();
565
- }
566
- break;
567
- }
568
- if (Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock) {
569
- hasLocalizedRelationshipField = true;
570
- }
571
- break;
572
- case 'text':
573
- {
574
- if (field.hasMany) {
575
- const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
576
- if (isLocalized) {
577
- hasLocalizedManyTextField = true;
578
- }
579
- if (field.index) {
580
- hasManyTextField = 'index';
581
- } else if (!hasManyTextField) {
582
- hasManyTextField = true;
583
- }
584
- if (field.unique) {
585
- throw new InvalidConfiguration('Unique is not supported in SQLite for hasMany text fields.');
586
- }
587
- } else {
588
- targetTable[fieldName] = withDefault(text(columnName), field);
589
- }
590
- break;
591
- }
592
- default:
593
- break;
594
- }
595
- const condition = field.admin && field.admin.condition;
596
- if (!disableNotNull && targetTable[fieldName] && 'required' in field && field.required && !condition) {
597
- targetTable[fieldName].notNull();
598
- }
599
- });
600
- return {
601
- hasLocalizedField,
602
- hasLocalizedManyNumberField,
603
- hasLocalizedManyTextField,
604
- hasLocalizedRelationshipField,
605
- hasManyNumberField,
606
- hasManyTextField
607
- };
608
- };
609
-
610
- //# sourceMappingURL=traverseFields.js.map