@payloadcms/db-postgres 3.0.0-canary.6041f49 → 3.0.0-canary.67aae47

Sign up to get free protection for your applications and to get access to all the features.
Files changed (369) 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 +45 -17
  5. package/dist/connect.js.map +1 -1
  6. package/dist/exports/migration-utils.d.ts +2 -0
  7. package/dist/exports/migration-utils.d.ts.map +1 -0
  8. package/dist/exports/migration-utils.js +3 -0
  9. package/dist/exports/migration-utils.js.map +1 -0
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +57 -69
  13. package/dist/index.js.map +1 -1
  14. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  15. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  16. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  17. package/dist/predefinedMigrations/relationships-v2-v3.mjs +11 -0
  18. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +20 -0
  19. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
  20. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +169 -0
  21. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
  22. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
  23. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
  24. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +193 -0
  25. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
  26. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
  27. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
  28. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js +56 -0
  29. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
  30. package/dist/predefinedMigrations/v2-v3/index.d.ts +23 -0
  31. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
  32. package/dist/predefinedMigrations/v2-v3/index.js +211 -0
  33. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -0
  34. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +20 -0
  35. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
  36. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +63 -0
  37. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
  38. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +23 -0
  39. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
  40. package/dist/predefinedMigrations/v2-v3/traverseFields.js +85 -0
  41. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
  42. package/dist/predefinedMigrations/v2-v3/types.d.ts +9 -0
  43. package/dist/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
  44. package/dist/predefinedMigrations/v2-v3/types.js +6 -0
  45. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -0
  46. package/dist/types.d.ts +65 -77
  47. package/dist/types.d.ts.map +1 -1
  48. package/dist/types.js.map +1 -1
  49. package/package.json +28 -17
  50. package/dist/count.d.ts +0 -3
  51. package/dist/count.d.ts.map +0 -1
  52. package/dist/count.js +0 -50
  53. package/dist/count.js.map +0 -1
  54. package/dist/create.d.ts +0 -3
  55. package/dist/create.d.ts.map +0 -1
  56. package/dist/create.js +0 -19
  57. package/dist/create.js.map +0 -1
  58. package/dist/createGlobal.d.ts +0 -5
  59. package/dist/createGlobal.d.ts.map +0 -1
  60. package/dist/createGlobal.js +0 -19
  61. package/dist/createGlobal.js.map +0 -1
  62. package/dist/createGlobalVersion.d.ts +0 -6
  63. package/dist/createGlobalVersion.d.ts.map +0 -1
  64. package/dist/createGlobalVersion.js +0 -33
  65. package/dist/createGlobalVersion.js.map +0 -1
  66. package/dist/createMigration.d.ts +0 -3
  67. package/dist/createMigration.d.ts.map +0 -1
  68. package/dist/createMigration.js +0 -81
  69. package/dist/createMigration.js.map +0 -1
  70. package/dist/createVersion.d.ts +0 -5
  71. package/dist/createVersion.d.ts.map +0 -1
  72. package/dist/createVersion.js +0 -44
  73. package/dist/createVersion.js.map +0 -1
  74. package/dist/deleteMany.d.ts +0 -3
  75. package/dist/deleteMany.d.ts.map +0 -1
  76. package/dist/deleteMany.js +0 -28
  77. package/dist/deleteMany.js.map +0 -1
  78. package/dist/deleteOne.d.ts +0 -3
  79. package/dist/deleteOne.d.ts.map +0 -1
  80. package/dist/deleteOne.js +0 -59
  81. package/dist/deleteOne.js.map +0 -1
  82. package/dist/deleteVersions.d.ts +0 -3
  83. package/dist/deleteVersions.d.ts.map +0 -1
  84. package/dist/deleteVersions.js +0 -31
  85. package/dist/deleteVersions.js.map +0 -1
  86. package/dist/destroy.d.ts +0 -3
  87. package/dist/destroy.d.ts.map +0 -1
  88. package/dist/destroy.js +0 -11
  89. package/dist/destroy.js.map +0 -1
  90. package/dist/find/buildFindManyArgs.d.ts +0 -13
  91. package/dist/find/buildFindManyArgs.d.ts.map +0 -1
  92. package/dist/find/buildFindManyArgs.js +0 -64
  93. package/dist/find/buildFindManyArgs.js.map +0 -1
  94. package/dist/find/chainMethods.d.ts +0 -16
  95. package/dist/find/chainMethods.d.ts.map +0 -1
  96. package/dist/find/chainMethods.js +0 -12
  97. package/dist/find/chainMethods.js.map +0 -1
  98. package/dist/find/findMany.d.ts +0 -22
  99. package/dist/find/findMany.d.ts.map +0 -1
  100. package/dist/find/findMany.js +0 -163
  101. package/dist/find/findMany.js.map +0 -1
  102. package/dist/find/traverseFields.d.ts +0 -16
  103. package/dist/find/traverseFields.d.ts.map +0 -1
  104. package/dist/find/traverseFields.js +0 -138
  105. package/dist/find/traverseFields.js.map +0 -1
  106. package/dist/find.d.ts +0 -3
  107. package/dist/find.d.ts.map +0 -1
  108. package/dist/find.js +0 -21
  109. package/dist/find.js.map +0 -1
  110. package/dist/findGlobal.d.ts +0 -3
  111. package/dist/findGlobal.d.ts.map +0 -1
  112. package/dist/findGlobal.js +0 -23
  113. package/dist/findGlobal.js.map +0 -1
  114. package/dist/findGlobalVersions.d.ts +0 -3
  115. package/dist/findGlobalVersions.d.ts.map +0 -1
  116. package/dist/findGlobalVersions.js +0 -24
  117. package/dist/findGlobalVersions.js.map +0 -1
  118. package/dist/findOne.d.ts +0 -5
  119. package/dist/findOne.d.ts.map +0 -1
  120. package/dist/findOne.js +0 -21
  121. package/dist/findOne.js.map +0 -1
  122. package/dist/findVersions.d.ts +0 -3
  123. package/dist/findVersions.d.ts.map +0 -1
  124. package/dist/findVersions.js +0 -24
  125. package/dist/findVersions.js.map +0 -1
  126. package/dist/init.d.ts +0 -3
  127. package/dist/init.d.ts.map +0 -1
  128. package/dist/init.js +0 -96
  129. package/dist/init.js.map +0 -1
  130. package/dist/migrate.d.ts +0 -3
  131. package/dist/migrate.d.ts.map +0 -1
  132. package/dist/migrate.js +0 -99
  133. package/dist/migrate.js.map +0 -1
  134. package/dist/migrateDown.d.ts +0 -3
  135. package/dist/migrateDown.d.ts.map +0 -1
  136. package/dist/migrateDown.js +0 -63
  137. package/dist/migrateDown.js.map +0 -1
  138. package/dist/migrateFresh.d.ts +0 -8
  139. package/dist/migrateFresh.d.ts.map +0 -1
  140. package/dist/migrateFresh.js +0 -72
  141. package/dist/migrateFresh.js.map +0 -1
  142. package/dist/migrateRefresh.d.ts +0 -6
  143. package/dist/migrateRefresh.d.ts.map +0 -1
  144. package/dist/migrateRefresh.js +0 -102
  145. package/dist/migrateRefresh.js.map +0 -1
  146. package/dist/migrateReset.d.ts +0 -6
  147. package/dist/migrateReset.d.ts.map +0 -1
  148. package/dist/migrateReset.js +0 -82
  149. package/dist/migrateReset.js.map +0 -1
  150. package/dist/migrateStatus.d.ts +0 -3
  151. package/dist/migrateStatus.d.ts.map +0 -1
  152. package/dist/migrateStatus.js +0 -44
  153. package/dist/migrateStatus.js.map +0 -1
  154. package/dist/queries/buildAndOrConditions.d.ts +0 -17
  155. package/dist/queries/buildAndOrConditions.d.ts.map +0 -1
  156. package/dist/queries/buildAndOrConditions.js +0 -29
  157. package/dist/queries/buildAndOrConditions.js.map +0 -1
  158. package/dist/queries/buildQuery.d.ts +0 -31
  159. package/dist/queries/buildQuery.d.ts.map +0 -1
  160. package/dist/queries/buildQuery.js +0 -76
  161. package/dist/queries/buildQuery.js.map +0 -1
  162. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts +0 -2
  163. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts.map +0 -1
  164. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js +0 -14
  165. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +0 -1
  166. package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts +0 -2
  167. package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts.map +0 -1
  168. package/dist/queries/createJSONQuery/formatJSONPathSegment.js +0 -5
  169. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +0 -1
  170. package/dist/queries/createJSONQuery/index.d.ts +0 -10
  171. package/dist/queries/createJSONQuery/index.d.ts.map +0 -1
  172. package/dist/queries/createJSONQuery/index.js +0 -54
  173. package/dist/queries/createJSONQuery/index.js.map +0 -1
  174. package/dist/queries/getTableColumnFromPath.d.ts +0 -51
  175. package/dist/queries/getTableColumnFromPath.d.ts.map +0 -1
  176. package/dist/queries/getTableColumnFromPath.js +0 -445
  177. package/dist/queries/getTableColumnFromPath.js.map +0 -1
  178. package/dist/queries/operatorMap.d.ts +0 -18
  179. package/dist/queries/operatorMap.d.ts.map +0 -1
  180. package/dist/queries/operatorMap.js +0 -24
  181. package/dist/queries/operatorMap.js.map +0 -1
  182. package/dist/queries/parseParams.d.ts +0 -17
  183. package/dist/queries/parseParams.d.ts.map +0 -1
  184. package/dist/queries/parseParams.js +0 -182
  185. package/dist/queries/parseParams.js.map +0 -1
  186. package/dist/queries/sanitizeQueryValue.d.ts +0 -15
  187. package/dist/queries/sanitizeQueryValue.d.ts.map +0 -1
  188. package/dist/queries/sanitizeQueryValue.js +0 -90
  189. package/dist/queries/sanitizeQueryValue.js.map +0 -1
  190. package/dist/queries/selectDistinct.d.ts +0 -23
  191. package/dist/queries/selectDistinct.d.ts.map +0 -1
  192. package/dist/queries/selectDistinct.js +0 -41
  193. package/dist/queries/selectDistinct.js.map +0 -1
  194. package/dist/queryDrafts.d.ts +0 -3
  195. package/dist/queryDrafts.d.ts.map +0 -1
  196. package/dist/queryDrafts.js +0 -41
  197. package/dist/queryDrafts.js.map +0 -1
  198. package/dist/schema/build.d.ts +0 -30
  199. package/dist/schema/build.d.ts.map +0 -1
  200. package/dist/schema/build.js +0 -320
  201. package/dist/schema/build.js.map +0 -1
  202. package/dist/schema/createIndex.d.ts +0 -12
  203. package/dist/schema/createIndex.d.ts.map +0 -1
  204. package/dist/schema/createIndex.js +0 -18
  205. package/dist/schema/createIndex.js.map +0 -1
  206. package/dist/schema/createTableName.d.ts +0 -30
  207. package/dist/schema/createTableName.d.ts.map +0 -1
  208. package/dist/schema/createTableName.js +0 -31
  209. package/dist/schema/createTableName.js.map +0 -1
  210. package/dist/schema/idToUUID.d.ts +0 -3
  211. package/dist/schema/idToUUID.d.ts.map +0 -1
  212. package/dist/schema/idToUUID.js +0 -11
  213. package/dist/schema/idToUUID.js.map +0 -1
  214. package/dist/schema/parentIDColumnMap.d.ts +0 -4
  215. package/dist/schema/parentIDColumnMap.d.ts.map +0 -1
  216. package/dist/schema/parentIDColumnMap.js +0 -9
  217. package/dist/schema/parentIDColumnMap.js.map +0 -1
  218. package/dist/schema/setColumnID.d.ts +0 -11
  219. package/dist/schema/setColumnID.d.ts.map +0 -1
  220. package/dist/schema/setColumnID.js +0 -24
  221. package/dist/schema/setColumnID.js.map +0 -1
  222. package/dist/schema/traverseFields.d.ts +0 -38
  223. package/dist/schema/traverseFields.d.ts.map +0 -1
  224. package/dist/schema/traverseFields.js +0 -551
  225. package/dist/schema/traverseFields.js.map +0 -1
  226. package/dist/schema/validateExistingBlockIsIdentical.d.ts +0 -12
  227. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +0 -1
  228. package/dist/schema/validateExistingBlockIsIdentical.js +0 -76
  229. package/dist/schema/validateExistingBlockIsIdentical.js.map +0 -1
  230. package/dist/transactions/beginTransaction.d.ts +0 -3
  231. package/dist/transactions/beginTransaction.d.ts.map +0 -1
  232. package/dist/transactions/beginTransaction.js +0 -47
  233. package/dist/transactions/beginTransaction.js.map +0 -1
  234. package/dist/transactions/commitTransaction.d.ts +0 -3
  235. package/dist/transactions/commitTransaction.d.ts.map +0 -1
  236. package/dist/transactions/commitTransaction.js +0 -14
  237. package/dist/transactions/commitTransaction.js.map +0 -1
  238. package/dist/transactions/rollbackTransaction.d.ts +0 -3
  239. package/dist/transactions/rollbackTransaction.d.ts.map +0 -1
  240. package/dist/transactions/rollbackTransaction.js +0 -13
  241. package/dist/transactions/rollbackTransaction.js.map +0 -1
  242. package/dist/transform/read/hasManyNumber.d.ts +0 -10
  243. package/dist/transform/read/hasManyNumber.d.ts.map +0 -1
  244. package/dist/transform/read/hasManyNumber.js +0 -10
  245. package/dist/transform/read/hasManyNumber.js.map +0 -1
  246. package/dist/transform/read/hasManyText.d.ts +0 -10
  247. package/dist/transform/read/hasManyText.d.ts.map +0 -1
  248. package/dist/transform/read/hasManyText.js +0 -10
  249. package/dist/transform/read/hasManyText.js.map +0 -1
  250. package/dist/transform/read/index.d.ts +0 -12
  251. package/dist/transform/read/index.d.ts.map +0 -1
  252. package/dist/transform/read/index.js +0 -43
  253. package/dist/transform/read/index.js.map +0 -1
  254. package/dist/transform/read/relationship.d.ts +0 -10
  255. package/dist/transform/read/relationship.d.ts.map +0 -1
  256. package/dist/transform/read/relationship.js +0 -64
  257. package/dist/transform/read/relationship.js.map +0 -1
  258. package/dist/transform/read/traverseFields.d.ts +0 -52
  259. package/dist/transform/read/traverseFields.d.ts.map +0 -1
  260. package/dist/transform/read/traverseFields.js +0 -421
  261. package/dist/transform/read/traverseFields.js.map +0 -1
  262. package/dist/transform/write/array.d.ts +0 -26
  263. package/dist/transform/write/array.d.ts.map +0 -1
  264. package/dist/transform/write/array.js +0 -58
  265. package/dist/transform/write/array.js.map +0 -1
  266. package/dist/transform/write/blocks.d.ts +0 -25
  267. package/dist/transform/write/blocks.d.ts.map +0 -1
  268. package/dist/transform/write/blocks.js +0 -54
  269. package/dist/transform/write/blocks.js.map +0 -1
  270. package/dist/transform/write/index.d.ts +0 -13
  271. package/dist/transform/write/index.d.ts.map +0 -1
  272. package/dist/transform/write/index.js +0 -41
  273. package/dist/transform/write/index.js.map +0 -1
  274. package/dist/transform/write/numbers.d.ts +0 -8
  275. package/dist/transform/write/numbers.d.ts.map +0 -1
  276. package/dist/transform/write/numbers.js +0 -11
  277. package/dist/transform/write/numbers.js.map +0 -1
  278. package/dist/transform/write/relationships.d.ts +0 -10
  279. package/dist/transform/write/relationships.d.ts.map +0 -1
  280. package/dist/transform/write/relationships.js +0 -23
  281. package/dist/transform/write/relationships.js.map +0 -1
  282. package/dist/transform/write/selects.d.ts +0 -8
  283. package/dist/transform/write/selects.d.ts.map +0 -1
  284. package/dist/transform/write/selects.js +0 -20
  285. package/dist/transform/write/selects.js.map +0 -1
  286. package/dist/transform/write/texts.d.ts +0 -8
  287. package/dist/transform/write/texts.d.ts.map +0 -1
  288. package/dist/transform/write/texts.js +0 -11
  289. package/dist/transform/write/texts.js.map +0 -1
  290. package/dist/transform/write/traverseFields.d.ts +0 -50
  291. package/dist/transform/write/traverseFields.d.ts.map +0 -1
  292. package/dist/transform/write/traverseFields.js +0 -428
  293. package/dist/transform/write/traverseFields.js.map +0 -1
  294. package/dist/transform/write/types.d.ts +0 -43
  295. package/dist/transform/write/types.d.ts.map +0 -1
  296. package/dist/transform/write/types.js +0 -3
  297. package/dist/transform/write/types.js.map +0 -1
  298. package/dist/update.d.ts +0 -3
  299. package/dist/update.d.ts.map +0 -1
  300. package/dist/update.js +0 -55
  301. package/dist/update.js.map +0 -1
  302. package/dist/updateGlobal.d.ts +0 -5
  303. package/dist/updateGlobal.d.ts.map +0 -1
  304. package/dist/updateGlobal.js +0 -25
  305. package/dist/updateGlobal.js.map +0 -1
  306. package/dist/updateGlobalVersion.d.ts +0 -5
  307. package/dist/updateGlobalVersion.d.ts.map +0 -1
  308. package/dist/updateGlobalVersion.js +0 -36
  309. package/dist/updateGlobalVersion.js.map +0 -1
  310. package/dist/updateVersion.d.ts +0 -5
  311. package/dist/updateVersion.d.ts.map +0 -1
  312. package/dist/updateVersion.js +0 -36
  313. package/dist/updateVersion.js.map +0 -1
  314. package/dist/upsertRow/deleteExistingArrayRows.d.ts +0 -10
  315. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +0 -1
  316. package/dist/upsertRow/deleteExistingArrayRows.js +0 -10
  317. package/dist/upsertRow/deleteExistingArrayRows.js.map +0 -1
  318. package/dist/upsertRow/deleteExistingRowsByPath.d.ts +0 -14
  319. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +0 -1
  320. package/dist/upsertRow/deleteExistingRowsByPath.js +0 -33
  321. package/dist/upsertRow/deleteExistingRowsByPath.js.map +0 -1
  322. package/dist/upsertRow/index.d.ts +0 -4
  323. package/dist/upsertRow/index.d.ts.map +0 -1
  324. package/dist/upsertRow/index.js +0 -277
  325. package/dist/upsertRow/index.js.map +0 -1
  326. package/dist/upsertRow/insertArrays.d.ts +0 -13
  327. package/dist/upsertRow/insertArrays.d.ts.map +0 -1
  328. package/dist/upsertRow/insertArrays.js +0 -68
  329. package/dist/upsertRow/insertArrays.js.map +0 -1
  330. package/dist/upsertRow/types.d.ts +0 -27
  331. package/dist/upsertRow/types.d.ts.map +0 -1
  332. package/dist/upsertRow/types.js +0 -3
  333. package/dist/upsertRow/types.js.map +0 -1
  334. package/dist/utilities/appendPrefixToKeys.d.ts +0 -2
  335. package/dist/utilities/appendPrefixToKeys.d.ts.map +0 -1
  336. package/dist/utilities/appendPrefixToKeys.js +0 -6
  337. package/dist/utilities/appendPrefixToKeys.js.map +0 -1
  338. package/dist/utilities/createBlocksMap.d.ts +0 -5
  339. package/dist/utilities/createBlocksMap.d.ts.map +0 -1
  340. package/dist/utilities/createBlocksMap.js +0 -29
  341. package/dist/utilities/createBlocksMap.js.map +0 -1
  342. package/dist/utilities/createMigrationTable.d.ts +0 -3
  343. package/dist/utilities/createMigrationTable.d.ts.map +0 -1
  344. package/dist/utilities/createMigrationTable.js +0 -13
  345. package/dist/utilities/createMigrationTable.js.map +0 -1
  346. package/dist/utilities/createRelationshipMap.d.ts +0 -2
  347. package/dist/utilities/createRelationshipMap.d.ts.map +0 -1
  348. package/dist/utilities/createRelationshipMap.js +0 -19
  349. package/dist/utilities/createRelationshipMap.js.map +0 -1
  350. package/dist/utilities/hasLocalesTable.d.ts +0 -3
  351. package/dist/utilities/hasLocalesTable.d.ts.map +0 -1
  352. package/dist/utilities/hasLocalesTable.js +0 -11
  353. package/dist/utilities/hasLocalesTable.js.map +0 -1
  354. package/dist/utilities/isArrayOfRows.d.ts +0 -2
  355. package/dist/utilities/isArrayOfRows.d.ts.map +0 -1
  356. package/dist/utilities/isArrayOfRows.js +0 -5
  357. package/dist/utilities/isArrayOfRows.js.map +0 -1
  358. package/dist/utilities/migrationTableExists.d.ts +0 -3
  359. package/dist/utilities/migrationTableExists.d.ts.map +0 -1
  360. package/dist/utilities/migrationTableExists.js +0 -9
  361. package/dist/utilities/migrationTableExists.js.map +0 -1
  362. package/dist/utilities/parseError.d.ts +0 -5
  363. package/dist/utilities/parseError.d.ts.map +0 -1
  364. package/dist/utilities/parseError.js +0 -17
  365. package/dist/utilities/parseError.js.map +0 -1
  366. package/dist/utilities/pushDevSchema.d.ts +0 -9
  367. package/dist/utilities/pushDevSchema.d.ts.map +0 -1
  368. package/dist/utilities/pushDevSchema.js +0 -58
  369. package/dist/utilities/pushDevSchema.js.map +0 -1
@@ -0,0 +1,169 @@
1
+ import { upsertRow } from '@payloadcms/drizzle';
2
+ import { traverseFields } from './traverseFields.js';
3
+ export const fetchAndResave = async ({ adapter, collectionSlug, db, debug, docsToResave, fields, globalSlug, isVersions, payload, req, tableName })=>{
4
+ for (const [id, rows] of Object.entries(docsToResave)){
5
+ if (collectionSlug) {
6
+ const collectionConfig = payload.collections[collectionSlug].config;
7
+ if (collectionConfig) {
8
+ if (isVersions) {
9
+ const doc = await payload.findVersionByID({
10
+ id,
11
+ collection: collectionSlug,
12
+ depth: 0,
13
+ fallbackLocale: null,
14
+ locale: 'all',
15
+ req,
16
+ showHiddenFields: true
17
+ });
18
+ if (debug) {
19
+ payload.logger.info(`The collection "${collectionConfig.slug}" version with ID ${id} will be migrated`);
20
+ }
21
+ traverseFields({
22
+ doc,
23
+ fields,
24
+ path: '',
25
+ rows
26
+ });
27
+ try {
28
+ await upsertRow({
29
+ id: doc.id,
30
+ adapter,
31
+ data: doc,
32
+ db,
33
+ fields,
34
+ ignoreResult: true,
35
+ operation: 'update',
36
+ req,
37
+ tableName
38
+ });
39
+ } catch (err) {
40
+ payload.logger.error(`"${collectionConfig.slug}" version with ID ${doc.id} FAILED TO MIGRATE`);
41
+ throw err;
42
+ }
43
+ if (debug) {
44
+ payload.logger.info(`"${collectionConfig.slug}" version with ID ${doc.id} migrated successfully!`);
45
+ }
46
+ } else {
47
+ const doc = await payload.findByID({
48
+ id,
49
+ collection: collectionSlug,
50
+ depth: 0,
51
+ fallbackLocale: null,
52
+ locale: 'all',
53
+ req,
54
+ showHiddenFields: true
55
+ });
56
+ if (debug) {
57
+ payload.logger.info(`The collection "${collectionConfig.slug}" with ID ${doc.id} will be migrated`);
58
+ }
59
+ traverseFields({
60
+ doc,
61
+ fields,
62
+ path: '',
63
+ rows
64
+ });
65
+ try {
66
+ await upsertRow({
67
+ id: doc.id,
68
+ adapter,
69
+ data: doc,
70
+ db,
71
+ fields,
72
+ ignoreResult: true,
73
+ operation: 'update',
74
+ req,
75
+ tableName
76
+ });
77
+ } catch (err) {
78
+ payload.logger.error(`The collection "${collectionConfig.slug}" with ID ${doc.id} has FAILED TO MIGRATE`);
79
+ throw err;
80
+ }
81
+ if (debug) {
82
+ payload.logger.info(`The collection "${collectionConfig.slug}" with ID ${doc.id} has migrated successfully!`);
83
+ }
84
+ }
85
+ }
86
+ }
87
+ if (globalSlug) {
88
+ const globalConfig = payload.config.globals?.find((global)=>global.slug === globalSlug);
89
+ if (globalConfig) {
90
+ if (isVersions) {
91
+ const { docs } = await payload.findGlobalVersions({
92
+ slug: globalSlug,
93
+ depth: 0,
94
+ fallbackLocale: null,
95
+ limit: 0,
96
+ locale: 'all',
97
+ req,
98
+ showHiddenFields: true
99
+ });
100
+ if (debug) {
101
+ payload.logger.info(`${docs.length} global "${globalSlug}" versions will be migrated`);
102
+ }
103
+ for (const doc of docs){
104
+ traverseFields({
105
+ doc,
106
+ fields,
107
+ path: '',
108
+ rows
109
+ });
110
+ try {
111
+ await upsertRow({
112
+ id: doc.id,
113
+ adapter,
114
+ data: doc,
115
+ db,
116
+ fields,
117
+ ignoreResult: true,
118
+ operation: 'update',
119
+ req,
120
+ tableName
121
+ });
122
+ } catch (err) {
123
+ payload.logger.error(`"${globalSlug}" version with ID ${doc.id} FAILED TO MIGRATE`);
124
+ throw err;
125
+ }
126
+ if (debug) {
127
+ payload.logger.info(`"${globalSlug}" version with ID ${doc.id} migrated successfully!`);
128
+ }
129
+ }
130
+ } else {
131
+ const doc = await payload.findGlobal({
132
+ slug: globalSlug,
133
+ depth: 0,
134
+ fallbackLocale: null,
135
+ locale: 'all',
136
+ req,
137
+ showHiddenFields: true
138
+ });
139
+ traverseFields({
140
+ doc,
141
+ fields,
142
+ path: '',
143
+ rows
144
+ });
145
+ try {
146
+ await upsertRow({
147
+ adapter,
148
+ data: doc,
149
+ db,
150
+ fields,
151
+ ignoreResult: true,
152
+ operation: 'update',
153
+ req,
154
+ tableName
155
+ });
156
+ } catch (err) {
157
+ payload.logger.error(`The global "${globalSlug}" has FAILED TO MIGRATE`);
158
+ throw err;
159
+ }
160
+ if (debug) {
161
+ payload.logger.info(`The global "${globalSlug}" has migrated successfully!`);
162
+ }
163
+ }
164
+ }
165
+ }
166
+ }
167
+ };
168
+
169
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/index.ts"],"sourcesContent":["import type { TransactionPg } from '@payloadcms/drizzle/types'\nimport type { Field, Payload, PayloadRequest } from 'payload'\n\nimport { upsertRow } from '@payloadcms/drizzle'\n\nimport type { PostgresAdapter } from '../../../types.js'\nimport type { DocsToResave } from '../types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n db: TransactionPg\n debug: boolean\n docsToResave: DocsToResave\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n payload: Payload\n req: PayloadRequest\n tableName: string\n}\n\nexport const fetchAndResave = async ({\n adapter,\n collectionSlug,\n db,\n debug,\n docsToResave,\n fields,\n globalSlug,\n isVersions,\n payload,\n req,\n tableName,\n}: Args) => {\n for (const [id, rows] of Object.entries(docsToResave)) {\n if (collectionSlug) {\n const collectionConfig = payload.collections[collectionSlug].config\n\n if (collectionConfig) {\n if (isVersions) {\n const doc = await payload.findVersionByID({\n id,\n collection: collectionSlug,\n depth: 0,\n fallbackLocale: null,\n locale: 'all',\n req,\n showHiddenFields: true,\n })\n\n if (debug) {\n payload.logger.info(\n `The collection \"${collectionConfig.slug}\" version with ID ${id} will be migrated`,\n )\n }\n\n traverseFields({\n doc,\n fields,\n path: '',\n rows,\n })\n\n try {\n await upsertRow({\n id: doc.id,\n adapter,\n data: doc,\n db,\n fields,\n ignoreResult: true,\n operation: 'update',\n req,\n tableName,\n })\n } catch (err) {\n payload.logger.error(\n `\"${collectionConfig.slug}\" version with ID ${doc.id} FAILED TO MIGRATE`,\n )\n\n throw err\n }\n\n if (debug) {\n payload.logger.info(\n `\"${collectionConfig.slug}\" version with ID ${doc.id} migrated successfully!`,\n )\n }\n } else {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n depth: 0,\n fallbackLocale: null,\n locale: 'all',\n req,\n showHiddenFields: true,\n })\n\n if (debug) {\n payload.logger.info(\n `The collection \"${collectionConfig.slug}\" with ID ${doc.id} will be migrated`,\n )\n }\n\n traverseFields({\n doc,\n fields,\n path: '',\n rows,\n })\n\n try {\n await upsertRow({\n id: doc.id,\n adapter,\n data: doc,\n db,\n fields,\n ignoreResult: true,\n operation: 'update',\n req,\n tableName,\n })\n } catch (err) {\n payload.logger.error(\n `The collection \"${collectionConfig.slug}\" with ID ${doc.id} has FAILED TO MIGRATE`,\n )\n\n throw err\n }\n\n if (debug) {\n payload.logger.info(\n `The collection \"${collectionConfig.slug}\" with ID ${doc.id} has migrated successfully!`,\n )\n }\n }\n }\n }\n\n if (globalSlug) {\n const globalConfig = payload.config.globals?.find((global) => global.slug === globalSlug)\n\n if (globalConfig) {\n if (isVersions) {\n const { docs } = await payload.findGlobalVersions({\n slug: globalSlug,\n depth: 0,\n fallbackLocale: null,\n limit: 0,\n locale: 'all',\n req,\n showHiddenFields: true,\n })\n\n if (debug) {\n payload.logger.info(`${docs.length} global \"${globalSlug}\" versions will be migrated`)\n }\n\n for (const doc of docs) {\n traverseFields({\n doc,\n fields,\n path: '',\n rows,\n })\n\n try {\n await upsertRow({\n id: doc.id,\n adapter,\n data: doc,\n db,\n fields,\n ignoreResult: true,\n operation: 'update',\n req,\n tableName,\n })\n } catch (err) {\n payload.logger.error(`\"${globalSlug}\" version with ID ${doc.id} FAILED TO MIGRATE`)\n\n throw err\n }\n\n if (debug) {\n payload.logger.info(\n `\"${globalSlug}\" version with ID ${doc.id} migrated successfully!`,\n )\n }\n }\n } else {\n const doc = await payload.findGlobal({\n slug: globalSlug,\n depth: 0,\n fallbackLocale: null,\n locale: 'all',\n req,\n showHiddenFields: true,\n })\n\n traverseFields({\n doc,\n fields,\n path: '',\n rows,\n })\n\n try {\n await upsertRow({\n adapter,\n data: doc,\n db,\n fields,\n ignoreResult: true,\n operation: 'update',\n req,\n tableName,\n })\n } catch (err) {\n payload.logger.error(`The global \"${globalSlug}\" has FAILED TO MIGRATE`)\n\n throw err\n }\n\n if (debug) {\n payload.logger.info(`The global \"${globalSlug}\" has migrated successfully!`)\n }\n }\n }\n }\n }\n}\n"],"names":["upsertRow","traverseFields","fetchAndResave","adapter","collectionSlug","db","debug","docsToResave","fields","globalSlug","isVersions","payload","req","tableName","id","rows","Object","entries","collectionConfig","collections","config","doc","findVersionByID","collection","depth","fallbackLocale","locale","showHiddenFields","logger","info","slug","path","data","ignoreResult","operation","err","error","findByID","globalConfig","globals","find","global","docs","findGlobalVersions","limit","length","findGlobal"],"mappings":"AAGA,SAASA,SAAS,QAAQ,sBAAqB;AAK/C,SAASC,cAAc,QAAQ,sBAAqB;AAgBpD,OAAO,MAAMC,iBAAiB,OAAO,EACnCC,OAAO,EACPC,cAAc,EACdC,EAAE,EACFC,KAAK,EACLC,YAAY,EACZC,MAAM,EACNC,UAAU,EACVC,UAAU,EACVC,OAAO,EACPC,GAAG,EACHC,SAAS,EACJ;IACL,KAAK,MAAM,CAACC,IAAIC,KAAK,IAAIC,OAAOC,OAAO,CAACV,cAAe;QACrD,IAAIH,gBAAgB;YAClB,MAAMc,mBAAmBP,QAAQQ,WAAW,CAACf,eAAe,CAACgB,MAAM;YAEnE,IAAIF,kBAAkB;gBACpB,IAAIR,YAAY;oBACd,MAAMW,MAAM,MAAMV,QAAQW,eAAe,CAAC;wBACxCR;wBACAS,YAAYnB;wBACZoB,OAAO;wBACPC,gBAAgB;wBAChBC,QAAQ;wBACRd;wBACAe,kBAAkB;oBACpB;oBAEA,IAAIrB,OAAO;wBACTK,QAAQiB,MAAM,CAACC,IAAI,CACjB,CAAC,gBAAgB,EAAEX,iBAAiBY,IAAI,CAAC,kBAAkB,EAAEhB,GAAG,iBAAiB,CAAC;oBA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ACF,OAAO;oBACL,MAAMO,MAAM,MAAMV,QAAQmC,UAAU,CAAC;wBACnChB,MAAMrB;wBACNe,OAAO;wBACPC,gBAAgB;wBAChBC,QAAQ;wBACRd;wBACAe,kBAAkB;oBACpB;oBAEA1B,eAAe;wBACboB;wBACAb;wBACAuB,MAAM;wBACNhB;oBACF;oBAEA,IAAI;wBACF,MAAMf,UAAU;4BACdG;4BACA6B,MAAMX;4BACNhB;4BACAG;4BACAyB,cAAc;4BACdC,WAAW;4BACXtB;4BACAC;wBACF;oBACF,EAAE,OAAOsB,KAAK;wBACZxB,QAAQiB,MAAM,CAACQ,KAAK,CAAC,CAAC,YAAY,EAAE3B,WAAW,uBAAuB,CAAC;wBAEvE,MAAM0B;oBACR;oBAEA,IAAI7B,OAAO;wBACTK,QAAQiB,MAAM,CAACC,IAAI,CAAC,CAAC,YAAY,EAAEpB,WAAW,4BAA4B,CAAC;oBAC7E;gBACF;YACF;QACF;IACF;AACF,EAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Field } from 'payload';
2
+ type Args = {
3
+ doc: Record<string, unknown>;
4
+ fields: Field[];
5
+ locale?: string;
6
+ path: string;
7
+ rows: Record<string, unknown>[];
8
+ };
9
+ export declare const traverseFields: ({ doc, fields, locale, path, rows }: Args) => void;
10
+ export {};
11
+ //# sourceMappingURL=traverseFields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpC,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CAChC,CAAA;AAED,eAAO,MAAM,cAAc,wCAAyC,IAAI,SA4MvE,CAAA"}
@@ -0,0 +1,193 @@
1
+ import { tabHasName } from 'payload/shared';
2
+ export const traverseFields = ({ doc, fields, locale, path, rows })=>{
3
+ fields.forEach((field)=>{
4
+ switch(field.type){
5
+ case 'group':
6
+ {
7
+ const newPath = `${path ? `${path}.` : ''}${field.name}`;
8
+ const newDoc = doc?.[field.name];
9
+ if (typeof newDoc === 'object' && newDoc !== null) {
10
+ if (field.localized) {
11
+ Object.entries(newDoc).forEach(([locale, localeDoc])=>{
12
+ return traverseFields({
13
+ doc: localeDoc,
14
+ fields: field.fields,
15
+ locale,
16
+ path: newPath,
17
+ rows
18
+ });
19
+ });
20
+ } else {
21
+ return traverseFields({
22
+ doc: newDoc,
23
+ fields: field.fields,
24
+ path: newPath,
25
+ rows
26
+ });
27
+ }
28
+ }
29
+ break;
30
+ }
31
+ case 'row':
32
+ case 'collapsible':
33
+ {
34
+ return traverseFields({
35
+ doc,
36
+ fields: field.fields,
37
+ path,
38
+ rows
39
+ });
40
+ }
41
+ case 'array':
42
+ {
43
+ const rowData = doc?.[field.name];
44
+ if (field.localized && typeof rowData === 'object' && rowData !== null) {
45
+ Object.entries(rowData).forEach(([locale, localeRows])=>{
46
+ if (Array.isArray(localeRows)) {
47
+ localeRows.forEach((row, i)=>{
48
+ return traverseFields({
49
+ doc: row,
50
+ fields: field.fields,
51
+ locale,
52
+ path: `${path ? `${path}.` : ''}${field.name}.${i}`,
53
+ rows
54
+ });
55
+ });
56
+ }
57
+ });
58
+ }
59
+ if (Array.isArray(rowData)) {
60
+ rowData.forEach((row, i)=>{
61
+ return traverseFields({
62
+ doc: row,
63
+ fields: field.fields,
64
+ path: `${path ? `${path}.` : ''}${field.name}.${i}`,
65
+ rows
66
+ });
67
+ });
68
+ }
69
+ break;
70
+ }
71
+ case 'blocks':
72
+ {
73
+ const rowData = doc?.[field.name];
74
+ if (field.localized && typeof rowData === 'object' && rowData !== null) {
75
+ Object.entries(rowData).forEach(([locale, localeRows])=>{
76
+ if (Array.isArray(localeRows)) {
77
+ localeRows.forEach((row, i)=>{
78
+ const matchedBlock = field.blocks.find((block)=>block.slug === row.blockType);
79
+ if (matchedBlock) {
80
+ return traverseFields({
81
+ doc: row,
82
+ fields: matchedBlock.fields,
83
+ locale,
84
+ path: `${path ? `${path}.` : ''}${field.name}.${i}`,
85
+ rows
86
+ });
87
+ }
88
+ });
89
+ }
90
+ });
91
+ }
92
+ if (Array.isArray(rowData)) {
93
+ rowData.forEach((row, i)=>{
94
+ const matchedBlock = field.blocks.find((block)=>block.slug === row.blockType);
95
+ if (matchedBlock) {
96
+ return traverseFields({
97
+ doc: row,
98
+ fields: matchedBlock.fields,
99
+ path: `${path ? `${path}.` : ''}${field.name}.${i}`,
100
+ rows
101
+ });
102
+ }
103
+ });
104
+ }
105
+ break;
106
+ }
107
+ case 'tabs':
108
+ {
109
+ return field.tabs.forEach((tab)=>{
110
+ if (tabHasName(tab)) {
111
+ const newDoc = doc?.[tab.name];
112
+ const newPath = `${path ? `${path}.` : ''}${tab.name}`;
113
+ if (typeof newDoc === 'object' && newDoc !== null) {
114
+ if (tab.localized) {
115
+ Object.entries(newDoc).forEach(([locale, localeDoc])=>{
116
+ return traverseFields({
117
+ doc: localeDoc,
118
+ fields: tab.fields,
119
+ locale,
120
+ path: newPath,
121
+ rows
122
+ });
123
+ });
124
+ } else {
125
+ return traverseFields({
126
+ doc: newDoc,
127
+ fields: tab.fields,
128
+ path: newPath,
129
+ rows
130
+ });
131
+ }
132
+ }
133
+ } else {
134
+ traverseFields({
135
+ doc,
136
+ fields: tab.fields,
137
+ path,
138
+ rows
139
+ });
140
+ }
141
+ });
142
+ }
143
+ case 'relationship':
144
+ case 'upload':
145
+ {
146
+ if (typeof field.relationTo === 'string') {
147
+ if (field.type === 'upload' || !field.hasMany) {
148
+ const relationshipPath = `${path ? `${path}.` : ''}${field.name}`;
149
+ if (field.localized) {
150
+ const matchedRelationshipsWithLocales = rows.filter((row)=>row.path === relationshipPath);
151
+ if (matchedRelationshipsWithLocales.length && !doc[field.name]) {
152
+ doc[field.name] = {};
153
+ }
154
+ const newDoc = doc[field.name];
155
+ matchedRelationshipsWithLocales.forEach((localeRow)=>{
156
+ if (typeof localeRow.locale === 'string') {
157
+ const [, id] = Object.entries(localeRow).find(([key, val])=>val !== null && ![
158
+ 'id',
159
+ 'locale',
160
+ 'order',
161
+ 'parent_id',
162
+ 'path'
163
+ ].includes(key));
164
+ newDoc[localeRow.locale] = id;
165
+ }
166
+ });
167
+ } else {
168
+ const matchedRelationship = rows.find((row)=>{
169
+ const matchesPath = row.path === relationshipPath;
170
+ if (locale) {
171
+ return matchesPath && locale === row.locale;
172
+ }
173
+ return row.path === relationshipPath;
174
+ });
175
+ if (matchedRelationship) {
176
+ const [, id] = Object.entries(matchedRelationship).find(([key, val])=>val !== null && ![
177
+ 'id',
178
+ 'locale',
179
+ 'order',
180
+ 'parent_id',
181
+ 'path'
182
+ ].includes(key));
183
+ doc[field.name] = id;
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
190
+ });
191
+ };
192
+
193
+ //# sourceMappingURL=traverseFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { tabHasName } from 'payload/shared'\n\ntype Args = {\n doc: Record<string, unknown>\n fields: Field[]\n locale?: string\n path: string\n rows: Record<string, unknown>[]\n}\n\nexport const traverseFields = ({ doc, fields, locale, path, rows }: Args) => {\n fields.forEach((field) => {\n switch (field.type) {\n case 'group': {\n const newPath = `${path ? `${path}.` : ''}${field.name}`\n const newDoc = doc?.[field.name]\n\n if (typeof newDoc === 'object' && newDoc !== null) {\n if (field.localized) {\n Object.entries(newDoc).forEach(([locale, localeDoc]) => {\n return traverseFields({\n doc: localeDoc,\n fields: field.fields,\n locale,\n path: newPath,\n rows,\n })\n })\n } else {\n return traverseFields({\n doc: newDoc as Record<string, unknown>,\n fields: field.fields,\n path: newPath,\n rows,\n })\n }\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n return traverseFields({\n doc,\n fields: field.fields,\n path,\n rows,\n })\n }\n\n case 'array': {\n const rowData = doc?.[field.name]\n\n if (field.localized && typeof rowData === 'object' && rowData !== null) {\n Object.entries(rowData).forEach(([locale, localeRows]) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, i) => {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: field.fields,\n locale,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n })\n }\n })\n }\n\n if (Array.isArray(rowData)) {\n rowData.forEach((row, i) => {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: field.fields,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n })\n }\n\n break\n }\n\n case 'blocks': {\n const rowData = doc?.[field.name]\n\n if (field.localized && typeof rowData === 'object' && rowData !== null) {\n Object.entries(rowData).forEach(([locale, localeRows]) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, i) => {\n const matchedBlock = field.blocks.find((block) => block.slug === row.blockType)\n\n if (matchedBlock) {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: matchedBlock.fields,\n locale,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n }\n })\n }\n })\n }\n\n if (Array.isArray(rowData)) {\n rowData.forEach((row, i) => {\n const matchedBlock = field.blocks.find((block) => block.slug === row.blockType)\n\n if (matchedBlock) {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: matchedBlock.fields,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n }\n })\n }\n\n break\n }\n\n case 'tabs': {\n return field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n const newDoc = doc?.[tab.name]\n const newPath = `${path ? `${path}.` : ''}${tab.name}`\n\n if (typeof newDoc === 'object' && newDoc !== null) {\n if (tab.localized) {\n Object.entries(newDoc).forEach(([locale, localeDoc]) => {\n return traverseFields({\n doc: localeDoc,\n fields: tab.fields,\n locale,\n path: newPath,\n rows,\n })\n })\n } else {\n return traverseFields({\n doc: newDoc as Record<string, unknown>,\n fields: tab.fields,\n path: newPath,\n rows,\n })\n }\n }\n } else {\n traverseFields({\n doc,\n fields: tab.fields,\n path,\n rows,\n })\n }\n })\n }\n\n case 'relationship':\n case 'upload': {\n if (typeof field.relationTo === 'string') {\n if (field.type === 'upload' || !field.hasMany) {\n const relationshipPath = `${path ? `${path}.` : ''}${field.name}`\n\n if (field.localized) {\n const matchedRelationshipsWithLocales = rows.filter(\n (row) => row.path === relationshipPath,\n )\n\n if (matchedRelationshipsWithLocales.length && !doc[field.name]) {\n doc[field.name] = {}\n }\n\n const newDoc = doc[field.name] as Record<string, unknown>\n\n matchedRelationshipsWithLocales.forEach((localeRow) => {\n if (typeof localeRow.locale === 'string') {\n const [, id] = Object.entries(localeRow).find(\n ([key, val]) =>\n val !== null && !['id', 'locale', 'order', 'parent_id', 'path'].includes(key),\n )\n\n newDoc[localeRow.locale] = id\n }\n })\n } else {\n const matchedRelationship = rows.find((row) => {\n const matchesPath = row.path === relationshipPath\n\n if (locale) {\n return matchesPath && locale === row.locale\n }\n\n return row.path === relationshipPath\n })\n\n if (matchedRelationship) {\n const [, id] = Object.entries(matchedRelationship).find(\n ([key, val]) =>\n val !== null && !['id', 'locale', 'order', 'parent_id', 'path'].includes(key),\n )\n\n doc[field.name] = id\n }\n }\n }\n }\n }\n }\n })\n}\n"],"names":["tabHasName","traverseFields","doc","fields","locale","path","rows","forEach","field","type","newPath","name","newDoc","localized","Object","entries","localeDoc","rowData","localeRows","Array","isArray","row","i","matchedBlock","blocks","find","block","slug","blockType","tabs","tab","relationTo","hasMany","relationshipPath","matchedRelationshipsWithLocales","filter","length","localeRow","id","key","val","includes","matchedRelationship","matchesPath"],"mappings":"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C;4CAAC;4CAAM;4CAAU;4CAAS;4CAAa;yCAAO,CAACC,QAAQ,CAACF;oCAG7ErC,GAAG,CAACM,MAAMG,IAAI,CAAC,GAAG2B;gCACpB;4BACF;wBACF;oBACF;gBACF;QACF;IACF;AACF,EAAC"}
@@ -0,0 +1,3 @@
1
+ export type Groups = 'addColumn' | 'addConstraint' | 'dropColumn' | 'dropConstraint' | 'dropTable' | 'notNull';
2
+ export declare const groupUpSQLStatements: (list: string[]) => Record<Groups, string[]>;
3
+ //# sourceMappingURL=groupUpSQLStatements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groupUpSQLStatements.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/groupUpSQLStatements.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GACd,WAAW,GACX,eAAe,GACf,YAAY,GACZ,gBAAgB,GAChB,WAAW,GACX,SAAS,CAAA;AAgBb,eAAO,MAAM,oBAAoB,SAAU,MAAM,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAmD5E,CAAA"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Convert an "ADD COLUMN" statement to an "ALTER COLUMN" statement
3
+ * example: ALTER TABLE "pages_blocks_my_block" ADD COLUMN "person_id" integer NOT NULL;
4
+ * to: ALTER TABLE "pages_blocks_my_block" ALTER COLUMN "person_id" SET NOT NULL;
5
+ * @param sql
6
+ */ function convertAddColumnToAlterColumn(sql) {
7
+ // Regular expression to match the ADD COLUMN statement with its constraints
8
+ const regex = /ALTER TABLE ("[^"]+") ADD COLUMN ("[^"]+") [\w\s]+ NOT NULL;/;
9
+ // Replace the matched part with "ALTER COLUMN ... SET NOT NULL;"
10
+ return sql.replace(regex, 'ALTER TABLE $1 ALTER COLUMN $2 SET NOT NULL;');
11
+ }
12
+ export const groupUpSQLStatements = (list)=>{
13
+ const groups = {
14
+ addColumn: 'ADD COLUMN',
15
+ // example: ALTER TABLE "posts" ADD COLUMN "category_id" integer
16
+ addConstraint: 'ADD CONSTRAINT',
17
+ //example:
18
+ // DO $$ BEGIN
19
+ // ALTER TABLE "pages_blocks_my_block" ADD CONSTRAINT "pages_blocks_my_block_person_id_users_id_fk" FOREIGN KEY ("person_id") REFERENCES "users"("id") ON DELETE cascade ON UPDATE no action;
20
+ // EXCEPTION
21
+ // WHEN duplicate_object THEN null;
22
+ // END $$;
23
+ dropColumn: 'DROP COLUMN',
24
+ // example: ALTER TABLE "_posts_v_rels" DROP COLUMN IF EXISTS "posts_id";
25
+ dropConstraint: 'DROP CONSTRAINT',
26
+ // example: ALTER TABLE "_posts_v_rels" DROP CONSTRAINT "_posts_v_rels_posts_fk";
27
+ dropTable: 'DROP TABLE',
28
+ // example: DROP TABLE "pages_rels";
29
+ notNull: 'NOT NULL'
30
+ };
31
+ const result = Object.keys(groups).reduce((result, group)=>{
32
+ result[group] = [];
33
+ return result;
34
+ }, {});
35
+ for (const line of list){
36
+ Object.entries(groups).some(([key, value])=>{
37
+ if (line.endsWith('NOT NULL;')) {
38
+ // split up the ADD COLUMN and ALTER COLUMN NOT NULL statements
39
+ // example: ALTER TABLE "pages_blocks_my_block" ADD COLUMN "person_id" integer NOT NULL;
40
+ // becomes two separate statements:
41
+ // 1. ALTER TABLE "pages_blocks_my_block" ADD COLUMN "person_id" integer;
42
+ // 2. ALTER TABLE "pages_blocks_my_block" ALTER COLUMN "person_id" SET NOT NULL;
43
+ result.addColumn.push(line.replace(' NOT NULL;', ';'));
44
+ result.notNull.push(convertAddColumnToAlterColumn(line));
45
+ return true;
46
+ }
47
+ if (line.includes(value)) {
48
+ result[key].push(line);
49
+ return true;
50
+ }
51
+ });
52
+ }
53
+ return result;
54
+ };
55
+
56
+ //# sourceMappingURL=groupUpSQLStatements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/groupUpSQLStatements.ts"],"sourcesContent":["export type Groups =\n | 'addColumn'\n | 'addConstraint'\n | 'dropColumn'\n | 'dropConstraint'\n | 'dropTable'\n | 'notNull'\n\n/**\n * Convert an \"ADD COLUMN\" statement to an \"ALTER COLUMN\" statement\n * example: ALTER TABLE \"pages_blocks_my_block\" ADD COLUMN \"person_id\" integer NOT NULL;\n * to: ALTER TABLE \"pages_blocks_my_block\" ALTER COLUMN \"person_id\" SET NOT NULL;\n * @param sql\n */\nfunction convertAddColumnToAlterColumn(sql) {\n // Regular expression to match the ADD COLUMN statement with its constraints\n const regex = /ALTER TABLE (\"[^\"]+\") ADD COLUMN (\"[^\"]+\") [\\w\\s]+ NOT NULL;/\n\n // Replace the matched part with \"ALTER COLUMN ... SET NOT NULL;\"\n return sql.replace(regex, 'ALTER TABLE $1 ALTER COLUMN $2 SET NOT NULL;')\n}\n\nexport const groupUpSQLStatements = (list: string[]): Record<Groups, string[]> => {\n const groups = {\n addColumn: 'ADD COLUMN',\n // example: ALTER TABLE \"posts\" ADD COLUMN \"category_id\" integer\n\n addConstraint: 'ADD CONSTRAINT',\n //example:\n // DO $$ BEGIN\n // ALTER TABLE \"pages_blocks_my_block\" ADD CONSTRAINT \"pages_blocks_my_block_person_id_users_id_fk\" FOREIGN KEY (\"person_id\") REFERENCES \"users\"(\"id\") ON DELETE cascade ON UPDATE no action;\n // EXCEPTION\n // WHEN duplicate_object THEN null;\n // END $$;\n\n dropColumn: 'DROP COLUMN',\n // example: ALTER TABLE \"_posts_v_rels\" DROP COLUMN IF EXISTS \"posts_id\";\n\n dropConstraint: 'DROP CONSTRAINT',\n // example: ALTER TABLE \"_posts_v_rels\" DROP CONSTRAINT \"_posts_v_rels_posts_fk\";\n\n dropTable: 'DROP TABLE',\n // example: DROP TABLE \"pages_rels\";\n\n notNull: 'NOT NULL',\n // example: ALTER TABLE \"pages_blocks_my_block\" ALTER COLUMN \"person_id\" SET NOT NULL;\n }\n\n const result = Object.keys(groups).reduce((result, group: Groups) => {\n result[group] = []\n return result\n }, {}) as Record<Groups, string[]>\n\n for (const line of list) {\n Object.entries(groups).some(([key, value]) => {\n if (line.endsWith('NOT NULL;')) {\n // split up the ADD COLUMN and ALTER COLUMN NOT NULL statements\n // example: ALTER TABLE \"pages_blocks_my_block\" ADD COLUMN \"person_id\" integer NOT NULL;\n // becomes two separate statements:\n // 1. ALTER TABLE \"pages_blocks_my_block\" ADD COLUMN \"person_id\" integer;\n // 2. ALTER TABLE \"pages_blocks_my_block\" ALTER COLUMN \"person_id\" SET NOT NULL;\n result.addColumn.push(line.replace(' NOT NULL;', ';'))\n result.notNull.push(convertAddColumnToAlterColumn(line))\n return true\n }\n if (line.includes(value)) {\n result[key].push(line)\n return true\n }\n })\n }\n\n return result\n}\n"],"names":["convertAddColumnToAlterColumn","sql","regex","replace","groupUpSQLStatements","list","groups","addColumn","addConstraint","dropColumn","dropConstraint","dropTable","notNull","result","Object","keys","reduce","group","line","entries","some","key","value","endsWith","push","includes"],"mappings":"AAQA;;;;;CAKC,GACD,SAASA,8BAA8BC,GAAG;IACxC,4EAA4E;IAC5E,MAAMC,QAAQ;IAEd,iEAAiE;IACjE,OAAOD,IAAIE,OAAO,CAACD,OAAO;AAC5B;AAEA,OAAO,MAAME,uBAAuB,CAACC;IACnC,MAAMC,SAAS;QACbC,WAAW;QACX,gEAAgE;QAEhEC,eAAe;QACf,UAAU;QACV,cAAc;QACd,8LAA8L;QAC9L,YAAY;QACZ,oCAAoC;QACpC,UAAU;QAEVC,YAAY;QACZ,yEAAyE;QAEzEC,gBAAgB;QAChB,iFAAiF;QAEjFC,WAAW;QACX,oCAAoC;QAEpCC,SAAS;IAEX;IAEA,MAAMC,SAASC,OAAOC,IAAI,CAACT,QAAQU,MAAM,CAAC,CAACH,QAAQI;QACjDJ,MAAM,CAACI,MAAM,GAAG,EAAE;QAClB,OAAOJ;IACT,GAAG,CAAC;IAEJ,KAAK,MAAMK,QAAQb,KAAM;QACvBS,OAAOK,OAAO,CAACb,QAAQc,IAAI,CAAC,CAAC,CAACC,KAAKC,MAAM;YACvC,IAAIJ,KAAKK,QAAQ,CAAC,cAAc;gBAC9B,+DAA+D;gBAC/D,wFAAwF;gBACxF,mCAAmC;gBACnC,0EAA0E;gBAC1E,kFAAkF;gBAClFV,OAAON,SAAS,CAACiB,IAAI,CAACN,KAAKf,OAAO,CAAC,cAAc;gBACjDU,OAAOD,OAAO,CAACY,IAAI,CAACxB,8BAA8BkB;gBAClD,OAAO;YACT;YACA,IAAIA,KAAKO,QAAQ,CAACH,QAAQ;gBACxBT,MAAM,CAACQ,IAAI,CAACG,IAAI,CAACN;gBACjB,OAAO;YACT;QACF;IACF;IAEA,OAAOL;AACT,EAAC"}
@@ -0,0 +1,23 @@
1
+ import type { Payload, PayloadRequest } from 'payload';
2
+ type Args = {
3
+ debug?: boolean;
4
+ payload: Payload;
5
+ req?: Partial<PayloadRequest>;
6
+ };
7
+ /**
8
+ * Moves upload and relationship columns from the join table and into the tables while moving data
9
+ * This is done in the following order:
10
+ * ADD COLUMNs
11
+ * -- manipulate data to move relationships to new columns
12
+ * ADD CONSTRAINTs
13
+ * NOT NULLs
14
+ * DROP TABLEs
15
+ * DROP CONSTRAINTs
16
+ * DROP COLUMNs
17
+ * @param debug
18
+ * @param payload
19
+ * @param req
20
+ */
21
+ export declare const migratePostgresV2toV3: ({ debug, payload, req }: Args) => Promise<void>;
22
+ export {};
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAiBtD,KAAK,IAAI,GAAG;IACV,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;CAC9B,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,4BAAmC,IAAI,kBA8OxE,CAAA"}