@payloadcms/db-postgres 3.0.0-canary.cee5702 → 3.0.0-canary.cf66341

Sign up to get free protection for your applications and to get access to all the features.
Files changed (357) 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 +10 -6
  5. package/dist/connect.js.map +1 -1
  6. package/dist/exports/migration-utils.js.map +1 -1
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +32 -68
  10. package/dist/index.js.map +1 -1
  11. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -1
  12. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +5 -5
  13. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
  14. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +1 -2
  15. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
  16. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +1 -1
  17. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
  18. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +1 -1
  19. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
  20. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -1
  21. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -1
  22. package/dist/predefinedMigrations/v2-v3/index.d.ts +2 -3
  23. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -1
  24. package/dist/predefinedMigrations/v2-v3/index.js +7 -7
  25. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -1
  26. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +5 -4
  27. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -1
  28. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -1
  29. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +4 -4
  30. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -1
  31. package/dist/predefinedMigrations/v2-v3/traverseFields.js +1 -1
  32. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -1
  33. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -1
  34. package/dist/types.d.ts +42 -80
  35. package/dist/types.d.ts.map +1 -1
  36. package/dist/types.js.map +1 -1
  37. package/package.json +20 -17
  38. package/dist/count.d.ts +0 -3
  39. package/dist/count.d.ts.map +0 -1
  40. package/dist/count.js +0 -41
  41. package/dist/count.js.map +0 -1
  42. package/dist/create.d.ts +0 -3
  43. package/dist/create.d.ts.map +0 -1
  44. package/dist/create.js +0 -19
  45. package/dist/create.js.map +0 -1
  46. package/dist/createGlobal.d.ts +0 -5
  47. package/dist/createGlobal.d.ts.map +0 -1
  48. package/dist/createGlobal.js +0 -19
  49. package/dist/createGlobal.js.map +0 -1
  50. package/dist/createGlobalVersion.d.ts +0 -6
  51. package/dist/createGlobalVersion.d.ts.map +0 -1
  52. package/dist/createGlobalVersion.js +0 -33
  53. package/dist/createGlobalVersion.js.map +0 -1
  54. package/dist/createMigration.d.ts +0 -3
  55. package/dist/createMigration.d.ts.map +0 -1
  56. package/dist/createMigration.js +0 -102
  57. package/dist/createMigration.js.map +0 -1
  58. package/dist/createVersion.d.ts +0 -5
  59. package/dist/createVersion.d.ts.map +0 -1
  60. package/dist/createVersion.js +0 -40
  61. package/dist/createVersion.js.map +0 -1
  62. package/dist/deleteMany.d.ts +0 -3
  63. package/dist/deleteMany.d.ts.map +0 -1
  64. package/dist/deleteMany.js +0 -28
  65. package/dist/deleteMany.js.map +0 -1
  66. package/dist/deleteOne.d.ts +0 -3
  67. package/dist/deleteOne.d.ts.map +0 -1
  68. package/dist/deleteOne.js +0 -59
  69. package/dist/deleteOne.js.map +0 -1
  70. package/dist/deleteVersions.d.ts +0 -3
  71. package/dist/deleteVersions.d.ts.map +0 -1
  72. package/dist/deleteVersions.js +0 -31
  73. package/dist/deleteVersions.js.map +0 -1
  74. package/dist/destroy.d.ts +0 -3
  75. package/dist/destroy.d.ts.map +0 -1
  76. package/dist/destroy.js +0 -15
  77. package/dist/destroy.js.map +0 -1
  78. package/dist/find/buildFindManyArgs.d.ts +0 -17
  79. package/dist/find/buildFindManyArgs.d.ts.map +0 -1
  80. package/dist/find/buildFindManyArgs.js +0 -65
  81. package/dist/find/buildFindManyArgs.js.map +0 -1
  82. package/dist/find/chainMethods.d.ts +0 -16
  83. package/dist/find/chainMethods.d.ts.map +0 -1
  84. package/dist/find/chainMethods.js +0 -12
  85. package/dist/find/chainMethods.js.map +0 -1
  86. package/dist/find/findMany.d.ts +0 -22
  87. package/dist/find/findMany.d.ts.map +0 -1
  88. package/dist/find/findMany.js +0 -152
  89. package/dist/find/findMany.js.map +0 -1
  90. package/dist/find/traverseFields.d.ts +0 -17
  91. package/dist/find/traverseFields.d.ts.map +0 -1
  92. package/dist/find/traverseFields.js +0 -156
  93. package/dist/find/traverseFields.js.map +0 -1
  94. package/dist/find.d.ts +0 -3
  95. package/dist/find.d.ts.map +0 -1
  96. package/dist/find.js +0 -21
  97. package/dist/find.js.map +0 -1
  98. package/dist/findGlobal.d.ts +0 -3
  99. package/dist/findGlobal.d.ts.map +0 -1
  100. package/dist/findGlobal.js +0 -23
  101. package/dist/findGlobal.js.map +0 -1
  102. package/dist/findGlobalVersions.d.ts +0 -3
  103. package/dist/findGlobalVersions.d.ts.map +0 -1
  104. package/dist/findGlobalVersions.js +0 -24
  105. package/dist/findGlobalVersions.js.map +0 -1
  106. package/dist/findOne.d.ts +0 -5
  107. package/dist/findOne.d.ts.map +0 -1
  108. package/dist/findOne.js +0 -21
  109. package/dist/findOne.js.map +0 -1
  110. package/dist/findVersions.d.ts +0 -3
  111. package/dist/findVersions.d.ts.map +0 -1
  112. package/dist/findVersions.js +0 -24
  113. package/dist/findVersions.js.map +0 -1
  114. package/dist/init.d.ts +0 -3
  115. package/dist/init.d.ts.map +0 -1
  116. package/dist/init.js +0 -91
  117. package/dist/init.js.map +0 -1
  118. package/dist/migrate.d.ts +0 -3
  119. package/dist/migrate.d.ts.map +0 -1
  120. package/dist/migrate.js +0 -99
  121. package/dist/migrate.js.map +0 -1
  122. package/dist/migrateDown.d.ts +0 -3
  123. package/dist/migrateDown.d.ts.map +0 -1
  124. package/dist/migrateDown.js +0 -63
  125. package/dist/migrateDown.js.map +0 -1
  126. package/dist/migrateFresh.d.ts +0 -8
  127. package/dist/migrateFresh.d.ts.map +0 -1
  128. package/dist/migrateFresh.js +0 -72
  129. package/dist/migrateFresh.js.map +0 -1
  130. package/dist/migrateRefresh.d.ts +0 -6
  131. package/dist/migrateRefresh.d.ts.map +0 -1
  132. package/dist/migrateRefresh.js +0 -102
  133. package/dist/migrateRefresh.js.map +0 -1
  134. package/dist/migrateReset.d.ts +0 -6
  135. package/dist/migrateReset.d.ts.map +0 -1
  136. package/dist/migrateReset.js +0 -82
  137. package/dist/migrateReset.js.map +0 -1
  138. package/dist/migrateStatus.d.ts +0 -3
  139. package/dist/migrateStatus.d.ts.map +0 -1
  140. package/dist/migrateStatus.js +0 -44
  141. package/dist/migrateStatus.js.map +0 -1
  142. package/dist/queries/buildAndOrConditions.d.ts +0 -16
  143. package/dist/queries/buildAndOrConditions.d.ts.map +0 -1
  144. package/dist/queries/buildAndOrConditions.js +0 -28
  145. package/dist/queries/buildAndOrConditions.js.map +0 -1
  146. package/dist/queries/buildQuery.d.ts +0 -30
  147. package/dist/queries/buildQuery.d.ts.map +0 -1
  148. package/dist/queries/buildQuery.js +0 -72
  149. package/dist/queries/buildQuery.js.map +0 -1
  150. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts +0 -2
  151. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts.map +0 -1
  152. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js +0 -14
  153. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +0 -1
  154. package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts +0 -2
  155. package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts.map +0 -1
  156. package/dist/queries/createJSONQuery/formatJSONPathSegment.js +0 -5
  157. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +0 -1
  158. package/dist/queries/createJSONQuery/index.d.ts +0 -10
  159. package/dist/queries/createJSONQuery/index.d.ts.map +0 -1
  160. package/dist/queries/createJSONQuery/index.js +0 -54
  161. package/dist/queries/createJSONQuery/index.js.map +0 -1
  162. package/dist/queries/getTableColumnFromPath.d.ts +0 -50
  163. package/dist/queries/getTableColumnFromPath.d.ts.map +0 -1
  164. package/dist/queries/getTableColumnFromPath.js +0 -517
  165. package/dist/queries/getTableColumnFromPath.js.map +0 -1
  166. package/dist/queries/operatorMap.d.ts +0 -18
  167. package/dist/queries/operatorMap.d.ts.map +0 -1
  168. package/dist/queries/operatorMap.js +0 -24
  169. package/dist/queries/operatorMap.js.map +0 -1
  170. package/dist/queries/parseParams.d.ts +0 -16
  171. package/dist/queries/parseParams.d.ts.map +0 -1
  172. package/dist/queries/parseParams.js +0 -183
  173. package/dist/queries/parseParams.js.map +0 -1
  174. package/dist/queries/sanitizeQueryValue.d.ts +0 -15
  175. package/dist/queries/sanitizeQueryValue.d.ts.map +0 -1
  176. package/dist/queries/sanitizeQueryValue.js +0 -90
  177. package/dist/queries/sanitizeQueryValue.js.map +0 -1
  178. package/dist/queries/selectDistinct.d.ts +0 -22
  179. package/dist/queries/selectDistinct.d.ts.map +0 -1
  180. package/dist/queries/selectDistinct.js +0 -30
  181. package/dist/queries/selectDistinct.js.map +0 -1
  182. package/dist/queryDrafts.d.ts +0 -3
  183. package/dist/queryDrafts.d.ts.map +0 -1
  184. package/dist/queryDrafts.js +0 -41
  185. package/dist/queryDrafts.js.map +0 -1
  186. package/dist/schema/build.d.ts +0 -34
  187. package/dist/schema/build.d.ts.map +0 -1
  188. package/dist/schema/build.js +0 -369
  189. package/dist/schema/build.js.map +0 -1
  190. package/dist/schema/createIndex.d.ts +0 -12
  191. package/dist/schema/createIndex.d.ts.map +0 -1
  192. package/dist/schema/createIndex.js +0 -18
  193. package/dist/schema/createIndex.js.map +0 -1
  194. package/dist/schema/createTableName.d.ts +0 -30
  195. package/dist/schema/createTableName.d.ts.map +0 -1
  196. package/dist/schema/createTableName.js +0 -31
  197. package/dist/schema/createTableName.js.map +0 -1
  198. package/dist/schema/idToUUID.d.ts +0 -3
  199. package/dist/schema/idToUUID.d.ts.map +0 -1
  200. package/dist/schema/idToUUID.js +0 -11
  201. package/dist/schema/idToUUID.js.map +0 -1
  202. package/dist/schema/parentIDColumnMap.d.ts +0 -4
  203. package/dist/schema/parentIDColumnMap.d.ts.map +0 -1
  204. package/dist/schema/parentIDColumnMap.js +0 -9
  205. package/dist/schema/parentIDColumnMap.js.map +0 -1
  206. package/dist/schema/setColumnID.d.ts +0 -11
  207. package/dist/schema/setColumnID.d.ts.map +0 -1
  208. package/dist/schema/setColumnID.js +0 -24
  209. package/dist/schema/setColumnID.js.map +0 -1
  210. package/dist/schema/traverseFields.d.ts +0 -36
  211. package/dist/schema/traverseFields.d.ts.map +0 -1
  212. package/dist/schema/traverseFields.js +0 -614
  213. package/dist/schema/traverseFields.js.map +0 -1
  214. package/dist/schema/validateExistingBlockIsIdentical.d.ts +0 -12
  215. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +0 -1
  216. package/dist/schema/validateExistingBlockIsIdentical.js +0 -76
  217. package/dist/schema/validateExistingBlockIsIdentical.js.map +0 -1
  218. package/dist/transactions/beginTransaction.d.ts +0 -3
  219. package/dist/transactions/beginTransaction.d.ts.map +0 -1
  220. package/dist/transactions/beginTransaction.js +0 -51
  221. package/dist/transactions/beginTransaction.js.map +0 -1
  222. package/dist/transactions/commitTransaction.d.ts +0 -3
  223. package/dist/transactions/commitTransaction.d.ts.map +0 -1
  224. package/dist/transactions/commitTransaction.js +0 -14
  225. package/dist/transactions/commitTransaction.js.map +0 -1
  226. package/dist/transactions/rollbackTransaction.d.ts +0 -3
  227. package/dist/transactions/rollbackTransaction.d.ts.map +0 -1
  228. package/dist/transactions/rollbackTransaction.js +0 -13
  229. package/dist/transactions/rollbackTransaction.js.map +0 -1
  230. package/dist/transform/read/hasManyNumber.d.ts +0 -10
  231. package/dist/transform/read/hasManyNumber.d.ts.map +0 -1
  232. package/dist/transform/read/hasManyNumber.js +0 -10
  233. package/dist/transform/read/hasManyNumber.js.map +0 -1
  234. package/dist/transform/read/hasManyText.d.ts +0 -10
  235. package/dist/transform/read/hasManyText.d.ts.map +0 -1
  236. package/dist/transform/read/hasManyText.js +0 -10
  237. package/dist/transform/read/hasManyText.js.map +0 -1
  238. package/dist/transform/read/index.d.ts +0 -14
  239. package/dist/transform/read/index.d.ts.map +0 -1
  240. package/dist/transform/read/index.js +0 -44
  241. package/dist/transform/read/index.js.map +0 -1
  242. package/dist/transform/read/relationship.d.ts +0 -10
  243. package/dist/transform/read/relationship.d.ts.map +0 -1
  244. package/dist/transform/read/relationship.js +0 -60
  245. package/dist/transform/read/relationship.js.map +0 -1
  246. package/dist/transform/read/traverseFields.d.ts +0 -57
  247. package/dist/transform/read/traverseFields.d.ts.map +0 -1
  248. package/dist/transform/read/traverseFields.js +0 -435
  249. package/dist/transform/read/traverseFields.js.map +0 -1
  250. package/dist/transform/write/array.d.ts +0 -26
  251. package/dist/transform/write/array.d.ts.map +0 -1
  252. package/dist/transform/write/array.js +0 -58
  253. package/dist/transform/write/array.js.map +0 -1
  254. package/dist/transform/write/blocks.d.ts +0 -25
  255. package/dist/transform/write/blocks.d.ts.map +0 -1
  256. package/dist/transform/write/blocks.js +0 -54
  257. package/dist/transform/write/blocks.js.map +0 -1
  258. package/dist/transform/write/index.d.ts +0 -13
  259. package/dist/transform/write/index.d.ts.map +0 -1
  260. package/dist/transform/write/index.js +0 -41
  261. package/dist/transform/write/index.js.map +0 -1
  262. package/dist/transform/write/numbers.d.ts +0 -8
  263. package/dist/transform/write/numbers.d.ts.map +0 -1
  264. package/dist/transform/write/numbers.js +0 -11
  265. package/dist/transform/write/numbers.js.map +0 -1
  266. package/dist/transform/write/relationships.d.ts +0 -10
  267. package/dist/transform/write/relationships.d.ts.map +0 -1
  268. package/dist/transform/write/relationships.js +0 -23
  269. package/dist/transform/write/relationships.js.map +0 -1
  270. package/dist/transform/write/selects.d.ts +0 -8
  271. package/dist/transform/write/selects.d.ts.map +0 -1
  272. package/dist/transform/write/selects.js +0 -20
  273. package/dist/transform/write/selects.js.map +0 -1
  274. package/dist/transform/write/texts.d.ts +0 -8
  275. package/dist/transform/write/texts.d.ts.map +0 -1
  276. package/dist/transform/write/texts.js +0 -11
  277. package/dist/transform/write/texts.js.map +0 -1
  278. package/dist/transform/write/traverseFields.d.ts +0 -50
  279. package/dist/transform/write/traverseFields.d.ts.map +0 -1
  280. package/dist/transform/write/traverseFields.js +0 -445
  281. package/dist/transform/write/traverseFields.js.map +0 -1
  282. package/dist/transform/write/types.d.ts +0 -43
  283. package/dist/transform/write/types.d.ts.map +0 -1
  284. package/dist/transform/write/types.js +0 -3
  285. package/dist/transform/write/types.js.map +0 -1
  286. package/dist/update.d.ts +0 -3
  287. package/dist/update.d.ts.map +0 -1
  288. package/dist/update.js +0 -54
  289. package/dist/update.js.map +0 -1
  290. package/dist/updateGlobal.d.ts +0 -5
  291. package/dist/updateGlobal.d.ts.map +0 -1
  292. package/dist/updateGlobal.js +0 -25
  293. package/dist/updateGlobal.js.map +0 -1
  294. package/dist/updateGlobalVersion.d.ts +0 -5
  295. package/dist/updateGlobalVersion.d.ts.map +0 -1
  296. package/dist/updateGlobalVersion.js +0 -36
  297. package/dist/updateGlobalVersion.js.map +0 -1
  298. package/dist/updateVersion.d.ts +0 -5
  299. package/dist/updateVersion.d.ts.map +0 -1
  300. package/dist/updateVersion.js +0 -36
  301. package/dist/updateVersion.js.map +0 -1
  302. package/dist/upsertRow/deleteExistingArrayRows.d.ts +0 -10
  303. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +0 -1
  304. package/dist/upsertRow/deleteExistingArrayRows.js +0 -10
  305. package/dist/upsertRow/deleteExistingArrayRows.js.map +0 -1
  306. package/dist/upsertRow/deleteExistingRowsByPath.d.ts +0 -14
  307. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +0 -1
  308. package/dist/upsertRow/deleteExistingRowsByPath.js +0 -33
  309. package/dist/upsertRow/deleteExistingRowsByPath.js.map +0 -1
  310. package/dist/upsertRow/index.d.ts +0 -4
  311. package/dist/upsertRow/index.d.ts.map +0 -1
  312. package/dist/upsertRow/index.js +0 -279
  313. package/dist/upsertRow/index.js.map +0 -1
  314. package/dist/upsertRow/insertArrays.d.ts +0 -13
  315. package/dist/upsertRow/insertArrays.d.ts.map +0 -1
  316. package/dist/upsertRow/insertArrays.js +0 -68
  317. package/dist/upsertRow/insertArrays.js.map +0 -1
  318. package/dist/upsertRow/types.d.ts +0 -32
  319. package/dist/upsertRow/types.d.ts.map +0 -1
  320. package/dist/upsertRow/types.js +0 -3
  321. package/dist/upsertRow/types.js.map +0 -1
  322. package/dist/utilities/appendPrefixToKeys.d.ts +0 -2
  323. package/dist/utilities/appendPrefixToKeys.d.ts.map +0 -1
  324. package/dist/utilities/appendPrefixToKeys.js +0 -6
  325. package/dist/utilities/appendPrefixToKeys.js.map +0 -1
  326. package/dist/utilities/createBlocksMap.d.ts +0 -5
  327. package/dist/utilities/createBlocksMap.d.ts.map +0 -1
  328. package/dist/utilities/createBlocksMap.js +0 -29
  329. package/dist/utilities/createBlocksMap.js.map +0 -1
  330. package/dist/utilities/createMigrationTable.d.ts +0 -3
  331. package/dist/utilities/createMigrationTable.d.ts.map +0 -1
  332. package/dist/utilities/createMigrationTable.js +0 -13
  333. package/dist/utilities/createMigrationTable.js.map +0 -1
  334. package/dist/utilities/createRelationshipMap.d.ts +0 -2
  335. package/dist/utilities/createRelationshipMap.d.ts.map +0 -1
  336. package/dist/utilities/createRelationshipMap.js +0 -19
  337. package/dist/utilities/createRelationshipMap.js.map +0 -1
  338. package/dist/utilities/hasLocalesTable.d.ts +0 -3
  339. package/dist/utilities/hasLocalesTable.d.ts.map +0 -1
  340. package/dist/utilities/hasLocalesTable.js +0 -11
  341. package/dist/utilities/hasLocalesTable.js.map +0 -1
  342. package/dist/utilities/isArrayOfRows.d.ts +0 -2
  343. package/dist/utilities/isArrayOfRows.d.ts.map +0 -1
  344. package/dist/utilities/isArrayOfRows.js +0 -5
  345. package/dist/utilities/isArrayOfRows.js.map +0 -1
  346. package/dist/utilities/migrationTableExists.d.ts +0 -3
  347. package/dist/utilities/migrationTableExists.d.ts.map +0 -1
  348. package/dist/utilities/migrationTableExists.js +0 -9
  349. package/dist/utilities/migrationTableExists.js.map +0 -1
  350. package/dist/utilities/parseError.d.ts +0 -5
  351. package/dist/utilities/parseError.d.ts.map +0 -1
  352. package/dist/utilities/parseError.js +0 -17
  353. package/dist/utilities/parseError.js.map +0 -1
  354. package/dist/utilities/pushDevSchema.d.ts +0 -9
  355. package/dist/utilities/pushDevSchema.d.ts.map +0 -1
  356. package/dist/utilities/pushDevSchema.js +0 -58
  357. package/dist/utilities/pushDevSchema.js.map +0 -1
package/dist/init.js DELETED
@@ -1,91 +0,0 @@
1
- /* eslint-disable no-param-reassign */ import { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core';
2
- import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions';
3
- import toSnakeCase from 'to-snake-case';
4
- import { buildTable } from './schema/build.js';
5
- import { createTableName } from './schema/createTableName.js';
6
- 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
- if (this.payload.config.localization) {
15
- this.enums.enum__locales = pgEnum('_locales', this.payload.config.localization.locales.map(({ code })=>code));
16
- }
17
- this.payload.config.collections.forEach((collection)=>{
18
- createTableName({
19
- adapter: this,
20
- config: collection
21
- });
22
- if (collection.versions) {
23
- createTableName({
24
- adapter: this,
25
- config: collection,
26
- versions: true,
27
- versionsCustomName: true
28
- });
29
- }
30
- });
31
- this.payload.config.collections.forEach((collection)=>{
32
- const tableName = this.tableNameMap.get(toSnakeCase(collection.slug));
33
- buildTable({
34
- adapter: this,
35
- disableNotNull: !!collection?.versions?.drafts,
36
- disableUnique: false,
37
- fields: collection.fields,
38
- tableName,
39
- timestamps: collection.timestamps,
40
- versions: false
41
- });
42
- if (collection.versions) {
43
- const versionsTableName = this.tableNameMap.get(`_${toSnakeCase(collection.slug)}${this.versionsSuffix}`);
44
- const versionFields = buildVersionCollectionFields(collection);
45
- buildTable({
46
- adapter: this,
47
- disableNotNull: !!collection.versions?.drafts,
48
- disableUnique: true,
49
- fields: versionFields,
50
- tableName: versionsTableName,
51
- timestamps: true,
52
- versions: true
53
- });
54
- }
55
- });
56
- this.payload.config.globals.forEach((global)=>{
57
- const tableName = createTableName({
58
- adapter: this,
59
- config: global
60
- });
61
- buildTable({
62
- adapter: this,
63
- disableNotNull: !!global?.versions?.drafts,
64
- disableUnique: false,
65
- fields: global.fields,
66
- tableName,
67
- timestamps: false,
68
- versions: false
69
- });
70
- if (global.versions) {
71
- const versionsTableName = createTableName({
72
- adapter: this,
73
- config: global,
74
- versions: true,
75
- versionsCustomName: true
76
- });
77
- const versionFields = buildVersionGlobalFields(global);
78
- buildTable({
79
- adapter: this,
80
- disableNotNull: !!global.versions?.drafts,
81
- disableUnique: true,
82
- fields: versionFields,
83
- tableName: versionsTableName,
84
- timestamps: true,
85
- versions: true
86
- });
87
- }
88
- });
89
- };
90
-
91
- //# sourceMappingURL=init.js.map
package/dist/init.js.map DELETED
@@ -1 +0,0 @@
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,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AAyBkC;YAE/ChC,WAAW;gBACTgB,SAAS,IAAI;gBACbO,gBAAgB,CAAC,CAACS,OAAOf,QAAQ,EAAEO;gBACnCC,eAAe;gBACfC,QAAQI;gBACRX,WAAWS;gBACXD,YAAY;gBACZV,UAAU;YACZ;QACF;IACF;AACF,EAAC"}
package/dist/migrate.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { PostgresAdapter } from './types.js';
2
- export declare function migrate(this: PostgresAdapter): Promise<void>;
3
- //# sourceMappingURL=migrate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAQjD,wBAAsB,OAAO,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CA8DlE"}
package/dist/migrate.js DELETED
@@ -1,99 +0,0 @@
1
- /* eslint-disable no-restricted-syntax, no-await-in-loop */ import { createRequire } from 'module';
2
- import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload/database';
3
- import prompts from 'prompts';
4
- import { createMigrationTable } from './utilities/createMigrationTable.js';
5
- import { migrationTableExists } from './utilities/migrationTableExists.js';
6
- import { parseError } from './utilities/parseError.js';
7
- const require = createRequire(import.meta.url);
8
- export async function migrate() {
9
- const { payload } = this;
10
- const migrationFiles = await readMigrationFiles({
11
- payload
12
- });
13
- if (!migrationFiles.length) {
14
- payload.logger.info({
15
- msg: 'No migrations to run.'
16
- });
17
- return;
18
- }
19
- let latestBatch = 0;
20
- let migrationsInDB = [];
21
- const hasMigrationTable = await migrationTableExists(this.drizzle);
22
- if (hasMigrationTable) {
23
- ({ docs: migrationsInDB } = await payload.find({
24
- collection: 'payload-migrations',
25
- limit: 0,
26
- sort: '-name'
27
- }));
28
- if (Number(migrationsInDB?.[0]?.batch) > 0) {
29
- latestBatch = Number(migrationsInDB[0]?.batch);
30
- }
31
- } else {
32
- await createMigrationTable(this);
33
- }
34
- if (migrationsInDB.find((m)=>m.batch === -1)) {
35
- const { confirm: runMigrations } = await prompts({
36
- name: 'confirm',
37
- type: 'confirm',
38
- initial: false,
39
- message: "It looks like you've run Payload in dev mode, meaning you've dynamically pushed changes to your database.\n\n" + "If you'd like to run migrations, data loss will occur. Would you like to proceed?"
40
- }, {
41
- onCancel: ()=>{
42
- process.exit(0);
43
- }
44
- });
45
- if (!runMigrations) {
46
- process.exit(0);
47
- }
48
- }
49
- const newBatch = latestBatch + 1;
50
- // Execute 'up' function for each migration sequentially
51
- for (const migration of migrationFiles){
52
- const alreadyRan = migrationsInDB.find((existing)=>existing.name === migration.name);
53
- // If already ran, skip
54
- if (alreadyRan) {
55
- continue; // eslint-disable-line no-continue
56
- }
57
- await runMigrationFile(payload, migration, newBatch);
58
- }
59
- }
60
- async function runMigrationFile(payload, migration, batch) {
61
- const { generateDrizzleJson } = require('drizzle-kit/payload');
62
- const start = Date.now();
63
- const req = {
64
- payload
65
- };
66
- payload.logger.info({
67
- msg: `Migrating: ${migration.name}`
68
- });
69
- const pgAdapter = payload.db;
70
- const drizzleJSON = generateDrizzleJson(pgAdapter.schema);
71
- try {
72
- await initTransaction(req);
73
- await migration.up({
74
- payload,
75
- req
76
- });
77
- payload.logger.info({
78
- msg: `Migrated: ${migration.name} (${Date.now() - start}ms)`
79
- });
80
- await payload.create({
81
- collection: 'payload-migrations',
82
- data: {
83
- name: migration.name,
84
- batch,
85
- schema: drizzleJSON
86
- },
87
- req
88
- });
89
- await commitTransaction(req);
90
- } catch (err) {
91
- await killTransaction(req);
92
- payload.logger.error({
93
- err,
94
- msg: parseError(err, `Error running migration ${migration.name}`)
95
- });
96
- }
97
- }
98
-
99
- //# sourceMappingURL=migrate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/migrate.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { Payload } from 'payload'\nimport type { Migration } from 'payload/database'\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport { createRequire } from 'module'\nimport {\n commitTransaction,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload/database'\nimport prompts from 'prompts'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { createMigrationTable } from './utilities/createMigrationTable.js'\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\nimport { parseError } from './utilities/parseError.js'\n\nconst require = createRequire(import.meta.url)\n\nexport async function migrate(this: PostgresAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n if (!migrationFiles.length) {\n payload.logger.info({ msg: 'No migrations to run.' })\n return\n }\n\n let latestBatch = 0\n let migrationsInDB = []\n\n const hasMigrationTable = await migrationTableExists(this.drizzle)\n\n if (hasMigrationTable) {\n ;({ docs: migrationsInDB } = await payload.find({\n collection: 'payload-migrations',\n limit: 0,\n sort: '-name',\n }))\n if (Number(migrationsInDB?.[0]?.batch) > 0) {\n latestBatch = Number(migrationsInDB[0]?.batch)\n }\n } else {\n await createMigrationTable(this)\n }\n\n if (migrationsInDB.find((m) => m.batch === -1)) {\n const { confirm: runMigrations } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message:\n \"It looks like you've run Payload in dev mode, meaning you've dynamically pushed changes to your database.\\n\\n\" +\n \"If you'd like to run migrations, data loss will occur. Would you like to proceed?\",\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!runMigrations) {\n process.exit(0)\n }\n }\n\n const newBatch = latestBatch + 1\n\n // Execute 'up' function for each migration sequentially\n for (const migration of migrationFiles) {\n const alreadyRan = migrationsInDB.find((existing) => existing.name === migration.name)\n\n // If already ran, skip\n if (alreadyRan) {\n continue // eslint-disable-line no-continue\n }\n\n await runMigrationFile(payload, migration, newBatch)\n }\n}\n\nasync function runMigrationFile(payload: Payload, migration: Migration, batch: number) {\n const { generateDrizzleJson } = require('drizzle-kit/payload')\n\n const start = Date.now()\n const req = { payload } as PayloadRequestWithData\n\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n\n const pgAdapter = payload.db\n const drizzleJSON = generateDrizzleJson(pgAdapter.schema)\n\n try {\n await initTransaction(req)\n await migration.up({ payload, req })\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch,\n schema: drizzleJSON,\n },\n req,\n })\n await commitTransaction(req)\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: parseError(err, `Error running migration ${migration.name}`),\n })\n }\n}\n"],"names":["createRequire","commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","createMigrationTable","migrationTableExists","parseError","require","url","migrate","payload","migrationFiles","length","logger","info","msg","latestBatch","migrationsInDB","hasMigrationTable","drizzle","docs","find","collection","limit","sort","Number","batch","m","confirm","runMigrations","name","type","initial","message","onCancel","process","exit","newBatch","migration","alreadyRan","existing","runMigrationFile","generateDrizzleJson","start","Date","now","req","pgAdapter","db","drizzleJSON","schema","up","create","data","err","error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,yDAAyD,GAKzD,SAASA,aAAa,QAAQ,SAAQ;AACtC,SACEC,iBAAiB,EACjBC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,mBAAkB;AACzB,OAAOC,aAAa,UAAS;AAI7B,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,MAAMC,UAAUT,cAAc,YAAYU,GAAG;AAE7C,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMT,mBAAmB;QAAEQ;IAAQ;IAE1D,IAAI,C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ACtB,MAAMC,MAAM;QAAEpC;IAAQ;IAEtBA,QAAQG,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK,CAAC,WAAW,EAAEuB,UAAUR,IAAI,CAAC,CAAC;IAAC;IAE1D,MAAMiB,YAAYrC,QAAQsC,EAAE;IAC5B,MAAMC,cAAcP,oBAAoBK,UAAUG,MAAM;IAExD,IAAI;QACF,MAAMlD,gBAAgB8C;QACtB,MAAMR,UAAUa,EAAE,CAAC;YAAEzC;YAASoC;QAAI;QAClCpC,QAAQG,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK,CAAC,WAAW,EAAEuB,UAAUR,IAAI,CAAC,EAAE,EAAEc,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;QAAC;QACpF,MAAMjC,QAAQ0C,MAAM,CAAC;YACnB9B,YAAY;YACZ+B,MAAM;gBACJvB,MAAMQ,UAAUR,IAAI;gBACpBJ;gBACAwB,QAAQD;YACV;YACAH;QACF;QACA,MAAM/C,kBAAkB+C;IAC1B,EAAE,OAAOQ,KAAc;QACrB,MAAMrD,gBAAgB6C;QACtBpC,QAAQG,MAAM,CAAC0C,KAAK,CAAC;YACnBD;YACAvC,KAAKT,WAAWgD,KAAK,CAAC,wBAAwB,EAAEhB,UAAUR,IAAI,CAAC,CAAC;QAClE;IACF;AACF"}
@@ -1,3 +0,0 @@
1
- import type { PostgresAdapter } from './types.js';
2
- export declare function migrateDown(this: PostgresAdapter): Promise<void>;
3
- //# sourceMappingURL=migrateDown.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrateDown.d.ts","sourceRoot":"","sources":["../src/migrateDown.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAKjD,wBAAsB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAwDtE"}
@@ -1,63 +0,0 @@
1
- /* eslint-disable no-restricted-syntax, no-await-in-loop */ import { commitTransaction, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload/database';
2
- import { migrationTableExists } from './utilities/migrationTableExists.js';
3
- import { parseError } from './utilities/parseError.js';
4
- export async function migrateDown() {
5
- const { payload } = this;
6
- const migrationFiles = await readMigrationFiles({
7
- payload
8
- });
9
- const { existingMigrations, latestBatch } = await getMigrations({
10
- payload
11
- });
12
- if (!existingMigrations?.length) {
13
- payload.logger.info({
14
- msg: 'No migrations to rollback.'
15
- });
16
- return;
17
- }
18
- payload.logger.info({
19
- msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`
20
- });
21
- const latestBatchMigrations = existingMigrations.filter(({ batch })=>batch === latestBatch);
22
- for (const migration of latestBatchMigrations){
23
- const migrationFile = migrationFiles.find((m)=>m.name === migration.name);
24
- if (!migrationFile) {
25
- throw new Error(`Migration ${migration.name} not found locally.`);
26
- }
27
- const start = Date.now();
28
- const req = {
29
- payload
30
- };
31
- try {
32
- payload.logger.info({
33
- msg: `Migrating down: ${migrationFile.name}`
34
- });
35
- await initTransaction(req);
36
- await migrationFile.down({
37
- payload,
38
- req
39
- });
40
- payload.logger.info({
41
- msg: `Migrated down: ${migrationFile.name} (${Date.now() - start}ms)`
42
- });
43
- const tableExists = await migrationTableExists(this.drizzle);
44
- if (tableExists) {
45
- await payload.delete({
46
- id: migration.id,
47
- collection: 'payload-migrations',
48
- req
49
- });
50
- }
51
- await commitTransaction(req);
52
- } catch (err) {
53
- await killTransaction(req);
54
- payload.logger.error({
55
- err,
56
- msg: parseError(err, `Error migrating down ${migrationFile.name}. Rolling back.`)
57
- });
58
- process.exit(1);
59
- }
60
- }
61
- }
62
-
63
- //# sourceMappingURL=migrateDown.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/migrateDown.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport {\n commitTransaction,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload/database'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\nimport { parseError } from './utilities/parseError.js'\n\nexport async function migrateDown(this: PostgresAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations, latestBatch } = await getMigrations({\n payload,\n })\n\n if (!existingMigrations?.length) {\n payload.logger.info({ msg: 'No migrations to rollback.' })\n return\n }\n\n payload.logger.info({\n msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`,\n })\n\n const latestBatchMigrations = existingMigrations.filter(({ batch }) => batch === latestBatch)\n\n for (const migration of latestBatchMigrations) {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n const start = Date.now()\n const req = { payload } as PayloadRequestWithData\n\n try {\n payload.logger.info({ msg: `Migrating down: ${migrationFile.name}` })\n await initTransaction(req)\n await migrationFile.down({ payload, req })\n payload.logger.info({\n msg: `Migrated down: ${migrationFile.name} (${Date.now() - start}ms)`,\n })\n\n const tableExists = await migrationTableExists(this.drizzle)\n if (tableExists) {\n await payload.delete({\n id: migration.id,\n collection: 'payload-migrations',\n req,\n })\n }\n\n await commitTransaction(req)\n } catch (err: unknown) {\n await killTransaction(req)\n\n payload.logger.error({\n err,\n msg: parseError(err, `Error migrating down ${migrationFile.name}. Rolling back.`),\n })\n process.exit(1)\n }\n }\n}\n"],"names":["commitTransaction","getMigrations","initTransaction","killTransaction","readMigrationFiles","migrationTableExists","parseError","migrateDown","payload","migrationFiles","existingMigrations","latestBatch","length","logger","info","msg","latestBatchMigrations","filter","batch","migration","migrationFile","find","m","name","Error","start","Date","now","req","down","tableExists","drizzle","delete","id","collection","err","error","process","exit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,yDAAyD,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K,CAAC,gBAAgB,EAAEK,cAAcG,IAAI,CAAC,EAAE,EAAEG,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YACxE;YAEA,MAAMK,cAAc,MAAMzB,qBAAqB,IAAI,CAAC0B,OAAO;YAC3D,IAAID,aAAa;gBACf,MAAMtB,QAAQwB,MAAM,CAAC;oBACnBC,IAAId,UAAUc,EAAE;oBAChBC,YAAY;oBACZN;gBACF;YACF;YAEA,MAAM5B,kBAAkB4B;QAC1B,EAAE,OAAOO,KAAc;YACrB,MAAMhC,gBAAgByB;YAEtBpB,QAAQK,MAAM,CAACuB,KAAK,CAAC;gBACnBD;gBACApB,KAAKT,WAAW6B,KAAK,CAAC,qBAAqB,EAAEf,cAAcG,IAAI,CAAC,eAAe,CAAC;YAClF;YACAc,QAAQC,IAAI,CAAC;QACf;IACF;AACF"}
@@ -1,8 +0,0 @@
1
- import type { PostgresAdapter } from './types.js';
2
- /**
3
- * Drop the current database and run all migrate up functions
4
- */
5
- export declare function migrateFresh(this: PostgresAdapter, { forceAcceptWarning }: {
6
- forceAcceptWarning?: boolean;
7
- }): Promise<void>;
8
- //# sourceMappingURL=migrateFresh.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrateFresh.d.ts","sourceRoot":"","sources":["../src/migrateFresh.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIjD;;GAEG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,eAAe,EACrB,EAAE,kBAA0B,EAAE;;CAAA,GAC7B,OAAO,CAAC,IAAI,CAAC,CAgEf"}
@@ -1,72 +0,0 @@
1
- import { sql } from 'drizzle-orm';
2
- import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload/database';
3
- import prompts from 'prompts';
4
- import { parseError } from './utilities/parseError.js';
5
- /**
6
- * Drop the current database and run all migrate up functions
7
- */ export async function migrateFresh({ forceAcceptWarning = false }) {
8
- const { payload } = this;
9
- if (forceAcceptWarning === false) {
10
- const { confirm: acceptWarning } = await prompts({
11
- name: 'confirm',
12
- type: 'confirm',
13
- initial: false,
14
- message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`
15
- }, {
16
- onCancel: ()=>{
17
- process.exit(0);
18
- }
19
- });
20
- if (!acceptWarning) {
21
- process.exit(0);
22
- }
23
- }
24
- payload.logger.info({
25
- msg: `Dropping database.`
26
- });
27
- await this.drizzle.execute(sql.raw(`drop schema ${this.schemaName || 'public'} cascade;
28
- create schema ${this.schemaName || 'public'};`));
29
- const migrationFiles = await readMigrationFiles({
30
- payload
31
- });
32
- payload.logger.debug({
33
- msg: `Found ${migrationFiles.length} migration files.`
34
- });
35
- const req = {
36
- payload
37
- };
38
- // Run all migrate up
39
- for (const migration of migrationFiles){
40
- payload.logger.info({
41
- msg: `Migrating: ${migration.name}`
42
- });
43
- try {
44
- const start = Date.now();
45
- await initTransaction(req);
46
- await migration.up({
47
- payload,
48
- req
49
- });
50
- await payload.create({
51
- collection: 'payload-migrations',
52
- data: {
53
- name: migration.name,
54
- batch: 1
55
- },
56
- req
57
- });
58
- await commitTransaction(req);
59
- payload.logger.info({
60
- msg: `Migrated: ${migration.name} (${Date.now() - start}ms)`
61
- });
62
- } catch (err) {
63
- await killTransaction(req);
64
- payload.logger.error({
65
- err,
66
- msg: parseError(err, `Error running migration ${migration.name}. Rolling back`)
67
- });
68
- }
69
- }
70
- }
71
-
72
- //# sourceMappingURL=migrateFresh.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { PayloadRequestWithData } from 'payload/types'\n\nimport { sql } from 'drizzle-orm'\nimport {\n commitTransaction,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload/database'\nimport prompts from 'prompts'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { parseError } from './utilities/parseError.js'\n\n/**\n * Drop the current database and run all migrate up functions\n */\nexport async function migrateFresh(\n this: PostgresAdapter,\n { forceAcceptWarning = false },\n): Promise<void> {\n const { payload } = this\n\n if (forceAcceptWarning === false) {\n const { confirm: acceptWarning } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`,\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!acceptWarning) {\n process.exit(0)\n }\n }\n\n payload.logger.info({\n msg: `Dropping database.`,\n })\n\n await this.drizzle.execute(\n sql.raw(`drop schema ${this.schemaName || 'public'} cascade;\n create schema ${this.schemaName || 'public'};`),\n )\n\n const migrationFiles = await readMigrationFiles({ payload })\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n const req = { payload } as PayloadRequestWithData\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.up({ payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch: 1,\n },\n req,\n })\n await commitTransaction(req)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: parseError(err, `Error running migration ${migration.name}. Rolling back`),\n })\n }\n }\n}\n"],"names":["sql","commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","parseError","migrateFresh","forceAcceptWarning","payload","confirm","acceptWarning","name","type","initial","message","onCancel","process","exit","logger","info","msg","drizzle","execute","raw","schemaName","migrationFiles","debug","length","req","migration","start","Date","now","up","create","collection","data","batch","err","error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,GAAG,QAAQ,cAAa;AACjC,SACEC,iBAAiB,EACjBC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,mBAAkB;AACzB,OAAOC,a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oBACJzB,MAAMkB,UAAUlB,IAAI;oBACpB0B,OAAO;gBACT;gBACAT;YACF;YACA,MAAM5B,kBAAkB4B;YAExBpB,QAAQU,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,WAAW,EAAES,UAAUlB,IAAI,CAAC,EAAE,EAAEoB,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YAAC;QACtF,EAAE,OAAOQ,KAAc;YACrB,MAAMpC,gBAAgB0B;YACtBpB,QAAQU,MAAM,CAACqB,KAAK,CAAC;gBACnBD;gBACAlB,KAAKf,WAAWiC,KAAK,CAAC,wBAAwB,EAAET,UAAUlB,IAAI,CAAC,cAAc,CAAC;YAChF;QACF;IACF;AACF"}
@@ -1,6 +0,0 @@
1
- import type { PostgresAdapter } from './types.js';
2
- /**
3
- * Run all migration down functions before running up
4
- */
5
- export declare function migrateRefresh(this: PostgresAdapter): Promise<void>;
6
- //# sourceMappingURL=migrateRefresh.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrateRefresh.d.ts","sourceRoot":"","sources":["../src/migrateRefresh.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAKjD;;GAEG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,eAAe,iBAsFzD"}
@@ -1,102 +0,0 @@
1
- /* eslint-disable no-restricted-syntax, no-await-in-loop */ import { commitTransaction, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload/database';
2
- import { migrationTableExists } from './utilities/migrationTableExists.js';
3
- import { parseError } from './utilities/parseError.js';
4
- /**
5
- * Run all migration down functions before running up
6
- */ export async function migrateRefresh() {
7
- const { payload } = this;
8
- const migrationFiles = await readMigrationFiles({
9
- payload
10
- });
11
- const { existingMigrations, latestBatch } = await getMigrations({
12
- payload
13
- });
14
- if (!existingMigrations?.length) {
15
- payload.logger.info({
16
- msg: 'No migrations to rollback.'
17
- });
18
- return;
19
- }
20
- payload.logger.info({
21
- msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`
22
- });
23
- const req = {
24
- payload
25
- };
26
- // Reverse order of migrations to rollback
27
- existingMigrations.reverse();
28
- for (const migration of existingMigrations){
29
- try {
30
- const migrationFile = migrationFiles.find((m)=>m.name === migration.name);
31
- if (!migrationFile) {
32
- throw new Error(`Migration ${migration.name} not found locally.`);
33
- }
34
- payload.logger.info({
35
- msg: `Migrating down: ${migration.name}`
36
- });
37
- const start = Date.now();
38
- await initTransaction(req);
39
- await migrationFile.down({
40
- payload,
41
- req
42
- });
43
- payload.logger.info({
44
- msg: `Migrated down: ${migration.name} (${Date.now() - start}ms)`
45
- });
46
- const tableExists = await migrationTableExists(this.drizzle);
47
- if (tableExists) {
48
- await payload.delete({
49
- collection: 'payload-migrations',
50
- req,
51
- where: {
52
- name: {
53
- equals: migration.name
54
- }
55
- }
56
- });
57
- }
58
- await commitTransaction(req);
59
- } catch (err) {
60
- await killTransaction(req);
61
- payload.logger.error({
62
- err,
63
- msg: parseError(err, `Error running migration ${migration.name}. Rolling back.`)
64
- });
65
- process.exit(1);
66
- }
67
- }
68
- // Run all migrate up
69
- for (const migration of migrationFiles){
70
- payload.logger.info({
71
- msg: `Migrating: ${migration.name}`
72
- });
73
- try {
74
- const start = Date.now();
75
- await initTransaction(req);
76
- await migration.up({
77
- payload,
78
- req
79
- });
80
- await payload.create({
81
- collection: 'payload-migrations',
82
- data: {
83
- name: migration.name,
84
- executed: true
85
- },
86
- req
87
- });
88
- await commitTransaction(req);
89
- payload.logger.info({
90
- msg: `Migrated: ${migration.name} (${Date.now() - start}ms)`
91
- });
92
- } catch (err) {
93
- await killTransaction(req);
94
- payload.logger.error({
95
- err,
96
- msg: parseError(err, `Error running migration ${migration.name}. Rolling back.`)
97
- });
98
- }
99
- }
100
- }
101
-
102
- //# sourceMappingURL=migrateRefresh.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/migrateRefresh.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport {\n commitTransaction,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload/database'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\nimport { parseError } from './utilities/parseError.js'\n\n/**\n * Run all migration down functions before running up\n */\nexport async function migrateRefresh(this: PostgresAdapter) {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations, latestBatch } = await getMigrations({\n payload,\n })\n\n if (!existingMigrations?.length) {\n payload.logger.info({ msg: 'No migrations to rollback.' })\n return\n }\n\n payload.logger.info({\n msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`,\n })\n\n const req = { payload } as PayloadRequestWithData\n\n // Reverse order of migrations to rollback\n existingMigrations.reverse()\n\n for (const migration of existingMigrations) {\n try {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n payload.logger.info({ msg: `Migrating down: ${migration.name}` })\n const start = Date.now()\n await initTransaction(req)\n await migrationFile.down({ payload, req })\n payload.logger.info({\n msg: `Migrated down: ${migration.name} (${Date.now() - start}ms)`,\n })\n\n const tableExists = await migrationTableExists(this.drizzle)\n if (tableExists) {\n await payload.delete({\n collection: 'payload-migrations',\n req,\n where: {\n name: {\n equals: migration.name,\n },\n },\n })\n }\n await commitTransaction(req)\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: parseError(err, `Error running migration ${migration.name}. Rolling back.`),\n })\n process.exit(1)\n }\n }\n\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.up({ payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n executed: true,\n },\n req,\n })\n await commitTransaction(req)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: parseError(err, `Error running migration ${migration.name}. Rolling back.`),\n })\n }\n }\n}\n"],"names":["commitTransaction","getMigrations","initTransaction","killTransaction","readMigrationFiles","migrationTableExists","parseError","migrateRefresh","payload","migrationFiles","existingMigrations","latestBatch","length","logger","info","msg","req","reverse","migration","migrationFile","find","m","name","Error","start","Date","now","down","tableExists","drizzle","delete","collection","where","equals","err","error","process","exit","up","create","data","executed"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,yDAAyD,GAGzD,SACEA,iBAAiB,EACjBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,mBAAkB;AAIzB,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,UAAU,QAAQ,4BAA2B;AAEtD;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAML,mBAAmB;QAAEI;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAEC,WAAW,EAAE,GAAG,MAAMV,cAAc;QAC9DO;IACF;IAEA,IAAI,CAACE,oBAAoBE,QAAQ;QAC/BJ,QAAQK,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAA6B;QACxD;IACF;IAEAP,QAAQK,MAAM,CAACC,IAAI,CAAC;QAClBC,KAAK,CAAC,mBAAmB,EAAEJ,YAAY,eAAe,EAAED,mBAAmBE,MAAM,CAAC,cAAc,CAAC;IACnG;IAEA,MAAMI,MAAM;QAAER;IAAQ;IAEtB,0CAA0C;IAC1CE,mBAAmBO,OAAO;IAE1B,KAAK,MAAMC,aAAaR,mBAAoB;QAC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AAG;YACtB,MAAMxB,gBAAgBc;YACtB,MAAME,UAAUoB,EAAE,CAAC;gBAAE9B;gBAASQ;YAAI;YAClC,MAAMR,QAAQ+B,MAAM,CAAC;gBACnBR,YAAY;gBACZS,MAAM;oBACJlB,MAAMJ,UAAUI,IAAI;oBACpBmB,UAAU;gBACZ;gBACAzB;YACF;YACA,MAAMhB,kBAAkBgB;YAExBR,QAAQK,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,WAAW,EAAEG,UAAUI,IAAI,CAAC,EAAE,EAAEG,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YAAC;QACtF,EAAE,OAAOU,KAAc;YACrB,MAAM/B,gBAAgBa;YACtBR,QAAQK,MAAM,CAACsB,KAAK,CAAC;gBACnBD;gBACAnB,KAAKT,WAAW4B,KAAK,CAAC,wBAAwB,EAAEhB,UAAUI,IAAI,CAAC,eAAe,CAAC;YACjF;QACF;IACF;AACF"}
@@ -1,6 +0,0 @@
1
- import type { PostgresAdapter } from './types.js';
2
- /**
3
- * Run all migrate down functions
4
- */
5
- export declare function migrateReset(this: PostgresAdapter): Promise<void>;
6
- //# sourceMappingURL=migrateReset.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrateReset.d.ts","sourceRoot":"","sources":["../src/migrateReset.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIjD;;GAEG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAsEvE"}
@@ -1,82 +0,0 @@
1
- /* eslint-disable no-restricted-syntax, no-await-in-loop */ import { commitTransaction, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload/database';
2
- import { migrationTableExists } from './utilities/migrationTableExists.js';
3
- /**
4
- * Run all migrate down functions
5
- */ export async function migrateReset() {
6
- const { payload } = this;
7
- const migrationFiles = await readMigrationFiles({
8
- payload
9
- });
10
- const { existingMigrations } = await getMigrations({
11
- payload
12
- });
13
- if (!existingMigrations?.length) {
14
- payload.logger.info({
15
- msg: 'No migrations to reset.'
16
- });
17
- return;
18
- }
19
- const req = {
20
- payload
21
- };
22
- // Rollback all migrations in order
23
- for (const migration of existingMigrations){
24
- const migrationFile = migrationFiles.find((m)=>m.name === migration.name);
25
- try {
26
- if (!migrationFile) {
27
- throw new Error(`Migration ${migration.name} not found locally.`);
28
- }
29
- const start = Date.now();
30
- payload.logger.info({
31
- msg: `Migrating down: ${migrationFile.name}`
32
- });
33
- await initTransaction(req);
34
- await migrationFile.down({
35
- payload,
36
- req
37
- });
38
- payload.logger.info({
39
- msg: `Migrated down: ${migrationFile.name} (${Date.now() - start}ms)`
40
- });
41
- const tableExists = await migrationTableExists(this.drizzle);
42
- if (tableExists) {
43
- await payload.delete({
44
- id: migration.id,
45
- collection: 'payload-migrations',
46
- req
47
- });
48
- }
49
- await commitTransaction(req);
50
- } catch (err) {
51
- let msg = `Error running migration ${migrationFile.name}.`;
52
- if (err instanceof Error) msg += ` ${err.message}`;
53
- await killTransaction(req);
54
- payload.logger.error({
55
- err,
56
- msg
57
- });
58
- process.exit(1);
59
- }
60
- }
61
- // Delete dev migration
62
- const tableExists = await migrationTableExists(this.drizzle);
63
- if (tableExists) {
64
- try {
65
- await payload.delete({
66
- collection: 'payload-migrations',
67
- where: {
68
- batch: {
69
- equals: -1
70
- }
71
- }
72
- });
73
- } catch (err) {
74
- payload.logger.error({
75
- error: err,
76
- msg: 'Error deleting dev migration'
77
- });
78
- }
79
- }
80
- }
81
-
82
- //# sourceMappingURL=migrateReset.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/migrateReset.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport {\n commitTransaction,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload/database'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\n\n/**\n * Run all migrate down functions\n */\nexport async function migrateReset(this: PostgresAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations } = await getMigrations({ payload })\n\n if (!existingMigrations?.length) {\n payload.logger.info({ msg: 'No migrations to reset.' })\n return\n }\n\n const req = { payload } as PayloadRequestWithData\n\n // Rollback all migrations in order\n for (const migration of existingMigrations) {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n try {\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n const start = Date.now()\n payload.logger.info({ msg: `Migrating down: ${migrationFile.name}` })\n await initTransaction(req)\n await migrationFile.down({ payload, req })\n payload.logger.info({\n msg: `Migrated down: ${migrationFile.name} (${Date.now() - start}ms)`,\n })\n\n const tableExists = await migrationTableExists(this.drizzle)\n if (tableExists) {\n await payload.delete({\n id: migration.id,\n collection: 'payload-migrations',\n req,\n })\n }\n\n await commitTransaction(req)\n } catch (err: unknown) {\n let msg = `Error running migration ${migrationFile.name}.`\n\n if (err instanceof Error) msg += ` ${err.message}`\n\n await killTransaction(req)\n payload.logger.error({\n err,\n msg,\n })\n process.exit(1)\n }\n }\n\n // Delete dev migration\n\n const tableExists = await migrationTableExists(this.drizzle)\n if (tableExists) {\n try {\n await payload.delete({\n collection: 'payload-migrations',\n where: {\n batch: {\n equals: -1,\n },\n },\n })\n } catch (err: unknown) {\n payload.logger.error({ error: err, msg: 'Error deleting dev migration' })\n }\n }\n}\n"],"names":["commitTransaction","getMigrations","initTransaction","killTransaction","readMigrationFiles","migrationTableExists","migrateReset","payload","migrationFiles","existingMigrations","length","logger","info","msg","req","migration","migrationFile","find","m","name","Error","start","Date","now","down","tableExists","drizzle","delete","id","collection","err","message","error","process","exit","where","batch","equals"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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