@payloadcms/db-postgres 3.0.0-beta.7 → 3.0.0-beta.71

Sign up to get free protection for your applications and to get access to all the features.
Files changed (397) hide show
  1. package/README.md +1 -1
  2. package/dist/connect.d.ts +1 -1
  3. package/dist/connect.d.ts.map +1 -1
  4. package/dist/connect.js +16 -13
  5. package/dist/connect.js.map +1 -1
  6. package/dist/countDistinct.d.ts +3 -0
  7. package/dist/countDistinct.d.ts.map +1 -0
  8. package/dist/countDistinct.js +24 -0
  9. package/dist/countDistinct.js.map +1 -0
  10. package/dist/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -0
  11. package/dist/createJSONQuery/convertPathToJSONTraversal.js.map +1 -0
  12. package/dist/createJSONQuery/formatJSONPathSegment.d.ts.map +1 -0
  13. package/dist/createJSONQuery/formatJSONPathSegment.js.map +1 -0
  14. package/dist/createJSONQuery/index.d.ts.map +1 -0
  15. package/dist/createJSONQuery/index.js.map +1 -0
  16. package/dist/createMigration.d.ts +1 -1
  17. package/dist/createMigration.d.ts.map +1 -1
  18. package/dist/createMigration.js +56 -57
  19. package/dist/createMigration.js.map +1 -1
  20. package/dist/defaultSnapshot.d.ts +3 -0
  21. package/dist/defaultSnapshot.d.ts.map +1 -0
  22. package/dist/defaultSnapshot.js +16 -0
  23. package/dist/defaultSnapshot.js.map +1 -0
  24. package/dist/deleteWhere.d.ts +3 -0
  25. package/dist/deleteWhere.d.ts.map +1 -0
  26. package/dist/deleteWhere.js +6 -0
  27. package/dist/deleteWhere.js.map +1 -0
  28. package/dist/dropDatabase.d.ts +3 -0
  29. package/dist/dropDatabase.d.ts.map +1 -0
  30. package/dist/dropDatabase.js +9 -0
  31. package/dist/dropDatabase.js.map +1 -0
  32. package/dist/execute.d.ts +3 -0
  33. package/dist/execute.d.ts.map +1 -0
  34. package/dist/execute.js +11 -0
  35. package/dist/execute.js.map +1 -0
  36. package/dist/exports/migration-utils.d.ts +2 -0
  37. package/dist/exports/migration-utils.d.ts.map +1 -0
  38. package/dist/exports/migration-utils.js +3 -0
  39. package/dist/exports/migration-utils.js.map +1 -0
  40. package/dist/getMigrationTemplate.d.ts +3 -0
  41. package/dist/getMigrationTemplate.d.ts.map +1 -0
  42. package/dist/getMigrationTemplate.js +12 -0
  43. package/dist/getMigrationTemplate.js.map +1 -0
  44. package/dist/index.d.ts +1 -1
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +44 -71
  47. package/dist/index.js.map +1 -1
  48. package/dist/init.d.ts +1 -1
  49. package/dist/init.d.ts.map +1 -1
  50. package/dist/init.js +21 -24
  51. package/dist/init.js.map +1 -1
  52. package/dist/insert.d.ts +3 -0
  53. package/dist/insert.d.ts.map +1 -0
  54. package/dist/insert.js +12 -0
  55. package/dist/insert.js.map +1 -0
  56. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  57. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  58. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  59. package/dist/predefinedMigrations/relationships-v2-v3.mjs +11 -0
  60. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +20 -0
  61. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
  62. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +169 -0
  63. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
  64. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
  65. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
  66. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +191 -0
  67. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
  68. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
  69. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
  70. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js +56 -0
  71. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
  72. package/dist/predefinedMigrations/v2-v3/index.d.ts +23 -0
  73. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
  74. package/dist/predefinedMigrations/v2-v3/index.js +211 -0
  75. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -0
  76. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +20 -0
  77. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
  78. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +57 -0
  79. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
  80. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +23 -0
  81. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
  82. package/dist/predefinedMigrations/v2-v3/traverseFields.js +85 -0
  83. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
  84. package/dist/predefinedMigrations/v2-v3/types.d.ts +9 -0
  85. package/dist/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
  86. package/dist/predefinedMigrations/v2-v3/types.js +6 -0
  87. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -0
  88. package/dist/requireDrizzleKit.d.ts +3 -0
  89. package/dist/requireDrizzleKit.d.ts.map +1 -0
  90. package/dist/requireDrizzleKit.js +5 -0
  91. package/dist/requireDrizzleKit.js.map +1 -0
  92. package/dist/schema/build.d.ts +12 -7
  93. package/dist/schema/build.d.ts.map +1 -1
  94. package/dist/schema/build.js +209 -125
  95. package/dist/schema/build.js.map +1 -1
  96. package/dist/schema/createIndex.js.map +1 -1
  97. package/dist/schema/idToUUID.d.ts +1 -1
  98. package/dist/schema/idToUUID.d.ts.map +1 -1
  99. package/dist/schema/idToUUID.js.map +1 -1
  100. package/dist/schema/parentIDColumnMap.js.map +1 -1
  101. package/dist/schema/setColumnID.d.ts +1 -1
  102. package/dist/schema/setColumnID.d.ts.map +1 -1
  103. package/dist/schema/setColumnID.js +2 -2
  104. package/dist/schema/setColumnID.js.map +1 -1
  105. package/dist/schema/traverseFields.d.ts +5 -7
  106. package/dist/schema/traverseFields.d.ts.map +1 -1
  107. package/dist/schema/traverseFields.js +148 -66
  108. package/dist/schema/traverseFields.js.map +1 -1
  109. package/dist/types.d.ts +77 -34
  110. package/dist/types.d.ts.map +1 -1
  111. package/dist/types.js.map +1 -1
  112. package/package.json +35 -30
  113. package/dist/create.d.ts +0 -3
  114. package/dist/create.d.ts.map +0 -1
  115. package/dist/create.js +0 -21
  116. package/dist/create.js.map +0 -1
  117. package/dist/createGlobal.d.ts +0 -5
  118. package/dist/createGlobal.d.ts.map +0 -1
  119. package/dist/createGlobal.js +0 -21
  120. package/dist/createGlobal.js.map +0 -1
  121. package/dist/createGlobalVersion.d.ts +0 -6
  122. package/dist/createGlobalVersion.d.ts.map +0 -1
  123. package/dist/createGlobalVersion.js +0 -37
  124. package/dist/createGlobalVersion.js.map +0 -1
  125. package/dist/createVersion.d.ts +0 -5
  126. package/dist/createVersion.d.ts.map +0 -1
  127. package/dist/createVersion.js +0 -48
  128. package/dist/createVersion.js.map +0 -1
  129. package/dist/deleteMany.d.ts +0 -3
  130. package/dist/deleteMany.d.ts.map +0 -1
  131. package/dist/deleteMany.js +0 -31
  132. package/dist/deleteMany.js.map +0 -1
  133. package/dist/deleteOne.d.ts +0 -3
  134. package/dist/deleteOne.d.ts.map +0 -1
  135. package/dist/deleteOne.js +0 -62
  136. package/dist/deleteOne.js.map +0 -1
  137. package/dist/deleteVersions.d.ts +0 -3
  138. package/dist/deleteVersions.d.ts.map +0 -1
  139. package/dist/deleteVersions.js +0 -35
  140. package/dist/deleteVersions.js.map +0 -1
  141. package/dist/destroy.d.ts +0 -3
  142. package/dist/destroy.d.ts.map +0 -1
  143. package/dist/destroy.js +0 -11
  144. package/dist/destroy.js.map +0 -1
  145. package/dist/find/buildFindManyArgs.d.ts +0 -13
  146. package/dist/find/buildFindManyArgs.d.ts.map +0 -1
  147. package/dist/find/buildFindManyArgs.js +0 -64
  148. package/dist/find/buildFindManyArgs.js.map +0 -1
  149. package/dist/find/chainMethods.d.ts +0 -16
  150. package/dist/find/chainMethods.d.ts.map +0 -1
  151. package/dist/find/chainMethods.js +0 -12
  152. package/dist/find/chainMethods.js.map +0 -1
  153. package/dist/find/findMany.d.ts +0 -22
  154. package/dist/find/findMany.d.ts.map +0 -1
  155. package/dist/find/findMany.js +0 -163
  156. package/dist/find/findMany.js.map +0 -1
  157. package/dist/find/traverseFields.d.ts +0 -16
  158. package/dist/find/traverseFields.d.ts.map +0 -1
  159. package/dist/find/traverseFields.js +0 -154
  160. package/dist/find/traverseFields.js.map +0 -1
  161. package/dist/find.d.ts +0 -3
  162. package/dist/find.d.ts.map +0 -1
  163. package/dist/find.js +0 -24
  164. package/dist/find.js.map +0 -1
  165. package/dist/findGlobal.d.ts +0 -3
  166. package/dist/findGlobal.d.ts.map +0 -1
  167. package/dist/findGlobal.js +0 -26
  168. package/dist/findGlobal.js.map +0 -1
  169. package/dist/findGlobalVersions.d.ts +0 -3
  170. package/dist/findGlobalVersions.d.ts.map +0 -1
  171. package/dist/findGlobalVersions.js +0 -28
  172. package/dist/findGlobalVersions.js.map +0 -1
  173. package/dist/findOne.d.ts +0 -5
  174. package/dist/findOne.d.ts.map +0 -1
  175. package/dist/findOne.js +0 -24
  176. package/dist/findOne.js.map +0 -1
  177. package/dist/findVersions.d.ts +0 -3
  178. package/dist/findVersions.d.ts.map +0 -1
  179. package/dist/findVersions.js +0 -28
  180. package/dist/findVersions.js.map +0 -1
  181. package/dist/migrate.d.ts +0 -3
  182. package/dist/migrate.d.ts.map +0 -1
  183. package/dist/migrate.js +0 -99
  184. package/dist/migrate.js.map +0 -1
  185. package/dist/migrateDown.d.ts +0 -3
  186. package/dist/migrateDown.d.ts.map +0 -1
  187. package/dist/migrateDown.js +0 -63
  188. package/dist/migrateDown.js.map +0 -1
  189. package/dist/migrateFresh.d.ts +0 -8
  190. package/dist/migrateFresh.d.ts.map +0 -1
  191. package/dist/migrateFresh.js +0 -72
  192. package/dist/migrateFresh.js.map +0 -1
  193. package/dist/migrateRefresh.d.ts +0 -6
  194. package/dist/migrateRefresh.d.ts.map +0 -1
  195. package/dist/migrateRefresh.js +0 -102
  196. package/dist/migrateRefresh.js.map +0 -1
  197. package/dist/migrateReset.d.ts +0 -6
  198. package/dist/migrateReset.d.ts.map +0 -1
  199. package/dist/migrateReset.js +0 -82
  200. package/dist/migrateReset.js.map +0 -1
  201. package/dist/migrateStatus.d.ts +0 -3
  202. package/dist/migrateStatus.d.ts.map +0 -1
  203. package/dist/migrateStatus.js +0 -44
  204. package/dist/migrateStatus.js.map +0 -1
  205. package/dist/queries/buildAndOrConditions.d.ts +0 -17
  206. package/dist/queries/buildAndOrConditions.d.ts.map +0 -1
  207. package/dist/queries/buildAndOrConditions.js +0 -29
  208. package/dist/queries/buildAndOrConditions.js.map +0 -1
  209. package/dist/queries/buildQuery.d.ts +0 -31
  210. package/dist/queries/buildQuery.d.ts.map +0 -1
  211. package/dist/queries/buildQuery.js +0 -76
  212. package/dist/queries/buildQuery.js.map +0 -1
  213. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts.map +0 -1
  214. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +0 -1
  215. package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts.map +0 -1
  216. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +0 -1
  217. package/dist/queries/createJSONQuery/index.d.ts.map +0 -1
  218. package/dist/queries/createJSONQuery/index.js.map +0 -1
  219. package/dist/queries/getTableColumnFromPath.d.ts +0 -51
  220. package/dist/queries/getTableColumnFromPath.d.ts.map +0 -1
  221. package/dist/queries/getTableColumnFromPath.js +0 -412
  222. package/dist/queries/getTableColumnFromPath.js.map +0 -1
  223. package/dist/queries/operatorMap.d.ts +0 -18
  224. package/dist/queries/operatorMap.d.ts.map +0 -1
  225. package/dist/queries/operatorMap.js +0 -24
  226. package/dist/queries/operatorMap.js.map +0 -1
  227. package/dist/queries/parseParams.d.ts +0 -17
  228. package/dist/queries/parseParams.d.ts.map +0 -1
  229. package/dist/queries/parseParams.js +0 -182
  230. package/dist/queries/parseParams.js.map +0 -1
  231. package/dist/queries/sanitizeQueryValue.d.ts +0 -15
  232. package/dist/queries/sanitizeQueryValue.d.ts.map +0 -1
  233. package/dist/queries/sanitizeQueryValue.js +0 -90
  234. package/dist/queries/sanitizeQueryValue.js.map +0 -1
  235. package/dist/queries/selectDistinct.d.ts +0 -23
  236. package/dist/queries/selectDistinct.d.ts.map +0 -1
  237. package/dist/queries/selectDistinct.js +0 -41
  238. package/dist/queries/selectDistinct.js.map +0 -1
  239. package/dist/queryDrafts.d.ts +0 -3
  240. package/dist/queryDrafts.d.ts.map +0 -1
  241. package/dist/queryDrafts.js +0 -45
  242. package/dist/queryDrafts.js.map +0 -1
  243. package/dist/schema/getTableName.d.ts +0 -32
  244. package/dist/schema/getTableName.d.ts.map +0 -1
  245. package/dist/schema/getTableName.js +0 -31
  246. package/dist/schema/getTableName.js.map +0 -1
  247. package/dist/schema/validateExistingBlockIsIdentical.d.ts +0 -11
  248. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +0 -1
  249. package/dist/schema/validateExistingBlockIsIdentical.js +0 -70
  250. package/dist/schema/validateExistingBlockIsIdentical.js.map +0 -1
  251. package/dist/transactions/beginTransaction.d.ts +0 -3
  252. package/dist/transactions/beginTransaction.d.ts.map +0 -1
  253. package/dist/transactions/beginTransaction.js +0 -47
  254. package/dist/transactions/beginTransaction.js.map +0 -1
  255. package/dist/transactions/commitTransaction.d.ts +0 -3
  256. package/dist/transactions/commitTransaction.d.ts.map +0 -1
  257. package/dist/transactions/commitTransaction.js +0 -14
  258. package/dist/transactions/commitTransaction.js.map +0 -1
  259. package/dist/transactions/rollbackTransaction.d.ts +0 -3
  260. package/dist/transactions/rollbackTransaction.d.ts.map +0 -1
  261. package/dist/transactions/rollbackTransaction.js +0 -13
  262. package/dist/transactions/rollbackTransaction.js.map +0 -1
  263. package/dist/transform/read/hasManyNumber.d.ts +0 -10
  264. package/dist/transform/read/hasManyNumber.d.ts.map +0 -1
  265. package/dist/transform/read/hasManyNumber.js +0 -10
  266. package/dist/transform/read/hasManyNumber.js.map +0 -1
  267. package/dist/transform/read/hasManyText.d.ts +0 -10
  268. package/dist/transform/read/hasManyText.d.ts.map +0 -1
  269. package/dist/transform/read/hasManyText.js +0 -10
  270. package/dist/transform/read/hasManyText.js.map +0 -1
  271. package/dist/transform/read/index.d.ts +0 -12
  272. package/dist/transform/read/index.d.ts.map +0 -1
  273. package/dist/transform/read/index.js +0 -43
  274. package/dist/transform/read/index.js.map +0 -1
  275. package/dist/transform/read/relationship.d.ts +0 -10
  276. package/dist/transform/read/relationship.d.ts.map +0 -1
  277. package/dist/transform/read/relationship.js +0 -64
  278. package/dist/transform/read/relationship.js.map +0 -1
  279. package/dist/transform/read/traverseFields.d.ts +0 -52
  280. package/dist/transform/read/traverseFields.d.ts.map +0 -1
  281. package/dist/transform/read/traverseFields.js +0 -421
  282. package/dist/transform/read/traverseFields.js.map +0 -1
  283. package/dist/transform/write/array.d.ts +0 -26
  284. package/dist/transform/write/array.d.ts.map +0 -1
  285. package/dist/transform/write/array.js +0 -58
  286. package/dist/transform/write/array.js.map +0 -1
  287. package/dist/transform/write/blocks.d.ts +0 -25
  288. package/dist/transform/write/blocks.d.ts.map +0 -1
  289. package/dist/transform/write/blocks.js +0 -54
  290. package/dist/transform/write/blocks.js.map +0 -1
  291. package/dist/transform/write/index.d.ts +0 -13
  292. package/dist/transform/write/index.d.ts.map +0 -1
  293. package/dist/transform/write/index.js +0 -41
  294. package/dist/transform/write/index.js.map +0 -1
  295. package/dist/transform/write/numbers.d.ts +0 -8
  296. package/dist/transform/write/numbers.d.ts.map +0 -1
  297. package/dist/transform/write/numbers.js +0 -11
  298. package/dist/transform/write/numbers.js.map +0 -1
  299. package/dist/transform/write/relationships.d.ts +0 -10
  300. package/dist/transform/write/relationships.d.ts.map +0 -1
  301. package/dist/transform/write/relationships.js +0 -23
  302. package/dist/transform/write/relationships.js.map +0 -1
  303. package/dist/transform/write/selects.d.ts +0 -8
  304. package/dist/transform/write/selects.d.ts.map +0 -1
  305. package/dist/transform/write/selects.js +0 -20
  306. package/dist/transform/write/selects.js.map +0 -1
  307. package/dist/transform/write/texts.d.ts +0 -8
  308. package/dist/transform/write/texts.d.ts.map +0 -1
  309. package/dist/transform/write/texts.js +0 -11
  310. package/dist/transform/write/texts.js.map +0 -1
  311. package/dist/transform/write/traverseFields.d.ts +0 -50
  312. package/dist/transform/write/traverseFields.d.ts.map +0 -1
  313. package/dist/transform/write/traverseFields.js +0 -428
  314. package/dist/transform/write/traverseFields.js.map +0 -1
  315. package/dist/transform/write/types.d.ts +0 -43
  316. package/dist/transform/write/types.d.ts.map +0 -1
  317. package/dist/transform/write/types.js +0 -3
  318. package/dist/transform/write/types.js.map +0 -1
  319. package/dist/update.d.ts +0 -3
  320. package/dist/update.d.ts.map +0 -1
  321. package/dist/update.js +0 -58
  322. package/dist/update.js.map +0 -1
  323. package/dist/updateGlobal.d.ts +0 -5
  324. package/dist/updateGlobal.d.ts.map +0 -1
  325. package/dist/updateGlobal.js +0 -28
  326. package/dist/updateGlobal.js.map +0 -1
  327. package/dist/updateGlobalVersion.d.ts +0 -5
  328. package/dist/updateGlobalVersion.d.ts.map +0 -1
  329. package/dist/updateGlobalVersion.js +0 -40
  330. package/dist/updateGlobalVersion.js.map +0 -1
  331. package/dist/updateVersion.d.ts +0 -5
  332. package/dist/updateVersion.d.ts.map +0 -1
  333. package/dist/updateVersion.js +0 -40
  334. package/dist/updateVersion.js.map +0 -1
  335. package/dist/upsertRow/deleteExistingArrayRows.d.ts +0 -10
  336. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +0 -1
  337. package/dist/upsertRow/deleteExistingArrayRows.js +0 -10
  338. package/dist/upsertRow/deleteExistingArrayRows.js.map +0 -1
  339. package/dist/upsertRow/deleteExistingRowsByPath.d.ts +0 -14
  340. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +0 -1
  341. package/dist/upsertRow/deleteExistingRowsByPath.js +0 -33
  342. package/dist/upsertRow/deleteExistingRowsByPath.js.map +0 -1
  343. package/dist/upsertRow/index.d.ts +0 -4
  344. package/dist/upsertRow/index.d.ts.map +0 -1
  345. package/dist/upsertRow/index.js +0 -276
  346. package/dist/upsertRow/index.js.map +0 -1
  347. package/dist/upsertRow/insertArrays.d.ts +0 -13
  348. package/dist/upsertRow/insertArrays.d.ts.map +0 -1
  349. package/dist/upsertRow/insertArrays.js +0 -68
  350. package/dist/upsertRow/insertArrays.js.map +0 -1
  351. package/dist/upsertRow/types.d.ts +0 -27
  352. package/dist/upsertRow/types.d.ts.map +0 -1
  353. package/dist/upsertRow/types.js +0 -3
  354. package/dist/upsertRow/types.js.map +0 -1
  355. package/dist/utilities/appendPrefixToKeys.d.ts +0 -2
  356. package/dist/utilities/appendPrefixToKeys.d.ts.map +0 -1
  357. package/dist/utilities/appendPrefixToKeys.js +0 -6
  358. package/dist/utilities/appendPrefixToKeys.js.map +0 -1
  359. package/dist/utilities/createBlocksMap.d.ts +0 -5
  360. package/dist/utilities/createBlocksMap.d.ts.map +0 -1
  361. package/dist/utilities/createBlocksMap.js +0 -29
  362. package/dist/utilities/createBlocksMap.js.map +0 -1
  363. package/dist/utilities/createMigrationTable.d.ts +0 -3
  364. package/dist/utilities/createMigrationTable.d.ts.map +0 -1
  365. package/dist/utilities/createMigrationTable.js +0 -13
  366. package/dist/utilities/createMigrationTable.js.map +0 -1
  367. package/dist/utilities/createRelationshipMap.d.ts +0 -2
  368. package/dist/utilities/createRelationshipMap.d.ts.map +0 -1
  369. package/dist/utilities/createRelationshipMap.js +0 -19
  370. package/dist/utilities/createRelationshipMap.js.map +0 -1
  371. package/dist/utilities/hasLocalesTable.d.ts +0 -3
  372. package/dist/utilities/hasLocalesTable.d.ts.map +0 -1
  373. package/dist/utilities/hasLocalesTable.js +0 -11
  374. package/dist/utilities/hasLocalesTable.js.map +0 -1
  375. package/dist/utilities/isArrayOfRows.d.ts +0 -2
  376. package/dist/utilities/isArrayOfRows.d.ts.map +0 -1
  377. package/dist/utilities/isArrayOfRows.js +0 -5
  378. package/dist/utilities/isArrayOfRows.js.map +0 -1
  379. package/dist/utilities/migrationTableExists.d.ts +0 -3
  380. package/dist/utilities/migrationTableExists.d.ts.map +0 -1
  381. package/dist/utilities/migrationTableExists.js +0 -9
  382. package/dist/utilities/migrationTableExists.js.map +0 -1
  383. package/dist/utilities/parseError.d.ts +0 -5
  384. package/dist/utilities/parseError.d.ts.map +0 -1
  385. package/dist/utilities/parseError.js +0 -17
  386. package/dist/utilities/parseError.js.map +0 -1
  387. package/dist/utilities/pushDevSchema.d.ts +0 -9
  388. package/dist/utilities/pushDevSchema.d.ts.map +0 -1
  389. package/dist/utilities/pushDevSchema.js +0 -58
  390. package/dist/utilities/pushDevSchema.js.map +0 -1
  391. package/src/index.ts +0 -156
  392. /package/dist/{queries/createJSONQuery → createJSONQuery}/convertPathToJSONTraversal.d.ts +0 -0
  393. /package/dist/{queries/createJSONQuery → createJSONQuery}/convertPathToJSONTraversal.js +0 -0
  394. /package/dist/{queries/createJSONQuery → createJSONQuery}/formatJSONPathSegment.d.ts +0 -0
  395. /package/dist/{queries/createJSONQuery → createJSONQuery}/formatJSONPathSegment.js +0 -0
  396. /package/dist/{queries/createJSONQuery → createJSONQuery}/index.d.ts +0 -0
  397. /package/dist/{queries/createJSONQuery → createJSONQuery}/index.js +0 -0
@@ -1,6 +1,6 @@
1
1
  import { numeric, serial, uuid, varchar } from 'drizzle-orm/pg-core';
2
- import { fieldAffectsData } from 'payload/types';
3
- import { flattenTopLevelFields } from 'payload/utilities';
2
+ import { flattenTopLevelFields } from 'payload';
3
+ import { fieldAffectsData } from 'payload/shared';
4
4
  export const setColumnID = ({ adapter, columns, fields })=>{
5
5
  const idField = flattenTopLevelFields(fields).find((field)=>fieldAffectsData(field) && field.name === 'id');
6
6
  if (idField) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/setColumnID.ts"],"sourcesContent":["import type { PgColumnBuilder } from 'drizzle-orm/pg-core'\n\nimport { numeric, serial, uuid, varchar } from 'drizzle-orm/pg-core'\nimport { type Field, fieldAffectsData } from 'payload/types'\nimport { flattenTopLevelFields } from 'payload/utilities'\n\nimport type { IDType, PostgresAdapter } from '../types.js'\n\ntype Args = { adapter: PostgresAdapter; columns: Record<string, PgColumnBuilder>; fields: Field[] }\nexport const setColumnID = ({ adapter, columns, fields }: Args): IDType => {\n const idField = flattenTopLevelFields(fields).find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n if (idField) {\n if (idField.type === 'number') {\n columns.id = numeric('id').primaryKey()\n return 'numeric'\n }\n\n if (idField.type === 'text') {\n columns.id = varchar('id').primaryKey()\n return 'varchar'\n }\n }\n\n if (adapter.idType === 'uuid') {\n columns.id = uuid('id').defaultRandom().primaryKey()\n return 'uuid'\n }\n\n columns.id = serial('id').primaryKey()\n return 'integer'\n}\n"],"names":["numeric","serial","uuid","varchar","fieldAffectsData","flattenTopLevelFields","setColumnID","adapter","columns","fields","idField","find","field","name","type","id","primaryKey","idType","defaultRandom"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,OAAO,EAAEC,MAAM,EAAEC,IAAI,EAAEC,OAAO,QAAQ,sBAAqB;AACpE,SAAqBC,gBAAgB,QAAQ,gBAAe;AAC5D,SAASC,qBAAqB,QAAQ,oBAAmB;AAKzD,OAAO,MAAMC,cAAc,CAAC,EAAEC,OAAO,EAAEC,OAAO,EAAEC,MAAM,EAAQ;IAC5D,MAAMC,UAAUL,sBAAsBI,QAAQE,IAAI,CAChD,CAACC,QAAUR,iBAAiBQ,UAAUA,MAAMC,IAAI,KAAK;IAEvD,IAAIH,SAAS;QACX,IAAIA,QAAQI,IAAI,KAAK,UAAU;YAC7BN,QAAQO,EAAE,GAAGf,QAAQ,MAAMgB,UAAU;YACrC,OAAO;QACT;QAEA,IAAIN,QAAQI,IAAI,KAAK,QAAQ;YAC3BN,QAAQO,EAAE,GAAGZ,QAAQ,MAAMa,UAAU;YACrC,OAAO;QACT;IACF;IAEA,IAAIT,QAAQU,MAAM,KAAK,QAAQ;QAC7BT,QAAQO,EAAE,GAAGb,KAAK,MAAMgB,aAAa,GAAGF,UAAU;QAClD,OAAO;IACT;IAEAR,QAAQO,EAAE,GAAGd,OAAO,MAAMe,UAAU;IACpC,OAAO;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/schema/setColumnID.ts"],"sourcesContent":["import type { PgColumnBuilder } from 'drizzle-orm/pg-core'\n\nimport { numeric, serial, uuid, varchar } from 'drizzle-orm/pg-core'\nimport { type Field, flattenTopLevelFields } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\nimport type { IDType, PostgresAdapter } from '../types.js'\n\ntype Args = { adapter: PostgresAdapter; columns: Record<string, PgColumnBuilder>; fields: Field[] }\nexport const setColumnID = ({ adapter, columns, fields }: Args): IDType => {\n const idField = flattenTopLevelFields(fields).find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n if (idField) {\n if (idField.type === 'number') {\n columns.id = numeric('id').primaryKey()\n return 'numeric'\n }\n\n if (idField.type === 'text') {\n columns.id = varchar('id').primaryKey()\n return 'varchar'\n }\n }\n\n if (adapter.idType === 'uuid') {\n columns.id = uuid('id').defaultRandom().primaryKey()\n return 'uuid'\n }\n\n columns.id = serial('id').primaryKey()\n return 'integer'\n}\n"],"names":["numeric","serial","uuid","varchar","flattenTopLevelFields","fieldAffectsData","setColumnID","adapter","columns","fields","idField","find","field","name","type","id","primaryKey","idType","defaultRandom"],"mappings":"AAEA,SAASA,OAAO,EAAEC,MAAM,EAAEC,IAAI,EAAEC,OAAO,QAAQ,sBAAqB;AACpE,SAAqBC,qBAAqB,QAAQ,UAAS;AAC3D,SAASC,gBAAgB,QAAQ,iBAAgB;AAKjD,OAAO,MAAMC,cAAc,CAAC,EAAEC,OAAO,EAAEC,OAAO,EAAEC,MAAM,EAAQ;IAC5D,MAAMC,UAAUN,sBAAsBK,QAAQE,IAAI,CAChD,CAACC,QAAUP,iBAAiBO,UAAUA,MAAMC,IAAI,KAAK;IAEvD,IAAIH,SAAS;QACX,IAAIA,QAAQI,IAAI,KAAK,UAAU;YAC7BN,QAAQO,EAAE,GAAGf,QAAQ,MAAMgB,UAAU;YACrC,OAAO;QACT;QAEA,IAAIN,QAAQI,IAAI,KAAK,QAAQ;YAC3BN,QAAQO,EAAE,GAAGZ,QAAQ,MAAMa,UAAU;YACrC,OAAO;QACT;IACF;IAEA,IAAIT,QAAQU,MAAM,KAAK,QAAQ;QAC7BT,QAAQO,EAAE,GAAGb,KAAK,MAAMgB,aAAa,GAAGF,UAAU;QAClD,OAAO;IACT;IAEAR,QAAQO,EAAE,GAAGd,OAAO,MAAMe,UAAU;IACpC,OAAO;AACT,EAAC"}
@@ -1,11 +1,9 @@
1
1
  import type { IndexBuilder, PgColumnBuilder } from 'drizzle-orm/pg-core';
2
- import type { Field, TabAsField } from 'payload/types';
2
+ import type { Field, TabAsField } from 'payload';
3
3
  import type { GenericColumns, PostgresAdapter } from '../types.js';
4
+ import type { RelationMap } from './build.js';
4
5
  type Args = {
5
6
  adapter: PostgresAdapter;
6
- buildNumbers: boolean;
7
- buildRelationships: boolean;
8
- buildTexts: boolean;
9
7
  columnPrefix?: string;
10
8
  columns: Record<string, PgColumnBuilder>;
11
9
  disableNotNull: boolean;
@@ -18,9 +16,9 @@ type Args = {
18
16
  localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder>;
19
17
  newTableName: string;
20
18
  parentTableName: string;
21
- relationsToBuild: Map<string, string>;
19
+ relationsToBuild: RelationMap;
22
20
  relationships: Set<string>;
23
- rootRelationsToBuild?: Map<string, string>;
21
+ rootRelationsToBuild?: RelationMap;
24
22
  rootTableIDColType: string;
25
23
  rootTableName: string;
26
24
  versions: boolean;
@@ -33,6 +31,6 @@ type Result = {
33
31
  hasManyNumberField: 'index' | boolean;
34
32
  hasManyTextField: 'index' | boolean;
35
33
  };
36
- export declare const traverseFields: ({ adapter, buildNumbers, buildRelationships, buildTexts, columnPrefix, columns, disableNotNull, disableUnique, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationsToBuild, relationships, rootRelationsToBuild, rootTableIDColType, rootTableName, versions, }: Args) => Result;
34
+ export declare const traverseFields: ({ adapter, columnPrefix, columns, disableNotNull, disableUnique, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationsToBuild, relationships, rootRelationsToBuild, rootTableIDColType, rootTableName, versions, }: Args) => Result;
37
35
  export {};
38
36
  //# sourceMappingURL=traverseFields.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/schema/traverseFields.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAA2B,MAAM,qBAAqB,CAAA;AACjG,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAqBtD,OAAO,KAAK,EAAE,cAAc,EAAU,eAAe,EAAE,MAAM,aAAa,CAAA;AAU1E,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,YAAY,EAAE,OAAO,CAAA;IACrB,kBAAkB,EAAE,OAAO,CAAA;IAC3B,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IACxC,cAAc,EAAE,OAAO,CAAA;IACvB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE,CAAA;IAC9B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,YAAY,CAAC,CAAA;IAC/D,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAC/C,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,YAAY,CAAC,CAAA;IACtE,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC1B,oBAAoB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC1C,kBAAkB,EAAE,MAAM,CAAA;IAC1B,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,iBAAiB,EAAE,OAAO,CAAA;IAC1B,2BAA2B,EAAE,OAAO,CAAA;IACpC,yBAAyB,EAAE,OAAO,CAAA;IAClC,6BAA6B,EAAE,OAAO,CAAA;IACtC,kBAAkB,EAAE,OAAO,GAAG,OAAO,CAAA;IACrC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,cAAc,sUAuBxB,IAAI,KAAG,MAknBT,CAAA"}
1
+ {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/schema/traverseFields.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACxE,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AA2BhD,OAAO,KAAK,EAAE,cAAc,EAAU,eAAe,EAAE,MAAM,aAAa,CAAA;AAC1E,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,YAAY,CAAA;AAO9D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IACxC,cAAc,EAAE,OAAO,CAAA;IACvB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE,CAAA;IAC9B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,YAAY,CAAC,CAAA;IAC/D,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAC/C,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,YAAY,CAAC,CAAA;IACtE,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,WAAW,CAAA;IAC7B,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC1B,oBAAoB,CAAC,EAAE,WAAW,CAAA;IAClC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,iBAAiB,EAAE,OAAO,CAAA;IAC1B,2BAA2B,EAAE,OAAO,CAAA;IACpC,yBAAyB,EAAE,OAAO,CAAA;IAClC,6BAA6B,EAAE,OAAO,CAAA;IACtC,kBAAkB,EAAE,OAAO,GAAG,OAAO,CAAA;IACrC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,cAAc,wRAoBxB,IAAI,KAAG,MA4rBT,CAAA"}
@@ -1,16 +1,14 @@
1
- /* eslint-disable no-param-reassign */ import { relations } from 'drizzle-orm';
2
- import { PgNumericBuilder, PgUUIDBuilder, PgVarcharBuilder, boolean, index, integer, jsonb, numeric, pgEnum, text, timestamp, varchar } from 'drizzle-orm/pg-core';
3
- import { InvalidConfiguration } from 'payload/errors';
4
- import { fieldAffectsData, optionIsObject } from 'payload/types';
1
+ /* eslint-disable no-param-reassign */ import { createTableName, hasLocalesTable, validateExistingBlockIsIdentical } from '@payloadcms/drizzle';
2
+ import { relations } from 'drizzle-orm';
3
+ import { PgNumericBuilder, PgUUIDBuilder, PgVarcharBuilder, boolean, foreignKey, index, integer, jsonb, numeric, pgEnum, text, timestamp, varchar } from 'drizzle-orm/pg-core';
4
+ import { InvalidConfiguration } from 'payload';
5
+ import { fieldAffectsData, optionIsObject } from 'payload/shared';
5
6
  import toSnakeCase from 'to-snake-case';
6
- import { hasLocalesTable } from '../utilities/hasLocalesTable.js';
7
7
  import { buildTable } from './build.js';
8
8
  import { createIndex } from './createIndex.js';
9
- import { getTableName } from './getTableName.js';
10
9
  import { idToUUID } from './idToUUID.js';
11
10
  import { parentIDColumnMap } from './parentIDColumnMap.js';
12
- import { validateExistingBlockIsIdentical } from './validateExistingBlockIsIdentical.js';
13
- export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buildTexts, columnPrefix, columns, disableNotNull, disableUnique = false, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationsToBuild, relationships, rootRelationsToBuild, rootTableIDColType, rootTableName, versions })=>{
11
+ export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull, disableUnique = false, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationsToBuild, relationships, rootRelationsToBuild, rootTableIDColType, rootTableName, versions })=>{
14
12
  const throwValidationError = true;
15
13
  let hasLocalizedField = false;
16
14
  let hasLocalizedRelationshipField = false;
@@ -33,7 +31,7 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
33
31
  fieldName = `${fieldPrefix?.replace('.', '_') || ''}${field.name}`;
34
32
  // If field is localized,
35
33
  // add the column to the locale table instead of main table
36
- if (adapter.payload.config.localization && (field.localized || forceLocalized)) {
34
+ if (adapter.payload.config.localization && (field.localized || forceLocalized) && field.type !== 'array' && field.type !== 'blocks' && ('hasMany' in field && field.hasMany !== true || !('hasMany' in field))) {
37
35
  hasLocalizedField = true;
38
36
  targetTable = localesColumns;
39
37
  targetIndexes = localesIndexes;
@@ -130,14 +128,13 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
130
128
  case 'radio':
131
129
  case 'select':
132
130
  {
133
- const enumName = getTableName({
131
+ const enumName = createTableName({
134
132
  adapter,
135
133
  config: field,
136
134
  parentTableName: newTableName,
137
135
  prefix: `enum_${newTableName}_`,
138
136
  target: 'enumName',
139
- throwValidationError,
140
- versions
137
+ throwValidationError
141
138
  });
142
139
  adapter.enums[enumName] = pgEnum(enumName, field.options.map((option)=>{
143
140
  if (optionIsObject(option)) {
@@ -146,23 +143,30 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
146
143
  return option;
147
144
  }));
148
145
  if (field.type === 'select' && field.hasMany) {
149
- const selectTableName = getTableName({
146
+ const selectTableName = createTableName({
150
147
  adapter,
151
148
  config: field,
152
149
  parentTableName: newTableName,
153
150
  prefix: `${newTableName}_`,
154
151
  throwValidationError,
155
- versions
152
+ versionsCustomName: versions
156
153
  });
157
154
  const baseColumns = {
158
155
  order: integer('order').notNull(),
159
- parent: parentIDColumnMap[parentIDColType]('parent_id').references(()=>adapter.tables[parentTableName].id, {
160
- onDelete: 'cascade'
161
- }).notNull(),
156
+ parent: parentIDColumnMap[parentIDColType]('parent_id').notNull(),
162
157
  value: adapter.enums[enumName]('value')
163
158
  };
164
159
  const baseExtraConfig = {
165
160
  orderIdx: (cols)=>index(`${selectTableName}_order_idx`).on(cols.order),
161
+ parentFk: (cols)=>foreignKey({
162
+ name: `${selectTableName}_parent_fk`,
163
+ columns: [
164
+ cols.parent
165
+ ],
166
+ foreignColumns: [
167
+ adapter.tables[parentTableName].id
168
+ ]
169
+ }).onDelete('cascade'),
166
170
  parentIdx: (cols)=>index(`${selectTableName}_parent_idx`).on(cols.parent)
167
171
  };
168
172
  if (field.localized) {
@@ -179,24 +183,27 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
179
183
  disableNotNull,
180
184
  disableUnique,
181
185
  fields: [],
186
+ rootTableName,
182
187
  tableName: selectTableName,
183
188
  versions
184
189
  });
185
- relationsToBuild.set(fieldName, selectTableName);
186
- const selectTableRelations = relations(adapter.tables[selectTableName], ({ one })=>{
187
- const result = {
190
+ relationsToBuild.set(fieldName, {
191
+ type: 'many',
192
+ // selects have their own localized table, independent of the base table.
193
+ localized: false,
194
+ target: selectTableName
195
+ });
196
+ adapter.relations[`relations_${selectTableName}`] = relations(adapter.tables[selectTableName], ({ one })=>({
188
197
  parent: one(adapter.tables[parentTableName], {
189
198
  fields: [
190
199
  adapter.tables[selectTableName].parent
191
200
  ],
192
201
  references: [
193
202
  adapter.tables[parentTableName].id
194
- ]
203
+ ],
204
+ relationName: fieldName
195
205
  })
196
- };
197
- return result;
198
- });
199
- adapter.relations[`relation_${selectTableName}`] = selectTableRelations;
206
+ }));
200
207
  } else {
201
208
  targetTable[fieldName] = adapter.enums[enumName](fieldName);
202
209
  }
@@ -210,21 +217,29 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
210
217
  case 'array':
211
218
  {
212
219
  const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
213
- const arrayTableName = getTableName({
220
+ const arrayTableName = createTableName({
214
221
  adapter,
215
222
  config: field,
216
223
  parentTableName: newTableName,
217
224
  prefix: `${newTableName}_`,
218
- throwValidationError
225
+ throwValidationError,
226
+ versionsCustomName: versions
219
227
  });
220
228
  const baseColumns = {
221
229
  _order: integer('_order').notNull(),
222
- _parentID: parentIDColumnMap[parentIDColType]('_parent_id').references(()=>adapter.tables[parentTableName].id, {
223
- onDelete: 'cascade'
224
- }).notNull()
230
+ _parentID: parentIDColumnMap[parentIDColType]('_parent_id').notNull()
225
231
  };
226
232
  const baseExtraConfig = {
227
233
  _orderIdx: (cols)=>index(`${arrayTableName}_order_idx`).on(cols._order),
234
+ _parentIDFk: (cols)=>foreignKey({
235
+ name: `${arrayTableName}_parent_id_fk`,
236
+ columns: [
237
+ cols['_parentID']
238
+ ],
239
+ foreignColumns: [
240
+ adapter.tables[parentTableName].id
241
+ ]
242
+ }).onDelete('cascade'),
228
243
  _parentIDIdx: (cols)=>index(`${arrayTableName}_parent_id_idx`).on(cols._parentID)
229
244
  };
230
245
  if (field.localized && adapter.payload.config.localization) {
@@ -251,8 +266,13 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
251
266
  if (subHasManyNumberField) {
252
267
  if (!hasManyNumberField || subHasManyNumberField === 'index') hasManyNumberField = subHasManyNumberField;
253
268
  }
254
- relationsToBuild.set(fieldName, arrayTableName);
255
- const arrayTableRelations = relations(adapter.tables[arrayTableName], ({ many, one })=>{
269
+ relationsToBuild.set(fieldName, {
270
+ type: 'many',
271
+ // arrays have their own localized table, independent of the base table.
272
+ localized: false,
273
+ target: arrayTableName
274
+ });
275
+ adapter.relations[`relations_${arrayTableName}`] = relations(adapter.tables[arrayTableName], ({ many, one })=>{
256
276
  const result = {
257
277
  _parentID: one(adapter.tables[parentTableName], {
258
278
  fields: [
@@ -260,42 +280,68 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
260
280
  ],
261
281
  references: [
262
282
  adapter.tables[parentTableName].id
263
- ]
283
+ ],
284
+ relationName: fieldName
264
285
  })
265
286
  };
266
287
  if (hasLocalesTable(field.fields)) {
267
- result._locales = many(adapter.tables[`${arrayTableName}${adapter.localesSuffix}`]);
288
+ result._locales = many(adapter.tables[`${arrayTableName}${adapter.localesSuffix}`], {
289
+ relationName: '_locales'
290
+ });
268
291
  }
269
- subRelationsToBuild.forEach((val, key)=>{
270
- result[key] = many(adapter.tables[val]);
292
+ subRelationsToBuild.forEach(({ type, localized, target }, key)=>{
293
+ if (type === 'one') {
294
+ const arrayWithLocalized = localized ? `${arrayTableName}${adapter.localesSuffix}` : arrayTableName;
295
+ result[key] = one(adapter.tables[target], {
296
+ fields: [
297
+ adapter.tables[arrayWithLocalized][key]
298
+ ],
299
+ references: [
300
+ adapter.tables[target].id
301
+ ],
302
+ relationName: key
303
+ });
304
+ }
305
+ if (type === 'many') {
306
+ result[key] = many(adapter.tables[target], {
307
+ relationName: key
308
+ });
309
+ }
271
310
  });
272
311
  return result;
273
312
  });
274
- adapter.relations[`relations_${arrayTableName}`] = arrayTableRelations;
275
313
  break;
276
314
  }
277
315
  case 'blocks':
278
316
  {
279
317
  const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
280
318
  field.blocks.forEach((block)=>{
281
- const blockTableName = getTableName({
319
+ const blockTableName = createTableName({
282
320
  adapter,
283
321
  config: block,
284
322
  parentTableName: rootTableName,
285
323
  prefix: `${rootTableName}_blocks_`,
286
- throwValidationError
324
+ throwValidationError,
325
+ versionsCustomName: versions
287
326
  });
288
327
  if (!adapter.tables[blockTableName]) {
289
328
  const baseColumns = {
290
329
  _order: integer('_order').notNull(),
291
- _parentID: parentIDColumnMap[rootTableIDColType]('_parent_id').references(()=>adapter.tables[rootTableName].id, {
292
- onDelete: 'cascade'
293
- }).notNull(),
330
+ _parentID: parentIDColumnMap[rootTableIDColType]('_parent_id').notNull(),
294
331
  _path: text('_path').notNull()
295
332
  };
296
333
  const baseExtraConfig = {
297
334
  _orderIdx: (cols)=>index(`${blockTableName}_order_idx`).on(cols._order),
298
335
  _parentIDIdx: (cols)=>index(`${blockTableName}_parent_id_idx`).on(cols._parentID),
336
+ _parentIdFk: (cols)=>foreignKey({
337
+ name: `${blockTableName}_parent_id_fk`,
338
+ columns: [
339
+ cols._parentID
340
+ ],
341
+ foreignColumns: [
342
+ adapter.tables[rootTableName].id
343
+ ]
344
+ }).onDelete('cascade'),
299
345
  _pathIdx: (cols)=>index(`${blockTableName}_path_idx`).on(cols._path)
300
346
  };
301
347
  if (field.localized && adapter.payload.config.localization) {
@@ -322,7 +368,7 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
322
368
  if (subHasManyNumberField) {
323
369
  if (!hasManyNumberField || subHasManyNumberField === 'index') hasManyNumberField = subHasManyNumberField;
324
370
  }
325
- const blockTableRelations = relations(adapter.tables[blockTableName], ({ many, one })=>{
371
+ adapter.relations[`relations_${blockTableName}`] = relations(adapter.tables[blockTableName], ({ many, one })=>{
326
372
  const result = {
327
373
  _parentID: one(adapter.tables[rootTableName], {
328
374
  fields: [
@@ -330,28 +376,52 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
330
376
  ],
331
377
  references: [
332
378
  adapter.tables[rootTableName].id
333
- ]
379
+ ],
380
+ relationName: `_blocks_${block.slug}`
334
381
  })
335
382
  };
336
383
  if (hasLocalesTable(block.fields)) {
337
- result._locales = many(adapter.tables[`${blockTableName}${adapter.localesSuffix}`]);
384
+ result._locales = many(adapter.tables[`${blockTableName}${adapter.localesSuffix}`], {
385
+ relationName: '_locales'
386
+ });
338
387
  }
339
- subRelationsToBuild.forEach((val, key)=>{
340
- result[key] = many(adapter.tables[val]);
388
+ subRelationsToBuild.forEach(({ type, localized, target }, key)=>{
389
+ if (type === 'one') {
390
+ const blockWithLocalized = localized ? `${blockTableName}${adapter.localesSuffix}` : blockTableName;
391
+ result[key] = one(adapter.tables[target], {
392
+ fields: [
393
+ adapter.tables[blockWithLocalized][key]
394
+ ],
395
+ references: [
396
+ adapter.tables[target].id
397
+ ],
398
+ relationName: key
399
+ });
400
+ }
401
+ if (type === 'many') {
402
+ result[key] = many(adapter.tables[target], {
403
+ relationName: key
404
+ });
405
+ }
341
406
  });
342
407
  return result;
343
408
  });
344
- adapter.relations[`relations_${blockTableName}`] = blockTableRelations;
345
409
  } else if (process.env.NODE_ENV !== 'production' && !versions) {
346
410
  validateExistingBlockIsIdentical({
347
411
  block,
348
412
  localized: field.localized,
349
413
  rootTableName,
350
- table: adapter.tables[blockTableName]
414
+ table: adapter.tables[blockTableName],
415
+ tableLocales: adapter.tables[`${blockTableName}${adapter.localesSuffix}`]
351
416
  });
352
417
  }
353
- adapter.blockTableNames[`${rootTableName}.${toSnakeCase(block.slug)}`] = blockTableName;
354
- rootRelationsToBuild.set(`_blocks_${block.slug}`, blockTableName);
418
+ // blocks relationships are defined from the collection or globals table down to the block, bypassing any subBlocks
419
+ rootRelationsToBuild.set(`_blocks_${block.slug}`, {
420
+ type: 'many',
421
+ // blocks are not localized on the parent table
422
+ localized: false,
423
+ target: blockTableName
424
+ });
355
425
  });
356
426
  break;
357
427
  }
@@ -361,9 +431,6 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
361
431
  if (!('name' in field)) {
362
432
  const { hasLocalizedField: groupHasLocalizedField, hasLocalizedManyNumberField: groupHasLocalizedManyNumberField, hasLocalizedManyTextField: groupHasLocalizedManyTextField, hasLocalizedRelationshipField: groupHasLocalizedRelationshipField, hasManyNumberField: groupHasManyNumberField, hasManyTextField: groupHasManyTextField } = traverseFields({
363
433
  adapter,
364
- buildNumbers,
365
- buildRelationships,
366
- buildTexts,
367
434
  columnPrefix,
368
435
  columns,
369
436
  disableNotNull,
@@ -394,9 +461,6 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
394
461
  const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
395
462
  const { hasLocalizedField: groupHasLocalizedField, hasLocalizedManyNumberField: groupHasLocalizedManyNumberField, hasLocalizedManyTextField: groupHasLocalizedManyTextField, hasLocalizedRelationshipField: groupHasLocalizedRelationshipField, hasManyNumberField: groupHasManyNumberField, hasManyTextField: groupHasManyTextField } = traverseFields({
396
463
  adapter,
397
- buildNumbers,
398
- buildRelationships,
399
- buildTexts,
400
464
  columnPrefix: `${columnName}_`,
401
465
  columns,
402
466
  disableNotNull: disableNotNullFromHere,
@@ -429,9 +493,6 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
429
493
  const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
430
494
  const { hasLocalizedField: tabHasLocalizedField, hasLocalizedManyNumberField: tabHasLocalizedManyNumberField, hasLocalizedManyTextField: tabHasLocalizedManyTextField, hasLocalizedRelationshipField: tabHasLocalizedRelationshipField, hasManyNumberField: tabHasManyNumberField, hasManyTextField: tabHasManyTextField } = traverseFields({
431
495
  adapter,
432
- buildNumbers,
433
- buildRelationships,
434
- buildTexts,
435
496
  columnPrefix,
436
497
  columns,
437
498
  disableNotNull: disableNotNullFromHere,
@@ -468,9 +529,6 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
468
529
  const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
469
530
  const { hasLocalizedField: rowHasLocalizedField, hasLocalizedManyNumberField: rowHasLocalizedManyNumberField, hasLocalizedManyTextField: rowHasLocalizedManyTextField, hasLocalizedRelationshipField: rowHasLocalizedRelationshipField, hasManyNumberField: rowHasManyNumberField, hasManyTextField: rowHasManyTextField } = traverseFields({
470
531
  adapter,
471
- buildNumbers,
472
- buildRelationships,
473
- buildTexts,
474
532
  columnPrefix,
475
533
  columns,
476
534
  disableNotNull: disableNotNullFromHere,
@@ -481,7 +539,7 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
481
539
  indexes,
482
540
  localesColumns,
483
541
  localesIndexes,
484
- newTableName: parentTableName,
542
+ newTableName,
485
543
  parentTableName,
486
544
  relationsToBuild,
487
545
  relationships,
@@ -502,10 +560,34 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
502
560
  case 'upload':
503
561
  if (Array.isArray(field.relationTo)) {
504
562
  field.relationTo.forEach((relation)=>relationships.add(relation));
505
- } else {
563
+ } else if (field.type === 'relationship' && field.hasMany) {
506
564
  relationships.add(field.relationTo);
565
+ } else {
566
+ // simple relationships get a column on the targetTable with a foreign key to the relationTo table
567
+ const relationshipConfig = adapter.payload.collections[field.relationTo].config;
568
+ const tableName = adapter.tableNameMap.get(toSnakeCase(field.relationTo));
569
+ // get the id type of the related collection
570
+ let colType = adapter.idType === 'uuid' ? 'uuid' : 'integer';
571
+ const relatedCollectionCustomID = relationshipConfig.fields.find((field)=>fieldAffectsData(field) && field.name === 'id');
572
+ if (relatedCollectionCustomID?.type === 'number') colType = 'numeric';
573
+ if (relatedCollectionCustomID?.type === 'text') colType = 'varchar';
574
+ // make the foreign key column for relationship using the correct id column type
575
+ targetTable[fieldName] = parentIDColumnMap[colType](`${columnName}_id`).references(()=>adapter.tables[tableName].id, {
576
+ onDelete: 'set null'
577
+ });
578
+ // add relationship to table
579
+ relationsToBuild.set(fieldName, {
580
+ type: 'one',
581
+ localized: adapter.payload.config.localization && field.localized,
582
+ target: tableName
583
+ });
584
+ // add notNull when not required
585
+ if (!disableNotNull && field.required && !field.admin?.condition) {
586
+ targetTable[fieldName].notNull();
587
+ }
588
+ break;
507
589
  }
508
- if (field.localized && adapter.payload.config.localization) {
590
+ if (adapter.payload.config.localization && field.localized) {
509
591
  hasLocalizedRelationshipField = true;
510
592
  }
511
593
  break;