@payloadcms/drizzle 3.0.0-canary.e14c80d → 3.0.0-canary.e198dc5

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 (284) hide show
  1. package/dist/count.d.ts.map +1 -1
  2. package/dist/count.js +1 -1
  3. package/dist/count.js.map +1 -1
  4. package/dist/createGlobalVersion.d.ts +1 -1
  5. package/dist/createGlobalVersion.d.ts.map +1 -1
  6. package/dist/createGlobalVersion.js +4 -2
  7. package/dist/createGlobalVersion.js.map +1 -1
  8. package/dist/createTableName.d.ts.map +1 -1
  9. package/dist/createTableName.js +6 -2
  10. package/dist/createTableName.js.map +1 -1
  11. package/dist/createVersion.d.ts +1 -1
  12. package/dist/createVersion.d.ts.map +1 -1
  13. package/dist/createVersion.js +22 -14
  14. package/dist/createVersion.js.map +1 -1
  15. package/dist/deleteOne.d.ts.map +1 -1
  16. package/dist/deleteOne.js +5 -3
  17. package/dist/deleteOne.js.map +1 -1
  18. package/dist/deleteVersions.js +1 -1
  19. package/dist/deleteVersions.js.map +1 -1
  20. package/dist/destroy.d.ts.map +1 -1
  21. package/dist/destroy.js +3 -1
  22. package/dist/destroy.js.map +1 -1
  23. package/dist/exports/postgres.d.ts +14 -0
  24. package/dist/exports/postgres.d.ts.map +1 -0
  25. package/dist/exports/postgres.js +15 -0
  26. package/dist/exports/postgres.js.map +1 -0
  27. package/dist/find/buildFindManyArgs.d.ts +13 -7
  28. package/dist/find/buildFindManyArgs.d.ts.map +1 -1
  29. package/dist/find/buildFindManyArgs.js +7 -1
  30. package/dist/find/buildFindManyArgs.js.map +1 -1
  31. package/dist/find/findMany.d.ts +1 -1
  32. package/dist/find/findMany.d.ts.map +1 -1
  33. package/dist/find/findMany.js +6 -3
  34. package/dist/find/findMany.js.map +1 -1
  35. package/dist/find/traverseFields.d.ts +7 -3
  36. package/dist/find/traverseFields.d.ts.map +1 -1
  37. package/dist/find/traverseFields.js +141 -16
  38. package/dist/find/traverseFields.js.map +1 -1
  39. package/dist/find.d.ts.map +1 -1
  40. package/dist/find.js +2 -1
  41. package/dist/find.js.map +1 -1
  42. package/dist/findGlobalVersions.js +1 -1
  43. package/dist/findGlobalVersions.js.map +1 -1
  44. package/dist/findMigrationDir.d.ts.map +1 -1
  45. package/dist/findMigrationDir.js +3 -1
  46. package/dist/findMigrationDir.js.map +1 -1
  47. package/dist/findOne.d.ts +1 -1
  48. package/dist/findOne.d.ts.map +1 -1
  49. package/dist/findOne.js +2 -1
  50. package/dist/findOne.js.map +1 -1
  51. package/dist/findVersions.js +1 -1
  52. package/dist/findVersions.js.map +1 -1
  53. package/dist/index.d.ts +2 -0
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +2 -0
  56. package/dist/index.js.map +1 -1
  57. package/dist/migrate.js +1 -0
  58. package/dist/migrate.js.map +1 -1
  59. package/dist/migrateDown.d.ts.map +1 -1
  60. package/dist/migrateDown.js +1 -1
  61. package/dist/migrateDown.js.map +1 -1
  62. package/dist/migrateFresh.d.ts.map +1 -1
  63. package/dist/migrateFresh.js +1 -0
  64. package/dist/migrateFresh.js.map +1 -1
  65. package/dist/migrateRefresh.d.ts.map +1 -1
  66. package/dist/migrateRefresh.js +2 -1
  67. package/dist/migrateRefresh.js.map +1 -1
  68. package/dist/migrateReset.d.ts.map +1 -1
  69. package/dist/migrateReset.js +4 -2
  70. package/dist/migrateReset.js.map +1 -1
  71. package/dist/migrateStatus.js +0 -1
  72. package/dist/migrateStatus.js.map +1 -1
  73. package/dist/postgres/countDistinct.d.ts +3 -0
  74. package/dist/postgres/countDistinct.d.ts.map +1 -0
  75. package/dist/postgres/countDistinct.js +24 -0
  76. package/dist/postgres/countDistinct.js.map +1 -0
  77. package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.d.ts +2 -0
  78. package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -0
  79. package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.js +16 -0
  80. package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.js.map +1 -0
  81. package/dist/postgres/createJSONQuery/formatJSONPathSegment.d.ts +2 -0
  82. package/dist/postgres/createJSONQuery/formatJSONPathSegment.d.ts.map +1 -0
  83. package/dist/postgres/createJSONQuery/formatJSONPathSegment.js +5 -0
  84. package/dist/postgres/createJSONQuery/formatJSONPathSegment.js.map +1 -0
  85. package/dist/postgres/createJSONQuery/index.d.ts +10 -0
  86. package/dist/postgres/createJSONQuery/index.d.ts.map +1 -0
  87. package/dist/postgres/createJSONQuery/index.js +54 -0
  88. package/dist/postgres/createJSONQuery/index.js.map +1 -0
  89. package/dist/postgres/createMigration.d.ts +3 -0
  90. package/dist/postgres/createMigration.d.ts.map +1 -0
  91. package/dist/postgres/createMigration.js +92 -0
  92. package/dist/postgres/createMigration.js.map +1 -0
  93. package/dist/postgres/defaultSnapshot.d.ts +3 -0
  94. package/dist/postgres/defaultSnapshot.d.ts.map +1 -0
  95. package/dist/postgres/defaultSnapshot.js +17 -0
  96. package/dist/postgres/defaultSnapshot.js.map +1 -0
  97. package/dist/postgres/deleteWhere.d.ts +3 -0
  98. package/dist/postgres/deleteWhere.d.ts.map +1 -0
  99. package/dist/postgres/deleteWhere.js +6 -0
  100. package/dist/postgres/deleteWhere.js.map +1 -0
  101. package/dist/postgres/dropDatabase.d.ts +3 -0
  102. package/dist/postgres/dropDatabase.d.ts.map +1 -0
  103. package/dist/postgres/dropDatabase.js +9 -0
  104. package/dist/postgres/dropDatabase.js.map +1 -0
  105. package/dist/postgres/execute.d.ts +3 -0
  106. package/dist/postgres/execute.d.ts.map +1 -0
  107. package/dist/postgres/execute.js +11 -0
  108. package/dist/postgres/execute.js.map +1 -0
  109. package/dist/postgres/getMigrationTemplate.d.ts +4 -0
  110. package/dist/postgres/getMigrationTemplate.d.ts.map +1 -0
  111. package/dist/postgres/getMigrationTemplate.js +13 -0
  112. package/dist/postgres/getMigrationTemplate.js.map +1 -0
  113. package/dist/postgres/init.d.ts +3 -0
  114. package/dist/postgres/init.d.ts.map +1 -0
  115. package/dist/postgres/init.js +105 -0
  116. package/dist/postgres/init.js.map +1 -0
  117. package/dist/postgres/insert.d.ts +3 -0
  118. package/dist/postgres/insert.d.ts.map +1 -0
  119. package/dist/postgres/insert.js +12 -0
  120. package/dist/postgres/insert.js.map +1 -0
  121. package/dist/postgres/requireDrizzleKit.d.ts +3 -0
  122. package/dist/postgres/requireDrizzleKit.d.ts.map +1 -0
  123. package/dist/postgres/requireDrizzleKit.js +5 -0
  124. package/dist/postgres/requireDrizzleKit.js.map +1 -0
  125. package/dist/postgres/schema/build.d.ts +41 -0
  126. package/dist/postgres/schema/build.d.ts.map +1 -0
  127. package/dist/postgres/schema/build.js +379 -0
  128. package/dist/postgres/schema/build.js.map +1 -0
  129. package/dist/postgres/schema/createIndex.d.ts +12 -0
  130. package/dist/postgres/schema/createIndex.d.ts.map +1 -0
  131. package/dist/postgres/schema/createIndex.js +20 -0
  132. package/dist/postgres/schema/createIndex.js.map +1 -0
  133. package/dist/postgres/schema/idToUUID.d.ts +3 -0
  134. package/dist/postgres/schema/idToUUID.d.ts.map +1 -0
  135. package/dist/postgres/schema/idToUUID.js +11 -0
  136. package/dist/postgres/schema/idToUUID.js.map +1 -0
  137. package/dist/postgres/schema/parentIDColumnMap.d.ts +4 -0
  138. package/dist/postgres/schema/parentIDColumnMap.d.ts.map +1 -0
  139. package/dist/postgres/schema/parentIDColumnMap.js +9 -0
  140. package/dist/postgres/schema/parentIDColumnMap.js.map +1 -0
  141. package/dist/postgres/schema/setColumnID.d.ts +11 -0
  142. package/dist/postgres/schema/setColumnID.d.ts.map +1 -0
  143. package/dist/postgres/schema/setColumnID.js +24 -0
  144. package/dist/postgres/schema/setColumnID.js.map +1 -0
  145. package/dist/postgres/schema/traverseFields.d.ts +41 -0
  146. package/dist/postgres/schema/traverseFields.d.ts.map +1 -0
  147. package/dist/postgres/schema/traverseFields.js +744 -0
  148. package/dist/postgres/schema/traverseFields.js.map +1 -0
  149. package/dist/postgres/schema/withDefault.d.ts +4 -0
  150. package/dist/postgres/schema/withDefault.d.ts.map +1 -0
  151. package/dist/postgres/schema/withDefault.js +12 -0
  152. package/dist/postgres/schema/withDefault.js.map +1 -0
  153. package/dist/postgres/types.d.ts +126 -0
  154. package/dist/postgres/types.d.ts.map +1 -0
  155. package/dist/postgres/types.js +3 -0
  156. package/dist/postgres/types.js.map +1 -0
  157. package/dist/queries/buildAndOrConditions.d.ts +1 -1
  158. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  159. package/dist/queries/buildAndOrConditions.js +2 -4
  160. package/dist/queries/buildAndOrConditions.js.map +1 -1
  161. package/dist/queries/buildOrderBy.d.ts +18 -0
  162. package/dist/queries/buildOrderBy.d.ts.map +1 -0
  163. package/dist/queries/buildOrderBy.js +52 -0
  164. package/dist/queries/buildOrderBy.js.map +1 -0
  165. package/dist/queries/buildQuery.d.ts +5 -4
  166. package/dist/queries/buildQuery.d.ts.map +1 -1
  167. package/dist/queries/buildQuery.js +12 -47
  168. package/dist/queries/buildQuery.js.map +1 -1
  169. package/dist/queries/getTableColumnFromPath.d.ts +8 -3
  170. package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
  171. package/dist/queries/getTableColumnFromPath.js +73 -23
  172. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  173. package/dist/queries/operatorMap.d.ts.map +1 -1
  174. package/dist/queries/operatorMap.js.map +1 -1
  175. package/dist/queries/parseParams.d.ts +1 -1
  176. package/dist/queries/parseParams.d.ts.map +1 -1
  177. package/dist/queries/parseParams.js +52 -6
  178. package/dist/queries/parseParams.js.map +1 -1
  179. package/dist/queries/sanitizeQueryValue.d.ts +12 -1
  180. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  181. package/dist/queries/sanitizeQueryValue.js +77 -21
  182. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  183. package/dist/queries/selectDistinct.d.ts +3 -4
  184. package/dist/queries/selectDistinct.d.ts.map +1 -1
  185. package/dist/queries/selectDistinct.js.map +1 -1
  186. package/dist/queryDrafts.d.ts.map +1 -1
  187. package/dist/queryDrafts.js +1 -2
  188. package/dist/queryDrafts.js.map +1 -1
  189. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  190. package/dist/transactions/beginTransaction.js +5 -1
  191. package/dist/transactions/beginTransaction.js.map +1 -1
  192. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  193. package/dist/transactions/commitTransaction.js +3 -1
  194. package/dist/transactions/commitTransaction.js.map +1 -1
  195. package/dist/transform/read/hasManyNumber.d.ts +2 -1
  196. package/dist/transform/read/hasManyNumber.d.ts.map +1 -1
  197. package/dist/transform/read/hasManyNumber.js +12 -2
  198. package/dist/transform/read/hasManyNumber.js.map +1 -1
  199. package/dist/transform/read/hasManyText.d.ts +2 -1
  200. package/dist/transform/read/hasManyText.d.ts.map +1 -1
  201. package/dist/transform/read/hasManyText.js +12 -2
  202. package/dist/transform/read/hasManyText.js.map +1 -1
  203. package/dist/transform/read/index.d.ts +3 -2
  204. package/dist/transform/read/index.d.ts.map +1 -1
  205. package/dist/transform/read/index.js +3 -2
  206. package/dist/transform/read/index.js.map +1 -1
  207. package/dist/transform/read/relationship.d.ts +2 -1
  208. package/dist/transform/read/relationship.d.ts.map +1 -1
  209. package/dist/transform/read/relationship.js +15 -6
  210. package/dist/transform/read/relationship.js.map +1 -1
  211. package/dist/transform/read/traverseFields.d.ts +10 -2
  212. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  213. package/dist/transform/read/traverseFields.js +170 -56
  214. package/dist/transform/read/traverseFields.js.map +1 -1
  215. package/dist/transform/write/array.d.ts +6 -1
  216. package/dist/transform/write/array.d.ts.map +1 -1
  217. package/dist/transform/write/array.js +7 -3
  218. package/dist/transform/write/array.js.map +1 -1
  219. package/dist/transform/write/blocks.d.ts +8 -3
  220. package/dist/transform/write/blocks.d.ts.map +1 -1
  221. package/dist/transform/write/blocks.js +19 -7
  222. package/dist/transform/write/blocks.js.map +1 -1
  223. package/dist/transform/write/index.d.ts.map +1 -1
  224. package/dist/transform/write/index.js +1 -1
  225. package/dist/transform/write/index.js.map +1 -1
  226. package/dist/transform/write/relationships.d.ts.map +1 -1
  227. package/dist/transform/write/relationships.js +6 -2
  228. package/dist/transform/write/relationships.js.map +1 -1
  229. package/dist/transform/write/selects.d.ts.map +1 -1
  230. package/dist/transform/write/selects.js +1 -1
  231. package/dist/transform/write/selects.js.map +1 -1
  232. package/dist/transform/write/traverseFields.d.ts +6 -1
  233. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  234. package/dist/transform/write/traverseFields.js +46 -17
  235. package/dist/transform/write/traverseFields.js.map +1 -1
  236. package/dist/types.d.ts +1 -1
  237. package/dist/types.d.ts.map +1 -1
  238. package/dist/types.js.map +1 -1
  239. package/dist/update.d.ts.map +1 -1
  240. package/dist/update.js +3 -2
  241. package/dist/update.js.map +1 -1
  242. package/dist/updateGlobalVersion.js +2 -2
  243. package/dist/updateGlobalVersion.js.map +1 -1
  244. package/dist/updateVersion.js +2 -2
  245. package/dist/updateVersion.js.map +1 -1
  246. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
  247. package/dist/upsertRow/deleteExistingRowsByPath.js +6 -2
  248. package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
  249. package/dist/upsertRow/index.d.ts +1 -1
  250. package/dist/upsertRow/index.d.ts.map +1 -1
  251. package/dist/upsertRow/index.js +50 -12
  252. package/dist/upsertRow/index.js.map +1 -1
  253. package/dist/upsertRow/insertArrays.d.ts.map +1 -1
  254. package/dist/upsertRow/insertArrays.js +5 -2
  255. package/dist/upsertRow/insertArrays.js.map +1 -1
  256. package/dist/upsertRow/types.d.ts +8 -5
  257. package/dist/upsertRow/types.d.ts.map +1 -1
  258. package/dist/upsertRow/types.js.map +1 -1
  259. package/dist/utilities/createBlocksMap.d.ts.map +1 -1
  260. package/dist/utilities/createBlocksMap.js +4 -2
  261. package/dist/utilities/createBlocksMap.js.map +1 -1
  262. package/dist/utilities/createRelationshipMap.d.ts.map +1 -1
  263. package/dist/utilities/createRelationshipMap.js +3 -1
  264. package/dist/utilities/createRelationshipMap.js.map +1 -1
  265. package/dist/utilities/executeSchemaHooks.d.ts +24 -0
  266. package/dist/utilities/executeSchemaHooks.d.ts.map +1 -0
  267. package/dist/utilities/executeSchemaHooks.js +21 -0
  268. package/dist/utilities/executeSchemaHooks.js.map +1 -0
  269. package/dist/utilities/extendDrizzleTable.d.ts +19 -0
  270. package/dist/utilities/extendDrizzleTable.d.ts.map +1 -0
  271. package/dist/utilities/extendDrizzleTable.js +38 -0
  272. package/dist/utilities/extendDrizzleTable.js.map +1 -0
  273. package/dist/utilities/getCollectionIdType.d.ts +7 -0
  274. package/dist/utilities/getCollectionIdType.d.ts.map +1 -0
  275. package/dist/utilities/getCollectionIdType.js +11 -0
  276. package/dist/utilities/getCollectionIdType.js.map +1 -0
  277. package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
  278. package/dist/utilities/hasLocalesTable.js +12 -4
  279. package/dist/utilities/hasLocalesTable.js.map +1 -1
  280. package/dist/utilities/isPolymorphicRelationship.d.ts +6 -0
  281. package/dist/utilities/isPolymorphicRelationship.d.ts.map +1 -0
  282. package/dist/utilities/isPolymorphicRelationship.js +5 -0
  283. package/dist/utilities/isPolymorphicRelationship.js.map +1 -0
  284. package/package.json +14 -7
@@ -0,0 +1,744 @@
1
+ import { relations } from 'drizzle-orm';
2
+ import { boolean, foreignKey, index, integer, jsonb, numeric, PgNumericBuilder, PgUUIDBuilder, PgVarcharBuilder, text, timestamp, varchar } from 'drizzle-orm/pg-core';
3
+ import { InvalidConfiguration } from 'payload';
4
+ import { fieldAffectsData, fieldIsVirtual, optionIsObject } from 'payload/shared';
5
+ import toSnakeCase from 'to-snake-case';
6
+ import { createTableName } from '../../createTableName.js';
7
+ import { hasLocalesTable } from '../../utilities/hasLocalesTable.js';
8
+ import { validateExistingBlockIsIdentical } from '../../utilities/validateExistingBlockIsIdentical.js';
9
+ import { buildTable } from './build.js';
10
+ import { createIndex } from './createIndex.js';
11
+ import { idToUUID } from './idToUUID.js';
12
+ import { parentIDColumnMap } from './parentIDColumnMap.js';
13
+ import { withDefault } from './withDefault.js';
14
+ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull, disableUnique = false, fieldPrefix, fields, forceLocalized, indexes, joins, localesColumns, localesIndexes, newTableName, parentTableName, relationships, relationsToBuild, rootRelationsToBuild, rootTableIDColType, rootTableName, versions, withinLocalizedArrayOrBlock })=>{
15
+ const throwValidationError = true;
16
+ let hasLocalizedField = false;
17
+ let hasLocalizedRelationshipField = false;
18
+ let hasManyTextField = false;
19
+ let hasLocalizedManyTextField = false;
20
+ let hasManyNumberField = false;
21
+ let hasLocalizedManyNumberField = false;
22
+ let parentIDColType = 'integer';
23
+ if (columns.id instanceof PgUUIDBuilder) {
24
+ parentIDColType = 'uuid';
25
+ }
26
+ if (columns.id instanceof PgNumericBuilder) {
27
+ parentIDColType = 'numeric';
28
+ }
29
+ if (columns.id instanceof PgVarcharBuilder) {
30
+ parentIDColType = 'varchar';
31
+ }
32
+ fields.forEach((field)=>{
33
+ if ('name' in field && field.name === 'id') {
34
+ return;
35
+ }
36
+ if (fieldIsVirtual(field)) {
37
+ return;
38
+ }
39
+ let columnName;
40
+ let fieldName;
41
+ let targetTable = columns;
42
+ let targetIndexes = indexes;
43
+ if (fieldAffectsData(field)) {
44
+ columnName = `${columnPrefix || ''}${field.name[0] === '_' ? '_' : ''}${toSnakeCase(field.name)}`;
45
+ fieldName = `${fieldPrefix?.replace('.', '_') || ''}${field.name}`;
46
+ // If field is localized,
47
+ // add the column to the locale table instead of main table
48
+ if (adapter.payload.config.localization && (field.localized || forceLocalized) && field.type !== 'array' && field.type !== 'blocks' && ('hasMany' in field && field.hasMany !== true || !('hasMany' in field))) {
49
+ hasLocalizedField = true;
50
+ targetTable = localesColumns;
51
+ targetIndexes = localesIndexes;
52
+ }
53
+ if ((field.unique || field.index) && ![
54
+ 'array',
55
+ 'blocks',
56
+ 'group',
57
+ 'point',
58
+ 'relationship',
59
+ 'upload'
60
+ ].includes(field.type) && !('hasMany' in field && field.hasMany === true)) {
61
+ const unique = disableUnique !== true && field.unique;
62
+ if (unique) {
63
+ const constraintValue = `${fieldPrefix || ''}${field.name}`;
64
+ if (!adapter.fieldConstraints?.[rootTableName]) {
65
+ adapter.fieldConstraints[rootTableName] = {};
66
+ }
67
+ adapter.fieldConstraints[rootTableName][`${columnName}_idx`] = constraintValue;
68
+ }
69
+ targetIndexes[`${newTableName}_${field.name}Idx`] = createIndex({
70
+ name: field.localized ? [
71
+ fieldName,
72
+ '_locale'
73
+ ] : fieldName,
74
+ columnName,
75
+ tableName: newTableName,
76
+ unique
77
+ });
78
+ }
79
+ }
80
+ switch(field.type){
81
+ case 'text':
82
+ {
83
+ if (field.hasMany) {
84
+ const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
85
+ if (isLocalized) {
86
+ hasLocalizedManyTextField = true;
87
+ }
88
+ if (field.index) {
89
+ hasManyTextField = 'index';
90
+ } else if (!hasManyTextField) {
91
+ hasManyTextField = true;
92
+ }
93
+ if (field.unique) {
94
+ throw new InvalidConfiguration('Unique is not supported in Postgres for hasMany text fields.');
95
+ }
96
+ } else {
97
+ targetTable[fieldName] = withDefault(varchar(columnName), field);
98
+ }
99
+ break;
100
+ }
101
+ case 'email':
102
+ case 'code':
103
+ case 'textarea':
104
+ {
105
+ targetTable[fieldName] = withDefault(varchar(columnName), field);
106
+ break;
107
+ }
108
+ case 'number':
109
+ {
110
+ if (field.hasMany) {
111
+ const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
112
+ if (isLocalized) {
113
+ hasLocalizedManyNumberField = true;
114
+ }
115
+ if (field.index) {
116
+ hasManyNumberField = 'index';
117
+ } else if (!hasManyNumberField) {
118
+ hasManyNumberField = true;
119
+ }
120
+ if (field.unique) {
121
+ throw new InvalidConfiguration('Unique is not supported in Postgres for hasMany number fields.');
122
+ }
123
+ } else {
124
+ targetTable[fieldName] = withDefault(numeric(columnName), field);
125
+ }
126
+ break;
127
+ }
128
+ case 'richText':
129
+ case 'json':
130
+ {
131
+ targetTable[fieldName] = withDefault(jsonb(columnName), field);
132
+ break;
133
+ }
134
+ case 'date':
135
+ {
136
+ targetTable[fieldName] = withDefault(timestamp(columnName, {
137
+ mode: 'string',
138
+ precision: 3,
139
+ withTimezone: true
140
+ }), field);
141
+ break;
142
+ }
143
+ case 'point':
144
+ {
145
+ break;
146
+ }
147
+ case 'radio':
148
+ case 'select':
149
+ {
150
+ const enumName = createTableName({
151
+ adapter,
152
+ config: field,
153
+ parentTableName: newTableName,
154
+ prefix: `enum_${newTableName}_`,
155
+ target: 'enumName',
156
+ throwValidationError
157
+ });
158
+ adapter.enums[enumName] = adapter.pgSchema.enum(enumName, field.options.map((option)=>{
159
+ if (optionIsObject(option)) {
160
+ return option.value;
161
+ }
162
+ return option;
163
+ }));
164
+ if (field.type === 'select' && field.hasMany) {
165
+ const selectTableName = createTableName({
166
+ adapter,
167
+ config: field,
168
+ parentTableName: newTableName,
169
+ prefix: `${newTableName}_`,
170
+ throwValidationError,
171
+ versionsCustomName: versions
172
+ });
173
+ const baseColumns = {
174
+ order: integer('order').notNull(),
175
+ parent: parentIDColumnMap[parentIDColType]('parent_id').notNull(),
176
+ value: adapter.enums[enumName]('value')
177
+ };
178
+ const baseExtraConfig = {
179
+ orderIdx: (cols)=>index(`${selectTableName}_order_idx`).on(cols.order),
180
+ parentFk: (cols)=>foreignKey({
181
+ name: `${selectTableName}_parent_fk`,
182
+ columns: [
183
+ cols.parent
184
+ ],
185
+ foreignColumns: [
186
+ adapter.tables[parentTableName].id
187
+ ]
188
+ }).onDelete('cascade'),
189
+ parentIdx: (cols)=>index(`${selectTableName}_parent_idx`).on(cols.parent)
190
+ };
191
+ const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
192
+ if (isLocalized) {
193
+ baseColumns.locale = adapter.enums.enum__locales('locale').notNull();
194
+ baseExtraConfig.localeIdx = (cols)=>index(`${selectTableName}_locale_idx`).on(cols.locale);
195
+ }
196
+ if (field.index) {
197
+ baseExtraConfig.value = (cols)=>index(`${selectTableName}_value_idx`).on(cols.value);
198
+ }
199
+ buildTable({
200
+ adapter,
201
+ baseColumns,
202
+ baseExtraConfig,
203
+ disableNotNull,
204
+ disableUnique,
205
+ fields: [],
206
+ rootTableName,
207
+ tableName: selectTableName,
208
+ versions
209
+ });
210
+ relationsToBuild.set(fieldName, {
211
+ type: 'many',
212
+ // selects have their own localized table, independent of the base table.
213
+ localized: false,
214
+ target: selectTableName
215
+ });
216
+ adapter.relations[`relations_${selectTableName}`] = relations(adapter.tables[selectTableName], ({ one })=>({
217
+ parent: one(adapter.tables[parentTableName], {
218
+ fields: [
219
+ adapter.tables[selectTableName].parent
220
+ ],
221
+ references: [
222
+ adapter.tables[parentTableName].id
223
+ ],
224
+ relationName: fieldName
225
+ })
226
+ }));
227
+ } else {
228
+ targetTable[fieldName] = withDefault(adapter.enums[enumName](columnName), field);
229
+ }
230
+ break;
231
+ }
232
+ case 'checkbox':
233
+ {
234
+ targetTable[fieldName] = withDefault(boolean(columnName), field);
235
+ break;
236
+ }
237
+ case 'array':
238
+ {
239
+ const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
240
+ const arrayTableName = createTableName({
241
+ adapter,
242
+ config: field,
243
+ parentTableName: newTableName,
244
+ prefix: `${newTableName}_`,
245
+ throwValidationError,
246
+ versionsCustomName: versions
247
+ });
248
+ const baseColumns = {
249
+ _order: integer('_order').notNull(),
250
+ _parentID: parentIDColumnMap[parentIDColType]('_parent_id').notNull()
251
+ };
252
+ const baseExtraConfig = {
253
+ _orderIdx: (cols)=>index(`${arrayTableName}_order_idx`).on(cols._order),
254
+ _parentIDFk: (cols)=>foreignKey({
255
+ name: `${arrayTableName}_parent_id_fk`,
256
+ columns: [
257
+ cols['_parentID']
258
+ ],
259
+ foreignColumns: [
260
+ adapter.tables[parentTableName].id
261
+ ]
262
+ }).onDelete('cascade'),
263
+ _parentIDIdx: (cols)=>index(`${arrayTableName}_parent_id_idx`).on(cols._parentID)
264
+ };
265
+ const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
266
+ if (isLocalized) {
267
+ baseColumns._locale = adapter.enums.enum__locales('_locale').notNull();
268
+ baseExtraConfig._localeIdx = (cols)=>index(`${arrayTableName}_locale_idx`).on(cols._locale);
269
+ }
270
+ const { hasLocalizedManyNumberField: subHasLocalizedManyNumberField, hasLocalizedManyTextField: subHasLocalizedManyTextField, hasLocalizedRelationshipField: subHasLocalizedRelationshipField, hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
271
+ adapter,
272
+ baseColumns,
273
+ baseExtraConfig,
274
+ disableNotNull: disableNotNullFromHere,
275
+ disableUnique,
276
+ fields: disableUnique ? idToUUID(field.fields) : field.fields,
277
+ rootRelationships: relationships,
278
+ rootRelationsToBuild,
279
+ rootTableIDColType,
280
+ rootTableName,
281
+ tableName: arrayTableName,
282
+ versions,
283
+ withinLocalizedArrayOrBlock: isLocalized
284
+ });
285
+ if (subHasLocalizedManyNumberField) {
286
+ hasLocalizedManyNumberField = subHasLocalizedManyNumberField;
287
+ }
288
+ if (subHasLocalizedRelationshipField) {
289
+ hasLocalizedRelationshipField = subHasLocalizedRelationshipField;
290
+ }
291
+ if (subHasLocalizedManyTextField) {
292
+ hasLocalizedManyTextField = subHasLocalizedManyTextField;
293
+ }
294
+ if (subHasManyTextField) {
295
+ if (!hasManyTextField || subHasManyTextField === 'index') {
296
+ hasManyTextField = subHasManyTextField;
297
+ }
298
+ }
299
+ if (subHasManyNumberField) {
300
+ if (!hasManyNumberField || subHasManyNumberField === 'index') {
301
+ hasManyNumberField = subHasManyNumberField;
302
+ }
303
+ }
304
+ relationsToBuild.set(fieldName, {
305
+ type: 'many',
306
+ // arrays have their own localized table, independent of the base table.
307
+ localized: false,
308
+ target: arrayTableName
309
+ });
310
+ adapter.relations[`relations_${arrayTableName}`] = relations(adapter.tables[arrayTableName], ({ many, one })=>{
311
+ const result = {
312
+ _parentID: one(adapter.tables[parentTableName], {
313
+ fields: [
314
+ adapter.tables[arrayTableName]._parentID
315
+ ],
316
+ references: [
317
+ adapter.tables[parentTableName].id
318
+ ],
319
+ relationName: fieldName
320
+ })
321
+ };
322
+ if (hasLocalesTable(field.fields)) {
323
+ result._locales = many(adapter.tables[`${arrayTableName}${adapter.localesSuffix}`], {
324
+ relationName: '_locales'
325
+ });
326
+ }
327
+ subRelationsToBuild.forEach(({ type, localized, target }, key)=>{
328
+ if (type === 'one') {
329
+ const arrayWithLocalized = localized ? `${arrayTableName}${adapter.localesSuffix}` : arrayTableName;
330
+ result[key] = one(adapter.tables[target], {
331
+ fields: [
332
+ adapter.tables[arrayWithLocalized][key]
333
+ ],
334
+ references: [
335
+ adapter.tables[target].id
336
+ ],
337
+ relationName: key
338
+ });
339
+ }
340
+ if (type === 'many') {
341
+ result[key] = many(adapter.tables[target], {
342
+ relationName: key
343
+ });
344
+ }
345
+ });
346
+ return result;
347
+ });
348
+ break;
349
+ }
350
+ case 'blocks':
351
+ {
352
+ const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
353
+ field.blocks.forEach((block)=>{
354
+ const blockTableName = createTableName({
355
+ adapter,
356
+ config: block,
357
+ parentTableName: rootTableName,
358
+ prefix: `${rootTableName}_blocks_`,
359
+ throwValidationError,
360
+ versionsCustomName: versions
361
+ });
362
+ if (!adapter.tables[blockTableName]) {
363
+ const baseColumns = {
364
+ _order: integer('_order').notNull(),
365
+ _parentID: parentIDColumnMap[rootTableIDColType]('_parent_id').notNull(),
366
+ _path: text('_path').notNull()
367
+ };
368
+ const baseExtraConfig = {
369
+ _orderIdx: (cols)=>index(`${blockTableName}_order_idx`).on(cols._order),
370
+ _parentIdFk: (cols)=>foreignKey({
371
+ name: `${blockTableName}_parent_id_fk`,
372
+ columns: [
373
+ cols._parentID
374
+ ],
375
+ foreignColumns: [
376
+ adapter.tables[rootTableName].id
377
+ ]
378
+ }).onDelete('cascade'),
379
+ _parentIDIdx: (cols)=>index(`${blockTableName}_parent_id_idx`).on(cols._parentID),
380
+ _pathIdx: (cols)=>index(`${blockTableName}_path_idx`).on(cols._path)
381
+ };
382
+ const isLocalized = Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
383
+ if (isLocalized) {
384
+ baseColumns._locale = adapter.enums.enum__locales('_locale').notNull();
385
+ baseExtraConfig._localeIdx = (cols)=>index(`${blockTableName}_locale_idx`).on(cols._locale);
386
+ }
387
+ const { hasLocalizedManyNumberField: subHasLocalizedManyNumberField, hasLocalizedManyTextField: subHasLocalizedManyTextField, hasLocalizedRelationshipField: subHasLocalizedRelationshipField, hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
388
+ adapter,
389
+ baseColumns,
390
+ baseExtraConfig,
391
+ disableNotNull: disableNotNullFromHere,
392
+ disableUnique,
393
+ fields: disableUnique ? idToUUID(block.fields) : block.fields,
394
+ rootRelationships: relationships,
395
+ rootRelationsToBuild,
396
+ rootTableIDColType,
397
+ rootTableName,
398
+ tableName: blockTableName,
399
+ versions,
400
+ withinLocalizedArrayOrBlock: isLocalized
401
+ });
402
+ if (subHasLocalizedManyNumberField) {
403
+ hasLocalizedManyNumberField = subHasLocalizedManyNumberField;
404
+ }
405
+ if (subHasLocalizedRelationshipField) {
406
+ hasLocalizedRelationshipField = subHasLocalizedRelationshipField;
407
+ }
408
+ if (subHasLocalizedManyTextField) {
409
+ hasLocalizedManyTextField = subHasLocalizedManyTextField;
410
+ }
411
+ if (subHasManyTextField) {
412
+ if (!hasManyTextField || subHasManyTextField === 'index') {
413
+ hasManyTextField = subHasManyTextField;
414
+ }
415
+ }
416
+ if (subHasManyNumberField) {
417
+ if (!hasManyNumberField || subHasManyNumberField === 'index') {
418
+ hasManyNumberField = subHasManyNumberField;
419
+ }
420
+ }
421
+ adapter.relations[`relations_${blockTableName}`] = relations(adapter.tables[blockTableName], ({ many, one })=>{
422
+ const result = {
423
+ _parentID: one(adapter.tables[rootTableName], {
424
+ fields: [
425
+ adapter.tables[blockTableName]._parentID
426
+ ],
427
+ references: [
428
+ adapter.tables[rootTableName].id
429
+ ],
430
+ relationName: `_blocks_${block.slug}`
431
+ })
432
+ };
433
+ if (hasLocalesTable(block.fields)) {
434
+ result._locales = many(adapter.tables[`${blockTableName}${adapter.localesSuffix}`], {
435
+ relationName: '_locales'
436
+ });
437
+ }
438
+ subRelationsToBuild.forEach(({ type, localized, target }, key)=>{
439
+ if (type === 'one') {
440
+ const blockWithLocalized = localized ? `${blockTableName}${adapter.localesSuffix}` : blockTableName;
441
+ result[key] = one(adapter.tables[target], {
442
+ fields: [
443
+ adapter.tables[blockWithLocalized][key]
444
+ ],
445
+ references: [
446
+ adapter.tables[target].id
447
+ ],
448
+ relationName: key
449
+ });
450
+ }
451
+ if (type === 'many') {
452
+ result[key] = many(adapter.tables[target], {
453
+ relationName: key
454
+ });
455
+ }
456
+ });
457
+ return result;
458
+ });
459
+ } else if (process.env.NODE_ENV !== 'production' && !versions) {
460
+ validateExistingBlockIsIdentical({
461
+ block,
462
+ localized: field.localized,
463
+ rootTableName,
464
+ table: adapter.tables[blockTableName],
465
+ tableLocales: adapter.tables[`${blockTableName}${adapter.localesSuffix}`]
466
+ });
467
+ }
468
+ // blocks relationships are defined from the collection or globals table down to the block, bypassing any subBlocks
469
+ rootRelationsToBuild.set(`_blocks_${block.slug}`, {
470
+ type: 'many',
471
+ // blocks are not localized on the parent table
472
+ localized: false,
473
+ target: blockTableName
474
+ });
475
+ });
476
+ break;
477
+ }
478
+ case 'tab':
479
+ case 'group':
480
+ {
481
+ if (!('name' in field)) {
482
+ const { hasLocalizedField: groupHasLocalizedField, hasLocalizedManyNumberField: groupHasLocalizedManyNumberField, hasLocalizedManyTextField: groupHasLocalizedManyTextField, hasLocalizedRelationshipField: groupHasLocalizedRelationshipField, hasManyNumberField: groupHasManyNumberField, hasManyTextField: groupHasManyTextField } = traverseFields({
483
+ adapter,
484
+ columnPrefix,
485
+ columns,
486
+ disableNotNull,
487
+ disableUnique,
488
+ fieldPrefix,
489
+ fields: field.fields,
490
+ forceLocalized,
491
+ indexes,
492
+ joins,
493
+ localesColumns,
494
+ localesIndexes,
495
+ newTableName,
496
+ parentTableName,
497
+ relationships,
498
+ relationsToBuild,
499
+ rootRelationsToBuild,
500
+ rootTableIDColType,
501
+ rootTableName,
502
+ versions,
503
+ withinLocalizedArrayOrBlock
504
+ });
505
+ if (groupHasLocalizedField) {
506
+ hasLocalizedField = true;
507
+ }
508
+ if (groupHasLocalizedRelationshipField) {
509
+ hasLocalizedRelationshipField = true;
510
+ }
511
+ if (groupHasManyTextField) {
512
+ hasManyTextField = true;
513
+ }
514
+ if (groupHasLocalizedManyTextField) {
515
+ hasLocalizedManyTextField = true;
516
+ }
517
+ if (groupHasManyNumberField) {
518
+ hasManyNumberField = true;
519
+ }
520
+ if (groupHasLocalizedManyNumberField) {
521
+ hasLocalizedManyNumberField = true;
522
+ }
523
+ break;
524
+ }
525
+ const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
526
+ const { hasLocalizedField: groupHasLocalizedField, hasLocalizedManyNumberField: groupHasLocalizedManyNumberField, hasLocalizedManyTextField: groupHasLocalizedManyTextField, hasLocalizedRelationshipField: groupHasLocalizedRelationshipField, hasManyNumberField: groupHasManyNumberField, hasManyTextField: groupHasManyTextField } = traverseFields({
527
+ adapter,
528
+ columnPrefix: `${columnName}_`,
529
+ columns,
530
+ disableNotNull: disableNotNullFromHere,
531
+ disableUnique,
532
+ fieldPrefix: `${fieldName}.`,
533
+ fields: field.fields,
534
+ forceLocalized: field.localized,
535
+ indexes,
536
+ joins,
537
+ localesColumns,
538
+ localesIndexes,
539
+ newTableName: `${parentTableName}_${columnName}`,
540
+ parentTableName,
541
+ relationships,
542
+ relationsToBuild,
543
+ rootRelationsToBuild,
544
+ rootTableIDColType,
545
+ rootTableName,
546
+ versions,
547
+ withinLocalizedArrayOrBlock: withinLocalizedArrayOrBlock || field.localized
548
+ });
549
+ if (groupHasLocalizedField) {
550
+ hasLocalizedField = true;
551
+ }
552
+ if (groupHasLocalizedRelationshipField) {
553
+ hasLocalizedRelationshipField = true;
554
+ }
555
+ if (groupHasManyTextField) {
556
+ hasManyTextField = true;
557
+ }
558
+ if (groupHasLocalizedManyTextField) {
559
+ hasLocalizedManyTextField = true;
560
+ }
561
+ if (groupHasManyNumberField) {
562
+ hasManyNumberField = true;
563
+ }
564
+ if (groupHasLocalizedManyNumberField) {
565
+ hasLocalizedManyNumberField = true;
566
+ }
567
+ break;
568
+ }
569
+ case 'tabs':
570
+ {
571
+ const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
572
+ const { hasLocalizedField: tabHasLocalizedField, hasLocalizedManyNumberField: tabHasLocalizedManyNumberField, hasLocalizedManyTextField: tabHasLocalizedManyTextField, hasLocalizedRelationshipField: tabHasLocalizedRelationshipField, hasManyNumberField: tabHasManyNumberField, hasManyTextField: tabHasManyTextField } = traverseFields({
573
+ adapter,
574
+ columnPrefix,
575
+ columns,
576
+ disableNotNull: disableNotNullFromHere,
577
+ disableUnique,
578
+ fieldPrefix,
579
+ fields: field.tabs.map((tab)=>({
580
+ ...tab,
581
+ type: 'tab'
582
+ })),
583
+ forceLocalized,
584
+ indexes,
585
+ joins,
586
+ localesColumns,
587
+ localesIndexes,
588
+ newTableName,
589
+ parentTableName,
590
+ relationships,
591
+ relationsToBuild,
592
+ rootRelationsToBuild,
593
+ rootTableIDColType,
594
+ rootTableName,
595
+ versions,
596
+ withinLocalizedArrayOrBlock
597
+ });
598
+ if (tabHasLocalizedField) {
599
+ hasLocalizedField = true;
600
+ }
601
+ if (tabHasLocalizedRelationshipField) {
602
+ hasLocalizedRelationshipField = true;
603
+ }
604
+ if (tabHasManyTextField) {
605
+ hasManyTextField = true;
606
+ }
607
+ if (tabHasLocalizedManyTextField) {
608
+ hasLocalizedManyTextField = true;
609
+ }
610
+ if (tabHasManyNumberField) {
611
+ hasManyNumberField = true;
612
+ }
613
+ if (tabHasLocalizedManyNumberField) {
614
+ hasLocalizedManyNumberField = true;
615
+ }
616
+ break;
617
+ }
618
+ case 'row':
619
+ case 'collapsible':
620
+ {
621
+ const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
622
+ const { hasLocalizedField: rowHasLocalizedField, hasLocalizedManyNumberField: rowHasLocalizedManyNumberField, hasLocalizedManyTextField: rowHasLocalizedManyTextField, hasLocalizedRelationshipField: rowHasLocalizedRelationshipField, hasManyNumberField: rowHasManyNumberField, hasManyTextField: rowHasManyTextField } = traverseFields({
623
+ adapter,
624
+ columnPrefix,
625
+ columns,
626
+ disableNotNull: disableNotNullFromHere,
627
+ disableUnique,
628
+ fieldPrefix,
629
+ fields: field.fields,
630
+ forceLocalized,
631
+ indexes,
632
+ joins,
633
+ localesColumns,
634
+ localesIndexes,
635
+ newTableName,
636
+ parentTableName,
637
+ relationships,
638
+ relationsToBuild,
639
+ rootRelationsToBuild,
640
+ rootTableIDColType,
641
+ rootTableName,
642
+ versions,
643
+ withinLocalizedArrayOrBlock
644
+ });
645
+ if (rowHasLocalizedField) {
646
+ hasLocalizedField = true;
647
+ }
648
+ if (rowHasLocalizedRelationshipField) {
649
+ hasLocalizedRelationshipField = true;
650
+ }
651
+ if (rowHasManyTextField) {
652
+ hasManyTextField = true;
653
+ }
654
+ if (rowHasLocalizedManyTextField) {
655
+ hasLocalizedManyTextField = true;
656
+ }
657
+ if (rowHasManyNumberField) {
658
+ hasManyNumberField = true;
659
+ }
660
+ if (rowHasLocalizedManyNumberField) {
661
+ hasLocalizedManyNumberField = true;
662
+ }
663
+ break;
664
+ }
665
+ case 'relationship':
666
+ case 'upload':
667
+ if (Array.isArray(field.relationTo)) {
668
+ field.relationTo.forEach((relation)=>relationships.add(relation));
669
+ } else if (field.hasMany) {
670
+ relationships.add(field.relationTo);
671
+ } else {
672
+ // simple relationships get a column on the targetTable with a foreign key to the relationTo table
673
+ const relationshipConfig = adapter.payload.collections[field.relationTo].config;
674
+ const tableName = adapter.tableNameMap.get(toSnakeCase(field.relationTo));
675
+ // get the id type of the related collection
676
+ let colType = adapter.idType === 'uuid' ? 'uuid' : 'integer';
677
+ const relatedCollectionCustomID = relationshipConfig.fields.find((field)=>fieldAffectsData(field) && field.name === 'id');
678
+ if (relatedCollectionCustomID?.type === 'number') {
679
+ colType = 'numeric';
680
+ }
681
+ if (relatedCollectionCustomID?.type === 'text') {
682
+ colType = 'varchar';
683
+ }
684
+ // make the foreign key column for relationship using the correct id column type
685
+ targetTable[fieldName] = parentIDColumnMap[colType](`${columnName}_id`).references(()=>adapter.tables[tableName].id, {
686
+ onDelete: 'set null'
687
+ });
688
+ // add relationship to table
689
+ relationsToBuild.set(fieldName, {
690
+ type: 'one',
691
+ localized: adapter.payload.config.localization && (field.localized || forceLocalized),
692
+ target: tableName
693
+ });
694
+ // add notNull when not required
695
+ if (!disableNotNull && field.required && !field.admin?.condition) {
696
+ targetTable[fieldName].notNull();
697
+ }
698
+ break;
699
+ }
700
+ if (Boolean(field.localized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock) {
701
+ hasLocalizedRelationshipField = true;
702
+ }
703
+ break;
704
+ case 'join':
705
+ {
706
+ // fieldName could be 'posts' or 'group_posts'
707
+ // using `on` as the key for the relation
708
+ const localized = adapter.payload.config.localization && field.localized;
709
+ const fieldSchemaPath = `${fieldPrefix || ''}${field.name}`;
710
+ let target;
711
+ const joinConfig = joins[field.collection].find(({ schemaPath })=>fieldSchemaPath === schemaPath);
712
+ if (joinConfig.targetField.hasMany) {
713
+ target = `${adapter.tableNameMap.get(toSnakeCase(field.collection))}${adapter.relationshipsSuffix}`;
714
+ } else {
715
+ target = `${adapter.tableNameMap.get(toSnakeCase(field.collection))}${localized ? adapter.localesSuffix : ''}`;
716
+ }
717
+ relationsToBuild.set(fieldName, {
718
+ type: 'many',
719
+ // joins are not localized on the parent table
720
+ localized: false,
721
+ relationName: field.on.replaceAll('.', '_'),
722
+ target
723
+ });
724
+ break;
725
+ }
726
+ default:
727
+ break;
728
+ }
729
+ const condition = field.admin && field.admin.condition;
730
+ if (!disableNotNull && targetTable[fieldName] && 'required' in field && field.required && !condition) {
731
+ targetTable[fieldName].notNull();
732
+ }
733
+ });
734
+ return {
735
+ hasLocalizedField,
736
+ hasLocalizedManyNumberField,
737
+ hasLocalizedManyTextField,
738
+ hasLocalizedRelationshipField,
739
+ hasManyNumberField,
740
+ hasManyTextField
741
+ };
742
+ };
743
+
744
+ //# sourceMappingURL=traverseFields.js.map