@payloadcms/drizzle 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.
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/postgres/init.d.ts.map +1 -1
- package/dist/postgres/init.js +16 -85
- package/dist/postgres/init.js.map +1 -1
- package/dist/postgres/schema/buildDrizzleTable.d.ts +7 -0
- package/dist/postgres/schema/buildDrizzleTable.d.ts.map +1 -0
- package/dist/postgres/schema/buildDrizzleTable.js +114 -0
- package/dist/postgres/schema/buildDrizzleTable.js.map +1 -0
- package/dist/postgres/schema/setColumnID.d.ts +2 -10
- package/dist/postgres/schema/setColumnID.d.ts.map +1 -1
- package/dist/postgres/schema/setColumnID.js +21 -5
- package/dist/postgres/schema/setColumnID.js.map +1 -1
- package/dist/{postgres/schema → schema}/build.d.ts +12 -7
- package/dist/schema/build.d.ts.map +1 -0
- package/dist/schema/build.js +603 -0
- package/dist/schema/build.js.map +1 -0
- package/dist/schema/buildDrizzleRelations.d.ts +5 -0
- package/dist/schema/buildDrizzleRelations.d.ts.map +1 -0
- package/dist/schema/buildDrizzleRelations.js +26 -0
- package/dist/schema/buildDrizzleRelations.js.map +1 -0
- package/dist/schema/buildRawSchema.d.ts +9 -0
- package/dist/schema/buildRawSchema.d.ts.map +1 -0
- package/dist/schema/buildRawSchema.js +97 -0
- package/dist/schema/buildRawSchema.js.map +1 -0
- package/dist/schema/idToUUID.d.ts.map +1 -0
- package/dist/schema/idToUUID.js.map +1 -0
- package/dist/{postgres/schema → schema}/traverseFields.d.ts +9 -9
- package/dist/schema/traverseFields.d.ts.map +1 -0
- package/dist/{postgres/schema → schema}/traverseFields.js +343 -174
- package/dist/schema/traverseFields.js.map +1 -0
- package/dist/schema/withDefault.d.ts +4 -0
- package/dist/schema/withDefault.d.ts.map +1 -0
- package/dist/{postgres/schema → schema}/withDefault.js +8 -5
- package/dist/schema/withDefault.js.map +1 -0
- package/dist/transform/read/traverseFields.d.ts.map +1 -1
- package/dist/transform/read/traverseFields.js +7 -0
- package/dist/transform/read/traverseFields.js.map +1 -1
- package/dist/types.d.ts +117 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/executeSchemaHooks.js +1 -1
- package/dist/utilities/executeSchemaHooks.js.map +1 -1
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts +3 -2
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts.map +1 -1
- package/dist/utilities/validateExistingBlockIsIdentical.js +2 -2
- package/dist/utilities/validateExistingBlockIsIdentical.js.map +1 -1
- package/package.json +4 -4
- package/dist/postgres/createMigration.d.ts +0 -3
- package/dist/postgres/createMigration.d.ts.map +0 -1
- package/dist/postgres/createMigration.js +0 -91
- package/dist/postgres/createMigration.js.map +0 -1
- package/dist/postgres/getMigrationTemplate.d.ts +0 -4
- package/dist/postgres/getMigrationTemplate.d.ts.map +0 -1
- package/dist/postgres/getMigrationTemplate.js +0 -13
- package/dist/postgres/getMigrationTemplate.js.map +0 -1
- package/dist/postgres/schema/build.d.ts.map +0 -1
- package/dist/postgres/schema/build.js +0 -404
- package/dist/postgres/schema/build.js.map +0 -1
- package/dist/postgres/schema/createIndex.d.ts +0 -11
- package/dist/postgres/schema/createIndex.d.ts.map +0 -1
- package/dist/postgres/schema/createIndex.js +0 -20
- package/dist/postgres/schema/createIndex.js.map +0 -1
- package/dist/postgres/schema/idToUUID.d.ts.map +0 -1
- package/dist/postgres/schema/idToUUID.js.map +0 -1
- package/dist/postgres/schema/parentIDColumnMap.d.ts +0 -4
- package/dist/postgres/schema/parentIDColumnMap.d.ts.map +0 -1
- package/dist/postgres/schema/parentIDColumnMap.js +0 -9
- package/dist/postgres/schema/parentIDColumnMap.js.map +0 -1
- package/dist/postgres/schema/traverseFields.d.ts.map +0 -1
- package/dist/postgres/schema/traverseFields.js.map +0 -1
- package/dist/postgres/schema/withDefault.d.ts +0 -4
- package/dist/postgres/schema/withDefault.d.ts.map +0 -1
- package/dist/postgres/schema/withDefault.js.map +0 -1
- /package/dist/{postgres/schema → schema}/idToUUID.d.ts +0 -0
- /package/dist/{postgres/schema → schema}/idToUUID.js +0 -0
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
import toSnakeCase from 'to-snake-case';
|
|
2
|
+
import { createTableName } from '../createTableName.js';
|
|
3
|
+
import { buildIndexName } from '../utilities/buildIndexName.js';
|
|
4
|
+
import { traverseFields } from './traverseFields.js';
|
|
5
|
+
export const buildTable = ({ adapter, baseColumns = {}, baseForeignKeys = {}, baseIndexes = {}, disableNotNull, disableRelsTableUnique = false, disableUnique = false, fields, rootRelationships, rootRelationsToBuild, rootTableIDColType, rootTableName: incomingRootTableName, rootUniqueRelationships, setColumnID, tableName, timestamps, versions, withinLocalizedArrayOrBlock })=>{
|
|
6
|
+
const isRoot = !incomingRootTableName;
|
|
7
|
+
const rootTableName = incomingRootTableName || tableName;
|
|
8
|
+
const columns = baseColumns;
|
|
9
|
+
const indexes = baseIndexes;
|
|
10
|
+
const localesColumns = {};
|
|
11
|
+
const localesIndexes = {};
|
|
12
|
+
let localesTable;
|
|
13
|
+
let textsTable;
|
|
14
|
+
let numbersTable;
|
|
15
|
+
// Relationships to the base collection
|
|
16
|
+
const relationships = rootRelationships || new Set();
|
|
17
|
+
// Unique relationships to the base collection
|
|
18
|
+
const uniqueRelationships = rootUniqueRelationships || new Set();
|
|
19
|
+
let relationshipsTable;
|
|
20
|
+
// Drizzle relations
|
|
21
|
+
const relationsToBuild = new Map();
|
|
22
|
+
const idColType = setColumnID({
|
|
23
|
+
adapter,
|
|
24
|
+
columns,
|
|
25
|
+
fields
|
|
26
|
+
});
|
|
27
|
+
const { hasLocalizedField, hasLocalizedManyNumberField, hasLocalizedManyTextField, hasLocalizedRelationshipField, hasManyNumberField, hasManyTextField } = traverseFields({
|
|
28
|
+
adapter,
|
|
29
|
+
columns,
|
|
30
|
+
disableNotNull,
|
|
31
|
+
disableRelsTableUnique,
|
|
32
|
+
disableUnique,
|
|
33
|
+
fields,
|
|
34
|
+
indexes,
|
|
35
|
+
localesColumns,
|
|
36
|
+
localesIndexes,
|
|
37
|
+
newTableName: tableName,
|
|
38
|
+
parentTableName: tableName,
|
|
39
|
+
relationships,
|
|
40
|
+
relationsToBuild,
|
|
41
|
+
rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,
|
|
42
|
+
rootTableIDColType: rootTableIDColType || idColType,
|
|
43
|
+
rootTableName,
|
|
44
|
+
setColumnID,
|
|
45
|
+
uniqueRelationships,
|
|
46
|
+
versions,
|
|
47
|
+
withinLocalizedArrayOrBlock
|
|
48
|
+
});
|
|
49
|
+
// split the relationsToBuild by localized and non-localized
|
|
50
|
+
const localizedRelations = new Map();
|
|
51
|
+
const nonLocalizedRelations = new Map();
|
|
52
|
+
relationsToBuild.forEach(({ type, localized, relationName, target }, key)=>{
|
|
53
|
+
const map = localized ? localizedRelations : nonLocalizedRelations;
|
|
54
|
+
map.set(key, {
|
|
55
|
+
type,
|
|
56
|
+
relationName,
|
|
57
|
+
target
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
if (timestamps) {
|
|
61
|
+
columns.createdAt = {
|
|
62
|
+
name: 'created_at',
|
|
63
|
+
type: 'timestamp',
|
|
64
|
+
defaultNow: true,
|
|
65
|
+
mode: 'string',
|
|
66
|
+
notNull: true,
|
|
67
|
+
precision: 3,
|
|
68
|
+
withTimezone: true
|
|
69
|
+
};
|
|
70
|
+
columns.updatedAt = {
|
|
71
|
+
name: 'updated_at',
|
|
72
|
+
type: 'timestamp',
|
|
73
|
+
defaultNow: true,
|
|
74
|
+
mode: 'string',
|
|
75
|
+
notNull: true,
|
|
76
|
+
precision: 3,
|
|
77
|
+
withTimezone: true
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const table = {
|
|
81
|
+
name: tableName,
|
|
82
|
+
columns,
|
|
83
|
+
foreignKeys: baseForeignKeys,
|
|
84
|
+
indexes
|
|
85
|
+
};
|
|
86
|
+
adapter.rawTables[tableName] = table;
|
|
87
|
+
if (hasLocalizedField || localizedRelations.size) {
|
|
88
|
+
const localeTableName = `${tableName}${adapter.localesSuffix}`;
|
|
89
|
+
localesColumns.id = {
|
|
90
|
+
name: 'id',
|
|
91
|
+
type: 'serial',
|
|
92
|
+
primaryKey: true
|
|
93
|
+
};
|
|
94
|
+
localesColumns._locale = {
|
|
95
|
+
name: '_locale',
|
|
96
|
+
type: 'enum',
|
|
97
|
+
locale: true,
|
|
98
|
+
notNull: true
|
|
99
|
+
};
|
|
100
|
+
localesColumns._parentID = {
|
|
101
|
+
name: '_parent_id',
|
|
102
|
+
type: idColType,
|
|
103
|
+
notNull: true
|
|
104
|
+
};
|
|
105
|
+
localesIndexes._localeParent = {
|
|
106
|
+
name: `${localeTableName}_locale_parent_id_unique`,
|
|
107
|
+
on: [
|
|
108
|
+
'_locale',
|
|
109
|
+
'_parentID'
|
|
110
|
+
],
|
|
111
|
+
unique: true
|
|
112
|
+
};
|
|
113
|
+
localesTable = {
|
|
114
|
+
name: localeTableName,
|
|
115
|
+
columns: localesColumns,
|
|
116
|
+
foreignKeys: {
|
|
117
|
+
_parentIdFk: {
|
|
118
|
+
name: `${localeTableName}_parent_id_fk`,
|
|
119
|
+
columns: [
|
|
120
|
+
'_parentID'
|
|
121
|
+
],
|
|
122
|
+
foreignColumns: [
|
|
123
|
+
{
|
|
124
|
+
name: 'id',
|
|
125
|
+
table: tableName
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
onDelete: 'cascade'
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
indexes: localesIndexes
|
|
132
|
+
};
|
|
133
|
+
adapter.rawTables[localeTableName] = localesTable;
|
|
134
|
+
const localeRelations = {
|
|
135
|
+
_parentID: {
|
|
136
|
+
type: 'one',
|
|
137
|
+
fields: [
|
|
138
|
+
{
|
|
139
|
+
name: '_parentID',
|
|
140
|
+
table: localeTableName
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
references: [
|
|
144
|
+
'id'
|
|
145
|
+
],
|
|
146
|
+
relationName: '_locales',
|
|
147
|
+
to: tableName
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
localizedRelations.forEach(({ type, target }, key)=>{
|
|
151
|
+
if (type === 'one') {
|
|
152
|
+
localeRelations[key] = {
|
|
153
|
+
type: 'one',
|
|
154
|
+
fields: [
|
|
155
|
+
{
|
|
156
|
+
name: key,
|
|
157
|
+
table: localeTableName
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
references: [
|
|
161
|
+
'id'
|
|
162
|
+
],
|
|
163
|
+
relationName: key,
|
|
164
|
+
to: target
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
if (type === 'many') {
|
|
168
|
+
localeRelations[key] = {
|
|
169
|
+
type: 'many',
|
|
170
|
+
relationName: key,
|
|
171
|
+
to: target
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
adapter.rawRelations[localeTableName] = localeRelations;
|
|
176
|
+
}
|
|
177
|
+
if (isRoot) {
|
|
178
|
+
if (hasManyTextField) {
|
|
179
|
+
const textsTableName = `${rootTableName}_texts`;
|
|
180
|
+
const columns = {
|
|
181
|
+
id: {
|
|
182
|
+
name: 'id',
|
|
183
|
+
type: 'serial',
|
|
184
|
+
primaryKey: true
|
|
185
|
+
},
|
|
186
|
+
order: {
|
|
187
|
+
name: 'order',
|
|
188
|
+
type: 'integer',
|
|
189
|
+
notNull: true
|
|
190
|
+
},
|
|
191
|
+
parent: {
|
|
192
|
+
name: 'parent_id',
|
|
193
|
+
type: idColType,
|
|
194
|
+
notNull: true
|
|
195
|
+
},
|
|
196
|
+
path: {
|
|
197
|
+
name: 'path',
|
|
198
|
+
type: 'varchar',
|
|
199
|
+
notNull: true
|
|
200
|
+
},
|
|
201
|
+
text: {
|
|
202
|
+
name: 'text',
|
|
203
|
+
type: 'varchar'
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
if (hasLocalizedManyTextField) {
|
|
207
|
+
columns.locale = {
|
|
208
|
+
name: 'locale',
|
|
209
|
+
type: 'enum',
|
|
210
|
+
locale: true
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const textsTableIndexes = {
|
|
214
|
+
orderParentIdx: {
|
|
215
|
+
name: `${textsTableName}_order_parent_idx`,
|
|
216
|
+
on: [
|
|
217
|
+
'order',
|
|
218
|
+
'parent'
|
|
219
|
+
]
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
if (hasManyTextField === 'index') {
|
|
223
|
+
textsTableIndexes.text_idx = {
|
|
224
|
+
name: `${textsTableName}_text_idx`,
|
|
225
|
+
on: 'text'
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
if (hasLocalizedManyTextField) {
|
|
229
|
+
textsTableIndexes.localeParent = {
|
|
230
|
+
name: `${textsTableName}_locale_parent`,
|
|
231
|
+
on: [
|
|
232
|
+
'locale',
|
|
233
|
+
'parent'
|
|
234
|
+
]
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
textsTable = {
|
|
238
|
+
name: textsTableName,
|
|
239
|
+
columns,
|
|
240
|
+
foreignKeys: {
|
|
241
|
+
parentFk: {
|
|
242
|
+
name: `${textsTableName}_parent_fk`,
|
|
243
|
+
columns: [
|
|
244
|
+
'parent'
|
|
245
|
+
],
|
|
246
|
+
foreignColumns: [
|
|
247
|
+
{
|
|
248
|
+
name: 'id',
|
|
249
|
+
table: tableName
|
|
250
|
+
}
|
|
251
|
+
],
|
|
252
|
+
onDelete: 'cascade'
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
indexes: textsTableIndexes
|
|
256
|
+
};
|
|
257
|
+
adapter.rawTables[textsTableName] = textsTable;
|
|
258
|
+
adapter.rawRelations[textsTableName] = {
|
|
259
|
+
parent: {
|
|
260
|
+
type: 'one',
|
|
261
|
+
fields: [
|
|
262
|
+
{
|
|
263
|
+
name: 'parent',
|
|
264
|
+
table: textsTableName
|
|
265
|
+
}
|
|
266
|
+
],
|
|
267
|
+
references: [
|
|
268
|
+
'id'
|
|
269
|
+
],
|
|
270
|
+
relationName: '_texts',
|
|
271
|
+
to: tableName
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
if (hasManyNumberField) {
|
|
276
|
+
const numbersTableName = `${rootTableName}_numbers`;
|
|
277
|
+
const columns = {
|
|
278
|
+
id: {
|
|
279
|
+
name: 'id',
|
|
280
|
+
type: 'serial',
|
|
281
|
+
primaryKey: true
|
|
282
|
+
},
|
|
283
|
+
number: {
|
|
284
|
+
name: 'number',
|
|
285
|
+
type: 'numeric'
|
|
286
|
+
},
|
|
287
|
+
order: {
|
|
288
|
+
name: 'order',
|
|
289
|
+
type: 'integer',
|
|
290
|
+
notNull: true
|
|
291
|
+
},
|
|
292
|
+
parent: {
|
|
293
|
+
name: 'parent_id',
|
|
294
|
+
type: idColType,
|
|
295
|
+
notNull: true
|
|
296
|
+
},
|
|
297
|
+
path: {
|
|
298
|
+
name: 'path',
|
|
299
|
+
type: 'varchar',
|
|
300
|
+
notNull: true
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
if (hasLocalizedManyNumberField) {
|
|
304
|
+
columns.locale = {
|
|
305
|
+
name: 'locale',
|
|
306
|
+
type: 'enum',
|
|
307
|
+
locale: true
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
const numbersTableIndexes = {
|
|
311
|
+
orderParentIdx: {
|
|
312
|
+
name: `${numbersTableName}_order_parent_idx`,
|
|
313
|
+
on: [
|
|
314
|
+
'order',
|
|
315
|
+
'parent'
|
|
316
|
+
]
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
if (hasManyNumberField === 'index') {
|
|
320
|
+
numbersTableIndexes.numberIdx = {
|
|
321
|
+
name: `${numbersTableName}_number_idx`,
|
|
322
|
+
on: 'number'
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
if (hasLocalizedManyNumberField) {
|
|
326
|
+
numbersTableIndexes.localeParent = {
|
|
327
|
+
name: `${numbersTableName}_locale_parent`,
|
|
328
|
+
on: [
|
|
329
|
+
'locale',
|
|
330
|
+
'parent'
|
|
331
|
+
]
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
numbersTable = {
|
|
335
|
+
name: numbersTableName,
|
|
336
|
+
columns,
|
|
337
|
+
foreignKeys: {
|
|
338
|
+
parentFk: {
|
|
339
|
+
name: `${numbersTableName}_parent_fk`,
|
|
340
|
+
columns: [
|
|
341
|
+
'parent'
|
|
342
|
+
],
|
|
343
|
+
foreignColumns: [
|
|
344
|
+
{
|
|
345
|
+
name: 'id',
|
|
346
|
+
table: tableName
|
|
347
|
+
}
|
|
348
|
+
],
|
|
349
|
+
onDelete: 'cascade'
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
indexes: numbersTableIndexes
|
|
353
|
+
};
|
|
354
|
+
adapter.rawTables[numbersTableName] = numbersTable;
|
|
355
|
+
adapter.rawRelations[numbersTableName] = {
|
|
356
|
+
parent: {
|
|
357
|
+
type: 'one',
|
|
358
|
+
fields: [
|
|
359
|
+
{
|
|
360
|
+
name: 'parent',
|
|
361
|
+
table: numbersTableName
|
|
362
|
+
}
|
|
363
|
+
],
|
|
364
|
+
references: [
|
|
365
|
+
'id'
|
|
366
|
+
],
|
|
367
|
+
relationName: '_numbers',
|
|
368
|
+
to: tableName
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
if (relationships.size) {
|
|
373
|
+
const relationshipColumns = {
|
|
374
|
+
id: {
|
|
375
|
+
name: 'id',
|
|
376
|
+
type: 'serial',
|
|
377
|
+
primaryKey: true
|
|
378
|
+
},
|
|
379
|
+
order: {
|
|
380
|
+
name: 'order',
|
|
381
|
+
type: 'integer'
|
|
382
|
+
},
|
|
383
|
+
parent: {
|
|
384
|
+
name: 'parent_id',
|
|
385
|
+
type: idColType,
|
|
386
|
+
notNull: true
|
|
387
|
+
},
|
|
388
|
+
path: {
|
|
389
|
+
name: 'path',
|
|
390
|
+
type: 'varchar',
|
|
391
|
+
notNull: true
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
if (hasLocalizedRelationshipField) {
|
|
395
|
+
relationshipColumns.locale = {
|
|
396
|
+
name: 'locale',
|
|
397
|
+
type: 'enum',
|
|
398
|
+
locale: true
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`;
|
|
402
|
+
const relationshipIndexes = {
|
|
403
|
+
order: {
|
|
404
|
+
name: `${relationshipsTableName}_order_idx`,
|
|
405
|
+
on: 'order'
|
|
406
|
+
},
|
|
407
|
+
parentIdx: {
|
|
408
|
+
name: `${relationshipsTableName}_parent_idx`,
|
|
409
|
+
on: 'parent'
|
|
410
|
+
},
|
|
411
|
+
pathIdx: {
|
|
412
|
+
name: `${relationshipsTableName}_path_idx`,
|
|
413
|
+
on: 'path'
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
if (hasLocalizedRelationshipField) {
|
|
417
|
+
relationshipIndexes.localeIdx = {
|
|
418
|
+
name: `${relationshipsTableName}_locale_idx`,
|
|
419
|
+
on: 'locale'
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
const relationshipForeignKeys = {
|
|
423
|
+
parentFk: {
|
|
424
|
+
name: `${relationshipsTableName}_parent_fk`,
|
|
425
|
+
columns: [
|
|
426
|
+
'parent'
|
|
427
|
+
],
|
|
428
|
+
foreignColumns: [
|
|
429
|
+
{
|
|
430
|
+
name: 'id',
|
|
431
|
+
table: tableName
|
|
432
|
+
}
|
|
433
|
+
],
|
|
434
|
+
onDelete: 'cascade'
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
relationships.forEach((relationTo)=>{
|
|
438
|
+
const relationshipConfig = adapter.payload.collections[relationTo].config;
|
|
439
|
+
const formattedRelationTo = createTableName({
|
|
440
|
+
adapter,
|
|
441
|
+
config: relationshipConfig,
|
|
442
|
+
throwValidationError: true
|
|
443
|
+
});
|
|
444
|
+
let colType = adapter.idType === 'uuid' ? 'uuid' : 'integer';
|
|
445
|
+
const relatedCollectionCustomIDType = adapter.payload.collections[relationshipConfig.slug]?.customIDType;
|
|
446
|
+
if (relatedCollectionCustomIDType === 'number') {
|
|
447
|
+
colType = 'numeric';
|
|
448
|
+
}
|
|
449
|
+
if (relatedCollectionCustomIDType === 'text') {
|
|
450
|
+
colType = 'varchar';
|
|
451
|
+
}
|
|
452
|
+
const colName = `${relationTo}ID`;
|
|
453
|
+
relationshipColumns[colName] = {
|
|
454
|
+
name: `${formattedRelationTo}_id`,
|
|
455
|
+
type: colType
|
|
456
|
+
};
|
|
457
|
+
relationshipForeignKeys[`${relationTo}IdFk`] = {
|
|
458
|
+
name: `${relationshipsTableName}_${toSnakeCase(relationTo)}_fk`,
|
|
459
|
+
columns: [
|
|
460
|
+
colName
|
|
461
|
+
],
|
|
462
|
+
foreignColumns: [
|
|
463
|
+
{
|
|
464
|
+
name: 'id',
|
|
465
|
+
table: formattedRelationTo
|
|
466
|
+
}
|
|
467
|
+
],
|
|
468
|
+
onDelete: 'cascade'
|
|
469
|
+
};
|
|
470
|
+
const indexColumns = [
|
|
471
|
+
colName
|
|
472
|
+
];
|
|
473
|
+
const unique = !disableUnique && uniqueRelationships.has(relationTo);
|
|
474
|
+
if (unique) {
|
|
475
|
+
indexColumns.push('path');
|
|
476
|
+
}
|
|
477
|
+
if (hasLocalizedRelationshipField) {
|
|
478
|
+
indexColumns.push('locale');
|
|
479
|
+
}
|
|
480
|
+
const indexName = buildIndexName({
|
|
481
|
+
name: `${relationshipsTableName}_${formattedRelationTo}_id`,
|
|
482
|
+
adapter
|
|
483
|
+
});
|
|
484
|
+
relationshipIndexes[indexName] = {
|
|
485
|
+
name: indexName,
|
|
486
|
+
on: indexColumns,
|
|
487
|
+
unique
|
|
488
|
+
};
|
|
489
|
+
});
|
|
490
|
+
relationshipsTable = {
|
|
491
|
+
name: relationshipsTableName,
|
|
492
|
+
columns: relationshipColumns,
|
|
493
|
+
foreignKeys: relationshipForeignKeys,
|
|
494
|
+
indexes: relationshipIndexes
|
|
495
|
+
};
|
|
496
|
+
adapter.rawTables[relationshipsTableName] = relationshipsTable;
|
|
497
|
+
const relationshipsTableRelations = {
|
|
498
|
+
parent: {
|
|
499
|
+
type: 'one',
|
|
500
|
+
fields: [
|
|
501
|
+
{
|
|
502
|
+
name: 'parent',
|
|
503
|
+
table: relationshipsTableName
|
|
504
|
+
}
|
|
505
|
+
],
|
|
506
|
+
references: [
|
|
507
|
+
'id'
|
|
508
|
+
],
|
|
509
|
+
relationName: '_rels',
|
|
510
|
+
to: tableName
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
relationships.forEach((relationTo)=>{
|
|
514
|
+
const relatedTableName = createTableName({
|
|
515
|
+
adapter,
|
|
516
|
+
config: adapter.payload.collections[relationTo].config,
|
|
517
|
+
throwValidationError: true
|
|
518
|
+
});
|
|
519
|
+
const idColumnName = `${relationTo}ID`;
|
|
520
|
+
relationshipsTableRelations[idColumnName] = {
|
|
521
|
+
type: 'one',
|
|
522
|
+
fields: [
|
|
523
|
+
{
|
|
524
|
+
name: idColumnName,
|
|
525
|
+
table: relationshipsTableName
|
|
526
|
+
}
|
|
527
|
+
],
|
|
528
|
+
references: [
|
|
529
|
+
'id'
|
|
530
|
+
],
|
|
531
|
+
relationName: relationTo,
|
|
532
|
+
to: relatedTableName
|
|
533
|
+
};
|
|
534
|
+
});
|
|
535
|
+
adapter.rawRelations[relationshipsTableName] = relationshipsTableRelations;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
const tableRelations = {};
|
|
539
|
+
nonLocalizedRelations.forEach(({ type, relationName, target }, key)=>{
|
|
540
|
+
if (type === 'one') {
|
|
541
|
+
tableRelations[key] = {
|
|
542
|
+
type: 'one',
|
|
543
|
+
fields: [
|
|
544
|
+
{
|
|
545
|
+
name: key,
|
|
546
|
+
table: tableName
|
|
547
|
+
}
|
|
548
|
+
],
|
|
549
|
+
references: [
|
|
550
|
+
'id'
|
|
551
|
+
],
|
|
552
|
+
relationName: key,
|
|
553
|
+
to: target
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
if (type === 'many') {
|
|
557
|
+
tableRelations[key] = {
|
|
558
|
+
type: 'many',
|
|
559
|
+
relationName: relationName || key,
|
|
560
|
+
to: target
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
if (hasLocalizedField) {
|
|
565
|
+
tableRelations._locales = {
|
|
566
|
+
type: 'many',
|
|
567
|
+
relationName: '_locales',
|
|
568
|
+
to: localesTable.name
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
if (isRoot && textsTable) {
|
|
572
|
+
tableRelations._texts = {
|
|
573
|
+
type: 'many',
|
|
574
|
+
relationName: '_texts',
|
|
575
|
+
to: textsTable.name
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
if (isRoot && numbersTable) {
|
|
579
|
+
tableRelations._numbers = {
|
|
580
|
+
type: 'many',
|
|
581
|
+
relationName: '_numbers',
|
|
582
|
+
to: numbersTable.name
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
if (relationships.size && relationshipsTable) {
|
|
586
|
+
tableRelations._rels = {
|
|
587
|
+
type: 'many',
|
|
588
|
+
relationName: '_rels',
|
|
589
|
+
to: relationshipsTable.name
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
adapter.rawRelations[tableName] = tableRelations;
|
|
593
|
+
return {
|
|
594
|
+
hasLocalizedManyNumberField,
|
|
595
|
+
hasLocalizedManyTextField,
|
|
596
|
+
hasLocalizedRelationshipField,
|
|
597
|
+
hasManyNumberField,
|
|
598
|
+
hasManyTextField,
|
|
599
|
+
relationsToBuild
|
|
600
|
+
};
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/schema/build.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\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 { buildIndexName } from '../utilities/buildIndexName.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 buildNumbers?: boolean\n buildRelationships?: boolean\n disableNotNull: boolean\n disableRelsTableUnique?: boolean\n disableUnique: boolean\n fields: FlattenedField[]\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 disableNotNull,\n disableRelsTableUnique = false,\n disableUnique = false,\n fields,\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 columns,\n disableNotNull,\n disableRelsTableUnique,\n disableUnique,\n fields,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: tableName,\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 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: `${localeTableName}_locale_parent_id_unique`,\n on: ['_locale', '_parentID'],\n unique: true,\n }\n\n localesTable = {\n name: localeTableName,\n columns: localesColumns,\n foreignKeys: {\n _parentIdFk: {\n name: `${localeTableName}_parent_id_fk`,\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 (isRoot) {\n if (hasManyTextField) {\n const textsTableName = `${rootTableName}_texts`\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: `${textsTableName}_order_parent_idx`,\n on: ['order', 'parent'],\n },\n }\n\n if (hasManyTextField === 'index') {\n textsTableIndexes.text_idx = {\n name: `${textsTableName}_text_idx`,\n on: 'text',\n }\n }\n\n if (hasLocalizedManyTextField) {\n textsTableIndexes.localeParent = {\n name: `${textsTableName}_locale_parent`,\n on: ['locale', 'parent'],\n }\n }\n\n textsTable = {\n name: textsTableName,\n columns,\n foreignKeys: {\n parentFk: {\n name: `${textsTableName}_parent_fk`,\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 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: { name: `${numbersTableName}_order_parent_idx`, on: ['order', 'parent'] },\n }\n\n if (hasManyNumberField === 'index') {\n numbersTableIndexes.numberIdx = {\n name: `${numbersTableName}_number_idx`,\n on: 'number',\n }\n }\n\n if (hasLocalizedManyNumberField) {\n numbersTableIndexes.localeParent = {\n name: `${numbersTableName}_locale_parent`,\n on: ['locale', 'parent'],\n }\n }\n\n numbersTable = {\n name: numbersTableName,\n columns,\n foreignKeys: {\n parentFk: {\n name: `${numbersTableName}_parent_fk`,\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: `${relationshipsTableName}_order_idx`,\n on: 'order',\n },\n parentIdx: {\n name: `${relationshipsTableName}_parent_idx`,\n on: 'parent',\n },\n pathIdx: {\n name: `${relationshipsTableName}_path_idx`,\n on: 'path',\n },\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipIndexes.localeIdx = {\n name: `${relationshipsTableName}_locale_idx`,\n on: 'locale',\n }\n }\n\n const relationshipForeignKeys: Record<string, RawForeignKey> = {\n parentFk: {\n name: `${relationshipsTableName}_parent_fk`,\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' =\n adapter.idType === 'uuid' ? 'uuid' : '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: `${relationshipsTableName}_${toSnakeCase(relationTo)}_fk`,\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":["toSnakeCase","createTableName","buildIndexName","traverseFields","buildTable","adapter","baseColumns","baseForeignKeys","baseIndexes","disableNotNull","disableRelsTableUnique","disableUnique","fields","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","on","unique","_parentIdFk","foreignColumns","onDelete","localeRelations","references","to","rawRelations","textsTableName","order","parent","path","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","push","indexName","relationshipsTableRelations","relatedTableName","idColumnName","tableRelations","_locales","_texts","_numbers","_rels"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAcvC,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,cAAc,QAAQ,sBAAqB;AA8CpD,OAAO,MAAMC,aAAa,CAAC,EACzBC,OAAO,EACPC,cAAc,CAAC,CAAC,EAChBC,kBAAkB,CAAC,CAAC,EACpBC,cAAc,CAAC,CAAC,EAChBC,cAAc,EACdC,yBAAyB,KAAK,EAC9BC,gBAAgB,KAAK,EACrBC,MAAM,EACNC,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,UAAqCnB;IAC3C,MAAMoB,UAAoClB;IAE1C,MAAMmB,iBAA4C,CAAC;IACnD,MAAMC,iBAA2C,CAAC;IAClD,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IAEJ,uCAAuC;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gF,YAAY,CAACgB,uBAAuB,GAAGwB;QACjD;IACF;IAEA,MAAMG,iBAA8C,CAAC;IAErDhF,sBAAsBC,OAAO,CAAC,CAAC,EAAEC,IAAI,EAAEE,YAAY,EAAEC,MAAM,EAAE,EAAEC;QAC7D,IAAIJ,SAAS,OAAO;YAClB8E,cAAc,CAAC1E,IAAI,GAAG;gBACpBJ,MAAM;gBACNtC,QAAQ;oBACN;wBACE8C,MAAMJ;wBACNW,OAAO7C;oBACT;iBACD;gBACD+D,YAAY;oBAAC;iBAAK;gBAClB/B,cAAcE;gBACd8B,IAAI/B;YACN;QACF;QACA,IAAIH,SAAS,QAAQ;YACnB8E,cAAc,CAAC1E,IAAI,GAAG;gBACpBJ,MAAM;gBACNE,cAAcA,gBAAgBE;gBAC9B8B,IAAI/B;YACN;QACF;IACF;IAEA,IAAId,mBAAmB;QACrByF,eAAeC,QAAQ,GAAG;YACxB/E,MAAM;YACNE,cAAc;YACdgC,IAAIvD,aAAa6B,IAAI;QACvB;IACF;IAEA,IAAIlC,UAAUM,YAAY;QACxBkG,eAAeE,MAAM,GAAG;YACtBhF,MAAM;YACNE,cAAc;YACdgC,IAAItD,WAAW4B,IAAI;QACrB;IACF;IAEA,IAAIlC,UAAUO,cAAc;QAC1BiG,eAAeG,QAAQ,GAAG;YACxBjF,MAAM;YACNE,cAAc;YACdgC,IAAIrD,aAAa2B,IAAI;QACvB;IACF;IAEA,IAAI1B,cAAcoC,IAAI,IAAIjC,oBAAoB;QAC5C6F,eAAeI,KAAK,GAAG;YACrBlF,MAAM;YACNE,cAAc;YACdgC,IAAIjD,mBAAmBuB,IAAI;QAC7B;IACF;IAEArD,QAAQgF,YAAY,CAACjE,UAAU,GAAG4G;IAElC,OAAO;QACLxF;QACAC;QACAC;QACAC;QACAC;QACAR;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildDrizzleRelations.d.ts","sourceRoot":"","sources":["../../src/schema/buildDrizzleRelations.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,eAAO,MAAM,qBAAqB,gBAAiB;IAAE,OAAO,EAAE,cAAc,CAAA;CAAE,SAiC7E,CAAA"}
|