@payloadcms/db-sqlite 3.0.0-canary.2c2c95f → 3.0.0-canary.3eda767
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/README.md +1 -1
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +15 -3
- package/dist/connect.js.map +1 -1
- package/dist/countDistinct.d.ts.map +1 -1
- package/dist/countDistinct.js +2 -3
- package/dist/countDistinct.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +9 -6
- package/dist/createMigration.js.map +1 -1
- package/dist/defaultSnapshot.d.ts +1 -1
- package/dist/defaultSnapshot.d.ts.map +1 -1
- package/dist/defaultSnapshot.js +2 -1
- package/dist/defaultSnapshot.js.map +1 -1
- package/dist/getMigrationTemplate.d.ts +1 -0
- package/dist/getMigrationTemplate.d.ts.map +1 -1
- package/dist/getMigrationTemplate.js +5 -4
- package/dist/getMigrationTemplate.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -8
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +34 -4
- package/dist/init.js.map +1 -1
- package/dist/requireDrizzleKit.d.ts +3 -0
- package/dist/requireDrizzleKit.d.ts.map +1 -1
- package/dist/requireDrizzleKit.js +5 -2
- package/dist/requireDrizzleKit.js.map +1 -1
- package/dist/schema/build.d.ts +19 -16
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/build.js +44 -11
- package/dist/schema/build.js.map +1 -1
- package/dist/schema/createIndex.d.ts +4 -5
- package/dist/schema/createIndex.d.ts.map +1 -1
- package/dist/schema/createIndex.js +6 -4
- package/dist/schema/createIndex.js.map +1 -1
- package/dist/schema/traverseFields.d.ts +9 -2
- package/dist/schema/traverseFields.d.ts.map +1 -1
- package/dist/schema/traverseFields.js +205 -81
- package/dist/schema/traverseFields.js.map +1 -1
- package/dist/schema/withDefault.d.ts +4 -0
- package/dist/schema/withDefault.d.ts.map +1 -0
- package/dist/schema/withDefault.js +12 -0
- package/dist/schema/withDefault.js.map +1 -0
- package/dist/types.d.ts +54 -27
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +11 -9
- package/dist/generateDrizzleJSON.d.ts +0 -3
- package/dist/generateDrizzleJSON.d.ts.map +0 -1
- package/dist/generateDrizzleJSON.js +0 -8
- package/dist/generateDrizzleJSON.js.map +0 -1
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { buildIndexName, createTableName, hasLocalesTable, validateExistingBlockIsIdentical } from '@payloadcms/drizzle';
|
|
2
2
|
import { relations } from 'drizzle-orm';
|
|
3
|
-
import {
|
|
3
|
+
import { foreignKey, index, integer, numeric, SQLiteIntegerBuilder, SQLiteNumericBuilder, SQLiteTextBuilder, text } from 'drizzle-orm/sqlite-core';
|
|
4
4
|
import { InvalidConfiguration } from 'payload';
|
|
5
|
-
import { fieldAffectsData, optionIsObject } from 'payload/shared';
|
|
5
|
+
import { fieldAffectsData, fieldIsVirtual, optionIsObject } from 'payload/shared';
|
|
6
6
|
import toSnakeCase from 'to-snake-case';
|
|
7
7
|
import { buildTable } from './build.js';
|
|
8
8
|
import { createIndex } from './createIndex.js';
|
|
9
9
|
import { getIDColumn } from './getIDColumn.js';
|
|
10
10
|
import { idToUUID } from './idToUUID.js';
|
|
11
|
-
|
|
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 })=>{
|
|
12
13
|
let hasLocalizedField = false;
|
|
13
14
|
let hasLocalizedRelationshipField = false;
|
|
14
15
|
let hasManyTextField = false;
|
|
@@ -16,11 +17,22 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
16
17
|
let hasManyNumberField = false;
|
|
17
18
|
let hasLocalizedManyNumberField = false;
|
|
18
19
|
let parentIDColType = 'integer';
|
|
19
|
-
if (columns.id instanceof SQLiteIntegerBuilder)
|
|
20
|
-
|
|
21
|
-
|
|
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
|
+
}
|
|
22
29
|
fields.forEach((field)=>{
|
|
23
|
-
if ('name' in field && field.name === 'id')
|
|
30
|
+
if ('name' in field && field.name === 'id') {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (fieldIsVirtual(field)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
24
36
|
let columnName;
|
|
25
37
|
let fieldName;
|
|
26
38
|
let targetTable = columns;
|
|
@@ -35,14 +47,15 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
35
47
|
targetTable = localesColumns;
|
|
36
48
|
targetIndexes = localesIndexes;
|
|
37
49
|
}
|
|
38
|
-
if ((field.unique || field.index
|
|
50
|
+
if ((field.unique || field.index || [
|
|
51
|
+
'relationship',
|
|
52
|
+
'upload'
|
|
53
|
+
].includes(field.type)) && ![
|
|
39
54
|
'array',
|
|
40
55
|
'blocks',
|
|
41
56
|
'group',
|
|
42
|
-
'point'
|
|
43
|
-
|
|
44
|
-
'upload'
|
|
45
|
-
].includes(field.type) && !('hasMany' in field && field.hasMany === true)) {
|
|
57
|
+
'point'
|
|
58
|
+
].includes(field.type) && !('hasMany' in field && field.hasMany === true) && !('relationTo' in field && Array.isArray(field.relationTo))) {
|
|
46
59
|
const unique = disableUnique !== true && field.unique;
|
|
47
60
|
if (unique) {
|
|
48
61
|
const constraintValue = `${fieldPrefix || ''}${field.name}`;
|
|
@@ -51,10 +64,16 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
51
64
|
}
|
|
52
65
|
adapter.fieldConstraints[rootTableName][`${columnName}_idx`] = constraintValue;
|
|
53
66
|
}
|
|
54
|
-
|
|
55
|
-
name:
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
const indexName = buildIndexName({
|
|
68
|
+
name: `${newTableName}_${columnName}`,
|
|
69
|
+
adapter: adapter
|
|
70
|
+
});
|
|
71
|
+
targetIndexes[indexName] = createIndex({
|
|
72
|
+
name: field.localized ? [
|
|
73
|
+
fieldName,
|
|
74
|
+
'_locale'
|
|
75
|
+
] : fieldName,
|
|
76
|
+
indexName,
|
|
58
77
|
unique
|
|
59
78
|
});
|
|
60
79
|
}
|
|
@@ -63,7 +82,8 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
63
82
|
case 'text':
|
|
64
83
|
{
|
|
65
84
|
if (field.hasMany) {
|
|
66
|
-
|
|
85
|
+
const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
86
|
+
if (isLocalized) {
|
|
67
87
|
hasLocalizedManyTextField = true;
|
|
68
88
|
}
|
|
69
89
|
if (field.index) {
|
|
@@ -75,7 +95,7 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
75
95
|
throw new InvalidConfiguration('Unique is not supported in SQLite for hasMany text fields.');
|
|
76
96
|
}
|
|
77
97
|
} else {
|
|
78
|
-
targetTable[fieldName] = text(columnName);
|
|
98
|
+
targetTable[fieldName] = withDefault(text(columnName), field);
|
|
79
99
|
}
|
|
80
100
|
break;
|
|
81
101
|
}
|
|
@@ -83,13 +103,14 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
83
103
|
case 'code':
|
|
84
104
|
case 'textarea':
|
|
85
105
|
{
|
|
86
|
-
targetTable[fieldName] = text(columnName);
|
|
106
|
+
targetTable[fieldName] = withDefault(text(columnName), field);
|
|
87
107
|
break;
|
|
88
108
|
}
|
|
89
109
|
case 'number':
|
|
90
110
|
{
|
|
91
111
|
if (field.hasMany) {
|
|
92
|
-
|
|
112
|
+
const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
113
|
+
if (isLocalized) {
|
|
93
114
|
hasLocalizedManyNumberField = true;
|
|
94
115
|
}
|
|
95
116
|
if (field.index) {
|
|
@@ -101,21 +122,21 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
101
122
|
throw new InvalidConfiguration('Unique is not supported in Postgres for hasMany number fields.');
|
|
102
123
|
}
|
|
103
124
|
} else {
|
|
104
|
-
targetTable[fieldName] = numeric(columnName);
|
|
125
|
+
targetTable[fieldName] = withDefault(numeric(columnName), field);
|
|
105
126
|
}
|
|
106
127
|
break;
|
|
107
128
|
}
|
|
108
129
|
case 'richText':
|
|
109
130
|
case 'json':
|
|
110
131
|
{
|
|
111
|
-
targetTable[fieldName] = text(columnName, {
|
|
132
|
+
targetTable[fieldName] = withDefault(text(columnName, {
|
|
112
133
|
mode: 'json'
|
|
113
|
-
});
|
|
134
|
+
}), field);
|
|
114
135
|
break;
|
|
115
136
|
}
|
|
116
137
|
case 'date':
|
|
117
138
|
{
|
|
118
|
-
targetTable[fieldName] = text(columnName);
|
|
139
|
+
targetTable[fieldName] = withDefault(text(columnName), field);
|
|
119
140
|
break;
|
|
120
141
|
}
|
|
121
142
|
case 'point':
|
|
@@ -164,7 +185,8 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
164
185
|
}).onDelete('cascade'),
|
|
165
186
|
parentIdx: (cols)=>index(`${selectTableName}_parent_idx`).on(cols.parent)
|
|
166
187
|
};
|
|
167
|
-
|
|
188
|
+
const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
189
|
+
if (isLocalized) {
|
|
168
190
|
baseColumns.locale = text('locale', {
|
|
169
191
|
enum: locales
|
|
170
192
|
}).notNull();
|
|
@@ -202,17 +224,17 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
202
224
|
})
|
|
203
225
|
}));
|
|
204
226
|
} else {
|
|
205
|
-
targetTable[fieldName] = text(
|
|
227
|
+
targetTable[fieldName] = withDefault(text(columnName, {
|
|
206
228
|
enum: options
|
|
207
|
-
});
|
|
229
|
+
}), field);
|
|
208
230
|
}
|
|
209
231
|
break;
|
|
210
232
|
}
|
|
211
233
|
case 'checkbox':
|
|
212
234
|
{
|
|
213
|
-
targetTable[fieldName] = integer(columnName, {
|
|
235
|
+
targetTable[fieldName] = withDefault(integer(columnName, {
|
|
214
236
|
mode: 'boolean'
|
|
215
|
-
});
|
|
237
|
+
}), field);
|
|
216
238
|
break;
|
|
217
239
|
}
|
|
218
240
|
case 'array':
|
|
@@ -247,31 +269,48 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
247
269
|
}).onDelete('cascade'),
|
|
248
270
|
_parentIDIdx: (cols)=>index(`${arrayTableName}_parent_id_idx`).on(cols._parentID)
|
|
249
271
|
};
|
|
250
|
-
|
|
272
|
+
const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
273
|
+
if (isLocalized) {
|
|
251
274
|
baseColumns._locale = text('_locale', {
|
|
252
275
|
enum: locales
|
|
253
276
|
}).notNull();
|
|
254
277
|
baseExtraConfig._localeIdx = (cols)=>index(`${arrayTableName}_locale_idx`).on(cols._locale);
|
|
255
278
|
}
|
|
256
|
-
const { hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
|
|
279
|
+
const { hasLocalizedManyNumberField: subHasLocalizedManyNumberField, hasLocalizedManyTextField: subHasLocalizedManyTextField, hasLocalizedRelationshipField: subHasLocalizedRelationshipField, hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
|
|
257
280
|
adapter,
|
|
258
281
|
baseColumns,
|
|
259
282
|
baseExtraConfig,
|
|
260
283
|
disableNotNull: disableNotNullFromHere,
|
|
284
|
+
disableRelsTableUnique: true,
|
|
261
285
|
disableUnique,
|
|
262
286
|
fields: disableUnique ? idToUUID(field.fields) : field.fields,
|
|
263
|
-
rootRelationsToBuild,
|
|
264
287
|
rootRelationships: relationships,
|
|
288
|
+
rootRelationsToBuild,
|
|
265
289
|
rootTableIDColType,
|
|
266
290
|
rootTableName,
|
|
291
|
+
rootUniqueRelationships: uniqueRelationships,
|
|
267
292
|
tableName: arrayTableName,
|
|
268
|
-
versions
|
|
293
|
+
versions,
|
|
294
|
+
withinLocalizedArrayOrBlock: isLocalized
|
|
269
295
|
});
|
|
296
|
+
if (subHasLocalizedManyNumberField) {
|
|
297
|
+
hasLocalizedManyNumberField = subHasLocalizedManyNumberField;
|
|
298
|
+
}
|
|
299
|
+
if (subHasLocalizedRelationshipField) {
|
|
300
|
+
hasLocalizedRelationshipField = subHasLocalizedRelationshipField;
|
|
301
|
+
}
|
|
302
|
+
if (subHasLocalizedManyTextField) {
|
|
303
|
+
hasLocalizedManyTextField = subHasLocalizedManyTextField;
|
|
304
|
+
}
|
|
270
305
|
if (subHasManyTextField) {
|
|
271
|
-
if (!hasManyTextField || subHasManyTextField === 'index')
|
|
306
|
+
if (!hasManyTextField || subHasManyTextField === 'index') {
|
|
307
|
+
hasManyTextField = subHasManyTextField;
|
|
308
|
+
}
|
|
272
309
|
}
|
|
273
310
|
if (subHasManyNumberField) {
|
|
274
|
-
if (!hasManyNumberField || subHasManyNumberField === 'index')
|
|
311
|
+
if (!hasManyNumberField || subHasManyNumberField === 'index') {
|
|
312
|
+
hasManyNumberField = subHasManyNumberField;
|
|
313
|
+
}
|
|
275
314
|
}
|
|
276
315
|
relationsToBuild.set(fieldName, {
|
|
277
316
|
type: 'many',
|
|
@@ -343,7 +382,6 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
343
382
|
};
|
|
344
383
|
const baseExtraConfig = {
|
|
345
384
|
_orderIdx: (cols)=>index(`${blockTableName}_order_idx`).on(cols._order),
|
|
346
|
-
_parentIDIdx: (cols)=>index(`${blockTableName}_parent_id_idx`).on(cols._parentID),
|
|
347
385
|
_parentIdFk: (cols)=>foreignKey({
|
|
348
386
|
name: `${blockTableName}_parent_id_fk`,
|
|
349
387
|
columns: [
|
|
@@ -353,33 +391,51 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
353
391
|
adapter.tables[rootTableName].id
|
|
354
392
|
]
|
|
355
393
|
}).onDelete('cascade'),
|
|
394
|
+
_parentIDIdx: (cols)=>index(`${blockTableName}_parent_id_idx`).on(cols._parentID),
|
|
356
395
|
_pathIdx: (cols)=>index(`${blockTableName}_path_idx`).on(cols._path)
|
|
357
396
|
};
|
|
358
|
-
|
|
397
|
+
const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
398
|
+
if (isLocalized) {
|
|
359
399
|
baseColumns._locale = text('_locale', {
|
|
360
400
|
enum: locales
|
|
361
401
|
}).notNull();
|
|
362
402
|
baseExtraConfig._localeIdx = (cols)=>index(`${blockTableName}_locale_idx`).on(cols._locale);
|
|
363
403
|
}
|
|
364
|
-
const { hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
|
|
404
|
+
const { hasLocalizedManyNumberField: subHasLocalizedManyNumberField, hasLocalizedManyTextField: subHasLocalizedManyTextField, hasLocalizedRelationshipField: subHasLocalizedRelationshipField, hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
|
|
365
405
|
adapter,
|
|
366
406
|
baseColumns,
|
|
367
407
|
baseExtraConfig,
|
|
368
408
|
disableNotNull: disableNotNullFromHere,
|
|
409
|
+
disableRelsTableUnique: true,
|
|
369
410
|
disableUnique,
|
|
370
411
|
fields: disableUnique ? idToUUID(block.fields) : block.fields,
|
|
371
|
-
rootRelationsToBuild,
|
|
372
412
|
rootRelationships: relationships,
|
|
413
|
+
rootRelationsToBuild,
|
|
373
414
|
rootTableIDColType,
|
|
374
415
|
rootTableName,
|
|
416
|
+
rootUniqueRelationships: uniqueRelationships,
|
|
375
417
|
tableName: blockTableName,
|
|
376
|
-
versions
|
|
418
|
+
versions,
|
|
419
|
+
withinLocalizedArrayOrBlock: isLocalized
|
|
377
420
|
});
|
|
421
|
+
if (subHasLocalizedManyNumberField) {
|
|
422
|
+
hasLocalizedManyNumberField = subHasLocalizedManyNumberField;
|
|
423
|
+
}
|
|
424
|
+
if (subHasLocalizedRelationshipField) {
|
|
425
|
+
hasLocalizedRelationshipField = subHasLocalizedRelationshipField;
|
|
426
|
+
}
|
|
427
|
+
if (subHasLocalizedManyTextField) {
|
|
428
|
+
hasLocalizedManyTextField = subHasLocalizedManyTextField;
|
|
429
|
+
}
|
|
378
430
|
if (subHasManyTextField) {
|
|
379
|
-
if (!hasManyTextField || subHasManyTextField === 'index')
|
|
431
|
+
if (!hasManyTextField || subHasManyTextField === 'index') {
|
|
432
|
+
hasManyTextField = subHasManyTextField;
|
|
433
|
+
}
|
|
380
434
|
}
|
|
381
435
|
if (subHasManyNumberField) {
|
|
382
|
-
if (!hasManyNumberField || subHasManyNumberField === 'index')
|
|
436
|
+
if (!hasManyNumberField || subHasManyNumberField === 'index') {
|
|
437
|
+
hasManyNumberField = subHasManyNumberField;
|
|
438
|
+
}
|
|
383
439
|
}
|
|
384
440
|
adapter.relations[`relations_${blockTableName}`] = relations(adapter.tables[blockTableName], ({ many, one })=>{
|
|
385
441
|
const result = {
|
|
@@ -457,19 +513,33 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
457
513
|
localesIndexes,
|
|
458
514
|
newTableName,
|
|
459
515
|
parentTableName,
|
|
460
|
-
relationsToBuild,
|
|
461
516
|
relationships,
|
|
517
|
+
relationsToBuild,
|
|
462
518
|
rootRelationsToBuild,
|
|
463
519
|
rootTableIDColType,
|
|
464
520
|
rootTableName,
|
|
465
|
-
|
|
521
|
+
uniqueRelationships,
|
|
522
|
+
versions,
|
|
523
|
+
withinLocalizedArrayOrBlock
|
|
466
524
|
});
|
|
467
|
-
if (groupHasLocalizedField)
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
if (
|
|
471
|
-
|
|
472
|
-
|
|
525
|
+
if (groupHasLocalizedField) {
|
|
526
|
+
hasLocalizedField = true;
|
|
527
|
+
}
|
|
528
|
+
if (groupHasLocalizedRelationshipField) {
|
|
529
|
+
hasLocalizedRelationshipField = true;
|
|
530
|
+
}
|
|
531
|
+
if (groupHasManyTextField) {
|
|
532
|
+
hasManyTextField = true;
|
|
533
|
+
}
|
|
534
|
+
if (groupHasLocalizedManyTextField) {
|
|
535
|
+
hasLocalizedManyTextField = true;
|
|
536
|
+
}
|
|
537
|
+
if (groupHasManyNumberField) {
|
|
538
|
+
hasManyNumberField = true;
|
|
539
|
+
}
|
|
540
|
+
if (groupHasLocalizedManyNumberField) {
|
|
541
|
+
hasLocalizedManyNumberField = true;
|
|
542
|
+
}
|
|
473
543
|
break;
|
|
474
544
|
}
|
|
475
545
|
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
|
@@ -488,19 +558,33 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
488
558
|
localesIndexes,
|
|
489
559
|
newTableName: `${parentTableName}_${columnName}`,
|
|
490
560
|
parentTableName,
|
|
491
|
-
relationsToBuild,
|
|
492
561
|
relationships,
|
|
562
|
+
relationsToBuild,
|
|
493
563
|
rootRelationsToBuild,
|
|
494
564
|
rootTableIDColType,
|
|
495
565
|
rootTableName,
|
|
496
|
-
|
|
566
|
+
uniqueRelationships,
|
|
567
|
+
versions,
|
|
568
|
+
withinLocalizedArrayOrBlock: withinLocalizedArrayOrBlock || field.localized
|
|
497
569
|
});
|
|
498
|
-
if (groupHasLocalizedField)
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
if (
|
|
502
|
-
|
|
503
|
-
|
|
570
|
+
if (groupHasLocalizedField) {
|
|
571
|
+
hasLocalizedField = true;
|
|
572
|
+
}
|
|
573
|
+
if (groupHasLocalizedRelationshipField) {
|
|
574
|
+
hasLocalizedRelationshipField = true;
|
|
575
|
+
}
|
|
576
|
+
if (groupHasManyTextField) {
|
|
577
|
+
hasManyTextField = true;
|
|
578
|
+
}
|
|
579
|
+
if (groupHasLocalizedManyTextField) {
|
|
580
|
+
hasLocalizedManyTextField = true;
|
|
581
|
+
}
|
|
582
|
+
if (groupHasManyNumberField) {
|
|
583
|
+
hasManyNumberField = true;
|
|
584
|
+
}
|
|
585
|
+
if (groupHasLocalizedManyNumberField) {
|
|
586
|
+
hasLocalizedManyNumberField = true;
|
|
587
|
+
}
|
|
504
588
|
break;
|
|
505
589
|
}
|
|
506
590
|
case 'tabs':
|
|
@@ -524,19 +608,33 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
524
608
|
localesIndexes,
|
|
525
609
|
newTableName,
|
|
526
610
|
parentTableName,
|
|
527
|
-
relationsToBuild,
|
|
528
611
|
relationships,
|
|
612
|
+
relationsToBuild,
|
|
529
613
|
rootRelationsToBuild,
|
|
530
614
|
rootTableIDColType,
|
|
531
615
|
rootTableName,
|
|
532
|
-
|
|
616
|
+
uniqueRelationships,
|
|
617
|
+
versions,
|
|
618
|
+
withinLocalizedArrayOrBlock
|
|
533
619
|
});
|
|
534
|
-
if (tabHasLocalizedField)
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
if (
|
|
538
|
-
|
|
539
|
-
|
|
620
|
+
if (tabHasLocalizedField) {
|
|
621
|
+
hasLocalizedField = true;
|
|
622
|
+
}
|
|
623
|
+
if (tabHasLocalizedRelationshipField) {
|
|
624
|
+
hasLocalizedRelationshipField = true;
|
|
625
|
+
}
|
|
626
|
+
if (tabHasManyTextField) {
|
|
627
|
+
hasManyTextField = true;
|
|
628
|
+
}
|
|
629
|
+
if (tabHasLocalizedManyTextField) {
|
|
630
|
+
hasLocalizedManyTextField = true;
|
|
631
|
+
}
|
|
632
|
+
if (tabHasManyNumberField) {
|
|
633
|
+
hasManyNumberField = true;
|
|
634
|
+
}
|
|
635
|
+
if (tabHasLocalizedManyNumberField) {
|
|
636
|
+
hasLocalizedManyNumberField = true;
|
|
637
|
+
}
|
|
540
638
|
break;
|
|
541
639
|
}
|
|
542
640
|
case 'row':
|
|
@@ -558,27 +656,49 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
558
656
|
localesIndexes,
|
|
559
657
|
newTableName,
|
|
560
658
|
parentTableName,
|
|
561
|
-
relationsToBuild,
|
|
562
659
|
relationships,
|
|
660
|
+
relationsToBuild,
|
|
563
661
|
rootRelationsToBuild,
|
|
564
662
|
rootTableIDColType,
|
|
565
663
|
rootTableName,
|
|
566
|
-
|
|
664
|
+
uniqueRelationships,
|
|
665
|
+
versions,
|
|
666
|
+
withinLocalizedArrayOrBlock
|
|
567
667
|
});
|
|
568
|
-
if (rowHasLocalizedField)
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
if (
|
|
572
|
-
|
|
573
|
-
|
|
668
|
+
if (rowHasLocalizedField) {
|
|
669
|
+
hasLocalizedField = true;
|
|
670
|
+
}
|
|
671
|
+
if (rowHasLocalizedRelationshipField) {
|
|
672
|
+
hasLocalizedRelationshipField = true;
|
|
673
|
+
}
|
|
674
|
+
if (rowHasManyTextField) {
|
|
675
|
+
hasManyTextField = true;
|
|
676
|
+
}
|
|
677
|
+
if (rowHasLocalizedManyTextField) {
|
|
678
|
+
hasLocalizedManyTextField = true;
|
|
679
|
+
}
|
|
680
|
+
if (rowHasManyNumberField) {
|
|
681
|
+
hasManyNumberField = true;
|
|
682
|
+
}
|
|
683
|
+
if (rowHasLocalizedManyNumberField) {
|
|
684
|
+
hasLocalizedManyNumberField = true;
|
|
685
|
+
}
|
|
574
686
|
break;
|
|
575
687
|
}
|
|
576
688
|
case 'relationship':
|
|
577
689
|
case 'upload':
|
|
578
690
|
if (Array.isArray(field.relationTo)) {
|
|
579
|
-
field.relationTo.forEach((relation)=>
|
|
580
|
-
|
|
691
|
+
field.relationTo.forEach((relation)=>{
|
|
692
|
+
relationships.add(relation);
|
|
693
|
+
if (field.unique && !disableUnique && !disableRelsTableUnique) {
|
|
694
|
+
uniqueRelationships.add(relation);
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
} else if (field.hasMany) {
|
|
581
698
|
relationships.add(field.relationTo);
|
|
699
|
+
if (field.unique && !disableUnique && !disableRelsTableUnique) {
|
|
700
|
+
uniqueRelationships.add(field.relationTo);
|
|
701
|
+
}
|
|
582
702
|
} else {
|
|
583
703
|
// simple relationships get a column on the targetTable with a foreign key to the relationTo table
|
|
584
704
|
const relationshipConfig = adapter.payload.collections[field.relationTo].config;
|
|
@@ -586,8 +706,12 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
586
706
|
// get the id type of the related collection
|
|
587
707
|
let colType = 'integer';
|
|
588
708
|
const relatedCollectionCustomID = relationshipConfig.fields.find((field)=>fieldAffectsData(field) && field.name === 'id');
|
|
589
|
-
if (relatedCollectionCustomID?.type === 'number')
|
|
590
|
-
|
|
709
|
+
if (relatedCollectionCustomID?.type === 'number') {
|
|
710
|
+
colType = 'numeric';
|
|
711
|
+
}
|
|
712
|
+
if (relatedCollectionCustomID?.type === 'text') {
|
|
713
|
+
colType = 'text';
|
|
714
|
+
}
|
|
591
715
|
// make the foreign key column for relationship using the correct id column type
|
|
592
716
|
targetTable[fieldName] = getIDColumn({
|
|
593
717
|
name: `${columnName}_id`,
|
|
@@ -599,7 +723,7 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
599
723
|
// add relationship to table
|
|
600
724
|
relationsToBuild.set(fieldName, {
|
|
601
725
|
type: 'one',
|
|
602
|
-
localized: adapter.payload.config.localization && field.localized,
|
|
726
|
+
localized: adapter.payload.config.localization && (field.localized || forceLocalized),
|
|
603
727
|
target: tableName
|
|
604
728
|
});
|
|
605
729
|
// add notNull when not required
|
|
@@ -608,7 +732,7 @@ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull,
|
|
|
608
732
|
}
|
|
609
733
|
break;
|
|
610
734
|
}
|
|
611
|
-
if (adapter.payload.config.localization
|
|
735
|
+
if (Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock) {
|
|
612
736
|
hasLocalizedRelationshipField = true;
|
|
613
737
|
}
|
|
614
738
|
break;
|