@payloadcms/db-postgres 3.0.0-canary.ee6d727 → 3.0.0-canary.f13d413

Sign up to get free protection for your applications and to get access to all the features.
Files changed (394) 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 +5 -6
  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 +12 -29
  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 +17 -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.js.map +1 -1
  37. package/dist/getMigrationTemplate.d.ts +3 -0
  38. package/dist/getMigrationTemplate.d.ts.map +1 -0
  39. package/dist/getMigrationTemplate.js +12 -0
  40. package/dist/getMigrationTemplate.js.map +1 -0
  41. package/dist/index.d.ts +1 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +39 -65
  44. package/dist/index.js.map +1 -1
  45. package/dist/init.d.ts +1 -1
  46. package/dist/init.d.ts.map +1 -1
  47. package/dist/init.js +3 -11
  48. package/dist/init.js.map +1 -1
  49. package/dist/insert.d.ts +3 -0
  50. package/dist/insert.d.ts.map +1 -0
  51. package/dist/insert.js +12 -0
  52. package/dist/insert.js.map +1 -0
  53. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -1
  54. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +5 -5
  55. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
  56. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +1 -2
  57. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
  58. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +1 -1
  59. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
  60. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +1 -1
  61. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
  62. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -1
  63. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -1
  64. package/dist/predefinedMigrations/v2-v3/index.d.ts +2 -3
  65. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -1
  66. package/dist/predefinedMigrations/v2-v3/index.js +7 -7
  67. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -1
  68. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +5 -4
  69. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -1
  70. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -1
  71. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +4 -4
  72. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -1
  73. package/dist/predefinedMigrations/v2-v3/traverseFields.js +1 -1
  74. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -1
  75. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -1
  76. package/dist/requireDrizzleKit.d.ts +3 -0
  77. package/dist/requireDrizzleKit.d.ts.map +1 -0
  78. package/dist/requireDrizzleKit.js +5 -0
  79. package/dist/requireDrizzleKit.js.map +1 -0
  80. package/dist/schema/build.d.ts +1 -1
  81. package/dist/schema/build.d.ts.map +1 -1
  82. package/dist/schema/build.js +2 -2
  83. package/dist/schema/build.js.map +1 -1
  84. package/dist/schema/createIndex.d.ts.map +1 -1
  85. package/dist/schema/createIndex.js +1 -1
  86. package/dist/schema/createIndex.js.map +1 -1
  87. package/dist/schema/idToUUID.d.ts +1 -1
  88. package/dist/schema/idToUUID.d.ts.map +1 -1
  89. package/dist/schema/idToUUID.js.map +1 -1
  90. package/dist/schema/parentIDColumnMap.js.map +1 -1
  91. package/dist/schema/setColumnID.d.ts +1 -1
  92. package/dist/schema/setColumnID.d.ts.map +1 -1
  93. package/dist/schema/setColumnID.js +2 -2
  94. package/dist/schema/setColumnID.js.map +1 -1
  95. package/dist/schema/traverseFields.d.ts +1 -1
  96. package/dist/schema/traverseFields.d.ts.map +1 -1
  97. package/dist/schema/traverseFields.js +15 -16
  98. package/dist/schema/traverseFields.js.map +1 -1
  99. package/dist/schema/withDefault.d.ts +4 -0
  100. package/dist/schema/withDefault.d.ts.map +1 -0
  101. package/dist/schema/withDefault.js +10 -0
  102. package/dist/schema/withDefault.js.map +1 -0
  103. package/dist/types.d.ts +82 -37
  104. package/dist/types.d.ts.map +1 -1
  105. package/dist/types.js.map +1 -1
  106. package/package.json +19 -16
  107. package/dist/count.d.ts +0 -3
  108. package/dist/count.d.ts.map +0 -1
  109. package/dist/count.js +0 -41
  110. package/dist/count.js.map +0 -1
  111. package/dist/create.d.ts +0 -3
  112. package/dist/create.d.ts.map +0 -1
  113. package/dist/create.js +0 -19
  114. package/dist/create.js.map +0 -1
  115. package/dist/createGlobal.d.ts +0 -5
  116. package/dist/createGlobal.d.ts.map +0 -1
  117. package/dist/createGlobal.js +0 -19
  118. package/dist/createGlobal.js.map +0 -1
  119. package/dist/createGlobalVersion.d.ts +0 -6
  120. package/dist/createGlobalVersion.d.ts.map +0 -1
  121. package/dist/createGlobalVersion.js +0 -33
  122. package/dist/createGlobalVersion.js.map +0 -1
  123. package/dist/createVersion.d.ts +0 -5
  124. package/dist/createVersion.d.ts.map +0 -1
  125. package/dist/createVersion.js +0 -40
  126. package/dist/createVersion.js.map +0 -1
  127. package/dist/deleteMany.d.ts +0 -3
  128. package/dist/deleteMany.d.ts.map +0 -1
  129. package/dist/deleteMany.js +0 -28
  130. package/dist/deleteMany.js.map +0 -1
  131. package/dist/deleteOne.d.ts +0 -3
  132. package/dist/deleteOne.d.ts.map +0 -1
  133. package/dist/deleteOne.js +0 -59
  134. package/dist/deleteOne.js.map +0 -1
  135. package/dist/deleteVersions.d.ts +0 -3
  136. package/dist/deleteVersions.d.ts.map +0 -1
  137. package/dist/deleteVersions.js +0 -31
  138. package/dist/deleteVersions.js.map +0 -1
  139. package/dist/destroy.d.ts +0 -3
  140. package/dist/destroy.d.ts.map +0 -1
  141. package/dist/destroy.js +0 -15
  142. package/dist/destroy.js.map +0 -1
  143. package/dist/find/buildFindManyArgs.d.ts +0 -17
  144. package/dist/find/buildFindManyArgs.d.ts.map +0 -1
  145. package/dist/find/buildFindManyArgs.js +0 -65
  146. package/dist/find/buildFindManyArgs.js.map +0 -1
  147. package/dist/find/chainMethods.d.ts +0 -16
  148. package/dist/find/chainMethods.d.ts.map +0 -1
  149. package/dist/find/chainMethods.js +0 -12
  150. package/dist/find/chainMethods.js.map +0 -1
  151. package/dist/find/findMany.d.ts +0 -22
  152. package/dist/find/findMany.d.ts.map +0 -1
  153. package/dist/find/findMany.js +0 -152
  154. package/dist/find/findMany.js.map +0 -1
  155. package/dist/find/traverseFields.d.ts +0 -17
  156. package/dist/find/traverseFields.d.ts.map +0 -1
  157. package/dist/find/traverseFields.js +0 -156
  158. package/dist/find/traverseFields.js.map +0 -1
  159. package/dist/find.d.ts +0 -3
  160. package/dist/find.d.ts.map +0 -1
  161. package/dist/find.js +0 -21
  162. package/dist/find.js.map +0 -1
  163. package/dist/findGlobal.d.ts +0 -3
  164. package/dist/findGlobal.d.ts.map +0 -1
  165. package/dist/findGlobal.js +0 -23
  166. package/dist/findGlobal.js.map +0 -1
  167. package/dist/findGlobalVersions.d.ts +0 -3
  168. package/dist/findGlobalVersions.d.ts.map +0 -1
  169. package/dist/findGlobalVersions.js +0 -24
  170. package/dist/findGlobalVersions.js.map +0 -1
  171. package/dist/findOne.d.ts +0 -5
  172. package/dist/findOne.d.ts.map +0 -1
  173. package/dist/findOne.js +0 -21
  174. package/dist/findOne.js.map +0 -1
  175. package/dist/findVersions.d.ts +0 -3
  176. package/dist/findVersions.d.ts.map +0 -1
  177. package/dist/findVersions.js +0 -24
  178. package/dist/findVersions.js.map +0 -1
  179. package/dist/migrate.d.ts +0 -3
  180. package/dist/migrate.d.ts.map +0 -1
  181. package/dist/migrate.js +0 -99
  182. package/dist/migrate.js.map +0 -1
  183. package/dist/migrateDown.d.ts +0 -3
  184. package/dist/migrateDown.d.ts.map +0 -1
  185. package/dist/migrateDown.js +0 -63
  186. package/dist/migrateDown.js.map +0 -1
  187. package/dist/migrateFresh.d.ts +0 -8
  188. package/dist/migrateFresh.d.ts.map +0 -1
  189. package/dist/migrateFresh.js +0 -72
  190. package/dist/migrateFresh.js.map +0 -1
  191. package/dist/migrateRefresh.d.ts +0 -6
  192. package/dist/migrateRefresh.d.ts.map +0 -1
  193. package/dist/migrateRefresh.js +0 -102
  194. package/dist/migrateRefresh.js.map +0 -1
  195. package/dist/migrateReset.d.ts +0 -6
  196. package/dist/migrateReset.d.ts.map +0 -1
  197. package/dist/migrateReset.js +0 -82
  198. package/dist/migrateReset.js.map +0 -1
  199. package/dist/migrateStatus.d.ts +0 -3
  200. package/dist/migrateStatus.d.ts.map +0 -1
  201. package/dist/migrateStatus.js +0 -44
  202. package/dist/migrateStatus.js.map +0 -1
  203. package/dist/queries/buildAndOrConditions.d.ts +0 -16
  204. package/dist/queries/buildAndOrConditions.d.ts.map +0 -1
  205. package/dist/queries/buildAndOrConditions.js +0 -28
  206. package/dist/queries/buildAndOrConditions.js.map +0 -1
  207. package/dist/queries/buildQuery.d.ts +0 -30
  208. package/dist/queries/buildQuery.d.ts.map +0 -1
  209. package/dist/queries/buildQuery.js +0 -72
  210. package/dist/queries/buildQuery.js.map +0 -1
  211. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts.map +0 -1
  212. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +0 -1
  213. package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts.map +0 -1
  214. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +0 -1
  215. package/dist/queries/createJSONQuery/index.d.ts.map +0 -1
  216. package/dist/queries/createJSONQuery/index.js.map +0 -1
  217. package/dist/queries/getTableColumnFromPath.d.ts +0 -50
  218. package/dist/queries/getTableColumnFromPath.d.ts.map +0 -1
  219. package/dist/queries/getTableColumnFromPath.js +0 -517
  220. package/dist/queries/getTableColumnFromPath.js.map +0 -1
  221. package/dist/queries/operatorMap.d.ts +0 -18
  222. package/dist/queries/operatorMap.d.ts.map +0 -1
  223. package/dist/queries/operatorMap.js +0 -24
  224. package/dist/queries/operatorMap.js.map +0 -1
  225. package/dist/queries/parseParams.d.ts +0 -16
  226. package/dist/queries/parseParams.d.ts.map +0 -1
  227. package/dist/queries/parseParams.js +0 -183
  228. package/dist/queries/parseParams.js.map +0 -1
  229. package/dist/queries/sanitizeQueryValue.d.ts +0 -15
  230. package/dist/queries/sanitizeQueryValue.d.ts.map +0 -1
  231. package/dist/queries/sanitizeQueryValue.js +0 -90
  232. package/dist/queries/sanitizeQueryValue.js.map +0 -1
  233. package/dist/queries/selectDistinct.d.ts +0 -22
  234. package/dist/queries/selectDistinct.d.ts.map +0 -1
  235. package/dist/queries/selectDistinct.js +0 -30
  236. package/dist/queries/selectDistinct.js.map +0 -1
  237. package/dist/queryDrafts.d.ts +0 -3
  238. package/dist/queryDrafts.d.ts.map +0 -1
  239. package/dist/queryDrafts.js +0 -41
  240. package/dist/queryDrafts.js.map +0 -1
  241. package/dist/schema/createTableName.d.ts +0 -30
  242. package/dist/schema/createTableName.d.ts.map +0 -1
  243. package/dist/schema/createTableName.js +0 -31
  244. package/dist/schema/createTableName.js.map +0 -1
  245. package/dist/schema/validateExistingBlockIsIdentical.d.ts +0 -12
  246. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +0 -1
  247. package/dist/schema/validateExistingBlockIsIdentical.js +0 -76
  248. package/dist/schema/validateExistingBlockIsIdentical.js.map +0 -1
  249. package/dist/transactions/beginTransaction.d.ts +0 -3
  250. package/dist/transactions/beginTransaction.d.ts.map +0 -1
  251. package/dist/transactions/beginTransaction.js +0 -51
  252. package/dist/transactions/beginTransaction.js.map +0 -1
  253. package/dist/transactions/commitTransaction.d.ts +0 -3
  254. package/dist/transactions/commitTransaction.d.ts.map +0 -1
  255. package/dist/transactions/commitTransaction.js +0 -14
  256. package/dist/transactions/commitTransaction.js.map +0 -1
  257. package/dist/transactions/rollbackTransaction.d.ts +0 -3
  258. package/dist/transactions/rollbackTransaction.d.ts.map +0 -1
  259. package/dist/transactions/rollbackTransaction.js +0 -13
  260. package/dist/transactions/rollbackTransaction.js.map +0 -1
  261. package/dist/transform/read/hasManyNumber.d.ts +0 -10
  262. package/dist/transform/read/hasManyNumber.d.ts.map +0 -1
  263. package/dist/transform/read/hasManyNumber.js +0 -10
  264. package/dist/transform/read/hasManyNumber.js.map +0 -1
  265. package/dist/transform/read/hasManyText.d.ts +0 -10
  266. package/dist/transform/read/hasManyText.d.ts.map +0 -1
  267. package/dist/transform/read/hasManyText.js +0 -10
  268. package/dist/transform/read/hasManyText.js.map +0 -1
  269. package/dist/transform/read/index.d.ts +0 -14
  270. package/dist/transform/read/index.d.ts.map +0 -1
  271. package/dist/transform/read/index.js +0 -44
  272. package/dist/transform/read/index.js.map +0 -1
  273. package/dist/transform/read/relationship.d.ts +0 -10
  274. package/dist/transform/read/relationship.d.ts.map +0 -1
  275. package/dist/transform/read/relationship.js +0 -60
  276. package/dist/transform/read/relationship.js.map +0 -1
  277. package/dist/transform/read/traverseFields.d.ts +0 -57
  278. package/dist/transform/read/traverseFields.d.ts.map +0 -1
  279. package/dist/transform/read/traverseFields.js +0 -435
  280. package/dist/transform/read/traverseFields.js.map +0 -1
  281. package/dist/transform/write/array.d.ts +0 -26
  282. package/dist/transform/write/array.d.ts.map +0 -1
  283. package/dist/transform/write/array.js +0 -58
  284. package/dist/transform/write/array.js.map +0 -1
  285. package/dist/transform/write/blocks.d.ts +0 -25
  286. package/dist/transform/write/blocks.d.ts.map +0 -1
  287. package/dist/transform/write/blocks.js +0 -54
  288. package/dist/transform/write/blocks.js.map +0 -1
  289. package/dist/transform/write/index.d.ts +0 -13
  290. package/dist/transform/write/index.d.ts.map +0 -1
  291. package/dist/transform/write/index.js +0 -41
  292. package/dist/transform/write/index.js.map +0 -1
  293. package/dist/transform/write/numbers.d.ts +0 -8
  294. package/dist/transform/write/numbers.d.ts.map +0 -1
  295. package/dist/transform/write/numbers.js +0 -11
  296. package/dist/transform/write/numbers.js.map +0 -1
  297. package/dist/transform/write/relationships.d.ts +0 -10
  298. package/dist/transform/write/relationships.d.ts.map +0 -1
  299. package/dist/transform/write/relationships.js +0 -23
  300. package/dist/transform/write/relationships.js.map +0 -1
  301. package/dist/transform/write/selects.d.ts +0 -8
  302. package/dist/transform/write/selects.d.ts.map +0 -1
  303. package/dist/transform/write/selects.js +0 -20
  304. package/dist/transform/write/selects.js.map +0 -1
  305. package/dist/transform/write/texts.d.ts +0 -8
  306. package/dist/transform/write/texts.d.ts.map +0 -1
  307. package/dist/transform/write/texts.js +0 -11
  308. package/dist/transform/write/texts.js.map +0 -1
  309. package/dist/transform/write/traverseFields.d.ts +0 -50
  310. package/dist/transform/write/traverseFields.d.ts.map +0 -1
  311. package/dist/transform/write/traverseFields.js +0 -445
  312. package/dist/transform/write/traverseFields.js.map +0 -1
  313. package/dist/transform/write/types.d.ts +0 -43
  314. package/dist/transform/write/types.d.ts.map +0 -1
  315. package/dist/transform/write/types.js +0 -3
  316. package/dist/transform/write/types.js.map +0 -1
  317. package/dist/update.d.ts +0 -3
  318. package/dist/update.d.ts.map +0 -1
  319. package/dist/update.js +0 -54
  320. package/dist/update.js.map +0 -1
  321. package/dist/updateGlobal.d.ts +0 -5
  322. package/dist/updateGlobal.d.ts.map +0 -1
  323. package/dist/updateGlobal.js +0 -25
  324. package/dist/updateGlobal.js.map +0 -1
  325. package/dist/updateGlobalVersion.d.ts +0 -5
  326. package/dist/updateGlobalVersion.d.ts.map +0 -1
  327. package/dist/updateGlobalVersion.js +0 -36
  328. package/dist/updateGlobalVersion.js.map +0 -1
  329. package/dist/updateVersion.d.ts +0 -5
  330. package/dist/updateVersion.d.ts.map +0 -1
  331. package/dist/updateVersion.js +0 -36
  332. package/dist/updateVersion.js.map +0 -1
  333. package/dist/upsertRow/deleteExistingArrayRows.d.ts +0 -10
  334. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +0 -1
  335. package/dist/upsertRow/deleteExistingArrayRows.js +0 -10
  336. package/dist/upsertRow/deleteExistingArrayRows.js.map +0 -1
  337. package/dist/upsertRow/deleteExistingRowsByPath.d.ts +0 -14
  338. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +0 -1
  339. package/dist/upsertRow/deleteExistingRowsByPath.js +0 -33
  340. package/dist/upsertRow/deleteExistingRowsByPath.js.map +0 -1
  341. package/dist/upsertRow/index.d.ts +0 -4
  342. package/dist/upsertRow/index.d.ts.map +0 -1
  343. package/dist/upsertRow/index.js +0 -279
  344. package/dist/upsertRow/index.js.map +0 -1
  345. package/dist/upsertRow/insertArrays.d.ts +0 -13
  346. package/dist/upsertRow/insertArrays.d.ts.map +0 -1
  347. package/dist/upsertRow/insertArrays.js +0 -68
  348. package/dist/upsertRow/insertArrays.js.map +0 -1
  349. package/dist/upsertRow/types.d.ts +0 -32
  350. package/dist/upsertRow/types.d.ts.map +0 -1
  351. package/dist/upsertRow/types.js +0 -3
  352. package/dist/upsertRow/types.js.map +0 -1
  353. package/dist/utilities/appendPrefixToKeys.d.ts +0 -2
  354. package/dist/utilities/appendPrefixToKeys.d.ts.map +0 -1
  355. package/dist/utilities/appendPrefixToKeys.js +0 -6
  356. package/dist/utilities/appendPrefixToKeys.js.map +0 -1
  357. package/dist/utilities/createBlocksMap.d.ts +0 -5
  358. package/dist/utilities/createBlocksMap.d.ts.map +0 -1
  359. package/dist/utilities/createBlocksMap.js +0 -29
  360. package/dist/utilities/createBlocksMap.js.map +0 -1
  361. package/dist/utilities/createMigrationTable.d.ts +0 -3
  362. package/dist/utilities/createMigrationTable.d.ts.map +0 -1
  363. package/dist/utilities/createMigrationTable.js +0 -13
  364. package/dist/utilities/createMigrationTable.js.map +0 -1
  365. package/dist/utilities/createRelationshipMap.d.ts +0 -2
  366. package/dist/utilities/createRelationshipMap.d.ts.map +0 -1
  367. package/dist/utilities/createRelationshipMap.js +0 -19
  368. package/dist/utilities/createRelationshipMap.js.map +0 -1
  369. package/dist/utilities/hasLocalesTable.d.ts +0 -3
  370. package/dist/utilities/hasLocalesTable.d.ts.map +0 -1
  371. package/dist/utilities/hasLocalesTable.js +0 -11
  372. package/dist/utilities/hasLocalesTable.js.map +0 -1
  373. package/dist/utilities/isArrayOfRows.d.ts +0 -2
  374. package/dist/utilities/isArrayOfRows.d.ts.map +0 -1
  375. package/dist/utilities/isArrayOfRows.js +0 -5
  376. package/dist/utilities/isArrayOfRows.js.map +0 -1
  377. package/dist/utilities/migrationTableExists.d.ts +0 -3
  378. package/dist/utilities/migrationTableExists.d.ts.map +0 -1
  379. package/dist/utilities/migrationTableExists.js +0 -9
  380. package/dist/utilities/migrationTableExists.js.map +0 -1
  381. package/dist/utilities/parseError.d.ts +0 -5
  382. package/dist/utilities/parseError.d.ts.map +0 -1
  383. package/dist/utilities/parseError.js +0 -17
  384. package/dist/utilities/parseError.js.map +0 -1
  385. package/dist/utilities/pushDevSchema.d.ts +0 -9
  386. package/dist/utilities/pushDevSchema.d.ts.map +0 -1
  387. package/dist/utilities/pushDevSchema.js +0 -58
  388. package/dist/utilities/pushDevSchema.js.map +0 -1
  389. /package/dist/{queries/createJSONQuery → createJSONQuery}/convertPathToJSONTraversal.d.ts +0 -0
  390. /package/dist/{queries/createJSONQuery → createJSONQuery}/convertPathToJSONTraversal.js +0 -0
  391. /package/dist/{queries/createJSONQuery → createJSONQuery}/formatJSONPathSegment.d.ts +0 -0
  392. /package/dist/{queries/createJSONQuery → createJSONQuery}/formatJSONPathSegment.js +0 -0
  393. /package/dist/{queries/createJSONQuery → createJSONQuery}/index.d.ts +0 -0
  394. /package/dist/{queries/createJSONQuery → createJSONQuery}/index.js +0 -0
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type { DatabaseAdapterObj } from 'payload/database'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { createDatabaseAdapter } from 'payload/database'\n\nimport type { Args, PostgresAdapter } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrate } from './migrate.js'\nimport { migrateDown } from './migrateDown.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { migrateRefresh } from './migrateRefresh.js'\nimport { migrateReset } from './migrateReset.js'\nimport { migrateStatus } from './migrateStatus.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateOne } from './update.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateVersion } from './updateVersion.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport { sql } from 'drizzle-orm'\n\nexport function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter> {\n const postgresIDType = args.idType || 'serial'\n const payloadIDType = postgresIDType === 'serial' ? 'number' : 'text'\n\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(args.migrationDir)\n let resolveInitializing\n let rejectInitializing\n\n const initializing = new Promise<void>((res, rej) => {\n resolveInitializing = res\n rejectInitializing = rej\n })\n\n return createDatabaseAdapter<PostgresAdapter>({\n name: 'postgres',\n drizzle: undefined,\n enums: {},\n fieldConstraints: {},\n idType: postgresIDType,\n initializing,\n localesSuffix: args.localesSuffix || '_locales',\n logger: args.logger,\n pgSchema: undefined,\n pool: undefined,\n poolOptions: args.pool,\n push: args.push,\n relations: {},\n relationshipsSuffix: args.relationshipsSuffix || '_rels',\n schema: {},\n schemaName: args.schemaName,\n sessions: {},\n tableNameMap: new Map<string, string>(),\n tables: {},\n versionsSuffix: args.versionsSuffix || '_v',\n\n // DatabaseAdapter\n beginTransaction,\n commitTransaction,\n connect,\n count,\n create,\n createGlobal,\n createGlobalVersion,\n createMigration,\n createVersion,\n defaultIDType: payloadIDType,\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n migrate,\n migrateDown,\n migrateFresh,\n migrateRefresh,\n migrateReset,\n migrateStatus,\n migrationDir,\n payload,\n queryDrafts,\n rejectInitializing,\n resolveInitializing,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: payloadIDType,\n init: adapter,\n }\n}\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nfunction findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) return migrationDir\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","path","createDatabaseAdapter","connect","count","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateOne","updateGlobal","updateGlobalVersion","updateVersion","sql","postgresAdapter","args","postgresIDType","idType","payloadIDType","adapter","payload","migrationDir","findMigrationDir","resolveInitializing","rejectInitializing","initializing","Promise","res","rej","name","drizzle","undefined","enums","fieldConstraints","localesSuffix","logger","pgSchema","pool","poolOptions","push","relations","relationshipsSuffix","schema","schemaName","sessions","tableNameMap","Map","tables","vers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AO;QACLqC,eAAe/B;QACfpB,MAAMqB;IACR;AACF;AAEA;;;;;;;;;;;;;CAaC,GACD,SAASG,iBAAiBD,YAAqB;IAC7C,MAAM6B,MAAMC,QAAQD,GAAG;IACvB,MAAME,SAASxE,KAAKyE,OAAO,CAACH,KAAK;IACjC,MAAMI,UAAU1E,KAAKyE,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqB3E,KAAKyE,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAI7B,cAAc,OAAOA;IAEzB,+BAA+B;IAC/B,IAAI1C,GAAG6E,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAIzE,GAAG6E,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAI3E,GAAG6E,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { DatabaseAdapterObj, Payload } from 'payload'\n\nimport {\n beginTransaction,\n commitTransaction,\n count,\n create,\n createGlobal,\n createGlobalVersion,\n createVersion,\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findMigrationDir,\n findOne,\n findVersions,\n migrate,\n migrateDown,\n migrateFresh,\n migrateRefresh,\n migrateReset,\n migrateStatus,\n operatorMap,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n} from '@payloadcms/drizzle'\nimport { type PgSchema, pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core'\nimport { createDatabaseAdapter } from 'payload'\n\nimport type { Args, PostgresAdapter } from './types.js'\n\nimport { connect } from './connect.js'\nimport { countDistinct } from './countDistinct.js'\nimport { convertPathToJSONTraversal } from './createJSONQuery/convertPathToJSONTraversal.js'\nimport { createJSONQuery } from './createJSONQuery/index.js'\nimport { createMigration } from './createMigration.js'\nimport { defaultDrizzleSnapshot } from './defaultSnapshot.js'\nimport { deleteWhere } from './deleteWhere.js'\nimport { dropDatabase } from './dropDatabase.js'\nimport { execute } from './execute.js'\nimport { getMigrationTemplate } from './getMigrationTemplate.js'\nimport { init } from './init.js'\nimport { insert } from './insert.js'\nimport { requireDrizzleKit } from './requireDrizzleKit.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport { sql } from 'drizzle-orm'\n\nexport function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter> {\n const postgresIDType = args.idType || 'serial'\n const payloadIDType = postgresIDType === 'serial' ? 'number' : 'text'\n\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(args.migrationDir)\n let resolveInitializing\n let rejectInitializing\n let adapterSchema: PostgresAdapter['pgSchema']\n\n const initializing = new Promise<void>((res, rej) => {\n resolveInitializing = res\n rejectInitializing = rej\n })\n\n if (args.schemaName) {\n adapterSchema = pgSchema(args.schemaName)\n } else {\n adapterSchema = { enum: pgEnum, table: pgTable }\n }\n\n return createDatabaseAdapter<PostgresAdapter>({\n name: 'postgres',\n defaultDrizzleSnapshot,\n drizzle: undefined,\n enums: {},\n features: {\n json: true,\n },\n fieldConstraints: {},\n getMigrationTemplate,\n idType: postgresIDType,\n initializing,\n localesSuffix: args.localesSuffix || '_locales',\n logger: args.logger,\n operators: operatorMap,\n pgSchema: adapterSchema,\n pool: undefined,\n poolOptions: args.pool,\n push: args.push,\n relations: {},\n relationshipsSuffix: args.relationshipsSuffix || '_rels',\n schema: {},\n schemaName: args.schemaName,\n sessions: {},\n tableNameMap: new Map<string, string>(),\n tables: {},\n transactionOptions: args.transactionOptions || undefined,\n versionsSuffix: args.versionsSuffix || '_v',\n\n // DatabaseAdapter\n beginTransaction: args.transactionOptions === false ? undefined : beginTransaction,\n commitTransaction,\n connect,\n convertPathToJSONTraversal,\n count,\n countDistinct,\n create,\n createGlobal,\n createGlobalVersion,\n createJSONQuery,\n createMigration,\n createVersion,\n defaultIDType: payloadIDType,\n deleteMany,\n deleteOne,\n deleteVersions,\n deleteWhere,\n destroy,\n dropDatabase,\n execute,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n insert,\n migrate,\n migrateDown,\n migrateFresh,\n migrateRefresh,\n migrateReset,\n migrateStatus,\n migrationDir,\n payload,\n queryDrafts,\n rejectInitializing,\n requireDrizzleKit,\n resolveInitializing,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: payloadIDType,\n init: adapter,\n }\n}\n"],"names":["beginTransaction","commitTransaction","count","create","createGlobal","createGlobalVersion","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findMigrationDir","findOne","findVersions","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","operatorMap","queryDrafts","rollbackTransaction","updateGlobal","updateGlobalVersion","updateOne","updateVersion","pgEnum","pgSchema","pgTable","createDatabaseAdapter","connect","countDistinct","convertPathToJSONTraversal","createJSONQuery","createMigration","defaultDrizzleSnapshot","deleteWhere","dropDatabase","execute","getMigrationTemplate","init","insert","requireDrizzleKit","sql","postgresAdapter","args","postgresIDType","idType","payloadIDType","adapter","payload","migrationDir","resolveInitializing","rejectInitializing","adapterSchema","initializing","Promise","res","rej","schemaName","enum","table","name","drizzle","undefined","enums","features","json","fieldConstraints","localesSuffix","logger","operators","pool","poolOptions","push","relations","relationshipsSuffix","schema","sessions","tableNameMap","Map","tables","transactionOptions","versionsSuffix","defaultIDType"],"mappings":"AAEA,SACEA,gBAAgB,EAChBC,iBAAiB,EACjBC,KAAK,EACLC,MAAM,EACNC,YAAY,EACZC,mBAAmB,EACnBC,aAAa,EACbC,UAAU,EACVC,SAAS,EACTC,cAAc,EACdC,OAAO,EACPC,IAAI,EACJC,UAAU,EACVC,kBAAkB,EAClBC,gBAAgB,EAChBC,OAAO,EACPC,YAAY,EACZC,OAAO,EACPC,WAAW,EACXC,YAAY,EACZC,cAAc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YACA4B,SAASC;YACTC,OAAO,CAAC;YACRC,UAAU;gBACRC,MAAM;YACR;YACAC,kBAAkB,CAAC;YACnB7B;YACAQ,QAAQD;YACRS;YACAc,eAAexB,KAAKwB,aAAa,IAAI;YACrCC,QAAQzB,KAAKyB,MAAM;YACnBC,WAAWpD;YACXQ,UAAU2B;YACVkB,MAAMR;YACNS,aAAa5B,KAAK2B,IAAI;YACtBE,MAAM7B,KAAK6B,IAAI;YACfC,WAAW,CAAC;YACZC,qBAAqB/B,KAAK+B,mBAAmB,IAAI;YACjDC,QAAQ,CAAC;YACTlB,YAAYd,KAAKc,UAAU;YAC3BmB,UAAU,CAAC;YACXC,cAAc,IAAIC;YAClBC,QAAQ,CAAC;YACTC,oBAAoBrC,KAAKqC,kBAAkB,IAAIlB;YAC/CmB,gBAAgBtC,KAAKsC,cAAc,IAAI;YAEvC,kBAAkB;YAClBvF,kBAAkBiD,KAAKqC,kBAAkB,KAAK,QAAQlB,YAAYpE;YAClEC;YACAiC;YACAE;YACAlC;YACAiC;YACAhC;YACAC;YACAC;YACAgC;YACAC;YACAhC;YACAkF,eAAepC;YACf7C;YACAC;YACAC;YACA+B;YACA9B;YACA+B;YACAC;YACA/B;YACAC;YACAC;YACAE;YACAC;YACA4B;YACAC;YACA5B;YACAC;YACAC;YACAC;YACAC;YACAC;YACAiC;YACAD;YACA9B;YACAiC;YACAX;YACAU;YACA/B;YACAC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAO;QACL2D,eAAepC;QACfR,MAAMS;IACR;AACF"}
package/dist/init.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { Init } from 'payload/database';
1
+ import type { Init } from 'payload';
2
2
  export declare const init: Init;
3
3
  //# sourceMappingURL=init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAY5C,eAAO,MAAM,IAAI,EAAE,IA6FlB,CAAA"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;AAU9D,eAAO,MAAM,IAAI,EAAE,IAuFlB,CAAA"}
package/dist/init.js CHANGED
@@ -1,18 +1,10 @@
1
- /* eslint-disable no-param-reassign */ import { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core';
2
- import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions';
1
+ import { createTableName } from '@payloadcms/drizzle';
2
+ import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
3
3
  import toSnakeCase from 'to-snake-case';
4
4
  import { buildTable } from './schema/build.js';
5
- import { createTableName } from './schema/createTableName.js';
6
5
  export const init = function init() {
7
- if (this.schemaName) {
8
- this.pgSchema = pgSchema(this.schemaName);
9
- } else {
10
- this.pgSchema = {
11
- table: pgTable
12
- };
13
- }
14
6
  if (this.payload.config.localization) {
15
- this.enums.enum__locales = pgEnum('_locales', this.payload.config.localization.locales.map(({ code })=>code));
7
+ this.enums.enum__locales = this.pgSchema.enum('_locales', this.payload.config.localization.locales.map(({ code })=>code));
16
8
  }
17
9
  this.payload.config.collections.forEach((collection)=>{
18
10
  createTableName({
package/dist/init.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/init.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Init } from 'payload/database'\nimport type { SanitizedCollectionConfig } from 'payload/types'\n\nimport { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { buildTable } from './schema/build.js'\nimport { createTableName } from './schema/createTableName.js'\n\nexport const init: Init = function init(this: PostgresAdapter) {\n if (this.schemaName) {\n this.pgSchema = pgSchema(this.schemaName)\n } else {\n this.pgSchema = { table: pgTable }\n }\n\n if (this.payload.config.localization) {\n this.enums.enum__locales = pgEnum(\n '_locales',\n this.payload.config.localization.locales.map(({ code }) => code) as [string, ...string[]],\n )\n }\n\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n createTableName({\n adapter: this,\n config: collection,\n })\n\n if (collection.versions) {\n createTableName({\n adapter: this,\n config: collection,\n versions: true,\n versionsCustomName: true,\n })\n }\n })\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n\n buildTable({\n adapter: this,\n disableNotNull: !!collection?.versions?.drafts,\n disableUnique: false,\n fields: collection.fields,\n tableName,\n timestamps: collection.timestamps,\n versions: false,\n })\n\n if (collection.versions) {\n const versionsTableName = this.tableNameMap.get(\n `_${toSnakeCase(collection.slug)}${this.versionsSuffix}`,\n )\n const versionFields = buildVersionCollectionFields(collection)\n\n buildTable({\n adapter: this,\n disableNotNull: !!collection.versions?.drafts,\n disableUnique: true,\n fields: versionFields,\n tableName: versionsTableName,\n timestamps: true,\n versions: true,\n })\n }\n })\n\n this.payload.config.globals.forEach((global) => {\n const tableName = createTableName({ adapter: this, config: global })\n\n buildTable({\n adapter: this,\n disableNotNull: !!global?.versions?.drafts,\n disableUnique: false,\n fields: global.fields,\n tableName,\n timestamps: false,\n versions: false,\n })\n\n if (global.versions) {\n const versionsTableName = createTableName({\n adapter: this,\n config: global,\n versions: true,\n versionsCustomName: true,\n })\n const versionFields = buildVersionGlobalFields(global)\n\n buildTable({\n adapter: this,\n disableNotNull: !!global.versions?.drafts,\n disableUnique: true,\n fields: versionFields,\n tableName: versionsTableName,\n timestamps: true,\n versions: true,\n })\n }\n })\n}\n"],"names":["pgEnum","pgSchema","pgTable","buildVersionCollectionFields","buildVersionGlobalFields","toSnakeCase","buildTable","createTableName","init","schemaName","table","payload","config","localization","enums","enum__locales","locales","map","code","collections","forEach","collection","adapter","versions","versionsCustomName","tableName","tableNameMap","get","slug","disableNotNull","drafts","disableUnique","fields","timestamps","versionsTableName","versionsSuffix","versionFields","globals","global"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAIpC,SAASA,MAAM,EAAEC,QAAQ,EAAEC,OAAO,QAAQ,sBAAqB;AAC/D,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,mBAAkB;AACzF,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,eAAe,QAAQ,8BAA6B;AAE7D,OAAO,MAAMC,OAAa,SAASA;IACjC,IAAI,IAAI,CAACC,UAAU,EAAE;QACnB,IAAI,CAACR,QAAQ,GAAGA,SAAS,IAAI,CAACQ,UAAU;IAC1C,OAAO;QACL,IAAI,CAACR,QAAQ,GAAG;YAAES,OAAOR;QAAQ;IACnC;IAEA,IAAI,IAAI,CAACS,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;QACpC,IAAI,CAACC,KAAK,CAACC,aAAa,GAAGf,OACzB,YACA,IAAI,CAACW,OAAO,CAACC,MAAM,CAACC,YAAY,CAACG,OAAO,CAACC,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA;IAE/D;IAEA,IAAI,CAACP,OAAO,CAACC,MAAM,CAACO,WAAW,CAACC,OAAO,CAAC,CAACC;QACvCd,gBAAgB;YACde,SAAS,IAAI;YACbV,QAAQS;QACV;QAEA,IAAIA,WAAWE,QAAQ,EAAE;YACvBhB,gBAAgB;gBACde,SAAS,IAAI;gBACbV,QAAQS;gBACRE,UAAU;gBACVC,oBAAoB;YACtB;QACF;IACF;IACA,IAAI,CAACb,OAAO,CAACC,MAAM,CAACO,WAAW,CAACC,OAAO,CAAC,CAACC;QACvC,MAAMI,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACt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}
1
+ {"version":3,"sources":["../src/init.ts"],"sourcesContent":["import type { Init, SanitizedCollectionConfig } from 'payload'\n\nimport { createTableName } from '@payloadcms/drizzle'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { buildTable } from './schema/build.js'\n\nexport const init: Init = function init(this: PostgresAdapter) {\n if (this.payload.config.localization) {\n this.enums.enum__locales = this.pgSchema.enum(\n '_locales',\n this.payload.config.localization.locales.map(({ code }) => code) as [string, ...string[]],\n )\n }\n\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n createTableName({\n adapter: this,\n config: collection,\n })\n\n if (collection.versions) {\n createTableName({\n adapter: this,\n config: collection,\n versions: true,\n versionsCustomName: true,\n })\n }\n })\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n\n buildTable({\n adapter: this,\n disableNotNull: !!collection?.versions?.drafts,\n disableUnique: false,\n fields: collection.fields,\n tableName,\n timestamps: collection.timestamps,\n versions: false,\n })\n\n if (collection.versions) {\n const versionsTableName = this.tableNameMap.get(\n `_${toSnakeCase(collection.slug)}${this.versionsSuffix}`,\n )\n const versionFields = buildVersionCollectionFields(collection)\n\n buildTable({\n adapter: this,\n disableNotNull: !!collection.versions?.drafts,\n disableUnique: true,\n fields: versionFields,\n tableName: versionsTableName,\n timestamps: true,\n versions: true,\n })\n }\n })\n\n this.payload.config.globals.forEach((global) => {\n const tableName = createTableName({ adapter: this, config: global })\n\n buildTable({\n adapter: this,\n disableNotNull: !!global?.versions?.drafts,\n disableUnique: false,\n fields: global.fields,\n tableName,\n timestamps: false,\n versions: false,\n })\n\n if (global.versions) {\n const versionsTableName = createTableName({\n adapter: this,\n config: global,\n versions: true,\n versionsCustomName: true,\n })\n const versionFields = buildVersionGlobalFields(global)\n\n buildTable({\n adapter: this,\n disableNotNull: !!global.versions?.drafts,\n disableUnique: true,\n fields: versionFields,\n tableName: versionsTableName,\n timestamps: true,\n versions: true,\n })\n }\n })\n}\n"],"names":["createTableName","buildVersionCollectionFields","buildVersionGlobalFields","toSnakeCase","buildTable","init","payload","config","localization","enums","enum__locales","pgSchema","enum","locales","map","code","collections","forEach","collection","adapter","versions","versionsCustomName","tableName","tableNameMap","get","slug","disableNotNull","drafts","disableUnique","fields","timestamps","versionsTableName","versionsSuffix","versionFields","globals","global"],"mappings":"AAEA,SAASA,eAAe,QAAQ,sBAAqB;AACrD,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAChF,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,UAAU,QAAQ,oBAAmB;AAE9C,OAAO,MAAMC,OAAa,SAASA;IACjC,IAAI,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;QACpC,IAAI,CAACC,KAAK,CAACC,aAAa,GAAG,IAAI,CAACC,QAAQ,CAACC,IAAI,CAC3C,YACA,IAAI,CAACN,OAAO,CAACC,MAAM,CAACC,YAAY,CAACK,OAAO,CAACC,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA;IAE/D;IAEA,IAAI,CAACT,OAAO,CAACC,MAAM,CAACS,WAAW,CAACC,OAAO,CAAC,CAACC;QACvClB,gBAAgB;YACdmB,SAAS,IAAI;YACbZ,QAAQW;QACV;QAEA,IAAIA,WAAWE,QAAQ,EAAE;YACvBpB,gBAAgB;gBACdmB,SAAS,IAAI;gBACbZ,QAAQW;gBACRE,UAAU;gBACVC,oBAAoB;YACtB;QACF;IACF;IACA,IAAI,CAACf,OAAO,CAACC,MAAM,CAACS,WAAW,CAACC,OAAO,CAAC,CAACC;QACvC,MAAMI,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACrB,YAAYe,WAAWO,IAAI;QAEnErB,WAAW;YACTe,SAAS,IAAI;YACbO,gBAAgB,CAAC,CAACR,YAAYE,UAAUO;YACxCC,eAAe;YACfC,QAAQX,WAAWW,MAAM;YACzBP;YACAQ,YAAYZ,WAAWY,UAAU;YACjCV,UAAU;QACZ;QAEA,IAAIF,WAAWE,QAAQ,EAAE;YACvB,MAAMW,oBAAoB,IAAI,CAACR,YAAY,CAACC,GAAG,CAC7C,CAAC,CAAC,EAAErB,YAAYe,WAAWO,IAAI,EAAE,EAAE,IAAI,CAACO,cAAc,CAAC,CAAC;YAE1D,MAAMC,gBAAgBhC,6BAA6BiB;YAEnDd,WAAW;gBACTe,SAAS,IAAI;gBACbO,gBAAgB,CAAC,CAACR,WAAWE,QAAQ,EAAEO;gBACvCC,eAAe;gBACfC,QAAQI;gBACRX,WAAWS;gBACXD,YAAY;gBACZV,UAAU;YACZ;QACF;IACF;IAEA,IAAI,CAACd,OAAO,CAACC,MAAM,CAAC2B,OAAO,CAACjB,OAAO,CAAC,CAACkB;QACnC,MAAMb,YAAYtB,gBAAgB;YAAEmB,SAAS,IAAI;YAAEZ,QAAQ4B;QAAO;QAElE/B,WAAW;YACTe,SAAS,IAAI;YACbO,gBAAgB,CAAC,CAACS,QAAQf,UAAUO;YACpCC,eAAe;YACfC,QAAQM,OAAON,MAAM;YACrBP;YACAQ,YAAY;YACZV,UAAU;QACZ;QAEA,IAAIe,OAAOf,QAAQ,EAAE;YACnB,MAAMW,oBAAoB/B,gBAAgB;gBACxCmB,SAAS,IAAI;gBACbZ,QAAQ4B;gBACRf,UAAU;gBACVC,oBAAoB;YACtB;YACA,MAAMY,gBAAgB/B,yBAAyBiC;YAE/C/B,WAAW;gBACTe,SAAS,IAAI;gBACbO,gBAAgB,CAAC,CAACS,OAAOf,QAAQ,EAAEO;gBACnCC,eAAe;gBACfC,QAAQI;gBACRX,WAAWS;gBACXD,YAAY;gBACZV,UAAU;YACZ;QACF;IACF;AACF,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Insert } from './types.js';
2
+ export declare const insert: Insert;
3
+ //# sourceMappingURL=insert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insert.d.ts","sourceRoot":"","sources":["../src/insert.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAExC,eAAO,MAAM,MAAM,EAAE,MAoBpB,CAAA"}
package/dist/insert.js ADDED
@@ -0,0 +1,12 @@
1
+ export const insert = async function insert({ db, onConflictDoUpdate, tableName, values }) {
2
+ const table = this.tables[tableName];
3
+ let result;
4
+ if (onConflictDoUpdate) {
5
+ result = await db.insert(table).values(values).onConflictDoUpdate(onConflictDoUpdate).returning();
6
+ } else {
7
+ result = await db.insert(table).values(values).returning();
8
+ }
9
+ return result;
10
+ };
11
+
12
+ //# sourceMappingURL=insert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/insert.ts"],"sourcesContent":["import type { TransactionPg } from '@payloadcms/drizzle/types'\n\nimport type { Insert } from './types.js'\n\nexport const insert: Insert = async function insert({\n db,\n onConflictDoUpdate,\n tableName,\n values,\n}): Promise<Record<string, unknown>[]> {\n const table = this.tables[tableName]\n let result\n\n if (onConflictDoUpdate) {\n result = await (db as TransactionPg)\n .insert(table)\n .values(values)\n .onConflictDoUpdate(onConflictDoUpdate)\n .returning()\n } else {\n result = await (db as TransactionPg).insert(table).values(values).returning()\n }\n\n return result\n}\n"],"names":["insert","db","onConflictDoUpdate","tableName","values","table","tables","result","returning"],"mappings":"AAIA,OAAO,MAAMA,SAAiB,eAAeA,OAAO,EAClDC,EAAE,EACFC,kBAAkB,EAClBC,SAAS,EACTC,MAAM,EACP;IACC,MAAMC,QAAQ,IAAI,CAACC,MAAM,CAACH,UAAU;IACpC,IAAII;IAEJ,IAAIL,oBAAoB;QACtBK,SAAS,MAAM,AAACN,GACbD,MAAM,CAACK,OACPD,MAAM,CAACA,QACPF,kBAAkB,CAACA,oBACnBM,SAAS;IACd,OAAO;QACLD,SAAS,MAAM,AAACN,GAAqBD,MAAM,CAACK,OAAOD,MAAM,CAACA,QAAQI,SAAS;IAC7E;IAEA,OAAOD;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/predefinedMigrations/relationships-v2-v3.ts"],"sourcesContent":["const imports = `import { migratePostgresV2toV3 } from '@payloadcms/db-postgres/migration-utils'`\nconst upSQL = ` await migratePostgresV2toV3({\n // enables logging of changes that will be made to the database\n debug: false,\n payload,\n req,\n })\n`\n\nexport { imports, upSQL }\n"],"names":["imports","upSQL"],"rangeMappings":";;;;;;;;","mappings":"AAAA,MAAMA,UAAU,CAAC,+EAA+E,CAAC;AACjG,MAAMC,QAAQ,CAAC;;;;;;AAMf,CAAC;AAED,SAASD,OAAO,EAAEC,KAAK,GAAE"}
1
+ {"version":3,"sources":["../../src/predefinedMigrations/relationships-v2-v3.ts"],"sourcesContent":["const imports = `import { migratePostgresV2toV3 } from '@payloadcms/db-postgres/migration-utils'`\nconst upSQL = ` await migratePostgresV2toV3({\n // enables logging of changes that will be made to the database\n debug: false,\n payload,\n req,\n })\n`\n\nexport { imports, upSQL }\n"],"names":["imports","upSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,+EAA+E,CAAC;AACjG,MAAMC,QAAQ,CAAC;;;;;;AAMf,CAAC;AAED,SAASD,OAAO,EAAEC,KAAK,GAAE"}
@@ -1,18 +1,18 @@
1
- import type { Payload } from 'payload';
2
- import type { Field, PayloadRequestWithData } from 'payload/types';
3
- import type { DrizzleTransaction, PostgresAdapter } from '../../../types.js';
1
+ import type { TransactionPg } from '@payloadcms/drizzle/types';
2
+ import type { Field, Payload, PayloadRequest } from 'payload';
3
+ import type { PostgresAdapter } from '../../../types.js';
4
4
  import type { DocsToResave } from '../types.js';
5
5
  type Args = {
6
6
  adapter: PostgresAdapter;
7
7
  collectionSlug?: string;
8
- db: DrizzleTransaction;
8
+ db: TransactionPg;
9
9
  debug: boolean;
10
10
  docsToResave: DocsToResave;
11
11
  fields: Field[];
12
12
  globalSlug?: string;
13
13
  isVersions: boolean;
14
14
  payload: Payload;
15
- req: PayloadRequestWithData;
15
+ req: PayloadRequest;
16
16
  tableName: string;
17
17
  };
18
18
  export declare const fetchAndResave: ({ adapter, collectionSlug, db, debug, docsToResave, fields, globalSlug, isVersions, payload, req, tableName, }: Args) => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAElE,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAK/C,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,kBAAkB,CAAA;IACtB,KAAK,EAAE,OAAO,CAAA;IACd,YAAY,EAAE,YAAY,CAAA;IAC1B,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,sBAAsB,CAAA;IAC3B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,cAAc,mHAYxB,IAAI,kBAyMN,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAI7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI/C,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,aAAa,CAAA;IACjB,KAAK,EAAE,OAAO,CAAA;IACd,YAAY,EAAE,YAAY,CAAA;IAC1B,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,cAAc,mHAYxB,IAAI,kBAwMN,CAAA"}
@@ -1,4 +1,4 @@
1
- import { upsertRow } from '../../../upsertRow/index.js';
1
+ import { upsertRow } from '@payloadcms/drizzle';
2
2
  import { traverseFields } from './traverseFields.js';
3
3
  export const fetchAndResave = async ({ adapter, collectionSlug, db, debug, docsToResave, fields, globalSlug, isVersions, payload, req, tableName })=>{
4
4
  for (const [id, rows] of Object.entries(docsToResave)){
@@ -144,7 +144,6 @@ export const fetchAndResave = async ({ adapter, collectionSlug, db, debug, docsT
144
144
  });
145
145
  try {
146
146
  await upsertRow({
147
- id: doc.id,
148
147
  adapter,
149
148
  data: doc,
150
149
  db,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/index.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type { Field, PayloadRequestWithData } from 'payload/types'\n\nimport type { DrizzleTransaction, PostgresAdapter } from '../../../types.js'\nimport type { DocsToResave } from '../types.js'\n\nimport { upsertRow } from '../../../upsertRow/index.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n db: DrizzleTransaction\n debug: boolean\n docsToResave: DocsToResave\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n payload: Payload\n req: PayloadRequestWithData\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 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(`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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AC;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"}
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,CAA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EAAEpB,WAAW,kBAAkB,EAAEY,IAAIP,EAAE,CAAC,uBAAuB,CAAC;wBAEtE;oBACF;gBACF,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"}
@@ -1,4 +1,4 @@
1
- import type { Field } from 'payload/types';
1
+ import type { Field } from 'payload';
2
2
  type Args = {
3
3
  doc: Record<string, unknown>;
4
4
  fields: Field[];
@@ -1 +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,eAAe,CAAA;AAI1C,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,SA0MvE,CAAA"}
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,SA0MvE,CAAA"}
@@ -1,4 +1,4 @@
1
- import { tabHasName } from 'payload/types';
1
+ import { tabHasName } from 'payload/shared';
2
2
  export const traverseFields = ({ doc, fields, locale, path, rows })=>{
3
3
  fields.forEach((field)=>{
4
4
  switch(field.type){
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.ts"],"sourcesContent":["import type { Field } from 'payload/types'\n\nimport { tabHasName } from 'payload/types'\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) return matchesPath && locale === row.locale\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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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MAAM,GAAGJ,GAAG,GAAGxB,OAAOC,OAAO,CAAC2B,qBAAqBjB,IAAI,CACrD,CAAC,CAACc,KAAKC,IAAI,GACTA,QAAQ,QAAQ,CAAC;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"}
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) return matchesPath && locale === row.locale\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":"AAEA,SAASA,UAAU,QAAQ,iBAAgB;AAU3C,OAAO,MAAMC,iBAAiB,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAQ;IACtEH,OAAOI,OAAO,CAAC,CAACC;QACd,OAAQA,MAAMC,IAAI;YAChB,KAAK;gBAAS;oBACZ,MAAMC,UAAU,CAAC,EAAEL,OAAO,CAAC,EAAEA,KAAK,CAAC,CAAC,GAAG,GAAG,EAAEG,MAAMG,IAAI,CAAC,CAAC;oBACxD,MAAMC,SAASV,KAAK,CAACM,MAAMG,IAAI,CAAC;oBAEhC,IAAI,OAAOC,WAAW,YAAYA,WAAW,MAAM;wBACjD,IAAIJ,MAAMK,SAAS,EAAE;4BACnBC,OAAOC,OAAO,CAACH,QAAQL,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E9BuB,gCAAgC3B,OAAO,CAAC,CAAC8B;oCACvC,IAAI,OAAOA,UAAUjC,MAAM,KAAK,UAAU;wCACxC,MAAM,GAAGkC,GAAG,GAAGxB,OAAOC,OAAO,CAACsB,WAAWZ,IAAI,CAC3C,CAAC,CAACc,KAAKC,IAAI,GACTA,QAAQ,QAAQ,CAAC;gDAAC;gDAAM;gDAAU;gDAAS;gDAAa;6CAAO,CAACC,QAAQ,CAACF;wCAG7E3B,MAAM,CAACyB,UAAUjC,MAAM,CAAC,GAAGkC;oCAC7B;gCACF;4BACF,OAAO;gCACL,MAAMI,sBAAsBpC,KAAKmB,IAAI,CAAC,CAACJ;oCACrC,MAAMsB,cAActB,IAAIhB,IAAI,KAAK4B;oCAEjC,IAAI7B,QAAQ,OAAOuC,eAAevC,WAAWiB,IAAIjB,MAAM;oCAEvD,OAAOiB,IAAIhB,IAAI,KAAK4B;gCACtB;gCAEA,IAAIS,qBAAqB;oCACvB,MAAM,GAAGJ,GAAG,GAAGxB,OAAOC,OAAO,CAAC2B,qBAAqBjB,IAAI,CACrD,CAAC,CAACc,KAAKC,IAAI,GACTA,QAAQ,QAAQ,CAAC;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"}
@@ -1 +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,OAAO,MAAM,EAAE,MAAM,EAAE,CAmD5E,CAAA"}
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"}
@@ -1 +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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","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"}
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"}
@@ -1,9 +1,8 @@
1
- import type { Payload } from 'payload';
2
- import type { PayloadRequestWithData } from 'payload/types';
1
+ import type { Payload, PayloadRequest } from 'payload';
3
2
  type Args = {
4
3
  debug?: boolean;
5
4
  payload: Payload;
6
- req?: Partial<PayloadRequestWithData>;
5
+ req?: Partial<PayloadRequest>;
7
6
  };
8
7
  /**
9
8
  * Moves upload and relationship columns from the join table and into the tables while moving data
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAiB3D,KAAK,IAAI,GAAG;IACV,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAA;CACtC,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,4BAAmC,IAAI,kBA8OxE,CAAA"}
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"}
@@ -1,7 +1,7 @@
1
1
  import { sql } from 'drizzle-orm';
2
2
  import fs from 'fs';
3
3
  import { createRequire } from 'module';
4
- import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions';
4
+ import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
5
5
  import toSnakeCase from 'to-snake-case';
6
6
  import { groupUpSQLStatements } from './groupUpSQLStatements.js';
7
7
  import { migrateRelationships } from './migrateRelationships.js';
@@ -22,17 +22,17 @@ const require = createRequire(import.meta.url);
22
22
  * @param req
23
23
  */ export const migratePostgresV2toV3 = async ({ debug, payload, req })=>{
24
24
  const adapter = payload.db;
25
- const db = adapter.sessions[req.transactionID]?.db;
25
+ const db = adapter.sessions[await req.transactionID].db;
26
26
  const dir = payload.db.migrationDir;
27
27
  // get the drizzle migrateUpSQL from drizzle using the last schema
28
- const { generateDrizzleJson, generateMigration } = require('drizzle-kit/payload');
28
+ const { generateDrizzleJson, generateMigration } = require('drizzle-kit/api');
29
29
  const drizzleJsonAfter = generateDrizzleJson(adapter.schema);
30
- // Get latest migration snapshot
31
- const latestSnapshot = fs.readdirSync(dir).filter((file)=>file.endsWith('.json')).sort().reverse()?.[0];
32
- if (!latestSnapshot) {
30
+ // Get the previous migration snapshot
31
+ const previousSnapshot = fs.readdirSync(dir).filter((file)=>file.endsWith('.json') && !file.endsWith('relationships_v2_v3.json')).sort().reverse()?.[0];
32
+ if (!previousSnapshot) {
33
33
  throw new Error(`No previous migration schema file found! A prior migration from v2 is required to migrate to v3.`);
34
34
  }
35
- const drizzleJsonBefore = JSON.parse(fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'));
35
+ const drizzleJsonBefore = JSON.parse(fs.readFileSync(`${dir}/${previousSnapshot}`, 'utf8'));
36
36
  const generatedSQL = await generateMigration(drizzleJsonBefore, drizzleJsonAfter);
37
37
  if (!generatedSQL.length) {
38
38
  payload.logger.info(`No schema changes needed.`);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/index.ts"],"sourcesContent":["import type { DrizzleSnapshotJSON } from 'drizzle-kit/payload'\nimport type { Payload } from 'payload'\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport { sql } from 'drizzle-orm'\nimport fs from 'fs'\nimport { createRequire } from 'module'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { PathsToQuery } from './types.js'\n\nimport { groupUpSQLStatements } from './groupUpSQLStatements.js'\nimport { migrateRelationships } from './migrateRelationships.js'\nimport { traverseFields } from './traverseFields.js'\n\nconst require = createRequire(import.meta.url)\n\ntype Args = {\n debug?: boolean\n payload: Payload\n req?: Partial<PayloadRequestWithData>\n}\n\n/**\n * Moves upload and relationship columns from the join table and into the tables while moving data\n * This is done in the following order:\n * ADD COLUMNs\n * -- manipulate data to move relationships to new columns\n * ADD CONSTRAINTs\n * NOT NULLs\n * DROP TABLEs\n * DROP CONSTRAINTs\n * DROP COLUMNs\n * @param debug\n * @param payload\n * @param req\n */\nexport const migratePostgresV2toV3 = async ({ debug, payload, req }: Args) => {\n const adapter = payload.db as PostgresAdapter\n const db = adapter.sessions[req.transactionID]?.db\n const dir = payload.db.migrationDir\n\n // get the drizzle migrateUpSQL from drizzle using the last schema\n const { generateDrizzleJson, generateMigration } = require('drizzle-kit/payload')\n const drizzleJsonAfter = generateDrizzleJson(adapter.schema)\n\n // Get latest migration snapshot\n const latestSnapshot = fs\n .readdirSync(dir)\n .filter((file) => file.endsWith('.json'))\n .sort()\n .reverse()?.[0]\n\n if (!latestSnapshot) {\n throw new Error(\n `No previous migration schema file found! A prior migration from v2 is required to migrate to v3.`,\n )\n }\n\n const drizzleJsonBefore = JSON.parse(\n fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'),\n ) as DrizzleSnapshotJSON\n\n const generatedSQL = await generateMigration(drizzleJsonBefore, drizzleJsonAfter)\n\n if (!generatedSQL.length) {\n payload.logger.info(`No schema changes needed.`)\n process.exit(0)\n }\n\n const sqlUpStatements = groupUpSQLStatements(generatedSQL)\n\n const addColumnsStatement = sqlUpStatements.addColumn.join('\\n')\n\n if (debug) {\n payload.logger.info('CREATING NEW RELATIONSHIP COLUMNS')\n payload.logger.info(addColumnsStatement)\n }\n\n await db.execute(sql.raw(addColumnsStatement))\n\n for (const collection of payload.config.collections) {\n const tableName = adapter.tableNameMap.get(toSnakeCase(collection.slug))\n const pathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n collectionSlug: collection.slug,\n columnPrefix: '',\n db,\n disableNotNull: false,\n fields: collection.fields,\n isVersions: false,\n newTableName: tableName,\n parentTableName: tableName,\n path: '',\n pathsToQuery,\n payload,\n rootTableName: tableName,\n })\n\n await migrateRelationships({\n adapter,\n collectionSlug: collection.slug,\n db,\n debug,\n fields: collection.fields,\n isVersions: false,\n pathsToQuery,\n payload,\n req,\n tableName,\n })\n\n if (collection.versions) {\n const versionsTableName = adapter.tableNameMap.get(\n `_${toSnakeCase(collection.slug)}${adapter.versionsSuffix}`,\n )\n const versionFields = buildVersionCollectionFields(collection)\n const versionPathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n collectionSlug: collection.slug,\n columnPrefix: '',\n db,\n disableNotNull: true,\n fields: versionFields,\n isVersions: true,\n newTableName: versionsTableName,\n parentTableName: versionsTableName,\n path: '',\n pathsToQuery: versionPathsToQuery,\n payload,\n rootTableName: versionsTableName,\n })\n\n await migrateRelationships({\n adapter,\n collectionSlug: collection.slug,\n db,\n debug,\n fields: versionFields,\n isVersions: true,\n pathsToQuery: versionPathsToQuery,\n payload,\n req,\n tableName: versionsTableName,\n })\n }\n }\n\n for (const global of payload.config.globals) {\n const tableName = adapter.tableNameMap.get(toSnakeCase(global.slug))\n\n const pathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n columnPrefix: '',\n db,\n disableNotNull: false,\n fields: global.fields,\n globalSlug: global.slug,\n isVersions: false,\n newTableName: tableName,\n parentTableName: tableName,\n path: '',\n pathsToQuery,\n payload,\n rootTableName: tableName,\n })\n\n await migrateRelationships({\n adapter,\n db,\n debug,\n fields: global.fields,\n globalSlug: global.slug,\n isVersions: false,\n pathsToQuery,\n payload,\n req,\n tableName,\n })\n\n if (global.versions) {\n const versionsTableName = adapter.tableNameMap.get(\n `_${toSnakeCase(global.slug)}${adapter.versionsSuffix}`,\n )\n\n const versionFields = buildVersionGlobalFields(global)\n\n const versionPathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n columnPrefix: '',\n db,\n disableNotNull: true,\n fields: versionFields,\n globalSlug: global.slug,\n isVersions: true,\n newTableName: versionsTableName,\n parentTableName: versionsTableName,\n path: '',\n pathsToQuery: versionPathsToQuery,\n payload,\n rootTableName: versionsTableName,\n })\n\n await migrateRelationships({\n adapter,\n db,\n debug,\n fields: versionFields,\n globalSlug: global.slug,\n isVersions: true,\n pathsToQuery: versionPathsToQuery,\n payload,\n req,\n tableName: versionsTableName,\n })\n }\n }\n\n // ADD CONSTRAINT\n const addConstraintsStatement = sqlUpStatements.addConstraint.join('\\n')\n\n if (debug) {\n payload.logger.info('ADDING CONSTRAINTS')\n payload.logger.info(addConstraintsStatement)\n }\n\n await db.execute(sql.raw(addConstraintsStatement))\n\n // NOT NULL\n const notNullStatements = sqlUpStatements.notNull.join('\\n')\n\n if (debug) {\n payload.logger.info('NOT NULL CONSTRAINTS')\n payload.logger.info(notNullStatements)\n }\n\n await db.execute(sql.raw(notNullStatements))\n\n // DROP TABLE\n const dropTablesStatement = sqlUpStatements.dropTable.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING TABLES')\n payload.logger.info(dropTablesStatement)\n }\n\n await db.execute(sql.raw(dropTablesStatement))\n\n // DROP CONSTRAINT\n const dropConstraintsStatement = sqlUpStatements.dropConstraint.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING CONSTRAINTS')\n payload.logger.info(dropConstraintsStatement)\n }\n\n await db.execute(sql.raw(dropConstraintsStatement))\n\n // DROP COLUMN\n const dropColumnsStatement = sqlUpStatements.dropColumn.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING COLUMNS')\n payload.logger.info(dropColumnsStatement)\n }\n\n await db.execute(sql.raw(dropColumnsStatement))\n}\n"],"names":["sql","fs","createRequire","buildVersionCollectionFields","buildVersionGlobalFields","toSnakeCase","groupUpSQLStatements","migrateRelationships","traverseFields","require","url","migratePostgresV2toV3","debug","payload","req","adapter","db","sessions","transactionID","dir","migrationDir","generateDrizzleJson","generateMigration","drizzleJsonAfter","schema","latestSnapshot","readdirSync","filter","file","endsWith","sort","reverse","Error","drizzleJsonBefore","JSON","parse","readFileSync","generatedSQL","length","logger","info","process","exit","sqlUpStatements","addColumnsStatement","addColumn","join","execute","raw","collection","config","collections","tableName","tableNameMap","get","slug","pathsToQuery","Set","collectionSlug","columnPrefix","disableNotNull","fields","isVersions","newTableName","parentTableName","path","rootTableName","versions","versionsTableName","versionsSuffix","versionFields","versionPathsToQuery","global","globals","globalSlug","addConstraintsStatement","addConstraint","notNullStatements","notNull","dropTablesStatement","dropTable","dropConstraintsStatement","dropConstraint","dropColumnsStatement","dropColumn"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,GAAG,QAAQ,cAAa;AACjC,OAAOC,QAAQ,KAAI;AACnB,SAASC,aAAa,QAAQ,SAAQ;AACtC,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,mBAAkB;AACzF,OAAOC,iBAAiB,gBAAe;AAKvC,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,oBAAoB,QAAQ,4B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MAAM,CAACC,IAAI,CAACmC;IACtB;IAEA,MAAM3D,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAAC2B;IAEzB,WAAW;IACX,MAAME,oBAAoBlC,gBAAgBmC,OAAO,CAAChC,IAAI,CAAC;IAEvD,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAACqC;IACtB;IAEA,MAAM7D,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAAC6B;IAEzB,aAAa;IACb,MAAME,sBAAsBpC,gBAAgBqC,SAAS,CAAClC,IAAI,CAAC;IAE3D,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAACuC;IACtB;IAEA,MAAM/D,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAAC+B;IAEzB,kBAAkB;IAClB,MAAME,2BAA2BtC,gBAAgBuC,cAAc,CAACpC,IAAI,CAAC;IAErE,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAACyC;IACtB;IAEA,MAAMjE,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAACiC;IAEzB,cAAc;IACd,MAAME,uBAAuBxC,gBAAgByC,UAAU,CAACtC,IAAI,CAAC;IAE7D,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAAC2C;IACtB;IAEA,MAAMnE,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAACmC;AAC3B,EAAC"}
1
+ {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/index.ts"],"sourcesContent":["import type { TransactionPg } from '@payloadcms/drizzle/types'\nimport type { DrizzleSnapshotJSON } from 'drizzle-kit/api'\nimport type { Payload, PayloadRequest } from 'payload'\n\nimport { sql } from 'drizzle-orm'\nimport fs from 'fs'\nimport { createRequire } from 'module'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { PathsToQuery } from './types.js'\n\nimport { groupUpSQLStatements } from './groupUpSQLStatements.js'\nimport { migrateRelationships } from './migrateRelationships.js'\nimport { traverseFields } from './traverseFields.js'\n\nconst require = createRequire(import.meta.url)\n\ntype Args = {\n debug?: boolean\n payload: Payload\n req?: Partial<PayloadRequest>\n}\n\n/**\n * Moves upload and relationship columns from the join table and into the tables while moving data\n * This is done in the following order:\n * ADD COLUMNs\n * -- manipulate data to move relationships to new columns\n * ADD CONSTRAINTs\n * NOT NULLs\n * DROP TABLEs\n * DROP CONSTRAINTs\n * DROP COLUMNs\n * @param debug\n * @param payload\n * @param req\n */\nexport const migratePostgresV2toV3 = async ({ debug, payload, req }: Args) => {\n const adapter = payload.db as unknown as PostgresAdapter\n const db = adapter.sessions[await req.transactionID].db as TransactionPg\n const dir = payload.db.migrationDir\n\n // get the drizzle migrateUpSQL from drizzle using the last schema\n const { generateDrizzleJson, generateMigration } = require('drizzle-kit/api')\n const drizzleJsonAfter = generateDrizzleJson(adapter.schema)\n\n // Get the previous migration snapshot\n const previousSnapshot = fs\n .readdirSync(dir)\n .filter((file) => file.endsWith('.json') && !file.endsWith('relationships_v2_v3.json'))\n .sort()\n .reverse()?.[0]\n\n if (!previousSnapshot) {\n throw new Error(\n `No previous migration schema file found! A prior migration from v2 is required to migrate to v3.`,\n )\n }\n\n const drizzleJsonBefore = JSON.parse(\n fs.readFileSync(`${dir}/${previousSnapshot}`, 'utf8'),\n ) as DrizzleSnapshotJSON\n\n const generatedSQL = await generateMigration(drizzleJsonBefore, drizzleJsonAfter)\n\n if (!generatedSQL.length) {\n payload.logger.info(`No schema changes needed.`)\n process.exit(0)\n }\n\n const sqlUpStatements = groupUpSQLStatements(generatedSQL)\n\n const addColumnsStatement = sqlUpStatements.addColumn.join('\\n')\n\n if (debug) {\n payload.logger.info('CREATING NEW RELATIONSHIP COLUMNS')\n payload.logger.info(addColumnsStatement)\n }\n\n await db.execute(sql.raw(addColumnsStatement))\n\n for (const collection of payload.config.collections) {\n const tableName = adapter.tableNameMap.get(toSnakeCase(collection.slug))\n const pathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n collectionSlug: collection.slug,\n columnPrefix: '',\n db,\n disableNotNull: false,\n fields: collection.fields,\n isVersions: false,\n newTableName: tableName,\n parentTableName: tableName,\n path: '',\n pathsToQuery,\n payload,\n rootTableName: tableName,\n })\n\n await migrateRelationships({\n adapter,\n collectionSlug: collection.slug,\n db,\n debug,\n fields: collection.fields,\n isVersions: false,\n pathsToQuery,\n payload,\n req,\n tableName,\n })\n\n if (collection.versions) {\n const versionsTableName = adapter.tableNameMap.get(\n `_${toSnakeCase(collection.slug)}${adapter.versionsSuffix}`,\n )\n const versionFields = buildVersionCollectionFields(collection)\n const versionPathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n collectionSlug: collection.slug,\n columnPrefix: '',\n db,\n disableNotNull: true,\n fields: versionFields,\n isVersions: true,\n newTableName: versionsTableName,\n parentTableName: versionsTableName,\n path: '',\n pathsToQuery: versionPathsToQuery,\n payload,\n rootTableName: versionsTableName,\n })\n\n await migrateRelationships({\n adapter,\n collectionSlug: collection.slug,\n db,\n debug,\n fields: versionFields,\n isVersions: true,\n pathsToQuery: versionPathsToQuery,\n payload,\n req,\n tableName: versionsTableName,\n })\n }\n }\n\n for (const global of payload.config.globals) {\n const tableName = adapter.tableNameMap.get(toSnakeCase(global.slug))\n\n const pathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n columnPrefix: '',\n db,\n disableNotNull: false,\n fields: global.fields,\n globalSlug: global.slug,\n isVersions: false,\n newTableName: tableName,\n parentTableName: tableName,\n path: '',\n pathsToQuery,\n payload,\n rootTableName: tableName,\n })\n\n await migrateRelationships({\n adapter,\n db,\n debug,\n fields: global.fields,\n globalSlug: global.slug,\n isVersions: false,\n pathsToQuery,\n payload,\n req,\n tableName,\n })\n\n if (global.versions) {\n const versionsTableName = adapter.tableNameMap.get(\n `_${toSnakeCase(global.slug)}${adapter.versionsSuffix}`,\n )\n\n const versionFields = buildVersionGlobalFields(global)\n\n const versionPathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n columnPrefix: '',\n db,\n disableNotNull: true,\n fields: versionFields,\n globalSlug: global.slug,\n isVersions: true,\n newTableName: versionsTableName,\n parentTableName: versionsTableName,\n path: '',\n pathsToQuery: versionPathsToQuery,\n payload,\n rootTableName: versionsTableName,\n })\n\n await migrateRelationships({\n adapter,\n db,\n debug,\n fields: versionFields,\n globalSlug: global.slug,\n isVersions: true,\n pathsToQuery: versionPathsToQuery,\n payload,\n req,\n tableName: versionsTableName,\n })\n }\n }\n\n // ADD CONSTRAINT\n const addConstraintsStatement = sqlUpStatements.addConstraint.join('\\n')\n\n if (debug) {\n payload.logger.info('ADDING CONSTRAINTS')\n payload.logger.info(addConstraintsStatement)\n }\n\n await db.execute(sql.raw(addConstraintsStatement))\n\n // NOT NULL\n const notNullStatements = sqlUpStatements.notNull.join('\\n')\n\n if (debug) {\n payload.logger.info('NOT NULL CONSTRAINTS')\n payload.logger.info(notNullStatements)\n }\n\n await db.execute(sql.raw(notNullStatements))\n\n // DROP TABLE\n const dropTablesStatement = sqlUpStatements.dropTable.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING TABLES')\n payload.logger.info(dropTablesStatement)\n }\n\n await db.execute(sql.raw(dropTablesStatement))\n\n // DROP CONSTRAINT\n const dropConstraintsStatement = sqlUpStatements.dropConstraint.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING CONSTRAINTS')\n payload.logger.info(dropConstraintsStatement)\n }\n\n await db.execute(sql.raw(dropConstraintsStatement))\n\n // DROP COLUMN\n const dropColumnsStatement = sqlUpStatements.dropColumn.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING COLUMNS')\n payload.logger.info(dropColumnsStatement)\n }\n\n await db.execute(sql.raw(dropColumnsStatement))\n}\n"],"names":["sql","fs","createRequire","buildVersionCollectionFields","buildVersionGlobalFields","toSnakeCase","groupUpSQLStatements","migrateRelationships","traverseFields","require","url","migratePostgresV2toV3","debug","payload","req","adapter","db","sessions","transactionID","dir","migrationDir","generateDrizzleJson","generateMigration","drizzleJsonAfter","schema","previousSnapshot","readdirSync","filter","file","endsWith","sort","reverse","Error","drizzleJsonBefore","JSON","parse","readFileSync","generatedSQL","length","logger","info","process","exit","sqlUpStatements","addColumnsStatement","addColumn","join","execute","raw","collection","config","collections","tableName","tableNameMap","get","slug","pathsToQuery","Set","collectionSlug","columnPrefix","disableNotNull","fields","isVersions","newTableName","parentTableName","path","rootTableName","versions","versionsTableName","versionsSuffix","versionFields","versionPathsToQuery","global","globals","globalSlug","addConstraintsStatement","addConstraint","notNullStatements","notNull","dropTablesStatement","dropTable","dropConstraintsStatement","dropConstraint","dropColumnsStatement","dropColumn"],"mappings":"AAIA,SAASA,GAAG,QAAQ,cAAa;AACjC,OAAOC,QAAQ,KAAI;AACnB,SAASC,aAAa,QAAQ,SAAQ;AACtC,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAChF,OAAOC,iBAAiB,gBAAe;AAKvC,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,cAAc,QAAQ,sBAAqB;AAEpD,MAAMC,UAAUP,cAAc,YAAYQ,GAAG;AAQ7C;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMC,wBAAwB,OAAO,EAAEC,KAAK,EAAEC,OAAO,EAAEC,GAAG,EAAQ;IACvE,MAAMC,UAAUF,QAAQG,EAAE;IAC1B,MAAMA,KAAKD,QAAQE,QAAQ,CAAC,MAAMH,IAAII,aAAa,CAAC,CAACF,EAAE;IACvD,MAAMG,MAAMN,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EA,MAAM7D,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAAC6B;IAEzB,aAAa;IACb,MAAME,sBAAsBpC,gBAAgBqC,SAAS,CAAClC,IAAI,CAAC;IAE3D,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAACuC;IACtB;IAEA,MAAM/D,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAAC+B;IAEzB,kBAAkB;IAClB,MAAME,2BAA2BtC,gBAAgBuC,cAAc,CAACpC,IAAI,CAAC;IAErE,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAACyC;IACtB;IAEA,MAAMjE,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAACiC;IAEzB,cAAc;IACd,MAAME,uBAAuBxC,gBAAgByC,UAAU,CAACtC,IAAI,CAAC;IAE7D,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAAC2C;IACtB;IAEA,MAAMnE,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAACmC;AAC3B,EAAC"}
@@ -1,17 +1,18 @@
1
- import type { Field, Payload, PayloadRequestWithData } from 'payload/types';
2
- import type { DrizzleTransaction, PostgresAdapter } from '../../types.js';
1
+ import type { TransactionPg } from '@payloadcms/drizzle/types';
2
+ import type { Field, Payload, PayloadRequest } from 'payload';
3
+ import type { PostgresAdapter } from '../../types.js';
3
4
  import type { PathsToQuery } from './types.js';
4
5
  type Args = {
5
6
  adapter: PostgresAdapter;
6
7
  collectionSlug?: string;
7
- db: DrizzleTransaction;
8
+ db: TransactionPg;
8
9
  debug: boolean;
9
10
  fields: Field[];
10
11
  globalSlug?: string;
11
12
  isVersions: boolean;
12
13
  pathsToQuery: PathsToQuery;
13
14
  payload: Payload;
14
- req?: Partial<PayloadRequestWithData>;
15
+ req?: Partial<PayloadRequest>;
15
16
  tableName: string;
16
17
  };
17
18
  export declare const migrateRelationships: ({ adapter, collectionSlug, db, debug, fields, globalSlug, isVersions, pathsToQuery, payload, req, tableName, }: Args) => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"migrateRelationships.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/migrateRelationships.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAI3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,YAAY,CAAA;AAI5D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,kBAAkB,CAAA;IACtB,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,YAAY,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAA;IACrC,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,oBAAoB,mHAY9B,IAAI,kBAkEN,CAAA"}
1
+ {"version":3,"file":"migrateRelationships.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/migrateRelationships.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAI7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,YAAY,CAAA;AAI5D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,aAAa,CAAA;IACjB,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,YAAY,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,oBAAoB,mHAY9B,IAAI,kBAkEN,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/migrateRelationships.ts"],"sourcesContent":["import type { Field, Payload, PayloadRequestWithData } from 'payload/types'\n\nimport { sql } from 'drizzle-orm'\n\nimport type { DrizzleTransaction, PostgresAdapter } from '../../types.js'\nimport type { DocsToResave, PathsToQuery } from './types.js'\n\nimport { fetchAndResave } from './fetchAndResave/index.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n db: DrizzleTransaction\n debug: boolean\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n pathsToQuery: PathsToQuery\n payload: Payload\n req?: Partial<PayloadRequestWithData>\n tableName: string\n}\n\nexport const migrateRelationships = async ({\n adapter,\n collectionSlug,\n db,\n debug,\n fields,\n globalSlug,\n isVersions,\n pathsToQuery,\n payload,\n req,\n tableName,\n}: Args) => {\n if (pathsToQuery.size === 0) return\n\n let offset = 0\n\n let paginationResult\n\n const where = Array.from(pathsToQuery).reduce((statement, path, i) => {\n return (statement += `\n\"${tableName}${adapter.relationshipsSuffix}\".\"path\" LIKE '${path}'${pathsToQuery.size !== i + 1 ? ' OR' : ''}\n`)\n }, '')\n\n while (typeof paginationResult === 'undefined' || paginationResult.rows.length > 0) {\n const paginationStatement = `SELECT DISTINCT parent_id FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n ${where} ORDER BY parent_id LIMIT 500 OFFSET ${offset * 500};\n `\n\n paginationResult = await adapter.drizzle.execute(sql.raw(`${paginationStatement}`))\n\n if (paginationResult.rows.length === 0) return\n\n offset += 1\n\n const statement = `SELECT * FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n (${where}) AND parent_id IN (${paginationResult.rows.map((row) => row.parent_id).join(', ')});\n`\n if (debug) {\n payload.logger.info('FINDING ROWS TO MIGRATE')\n payload.logger.info(statement)\n }\n\n const result = await adapter.drizzle.execute(sql.raw(`${statement}`))\n\n const docsToResave: DocsToResave = {}\n\n result.rows.forEach((row) => {\n const parentID = row.parent_id\n\n if (typeof parentID === 'string' || typeof parentID === 'number') {\n if (!docsToResave[parentID]) docsToResave[parentID] = []\n docsToResave[parentID].push(row)\n }\n })\n\n await fetchAndResave({\n adapter,\n collectionSlug,\n db,\n debug,\n docsToResave,\n fields,\n globalSlug,\n isVersions,\n payload,\n req: req as PayloadRequestWithData,\n tableName,\n })\n }\n\n const deleteStatement = `DELETE FROM ${tableName}${adapter.relationshipsSuffix} WHERE ${where}`\n if (debug) {\n payload.logger.info('DELETING ROWS')\n payload.logger.info(deleteStatement)\n }\n await db.execute(sql.raw(`${deleteStatement}`))\n}\n"],"names":["sql","fetchAndResave","migrateRelationships","adapter","collectionSlug","db","debug","fields","globalSlug","isVersions","pathsToQuery","payload","req","tableName","size","offset","paginationResult","where","Array","from","reduce","statement","path","i","relationshipsSuffix","rows","length","paginationStatement","drizzle","execute","raw","map","row","parent_id","join","logger","info","result","docsToResave","forEach","parentID","push","deleteStatement"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,GAAG,QAAQ,c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ACf;QACtB;QAEA,MAAMgB,SAAS,MAAMlC,QAAQyB,OAAO,CAACC,OAAO,CAAC7B,IAAI8B,GAAG,CAAC,CAAC,EAAET,UAAU,CAAC;QAEnE,MAAMiB,eAA6B,CAAC;QAEpCD,OAAOZ,IAAI,CAACc,OAAO,CAAC,CAACP;YACnB,MAAMQ,WAAWR,IAAIC,SAAS;YAE9B,IAAI,OAAOO,aAAa,YAAY,OAAOA,aAAa,UAAU;gBAChE,IAAI,CAACF,YAAY,CAACE,SAAS,EAAEF,YAAY,CAACE,SAAS,GAAG,EAAE;gBACxDF,YAAY,CAACE,SAAS,CAACC,IAAI,CAACT;YAC9B;QACF;QAEA,MAAM/B,eAAe;YACnBE;YACAC;YACAC;YACAC;YACAgC;YACA/B;YACAC;YACAC;YACAE;YACAC,KAAKA;YACLC;QACF;IACF;IAEA,MAAM6B,kBAAkB,CAAC,YAAY,EAAE7B,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC,OAAO,EAAEP,MAAM,CAAC;IAC/F,IAAIX,OAAO;QACTK,QAAQwB,MAAM,CAACC,IAAI,CAAC;QACpBzB,QAAQwB,MAAM,CAACC,IAAI,CAACM;IACtB;IACA,MAAMrC,GAAGwB,OAAO,CAAC7B,IAAI8B,GAAG,CAAC,CAAC,EAAEY,gBAAgB,CAAC;AAC/C,EAAC"}
1
+ {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/migrateRelationships.ts"],"sourcesContent":["import type { TransactionPg } from '@payloadcms/drizzle/types'\nimport type { Field, Payload, PayloadRequest } from 'payload'\n\nimport { sql } from 'drizzle-orm'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { DocsToResave, PathsToQuery } from './types.js'\n\nimport { fetchAndResave } from './fetchAndResave/index.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n db: TransactionPg\n debug: boolean\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n pathsToQuery: PathsToQuery\n payload: Payload\n req?: Partial<PayloadRequest>\n tableName: string\n}\n\nexport const migrateRelationships = async ({\n adapter,\n collectionSlug,\n db,\n debug,\n fields,\n globalSlug,\n isVersions,\n pathsToQuery,\n payload,\n req,\n tableName,\n}: Args) => {\n if (pathsToQuery.size === 0) return\n\n let offset = 0\n\n let paginationResult\n\n const where = Array.from(pathsToQuery).reduce((statement, path, i) => {\n return (statement += `\n\"${tableName}${adapter.relationshipsSuffix}\".\"path\" LIKE '${path}'${pathsToQuery.size !== i + 1 ? ' OR' : ''}\n`)\n }, '')\n\n while (typeof paginationResult === 'undefined' || paginationResult.rows.length > 0) {\n const paginationStatement = `SELECT DISTINCT parent_id FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n ${where} ORDER BY parent_id LIMIT 500 OFFSET ${offset * 500};\n `\n\n paginationResult = await adapter.drizzle.execute(sql.raw(`${paginationStatement}`))\n\n if (paginationResult.rows.length === 0) return\n\n offset += 1\n\n const statement = `SELECT * FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n (${where}) AND parent_id IN (${paginationResult.rows.map((row) => row.parent_id).join(', ')});\n`\n if (debug) {\n payload.logger.info('FINDING ROWS TO MIGRATE')\n payload.logger.info(statement)\n }\n\n const result = await adapter.drizzle.execute(sql.raw(`${statement}`))\n\n const docsToResave: DocsToResave = {}\n\n result.rows.forEach((row) => {\n const parentID = row.parent_id\n\n if (typeof parentID === 'string' || typeof parentID === 'number') {\n if (!docsToResave[parentID]) docsToResave[parentID] = []\n docsToResave[parentID].push(row)\n }\n })\n\n await fetchAndResave({\n adapter,\n collectionSlug,\n db,\n debug,\n docsToResave,\n fields,\n globalSlug,\n isVersions,\n payload,\n req: req as unknown as PayloadRequest,\n tableName,\n })\n }\n\n const deleteStatement = `DELETE FROM ${tableName}${adapter.relationshipsSuffix} WHERE ${where}`\n if (debug) {\n payload.logger.info('DELETING ROWS')\n payload.logger.info(deleteStatement)\n }\n await db.execute(sql.raw(`${deleteStatement}`))\n}\n"],"names":["sql","fetchAndResave","migrateRelationships","adapter","collectionSlug","db","debug","fields","globalSlug","isVersions","pathsToQuery","payload","req","tableName","size","offset","paginationResult","where","Array","from","reduce","statement","path","i","relationshipsSuffix","rows","length","paginationStatement","drizzle","execute","raw","map","row","parent_id","join","logger","info","result","docsToResave","forEach","parentID","push","deleteStatement"],"mappings":"AAGA,SAASA,GAAG,QAAQ,cAAa;AAKjC,SAASC,cAAc,QAAQ,4BAA2B;AAgB1D,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,OAAO,EACPC,cAAc,EACdC,EAAE,EACFC,KAAK,EACLC,MAAM,EACNC,UAAU,EACVC,UAAU,EACVC,YAAY,EACZC,OAAO,EACPC,GAAG,EACHC,SAAS,EACJ;IACL,IAAIH,aAAaI,IAAI,KAAK,GAAG;IAE7B,IAAIC,SAAS;IAEb,IAAIC;IAEJ,MAAMC,QAAQC,MAAMC,IAAI,CAACT,cAAcU,MAAM,CAAC,CAACC,WAAWC,MAAMC;QAC9D,OAAQF,aAAa,CAAC;CACzB,EAAER,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC,eAAe,EAAEF,KAAK,CAAC,EAAEZ,aAAaI,IAAI,KAAKS,IAAI,IAAI,QAAQ,GAAG;AAC7G,CAAC;IACC,GAAG;IAEH,MAAO,OAAOP,qBAAqB,eAAeA,iBAAiBS,IAAI,CAACC,MAAM,GAAG,EAAG;QAClF,MAAMC,sBAAsB,CAAC,+BAA+B,EAAEd,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC;IACtG,EAAEP,MAAM,qCAAqC,EAAEF,SAAS,IAAI;EAC9D,CAAC;QAECC,mBAAmB,MAAMb,QAAQyB,OAAO,CAACC,OAAO,CAAC7B,IAAI8B,GAAG,CAAC,CAAC,EAAEH,oBAAoB,CAAC;QAEjF,IAAIX,iBAAiBS,IAAI,CAACC,MAAM,KAAK,GAAG;QAExCX,UAAU;QAEV,MAAMM,YAAY,CAAC,cAAc,EAAER,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC;KAC1E,EAAEP,MAAM,oBAAoB,EAAED,iBAAiBS,IAAI,CAACM,GAAG,CAAC,CAACC,MAAQA,IAAIC,SAAS,EAAEC,IAAI,CAAC,MAAM;AAChG,CAAC;QACG,IAAI5B,OAAO;YACTK,QAAQwB,MAAM,CAACC,IAAI,CAAC;YACpBzB,QAAQwB,MAAM,CAACC,IAAI,CAACf;QACtB;QAEA,MAAMgB,SAAS,MAAMlC,QAAQyB,OAAO,CAACC,OAAO,CAAC7B,IAAI8B,GAAG,CAAC,CAAC,EAAET,UAAU,CAAC;QAEnE,MAAMiB,eAA6B,CAAC;QAEpCD,OAAOZ,IAAI,CAACc,OAAO,CAAC,CAACP;YACnB,MAAMQ,WAAWR,IAAIC,SAAS;YAE9B,IAAI,OAAOO,aAAa,YAAY,OAAOA,aAAa,UAAU;gBAChE,IAAI,CAACF,YAAY,CAACE,SAAS,EAAEF,YAAY,CAACE,SAAS,GAAG,EAAE;gBACxDF,YAAY,CAACE,SAAS,CAACC,IAAI,CAACT;YAC9B;QACF;QAEA,MAAM/B,eAAe;YACnBE;YACAC;YACAC;YACAC;YACAgC;YACA/B;YACAC;YACAC;YACAE;YACAC,KAAKA;YACLC;QACF;IACF;IAEA,MAAM6B,kBAAkB,CAAC,YAAY,EAAE7B,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC,OAAO,EAAEP,MAAM,CAAC;IAC/F,IAAIX,OAAO;QACTK,QAAQwB,MAAM,CAACC,IAAI,CAAC;QACpBzB,QAAQwB,MAAM,CAACC,IAAI,CAACM;IACtB;IACA,MAAMrC,GAAGwB,OAAO,CAAC7B,IAAI8B,GAAG,CAAC,CAAC,EAAEY,gBAAgB,CAAC;AAC/C,EAAC"}
@@ -1,12 +1,12 @@
1
- import type { Payload } from 'payload';
2
- import { type Field } from 'payload/types';
3
- import type { DrizzleTransaction, PostgresAdapter } from '../../types.js';
1
+ import type { TransactionPg } from '@payloadcms/drizzle/types';
2
+ import type { Field, Payload } from 'payload';
3
+ import type { PostgresAdapter } from '../../types.js';
4
4
  import type { PathsToQuery } from './types.js';
5
5
  type Args = {
6
6
  adapter: PostgresAdapter;
7
7
  collectionSlug?: string;
8
8
  columnPrefix: string;
9
- db: DrizzleTransaction;
9
+ db: TransactionPg;
10
10
  disableNotNull: boolean;
11
11
  fields: Field[];
12
12
  globalSlug?: string;