@payloadcms/db-postgres 3.0.0-canary.f6e77b8 → 3.0.0-canary.fb81f02

Sign up to get free protection for your applications and to get access to all the features.
Files changed (410) 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 +17 -51
  5. package/dist/connect.js.map +1 -1
  6. package/dist/connectionHelpers/nodePostgres.d.ts +11 -0
  7. package/dist/connectionHelpers/nodePostgres.d.ts.map +1 -0
  8. package/dist/connectionHelpers/nodePostgres.js +6 -0
  9. package/dist/connectionHelpers/nodePostgres.js.map +1 -0
  10. package/dist/countDistinct.d.ts +3 -0
  11. package/dist/countDistinct.d.ts.map +1 -0
  12. package/dist/countDistinct.js +24 -0
  13. package/dist/countDistinct.js.map +1 -0
  14. package/dist/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -0
  15. package/dist/createJSONQuery/convertPathToJSONTraversal.js.map +1 -0
  16. package/dist/createJSONQuery/formatJSONPathSegment.d.ts.map +1 -0
  17. package/dist/createJSONQuery/formatJSONPathSegment.js.map +1 -0
  18. package/dist/createJSONQuery/index.d.ts.map +1 -0
  19. package/dist/createJSONQuery/index.js.map +1 -0
  20. package/dist/createMigration.d.ts +1 -1
  21. package/dist/createMigration.d.ts.map +1 -1
  22. package/dist/createMigration.js +67 -57
  23. package/dist/createMigration.js.map +1 -1
  24. package/dist/defaultSnapshot.d.ts +3 -0
  25. package/dist/defaultSnapshot.d.ts.map +1 -0
  26. package/dist/defaultSnapshot.js +17 -0
  27. package/dist/defaultSnapshot.js.map +1 -0
  28. package/dist/deleteWhere.d.ts +3 -0
  29. package/dist/deleteWhere.d.ts.map +1 -0
  30. package/dist/deleteWhere.js +6 -0
  31. package/dist/deleteWhere.js.map +1 -0
  32. package/dist/dropDatabase.d.ts +3 -0
  33. package/dist/dropDatabase.d.ts.map +1 -0
  34. package/dist/dropDatabase.js +9 -0
  35. package/dist/dropDatabase.js.map +1 -0
  36. package/dist/execute.d.ts +3 -0
  37. package/dist/execute.d.ts.map +1 -0
  38. package/dist/execute.js +11 -0
  39. package/dist/execute.js.map +1 -0
  40. package/dist/exports/migration-utils.d.ts +2 -0
  41. package/dist/exports/migration-utils.d.ts.map +1 -0
  42. package/dist/exports/migration-utils.js +3 -0
  43. package/dist/exports/migration-utils.js.map +1 -0
  44. package/dist/getMigrationTemplate.d.ts +4 -0
  45. package/dist/getMigrationTemplate.d.ts.map +1 -0
  46. package/dist/getMigrationTemplate.js +13 -0
  47. package/dist/getMigrationTemplate.js.map +1 -0
  48. package/dist/index.d.ts +2 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +51 -66
  51. package/dist/index.js.map +1 -1
  52. package/dist/init.d.ts +1 -1
  53. package/dist/init.d.ts.map +1 -1
  54. package/dist/init.js +17 -30
  55. package/dist/init.js.map +1 -1
  56. package/dist/insert.d.ts +3 -0
  57. package/dist/insert.d.ts.map +1 -0
  58. package/dist/insert.js +12 -0
  59. package/dist/insert.js.map +1 -0
  60. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  61. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  62. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  63. package/dist/predefinedMigrations/relationships-v2-v3.mjs +11 -0
  64. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +20 -0
  65. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
  66. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +169 -0
  67. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
  68. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
  69. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
  70. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +191 -0
  71. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
  72. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
  73. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
  74. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js +56 -0
  75. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
  76. package/dist/predefinedMigrations/v2-v3/index.d.ts +23 -0
  77. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
  78. package/dist/predefinedMigrations/v2-v3/index.js +211 -0
  79. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -0
  80. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +20 -0
  81. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
  82. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +57 -0
  83. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
  84. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +23 -0
  85. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
  86. package/dist/predefinedMigrations/v2-v3/traverseFields.js +85 -0
  87. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
  88. package/dist/predefinedMigrations/v2-v3/types.d.ts +9 -0
  89. package/dist/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
  90. package/dist/predefinedMigrations/v2-v3/types.js +6 -0
  91. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -0
  92. package/dist/requireDrizzleKit.d.ts +3 -0
  93. package/dist/requireDrizzleKit.d.ts.map +1 -0
  94. package/dist/requireDrizzleKit.js +5 -0
  95. package/dist/requireDrizzleKit.js.map +1 -0
  96. package/dist/schema/build.d.ts +9 -5
  97. package/dist/schema/build.d.ts.map +1 -1
  98. package/dist/schema/build.js +163 -114
  99. package/dist/schema/build.js.map +1 -1
  100. package/dist/schema/createIndex.d.ts.map +1 -1
  101. package/dist/schema/createIndex.js +1 -1
  102. package/dist/schema/createIndex.js.map +1 -1
  103. package/dist/schema/idToUUID.d.ts +1 -1
  104. package/dist/schema/idToUUID.d.ts.map +1 -1
  105. package/dist/schema/idToUUID.js.map +1 -1
  106. package/dist/schema/parentIDColumnMap.js.map +1 -1
  107. package/dist/schema/setColumnID.d.ts +1 -1
  108. package/dist/schema/setColumnID.d.ts.map +1 -1
  109. package/dist/schema/setColumnID.js +2 -2
  110. package/dist/schema/setColumnID.js.map +1 -1
  111. package/dist/schema/traverseFields.d.ts +5 -7
  112. package/dist/schema/traverseFields.d.ts.map +1 -1
  113. package/dist/schema/traverseFields.js +118 -56
  114. package/dist/schema/traverseFields.js.map +1 -1
  115. package/dist/schema/withDefault.d.ts +4 -0
  116. package/dist/schema/withDefault.d.ts.map +1 -0
  117. package/dist/schema/withDefault.js +10 -0
  118. package/dist/schema/withDefault.js.map +1 -0
  119. package/dist/types.d.ts +111 -39
  120. package/dist/types.d.ts.map +1 -1
  121. package/dist/types.js.map +1 -1
  122. package/package.json +25 -15
  123. package/dist/count.d.ts +0 -3
  124. package/dist/count.d.ts.map +0 -1
  125. package/dist/count.js +0 -50
  126. package/dist/count.js.map +0 -1
  127. package/dist/create.d.ts +0 -3
  128. package/dist/create.d.ts.map +0 -1
  129. package/dist/create.js +0 -19
  130. package/dist/create.js.map +0 -1
  131. package/dist/createGlobal.d.ts +0 -5
  132. package/dist/createGlobal.d.ts.map +0 -1
  133. package/dist/createGlobal.js +0 -19
  134. package/dist/createGlobal.js.map +0 -1
  135. package/dist/createGlobalVersion.d.ts +0 -6
  136. package/dist/createGlobalVersion.d.ts.map +0 -1
  137. package/dist/createGlobalVersion.js +0 -33
  138. package/dist/createGlobalVersion.js.map +0 -1
  139. package/dist/createVersion.d.ts +0 -5
  140. package/dist/createVersion.d.ts.map +0 -1
  141. package/dist/createVersion.js +0 -44
  142. package/dist/createVersion.js.map +0 -1
  143. package/dist/deleteMany.d.ts +0 -3
  144. package/dist/deleteMany.d.ts.map +0 -1
  145. package/dist/deleteMany.js +0 -28
  146. package/dist/deleteMany.js.map +0 -1
  147. package/dist/deleteOne.d.ts +0 -3
  148. package/dist/deleteOne.d.ts.map +0 -1
  149. package/dist/deleteOne.js +0 -59
  150. package/dist/deleteOne.js.map +0 -1
  151. package/dist/deleteVersions.d.ts +0 -3
  152. package/dist/deleteVersions.d.ts.map +0 -1
  153. package/dist/deleteVersions.js +0 -31
  154. package/dist/deleteVersions.js.map +0 -1
  155. package/dist/destroy.d.ts +0 -3
  156. package/dist/destroy.d.ts.map +0 -1
  157. package/dist/destroy.js +0 -11
  158. package/dist/destroy.js.map +0 -1
  159. package/dist/find/buildFindManyArgs.d.ts +0 -13
  160. package/dist/find/buildFindManyArgs.d.ts.map +0 -1
  161. package/dist/find/buildFindManyArgs.js +0 -64
  162. package/dist/find/buildFindManyArgs.js.map +0 -1
  163. package/dist/find/chainMethods.d.ts +0 -16
  164. package/dist/find/chainMethods.d.ts.map +0 -1
  165. package/dist/find/chainMethods.js +0 -12
  166. package/dist/find/chainMethods.js.map +0 -1
  167. package/dist/find/findMany.d.ts +0 -22
  168. package/dist/find/findMany.d.ts.map +0 -1
  169. package/dist/find/findMany.js +0 -163
  170. package/dist/find/findMany.js.map +0 -1
  171. package/dist/find/traverseFields.d.ts +0 -16
  172. package/dist/find/traverseFields.d.ts.map +0 -1
  173. package/dist/find/traverseFields.js +0 -138
  174. package/dist/find/traverseFields.js.map +0 -1
  175. package/dist/find.d.ts +0 -3
  176. package/dist/find.d.ts.map +0 -1
  177. package/dist/find.js +0 -21
  178. package/dist/find.js.map +0 -1
  179. package/dist/findGlobal.d.ts +0 -3
  180. package/dist/findGlobal.d.ts.map +0 -1
  181. package/dist/findGlobal.js +0 -23
  182. package/dist/findGlobal.js.map +0 -1
  183. package/dist/findGlobalVersions.d.ts +0 -3
  184. package/dist/findGlobalVersions.d.ts.map +0 -1
  185. package/dist/findGlobalVersions.js +0 -24
  186. package/dist/findGlobalVersions.js.map +0 -1
  187. package/dist/findOne.d.ts +0 -5
  188. package/dist/findOne.d.ts.map +0 -1
  189. package/dist/findOne.js +0 -21
  190. package/dist/findOne.js.map +0 -1
  191. package/dist/findVersions.d.ts +0 -3
  192. package/dist/findVersions.d.ts.map +0 -1
  193. package/dist/findVersions.js +0 -24
  194. package/dist/findVersions.js.map +0 -1
  195. package/dist/migrate.d.ts +0 -3
  196. package/dist/migrate.d.ts.map +0 -1
  197. package/dist/migrate.js +0 -99
  198. package/dist/migrate.js.map +0 -1
  199. package/dist/migrateDown.d.ts +0 -3
  200. package/dist/migrateDown.d.ts.map +0 -1
  201. package/dist/migrateDown.js +0 -63
  202. package/dist/migrateDown.js.map +0 -1
  203. package/dist/migrateFresh.d.ts +0 -8
  204. package/dist/migrateFresh.d.ts.map +0 -1
  205. package/dist/migrateFresh.js +0 -72
  206. package/dist/migrateFresh.js.map +0 -1
  207. package/dist/migrateRefresh.d.ts +0 -6
  208. package/dist/migrateRefresh.d.ts.map +0 -1
  209. package/dist/migrateRefresh.js +0 -102
  210. package/dist/migrateRefresh.js.map +0 -1
  211. package/dist/migrateReset.d.ts +0 -6
  212. package/dist/migrateReset.d.ts.map +0 -1
  213. package/dist/migrateReset.js +0 -82
  214. package/dist/migrateReset.js.map +0 -1
  215. package/dist/migrateStatus.d.ts +0 -3
  216. package/dist/migrateStatus.d.ts.map +0 -1
  217. package/dist/migrateStatus.js +0 -44
  218. package/dist/migrateStatus.js.map +0 -1
  219. package/dist/queries/buildAndOrConditions.d.ts +0 -17
  220. package/dist/queries/buildAndOrConditions.d.ts.map +0 -1
  221. package/dist/queries/buildAndOrConditions.js +0 -29
  222. package/dist/queries/buildAndOrConditions.js.map +0 -1
  223. package/dist/queries/buildQuery.d.ts +0 -31
  224. package/dist/queries/buildQuery.d.ts.map +0 -1
  225. package/dist/queries/buildQuery.js +0 -76
  226. package/dist/queries/buildQuery.js.map +0 -1
  227. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts.map +0 -1
  228. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +0 -1
  229. package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts.map +0 -1
  230. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +0 -1
  231. package/dist/queries/createJSONQuery/index.d.ts.map +0 -1
  232. package/dist/queries/createJSONQuery/index.js.map +0 -1
  233. package/dist/queries/getTableColumnFromPath.d.ts +0 -51
  234. package/dist/queries/getTableColumnFromPath.d.ts.map +0 -1
  235. package/dist/queries/getTableColumnFromPath.js +0 -445
  236. package/dist/queries/getTableColumnFromPath.js.map +0 -1
  237. package/dist/queries/operatorMap.d.ts +0 -18
  238. package/dist/queries/operatorMap.d.ts.map +0 -1
  239. package/dist/queries/operatorMap.js +0 -24
  240. package/dist/queries/operatorMap.js.map +0 -1
  241. package/dist/queries/parseParams.d.ts +0 -17
  242. package/dist/queries/parseParams.d.ts.map +0 -1
  243. package/dist/queries/parseParams.js +0 -182
  244. package/dist/queries/parseParams.js.map +0 -1
  245. package/dist/queries/sanitizeQueryValue.d.ts +0 -15
  246. package/dist/queries/sanitizeQueryValue.d.ts.map +0 -1
  247. package/dist/queries/sanitizeQueryValue.js +0 -90
  248. package/dist/queries/sanitizeQueryValue.js.map +0 -1
  249. package/dist/queries/selectDistinct.d.ts +0 -23
  250. package/dist/queries/selectDistinct.d.ts.map +0 -1
  251. package/dist/queries/selectDistinct.js +0 -41
  252. package/dist/queries/selectDistinct.js.map +0 -1
  253. package/dist/queryDrafts.d.ts +0 -3
  254. package/dist/queryDrafts.d.ts.map +0 -1
  255. package/dist/queryDrafts.js +0 -41
  256. package/dist/queryDrafts.js.map +0 -1
  257. package/dist/schema/createTableName.d.ts +0 -30
  258. package/dist/schema/createTableName.d.ts.map +0 -1
  259. package/dist/schema/createTableName.js +0 -31
  260. package/dist/schema/createTableName.js.map +0 -1
  261. package/dist/schema/validateExistingBlockIsIdentical.d.ts +0 -12
  262. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +0 -1
  263. package/dist/schema/validateExistingBlockIsIdentical.js +0 -76
  264. package/dist/schema/validateExistingBlockIsIdentical.js.map +0 -1
  265. package/dist/transactions/beginTransaction.d.ts +0 -3
  266. package/dist/transactions/beginTransaction.d.ts.map +0 -1
  267. package/dist/transactions/beginTransaction.js +0 -47
  268. package/dist/transactions/beginTransaction.js.map +0 -1
  269. package/dist/transactions/commitTransaction.d.ts +0 -3
  270. package/dist/transactions/commitTransaction.d.ts.map +0 -1
  271. package/dist/transactions/commitTransaction.js +0 -14
  272. package/dist/transactions/commitTransaction.js.map +0 -1
  273. package/dist/transactions/rollbackTransaction.d.ts +0 -3
  274. package/dist/transactions/rollbackTransaction.d.ts.map +0 -1
  275. package/dist/transactions/rollbackTransaction.js +0 -13
  276. package/dist/transactions/rollbackTransaction.js.map +0 -1
  277. package/dist/transform/read/hasManyNumber.d.ts +0 -10
  278. package/dist/transform/read/hasManyNumber.d.ts.map +0 -1
  279. package/dist/transform/read/hasManyNumber.js +0 -10
  280. package/dist/transform/read/hasManyNumber.js.map +0 -1
  281. package/dist/transform/read/hasManyText.d.ts +0 -10
  282. package/dist/transform/read/hasManyText.d.ts.map +0 -1
  283. package/dist/transform/read/hasManyText.js +0 -10
  284. package/dist/transform/read/hasManyText.js.map +0 -1
  285. package/dist/transform/read/index.d.ts +0 -12
  286. package/dist/transform/read/index.d.ts.map +0 -1
  287. package/dist/transform/read/index.js +0 -43
  288. package/dist/transform/read/index.js.map +0 -1
  289. package/dist/transform/read/relationship.d.ts +0 -10
  290. package/dist/transform/read/relationship.d.ts.map +0 -1
  291. package/dist/transform/read/relationship.js +0 -64
  292. package/dist/transform/read/relationship.js.map +0 -1
  293. package/dist/transform/read/traverseFields.d.ts +0 -52
  294. package/dist/transform/read/traverseFields.d.ts.map +0 -1
  295. package/dist/transform/read/traverseFields.js +0 -421
  296. package/dist/transform/read/traverseFields.js.map +0 -1
  297. package/dist/transform/write/array.d.ts +0 -26
  298. package/dist/transform/write/array.d.ts.map +0 -1
  299. package/dist/transform/write/array.js +0 -58
  300. package/dist/transform/write/array.js.map +0 -1
  301. package/dist/transform/write/blocks.d.ts +0 -25
  302. package/dist/transform/write/blocks.d.ts.map +0 -1
  303. package/dist/transform/write/blocks.js +0 -54
  304. package/dist/transform/write/blocks.js.map +0 -1
  305. package/dist/transform/write/index.d.ts +0 -13
  306. package/dist/transform/write/index.d.ts.map +0 -1
  307. package/dist/transform/write/index.js +0 -41
  308. package/dist/transform/write/index.js.map +0 -1
  309. package/dist/transform/write/numbers.d.ts +0 -8
  310. package/dist/transform/write/numbers.d.ts.map +0 -1
  311. package/dist/transform/write/numbers.js +0 -11
  312. package/dist/transform/write/numbers.js.map +0 -1
  313. package/dist/transform/write/relationships.d.ts +0 -10
  314. package/dist/transform/write/relationships.d.ts.map +0 -1
  315. package/dist/transform/write/relationships.js +0 -23
  316. package/dist/transform/write/relationships.js.map +0 -1
  317. package/dist/transform/write/selects.d.ts +0 -8
  318. package/dist/transform/write/selects.d.ts.map +0 -1
  319. package/dist/transform/write/selects.js +0 -20
  320. package/dist/transform/write/selects.js.map +0 -1
  321. package/dist/transform/write/texts.d.ts +0 -8
  322. package/dist/transform/write/texts.d.ts.map +0 -1
  323. package/dist/transform/write/texts.js +0 -11
  324. package/dist/transform/write/texts.js.map +0 -1
  325. package/dist/transform/write/traverseFields.d.ts +0 -50
  326. package/dist/transform/write/traverseFields.d.ts.map +0 -1
  327. package/dist/transform/write/traverseFields.js +0 -428
  328. package/dist/transform/write/traverseFields.js.map +0 -1
  329. package/dist/transform/write/types.d.ts +0 -43
  330. package/dist/transform/write/types.d.ts.map +0 -1
  331. package/dist/transform/write/types.js +0 -3
  332. package/dist/transform/write/types.js.map +0 -1
  333. package/dist/update.d.ts +0 -3
  334. package/dist/update.d.ts.map +0 -1
  335. package/dist/update.js +0 -55
  336. package/dist/update.js.map +0 -1
  337. package/dist/updateGlobal.d.ts +0 -5
  338. package/dist/updateGlobal.d.ts.map +0 -1
  339. package/dist/updateGlobal.js +0 -25
  340. package/dist/updateGlobal.js.map +0 -1
  341. package/dist/updateGlobalVersion.d.ts +0 -5
  342. package/dist/updateGlobalVersion.d.ts.map +0 -1
  343. package/dist/updateGlobalVersion.js +0 -36
  344. package/dist/updateGlobalVersion.js.map +0 -1
  345. package/dist/updateVersion.d.ts +0 -5
  346. package/dist/updateVersion.d.ts.map +0 -1
  347. package/dist/updateVersion.js +0 -36
  348. package/dist/updateVersion.js.map +0 -1
  349. package/dist/upsertRow/deleteExistingArrayRows.d.ts +0 -10
  350. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +0 -1
  351. package/dist/upsertRow/deleteExistingArrayRows.js +0 -10
  352. package/dist/upsertRow/deleteExistingArrayRows.js.map +0 -1
  353. package/dist/upsertRow/deleteExistingRowsByPath.d.ts +0 -14
  354. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +0 -1
  355. package/dist/upsertRow/deleteExistingRowsByPath.js +0 -33
  356. package/dist/upsertRow/deleteExistingRowsByPath.js.map +0 -1
  357. package/dist/upsertRow/index.d.ts +0 -4
  358. package/dist/upsertRow/index.d.ts.map +0 -1
  359. package/dist/upsertRow/index.js +0 -277
  360. package/dist/upsertRow/index.js.map +0 -1
  361. package/dist/upsertRow/insertArrays.d.ts +0 -13
  362. package/dist/upsertRow/insertArrays.d.ts.map +0 -1
  363. package/dist/upsertRow/insertArrays.js +0 -68
  364. package/dist/upsertRow/insertArrays.js.map +0 -1
  365. package/dist/upsertRow/types.d.ts +0 -27
  366. package/dist/upsertRow/types.d.ts.map +0 -1
  367. package/dist/upsertRow/types.js +0 -3
  368. package/dist/upsertRow/types.js.map +0 -1
  369. package/dist/utilities/appendPrefixToKeys.d.ts +0 -2
  370. package/dist/utilities/appendPrefixToKeys.d.ts.map +0 -1
  371. package/dist/utilities/appendPrefixToKeys.js +0 -6
  372. package/dist/utilities/appendPrefixToKeys.js.map +0 -1
  373. package/dist/utilities/createBlocksMap.d.ts +0 -5
  374. package/dist/utilities/createBlocksMap.d.ts.map +0 -1
  375. package/dist/utilities/createBlocksMap.js +0 -29
  376. package/dist/utilities/createBlocksMap.js.map +0 -1
  377. package/dist/utilities/createMigrationTable.d.ts +0 -3
  378. package/dist/utilities/createMigrationTable.d.ts.map +0 -1
  379. package/dist/utilities/createMigrationTable.js +0 -13
  380. package/dist/utilities/createMigrationTable.js.map +0 -1
  381. package/dist/utilities/createRelationshipMap.d.ts +0 -2
  382. package/dist/utilities/createRelationshipMap.d.ts.map +0 -1
  383. package/dist/utilities/createRelationshipMap.js +0 -19
  384. package/dist/utilities/createRelationshipMap.js.map +0 -1
  385. package/dist/utilities/hasLocalesTable.d.ts +0 -3
  386. package/dist/utilities/hasLocalesTable.d.ts.map +0 -1
  387. package/dist/utilities/hasLocalesTable.js +0 -11
  388. package/dist/utilities/hasLocalesTable.js.map +0 -1
  389. package/dist/utilities/isArrayOfRows.d.ts +0 -2
  390. package/dist/utilities/isArrayOfRows.d.ts.map +0 -1
  391. package/dist/utilities/isArrayOfRows.js +0 -5
  392. package/dist/utilities/isArrayOfRows.js.map +0 -1
  393. package/dist/utilities/migrationTableExists.d.ts +0 -3
  394. package/dist/utilities/migrationTableExists.d.ts.map +0 -1
  395. package/dist/utilities/migrationTableExists.js +0 -9
  396. package/dist/utilities/migrationTableExists.js.map +0 -1
  397. package/dist/utilities/parseError.d.ts +0 -5
  398. package/dist/utilities/parseError.d.ts.map +0 -1
  399. package/dist/utilities/parseError.js +0 -17
  400. package/dist/utilities/parseError.js.map +0 -1
  401. package/dist/utilities/pushDevSchema.d.ts +0 -9
  402. package/dist/utilities/pushDevSchema.d.ts.map +0 -1
  403. package/dist/utilities/pushDevSchema.js +0 -58
  404. package/dist/utilities/pushDevSchema.js.map +0 -1
  405. /package/dist/{queries/createJSONQuery → createJSONQuery}/convertPathToJSONTraversal.d.ts +0 -0
  406. /package/dist/{queries/createJSONQuery → createJSONQuery}/convertPathToJSONTraversal.js +0 -0
  407. /package/dist/{queries/createJSONQuery → createJSONQuery}/formatJSONPathSegment.d.ts +0 -0
  408. /package/dist/{queries/createJSONQuery → createJSONQuery}/formatJSONPathSegment.js +0 -0
  409. /package/dist/{queries/createJSONQuery → createJSONQuery}/index.d.ts +0 -0
  410. /package/dist/{queries/createJSONQuery → createJSONQuery}/index.js +0 -0
package/README.md CHANGED
@@ -14,7 +14,7 @@ npm install @payloadcms/db-postgres
14
14
  ## Usage
15
15
 
16
16
  ```ts
17
- import { buildConfig } from 'payload/config'
17
+ import { buildConfig } from 'payload'
18
18
  import { postgresAdapter } from '@payloadcms/db-postgres'
19
19
 
20
20
  export default buildConfig({
package/dist/connect.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { Connect } from 'payload/database';
1
+ import type { Connect } from 'payload';
2
2
  export declare const connect: Connect;
3
3
  //# sourceMappingURL=connect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AA+C/C,eAAO,MAAM,OAAO,EAAE,OAgDrB,CAAA"}
1
+ {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAMtC,eAAO,MAAM,OAAO,EAAE,OAgDrB,CAAA"}
package/dist/connect.js CHANGED
@@ -1,79 +1,45 @@
1
- import { sql } from 'drizzle-orm';
2
- import { drizzle } from 'drizzle-orm/node-postgres';
3
- import pg from 'pg';
4
- import { pushDevSchema } from './utilities/pushDevSchema.js';
5
- const connectWithReconnect = async function({ adapter, payload, reconnect = false }) {
6
- let result;
7
- if (!reconnect) {
8
- result = await adapter.pool.connect();
9
- } else {
10
- try {
11
- result = await adapter.pool.connect();
12
- } catch (err) {
13
- setTimeout(()=>{
14
- payload.logger.info('Reconnecting to postgres');
15
- void connectWithReconnect({
16
- adapter,
17
- payload,
18
- reconnect: true
19
- });
20
- }, 1000);
21
- }
22
- }
23
- if (!result) {
24
- return;
25
- }
26
- result.prependListener('error', (err)=>{
27
- try {
28
- if (err.code === 'ECONNRESET') {
29
- void connectWithReconnect({
30
- adapter,
31
- payload,
32
- reconnect: true
33
- });
34
- }
35
- } catch (err) {
36
- // swallow error
37
- }
38
- });
39
- };
1
+ import { pushDevSchema } from '@payloadcms/drizzle';
40
2
  export const connect = async function connect(options = {
41
3
  hotReload: false
42
4
  }) {
43
5
  const { hotReload } = options;
44
6
  this.schema = {
7
+ pgSchema: this.pgSchema,
45
8
  ...this.tables,
46
9
  ...this.relations,
47
10
  ...this.enums
48
11
  };
49
12
  try {
50
- this.pool = new pg.Pool(this.poolOptions);
51
- await connectWithReconnect({
52
- adapter: this,
53
- payload: this.payload
54
- });
55
13
  const logger = this.logger || false;
56
- this.drizzle = drizzle(this.pool, {
14
+ const { drizzle } = await this.getDrizzle({
57
15
  logger,
58
16
  schema: this.schema
59
17
  });
18
+ this.drizzle = drizzle;
60
19
  if (!hotReload) {
61
20
  if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
62
21
  this.payload.logger.info(`---- DROPPING TABLES SCHEMA(${this.schemaName || 'public'}) ----`);
63
- await this.drizzle.execute(sql.raw(`
64
- drop schema if exists ${this.schemaName || 'public'} cascade;
65
- create schema ${this.schemaName || 'public'};
66
- `));
22
+ await this.dropDatabase({
23
+ adapter: this
24
+ });
67
25
  this.payload.logger.info('---- DROPPED TABLES ----');
68
26
  }
69
27
  }
70
28
  } catch (err) {
71
29
  this.payload.logger.error(`Error: cannot connect to Postgres. Details: ${err.message}`, err);
30
+ if (typeof this.rejectInitializing === 'function') this.rejectInitializing();
72
31
  process.exit(1);
73
32
  }
74
33
  // Only push schema if not in production
75
- if (process.env.NODE_ENV === 'production' || process.env.PAYLOAD_MIGRATING === 'true' || this.push === false) return;
76
- await pushDevSchema(this);
34
+ if (process.env.NODE_ENV !== 'production' && process.env.PAYLOAD_MIGRATING !== 'true' && this.push !== false) {
35
+ await pushDevSchema(this);
36
+ }
37
+ if (typeof this.resolveInitializing === 'function') this.resolveInitializing();
38
+ if (process.env.NODE_ENV === 'production' && this.prodMigrations) {
39
+ await this.migrate({
40
+ migrations: this.prodMigrations
41
+ });
42
+ }
77
43
  };
78
44
 
79
45
  //# sourceMappingURL=connect.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type { Connect } from 'payload/database'\n\nimport { sql } from 'drizzle-orm'\nimport { drizzle } from 'drizzle-orm/node-postgres'\nimport pg from 'pg'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { pushDevSchema } from './utilities/pushDevSchema.js'\n\nconst connectWithReconnect = async function ({\n adapter,\n payload,\n reconnect = false,\n}: {\n adapter: PostgresAdapter\n payload: Payload\n reconnect?: boolean\n}) {\n let result\n\n if (!reconnect) {\n result = await adapter.pool.connect()\n } else {\n try {\n result = await adapter.pool.connect()\n } catch (err) {\n setTimeout(() => {\n payload.logger.info('Reconnecting to postgres')\n void connectWithReconnect({ adapter, payload, reconnect: true })\n }, 1000)\n }\n }\n if (!result) {\n return\n }\n result.prependListener('error', (err) => {\n try {\n if (err.code === 'ECONNRESET') {\n void connectWithReconnect({ adapter, payload, reconnect: true })\n }\n } catch (err) {\n // swallow error\n }\n })\n}\n\nexport const connect: Connect = async function connect(\n this: PostgresAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n this.schema = {\n ...this.tables,\n ...this.relations,\n ...this.enums,\n }\n\n try {\n this.pool = new pg.Pool(this.poolOptions)\n await connectWithReconnect({ adapter: this, payload: this.payload })\n\n const logger = this.logger || false\n\n this.drizzle = drizzle(this.pool, { logger, schema: this.schema })\n\n if (!hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info(`---- DROPPING TABLES SCHEMA(${this.schemaName || 'public'}) ----`)\n await this.drizzle.execute(\n sql.raw(`\n drop schema if exists ${this.schemaName || 'public'} cascade;\n create schema ${this.schemaName || 'public'};\n `),\n )\n this.payload.logger.info('---- DROPPED TABLES ----')\n }\n }\n } catch (err) {\n this.payload.logger.error(`Error: cannot connect to Postgres. Details: ${err.message}`, err)\n process.exit(1)\n }\n\n // Only push schema if not in production\n if (\n process.env.NODE_ENV === 'production' ||\n process.env.PAYLOAD_MIGRATING === 'true' ||\n this.push === false\n )\n return\n\n await pushDevSchema(this)\n}\n"],"names":["sql","drizzle","pg","pushDevSchema","connectWithReconnect","adapter","payload","reconnect","result","pool","connect","err","setTimeout","logger","info","prependListener","code","options","hotReload","schema","tables","relations","enums","Pool","poolOptions","process","env","PAYLOAD_DROP_DATABASE","schemaName","execute","raw","error","message","exit","NODE_ENV","PAYLOAD_MIGRATING","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,GAAG,QAAQ,cAAa;AACjC,SAASC,OAAO,QAAQ,4BAA2B;AACnD,OAAOC,QAAQ,KAAI;AAInB,SAASC,aAAa,QAAQ,+BAA8B;AAE5D,MAAMC,uBAAuB,eAAgB,EAC3CC,OAAO,EACPC,OAAO,EACPC,YAAY,KAAK,EAKlB;IACC,IAAIC;IAEJ,IAAI,CAACD,WAAW;QACdC,SAAS,MAAMH,QAAQI,IAAI,CAACC,OAAO;IACrC,OAAO;QACL,IAAI;YACFF,SAAS,MAAMH,QAAQI,IAAI,CAACC,OAAO;QACrC,EAAE,OAAOC,KAAK;YACZC,WAAW;gBACTN,QAAQO,MAAM,CAACC,IAAI,CAAC;gBACpB,KAAKV,qBAAqB;oBAAEC;oBAASC;oBAASC,WAAW;gBAAK;YAChE,GAAG;QACL;IACF;IACA,IAAI,CAACC,QAAQ;QACX;IACF;IACAA,OAAOO,eAAe,CAAC,SAAS,CAACJ;QAC/B,IAAI;YACF,IAAIA,IAAIK,IAAI,KAAK,cAAc;gBAC7B,KAAKZ,qBAAqB;oBAAEC;oBAASC;oBAASC,WAAW;gBAAK;YAChE;QACF,EAAE,OAAOI,KAAK;QACZ,gBAAgB;QAClB;IACF;AACF;AAEA,OAAO,MAAMD,UAAmB,eAAeA,QAE7CO,UAAU;IACRC,WAAW;AACb,CAAC;IAED,MAAM,EAAEA,SAAS,EAAE,GAAGD;IAEtB,IAAI,CAACE,MAAM,GAAG;QACZ,GAAG,IAAI,CAACC,MAAM;QACd,GAAG,IAAI,CAACC,SAAS;QACjB,GAAG,IAAI,CAACC,KAAK;IACf;IAEA,IAAI;QACF,IAAI,CAACb,IAAI,GAAG,IAAIP,GAAGqB,IAAI,CAAC,IAAI,CAACC,WAAW;QACxC,MAAMpB,qBAAqB;YAAEC,SAAS,IAAI;YAAEC,SAAS,IAAI,CAACA,OAAO;QAAC;QAElE,MAAMO,SAAS,IAAI,CAACA,MAAM,IAAI;QAE9B,IAAI,CAACZ,OAAO,GAAGA,QAAQ,IAAI,CAACQ,IAAI,EAAE;YAAEI;YAAQM,QAAQ,IAAI,CAACA,MAAM;QAAC;QAEhE,IAAI,CAACD,WAAW;YACd,IAAIO,QAAQC,GAAG,CAACC,qBAAqB,KAAK,QAAQ;gBAChD,IAAI,CAACrB,OAAO,CAACO,MAAM,CAACC,IAAI,CAAC,CAAC,4BAA4B,EAAE,IAAI,CAACc,UAAU,IAAI,SAAS,MAAM,CAAC;gBAC3F,MAAM,IAAI,CAAC3B,OAAO,CAAC4B,OAAO,CACxB7B,IAAI8B,GAAG,CAAC,CAAC;gCACa,EAAE,IAAI,CAACF,UAAU,IAAI,SAAS;wBACtC,EAAE,IAAI,CAACA,UAAU,IAAI,SAAS;QAC9C,CAAC;gBAED,IAAI,CAACtB,OAAO,CAACO,MAAM,CAACC,IAAI,CAAC;YAC3B;QACF;IACF,EAAE,OAAOH,KAAK;QACZ,IAAI,CAACL,OAAO,CAACO,MAAM,CAACkB,KAAK,CAAC,CAAC,4CAA4C,EAAEpB,IAAIqB,OAAO,CAAC,CAAC,EAAErB;QACxFc,QAAQQ,IAAI,CAAC;IACf;IAEA,wCAAwC;IACxC,IACER,QAAQC,GAAG,CAACQ,QAAQ,KAAK,gBACzBT,QAAQC,GAAG,CAACS,iBAAiB,KAAK,UAClC,IAAI,CAACC,IAAI,KAAK,OAEd;IAEF,MAAMjC,cAAc,IAAI;AAC1B,EAAC"}
1
+ {"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { DrizzleAdapter } from '@payloadcms/drizzle/types'\nimport type { Connect } from 'payload'\n\nimport { pushDevSchema } from '@payloadcms/drizzle'\n\nimport type { PostgresAdapter } from './types.js'\n\nexport const connect: Connect = async function connect(\n this: PostgresAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n this.schema = {\n pgSchema: this.pgSchema,\n ...this.tables,\n ...this.relations,\n ...this.enums,\n }\n\n try {\n const logger = this.logger || false\n\n const { drizzle } = await this.getDrizzle({ logger, schema: this.schema })\n this.drizzle = drizzle\n\n if (!hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info(`---- DROPPING TABLES SCHEMA(${this.schemaName || 'public'}) ----`)\n await this.dropDatabase({ adapter: this })\n this.payload.logger.info('---- DROPPED TABLES ----')\n }\n }\n } catch (err) {\n this.payload.logger.error(`Error: cannot connect to Postgres. Details: ${err.message}`, err)\n if (typeof this.rejectInitializing === 'function') this.rejectInitializing()\n process.exit(1)\n }\n\n // Only push schema if not in production\n if (\n process.env.NODE_ENV !== 'production' &&\n process.env.PAYLOAD_MIGRATING !== 'true' &&\n this.push !== false\n ) {\n await pushDevSchema(this as unknown as DrizzleAdapter)\n }\n\n if (typeof this.resolveInitializing === 'function') this.resolveInitializing()\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations })\n }\n}\n"],"names":["pushDevSchema","connect","options","hotReload","schema","pgSchema","tables","relations","enums","logger","drizzle","getDrizzle","process","env","PAYLOAD_DROP_DATABASE","payload","info","schemaName","dropDatabase","adapter","err","error","message","rejectInitializing","exit","NODE_ENV","PAYLOAD_MIGRATING","push","resolveInitializing","prodMigrations","migrate","migrations"],"mappings":"AAGA,SAASA,aAAa,QAAQ,sBAAqB;AAInD,OAAO,MAAMC,UAAmB,eAAeA,QAE7CC,UAAU;IACRC,WAAW;AACb,CAAC;IAED,MAAM,EAAEA,SAAS,EAAE,GAAGD;IAEtB,IAAI,CAACE,MAAM,GAAG;QACZC,UAAU,IAAI,CAACA,QAAQ;QACvB,GAAG,IAAI,CAACC,MAAM;QACd,GAAG,IAAI,CAACC,SAAS;QACjB,GAAG,IAAI,CAACC,KAAK;IACf;IAEA,IAAI;QACF,MAAMC,SAAS,IAAI,CAACA,MAAM,IAAI;QAE9B,MAAM,EAAEC,OAAO,EAAE,GAAG,MAAM,IAAI,CAACC,UAAU,CAAC;YAAEF;YAAQL,QAAQ,IAAI,CAACA,MAAM;QAAC;QACxE,IAAI,CAACM,OAAO,GAAGA;QAEf,IAAI,CAACP,WAAW;YACd,IAAIS,QAAQC,GAAG,CAACC,qBAAqB,KAAK,QAAQ;gBAChD,IAAI,CAACC,OAAO,CAACN,MAAM,CAACO,IAAI,CAAC,CAAC,4BAA4B,EAAE,IAAI,CAACC,UAAU,IAAI,SAAS,MAAM,CAAC;gBAC3F,MAAM,IAAI,CAACC,YAAY,CAAC;oBAAEC,SAAS,IAAI;gBAAC;gBACxC,IAAI,CAACJ,OAAO,CAACN,MAAM,CAACO,IAAI,CAAC;YAC3B;QACF;IACF,EAAE,OAAOI,KAAK;QACZ,IAAI,CAACL,OAAO,CAACN,MAAM,CAACY,KAAK,CAAC,CAAC,4CAA4C,EAAED,IAAIE,OAAO,CAAC,CAAC,EAAEF;QACxF,IAAI,OAAO,IAAI,CAACG,kBAAkB,KAAK,YAAY,IAAI,CAACA,kBAAkB;QAC1EX,QAAQY,IAAI,CAAC;IACf;IAEA,wCAAwC;IACxC,IACEZ,QAAQC,GAAG,CAACY,QAAQ,KAAK,gBACzBb,QAAQC,GAAG,CAACa,iBAAiB,KAAK,UAClC,IAAI,CAACC,IAAI,KAAK,OACd;QACA,MAAM3B,cAAc,IAAI;IAC1B;IAEA,IAAI,OAAO,IAAI,CAAC4B,mBAAmB,KAAK,YAAY,IAAI,CAACA,mBAAmB;IAE5E,IAAIhB,QAAQC,GAAG,CAACY,QAAQ,KAAK,gBAAgB,IAAI,CAACI,cAAc,EAAE;QAChE,MAAM,IAAI,CAACC,OAAO,CAAC;YAAEC,YAAY,IAAI,CAACF,cAAc;QAAC;IACvD;AACF,EAAC"}
@@ -0,0 +1,11 @@
1
+ import type { TransactionPg } from '@payloadcms/drizzle/types';
2
+ import type { DrizzleConfig } from 'drizzle-orm';
3
+ import type { NodePgClient } from 'drizzle-orm/node-postgres';
4
+ import type { PostgresDB } from '../types.js';
5
+ export declare const nodePostgres: (args: {
6
+ client: NodePgClient;
7
+ config?: Pick<DrizzleConfig, "logger" | "schema">;
8
+ }) => {
9
+ drizzle: PostgresDB | TransactionPg;
10
+ };
11
+ //# sourceMappingURL=nodePostgres.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodePostgres.d.ts","sourceRoot":"","sources":["../../src/connectionHelpers/nodePostgres.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAI7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,eAAO,MAAM,YAAY,SAAU;IACjC,MAAM,EAAE,YAAY,CAAA;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,QAAQ,CAAC,CAAA;CAClD,KAAG;IAAE,OAAO,EAAE,UAAU,GAAG,aAAa,CAAA;CAExC,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { drizzle } from 'drizzle-orm/node-postgres';
2
+ export const nodePostgres = (args)=>{
3
+ return drizzle(args.client, args.config);
4
+ };
5
+
6
+ //# sourceMappingURL=nodePostgres.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/connectionHelpers/nodePostgres.ts"],"sourcesContent":["import type { TransactionPg } from '@payloadcms/drizzle/types'\nimport type { DrizzleConfig } from 'drizzle-orm'\nimport type { NodePgClient } from 'drizzle-orm/node-postgres'\n\nimport { drizzle } from 'drizzle-orm/node-postgres'\n\nimport type { PostgresDB } from '../types.js'\n\nexport const nodePostgres = (args: {\n client: NodePgClient\n config?: Pick<DrizzleConfig, 'logger' | 'schema'>\n}): { drizzle: PostgresDB | TransactionPg } => {\n return drizzle(args.client, args.config) as unknown as { drizzle: PostgresDB | TransactionPg }\n}\n"],"names":["drizzle","nodePostgres","args","client","config"],"mappings":"AAIA,SAASA,OAAO,QAAQ,4BAA2B;AAInD,OAAO,MAAMC,eAAe,CAACC;IAI3B,OAAOF,QAAQE,KAAKC,MAAM,EAAED,KAAKE,MAAM;AACzC,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { CountDistinct } from './types.js';
2
+ export declare const countDistinct: CountDistinct;
3
+ //# sourceMappingURL=countDistinct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countDistinct.d.ts","sourceRoot":"","sources":["../src/countDistinct.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAmB,MAAM,YAAY,CAAA;AAEhE,eAAO,MAAM,aAAa,EAAE,aAyB3B,CAAA"}
@@ -0,0 +1,24 @@
1
+ import { chainMethods } from '@payloadcms/drizzle';
2
+ import { sql } from 'drizzle-orm';
3
+ export const countDistinct = async function countDistinct({ db, joins, tableName, where }) {
4
+ const chainedMethods = [];
5
+ joins.forEach(({ condition, table })=>{
6
+ chainedMethods.push({
7
+ args: [
8
+ table,
9
+ condition
10
+ ],
11
+ method: 'leftJoin'
12
+ });
13
+ });
14
+ const countResult = await chainMethods({
15
+ methods: chainedMethods,
16
+ query: db.select({
17
+ count: sql`count
18
+ (DISTINCT ${this.tables[tableName].id})`
19
+ }).from(this.tables[tableName]).where(where)
20
+ });
21
+ return Number(countResult[0].count);
22
+ };
23
+
24
+ //# sourceMappingURL=countDistinct.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/countDistinct.ts"],"sourcesContent":["import type { ChainedMethods, TransactionPg } from '@payloadcms/drizzle/types'\n\nimport { chainMethods } from '@payloadcms/drizzle'\nimport { sql } from 'drizzle-orm'\n\nimport type { CountDistinct, PostgresAdapter } from './types.js'\n\nexport const countDistinct: CountDistinct = async function countDistinct(\n this: PostgresAdapter,\n { db, joins, tableName, where },\n) {\n const chainedMethods: ChainedMethods = []\n\n joins.forEach(({ condition, table }) => {\n chainedMethods.push({\n args: [table, condition],\n method: 'leftJoin',\n })\n })\n\n const countResult = await chainMethods({\n methods: chainedMethods,\n query: (db as TransactionPg)\n .select({\n count: sql<string>`count\n (DISTINCT ${this.tables[tableName].id})`,\n })\n .from(this.tables[tableName])\n .where(where),\n })\n\n return Number(countResult[0].count)\n}\n"],"names":["chainMethods","sql","countDistinct","db","joins","tableName","where","chainedMethods","forEach","condition","table","push","args","method","countResult","methods","query","select","count","tables","id","from","Number"],"mappings":"AAEA,SAASA,YAAY,QAAQ,sBAAqB;AAClD,SAASC,GAAG,QAAQ,cAAa;AAIjC,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,KAAK,EAAEC,SAAS,EAAEC,KAAK,EAAE;IAE/B,MAAMC,iBAAiC,EAAE;IAEzCH,MAAMI,OAAO,CAAC,CAAC,EAAEC,SAAS,EAAEC,KAAK,EAAE;QACjCH,eAAeI,IAAI,CAAC;YAClBC,MAAM;gBAACF;gBAAOD;aAAU;YACxBI,QAAQ;QACV;IACF;IAEA,MAAMC,cAAc,MAAMd,aAAa;QACrCe,SAASR;QACTS,OAAO,AAACb,GACLc,MAAM,CAAC;YACNC,OAAOjB,GAAW,CAAC;sBACL,EAAE,IAAI,CAACkB,MAAM,CAACd,UAAU,CAACe,EAAE,CAAC,CAAC,CAAC;QAC9C,GACCC,IAAI,CAAC,IAAI,CAACF,MAAM,CAACd,UAAU,EAC3BC,KAAK,CAACA;IACX;IAEA,OAAOgB,OAAOR,WAAW,CAAC,EAAE,CAACI,KAAK;AACpC,EAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertPathToJSONTraversal.d.ts","sourceRoot":"","sources":["../../src/createJSONQuery/convertPathToJSONTraversal.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,0BAA0B,qBAAsB,MAAM,EAAE,WAUpE,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/createJSONQuery/convertPathToJSONTraversal.ts"],"sourcesContent":["import { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nexport const convertPathToJSONTraversal = (incomingSegments: string[]) => {\n const segments = [...incomingSegments]\n segments.shift()\n\n return segments.reduce((res, segment, i) => {\n const formattedSegment = formatJSONPathSegment(segment)\n\n if (i + 1 === segments.length) return `${res}->>${formattedSegment}`\n return `${res}->${formattedSegment}`\n }, '')\n}\n"],"names":["formatJSONPathSegment","convertPathToJSONTraversal","incomingSegments","segments","shift","reduce","res","segment","i","formattedSegment","length"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,6BAA4B;AAElE,OAAO,MAAMC,6BAA6B,CAACC;IACzC,MAAMC,WAAW;WAAID;KAAiB;IACtCC,SAASC,KAAK;IAEd,OAAOD,SAASE,MAAM,CAAC,CAACC,KAAKC,SAASC;QACpC,MAAMC,mBAAmBT,sBAAsBO;QAE/C,IAAIC,IAAI,MAAML,SAASO,MAAM,EAAE,OAAO,CAAC,EAAEJ,IAAI,GAAG,EAAEG,iBAAiB,CAAC;QACpE,OAAO,CAAC,EAAEH,IAAI,EAAE,EAAEG,iBAAiB,CAAC;IACtC,GAAG;AACL,EAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatJSONPathSegment.d.ts","sourceRoot":"","sources":["../../src/createJSONQuery/formatJSONPathSegment.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,YAAa,MAAM,WAEpD,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/createJSONQuery/formatJSONPathSegment.ts"],"sourcesContent":["export const formatJSONPathSegment = (segment: string) => {\n return Number.isNaN(parseInt(segment)) ? `'${segment}'` : segment\n}\n"],"names":["formatJSONPathSegment","segment","Number","isNaN","parseInt"],"mappings":"AAAA,OAAO,MAAMA,wBAAwB,CAACC;IACpC,OAAOC,OAAOC,KAAK,CAACC,SAASH,YAAY,CAAC,CAAC,EAAEA,QAAQ,CAAC,CAAC,GAAGA;AAC5D,EAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/createJSONQuery/index.ts"],"names":[],"mappings":"AAmDA,KAAK,IAAI,GAAG;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,eAAO,MAAM,eAAe,uEAMzB,IAAI,KAAG,MAqBT,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/createJSONQuery/index.ts"],"sourcesContent":["import { convertPathToJSONTraversal } from './convertPathToJSONTraversal.js'\nimport { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nconst operatorMap = {\n contains: '~*',\n equals: '=',\n like: '~*',\n}\n\ntype FromArrayArgs = {\n isRoot?: true\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst fromArray = ({ isRoot, operator, pathSegments, treatAsArray, value }: FromArrayArgs) => {\n const newPathSegments = pathSegments.slice(isRoot ? 1 : 2)\n const alias = `${pathSegments[isRoot ? 0 : 1]}_alias_${newPathSegments.length}`\n\n newPathSegments.unshift(alias)\n\n const arrayElements = isRoot\n ? pathSegments[0]\n : `${pathSegments[0]} -> ${formatJSONPathSegment(pathSegments[1])}`\n\n return `EXISTS (\n SELECT 1\n FROM jsonb_array_elements(${arrayElements}) AS ${alias}\n WHERE ${createJSONQuery({\n operator,\n pathSegments: newPathSegments,\n treatAsArray,\n value,\n })}\n )`\n}\n\ntype CreateConstraintArgs = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst createConstraint = ({ operator, pathSegments, value }: CreateConstraintArgs): string => {\n const jsonQuery = convertPathToJSONTraversal(pathSegments)\n return `${pathSegments[0]}${jsonQuery} ${operatorMap[operator]} '${value}'`\n}\n\ntype Args = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n treatRootAsArray?: boolean\n value: unknown\n}\n\nexport const createJSONQuery = ({\n operator,\n pathSegments,\n treatAsArray,\n treatRootAsArray,\n value,\n}: Args): string => {\n if (treatRootAsArray) {\n return fromArray({\n isRoot: true,\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n if (treatAsArray.includes(pathSegments[1])) {\n return fromArray({\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n return createConstraint({ operator, pathSegments, treatAsArray, value })\n}\n"],"names":["convertPathToJSONTraversal","formatJSONPathSegment","operatorMap","contains","equals","like","fromArray","isRoot","operator","pathSegments","treatAsArray","value","newPathSegments","slice","alias","length","unshift","arrayElements","createJSONQuery","createConstraint","jsonQuery","treatRootAsArray","includes"],"mappings":"AAAA,SAASA,0BAA0B,QAAQ,kCAAiC;AAC5E,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,MAAMC,cAAc;IAClBC,UAAU;IACVC,QAAQ;IACRC,MAAM;AACR;AAUA,MAAMC,YAAY,CAAC,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,YAAY,EAAEC,KAAK,EAAiB;IACvF,MAAMC,kBAAkBH,aAAaI,KAAK,CAACN,SAAS,IAAI;IACxD,MAAMO,QAAQ,CAAC,EAAEL,YAAY,CAACF,SAAS,IAAI,EAAE,CAAC,OAAO,EAAEK,gBAAgBG,MAAM,CAAC,CAAC;IAE/EH,gBAAgBI,OAAO,CAACF;IAExB,MAAMG,gBAAgBV,SAClBE,YAAY,CAAC,EAAE,GACf,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,IAAI,EAAER,sBAAsBQ,YAAY,CAAC,EAAE,EAAE,CAAC;IAErE,OAAO,CAAC;;8BAEoB,EAAEQ,cAAc,KAAK,EAAEH,MAAM;UACjD,EAAEI,gBAAgB;QACtBV;QACAC,cAAcG;QACdF;QACAC;IACF,GAAG;GACJ,CAAC;AACJ;AASA,MAAMQ,mBAAmB,CAAC,EAAEX,QAAQ,EAAEC,YAAY,EAAEE,KAAK,EAAwB;IAC/E,MAAMS,YAAYpB,2BAA2BS;IAC7C,OAAO,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,EAAEW,UAAU,CAAC,EAAElB,WAAW,CAACM,SAAS,CAAC,EAAE,EAAEG,MAAM,CAAC,CAAC;AAC7E;AAUA,OAAO,MAAMO,kBAAkB,CAAC,EAC9BV,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZW,gBAAgB,EAChBV,KAAK,EACA;IACL,IAAIU,kBAAkB;QACpB,OAAOf,UAAU;YACfC,QAAQ;YACRC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,IAAID,aAAaY,QAAQ,CAACb,YAAY,CAAC,EAAE,GAAG;QAC1C,OAAOH,UAAU;YACfE;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAOQ,iBAAiB;QAAEX;QAAUC;QAAcC;QAAcC;IAAM;AACxE,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { CreateMigration } from 'payload/database';
1
+ import type { CreateMigration } from 'payload';
2
2
  export declare const createMigration: CreateMigration;
3
3
  //# sourceMappingURL=createMigration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAqDvD,eAAO,MAAM,eAAe,EAAE,eA4E7B,CAAA"}
1
+ {"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAgB9C,eAAO,MAAM,eAAe,EAAE,eAwG7B,CAAA"}
@@ -1,78 +1,88 @@
1
- /* eslint-disable no-restricted-syntax, no-await-in-loop */ import fs from 'fs';
1
+ import fs from 'fs';
2
2
  import { createRequire } from 'module';
3
+ import path from 'path';
4
+ import { getPredefinedMigration, writeMigrationIndex } from 'payload';
3
5
  import prompts from 'prompts';
6
+ import { fileURLToPath } from 'url';
7
+ import { defaultDrizzleSnapshot } from './defaultSnapshot.js';
8
+ import { getMigrationTemplate } from './getMigrationTemplate.js';
4
9
  const require = createRequire(import.meta.url);
5
- const migrationTemplate = (upSQL, downSQL)=>`import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
6
-
7
- export async function up({ payload }: MigrateUpArgs): Promise<void> {
8
- ${upSQL ? `await payload.db.drizzle.execute(sql\`
9
-
10
- ${upSQL}\`);
11
- ` : '// Migration code'}
12
- };
13
-
14
- export async function down({ payload }: MigrateDownArgs): Promise<void> {
15
- ${downSQL ? `await payload.db.drizzle.execute(sql\`
16
-
17
- ${downSQL}\`);
18
- ` : '// Migration code'}
19
- };
20
- `;
21
- const getDefaultDrizzleSnapshot = ()=>({
22
- id: '00000000-0000-0000-0000-000000000000',
23
- _meta: {
24
- columns: {},
25
- schemas: {},
26
- tables: {}
27
- },
28
- dialect: 'pg',
29
- enums: {},
30
- prevId: '00000000-0000-0000-0000-00000000000',
31
- schemas: {},
32
- tables: {},
33
- version: '5'
34
- });
35
- export const createMigration = async function createMigration({ forceAcceptWarning, migrationName, payload }) {
10
+ export const createMigration = async function createMigration({ file, forceAcceptWarning, migrationName, payload }) {
11
+ const filename = fileURLToPath(import.meta.url);
12
+ const dirname = path.dirname(filename);
36
13
  const dir = payload.db.migrationDir;
37
14
  if (!fs.existsSync(dir)) {
38
15
  fs.mkdirSync(dir);
39
16
  }
40
- const { generateDrizzleJson, generateMigration } = require('drizzle-kit/payload');
17
+ const { generateDrizzleJson, generateMigration, upPgSnapshot } = require('drizzle-kit/api');
18
+ const drizzleJsonAfter = generateDrizzleJson(this.schema);
41
19
  const [yyymmdd, hhmmss] = new Date().toISOString().split('T');
42
20
  const formattedDate = yyymmdd.replace(/\D/g, '');
43
21
  const formattedTime = hhmmss.split('.')[0].replace(/\D/g, '');
22
+ let imports = '';
23
+ let downSQL;
24
+ let upSQL;
25
+ ({ downSQL, imports, upSQL } = await getPredefinedMigration({
26
+ dirname,
27
+ file,
28
+ migrationName,
29
+ payload
30
+ }));
44
31
  const timestamp = `${formattedDate}_${formattedTime}`;
45
- const fileName = migrationName ? `${timestamp}_${migrationName.replace(/\W/g, '_')}` : `${timestamp}`;
32
+ const name = migrationName || file?.split('/').slice(2).join('/');
33
+ const fileName = `${timestamp}${name ? `_${name.replace(/\W/g, '_')}` : ''}`;
46
34
  const filePath = `${dir}/${fileName}`;
47
- let drizzleJsonBefore = getDefaultDrizzleSnapshot();
48
- // Get latest migration snapshot
49
- const latestSnapshot = fs.readdirSync(dir).filter((file)=>file.endsWith('.json')).sort().reverse()?.[0];
50
- if (latestSnapshot) {
51
- const latestSnapshotJSON = JSON.parse(fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'));
52
- drizzleJsonBefore = latestSnapshotJSON;
35
+ let drizzleJsonBefore = defaultDrizzleSnapshot;
36
+ if (this.schemaName) {
37
+ drizzleJsonBefore.schemas = {
38
+ [this.schemaName]: this.schemaName
39
+ };
53
40
  }
54
- const drizzleJsonAfter = generateDrizzleJson(this.schema);
55
- const sqlStatementsUp = await generateMigration(drizzleJsonBefore, drizzleJsonAfter);
56
- const sqlStatementsDown = await generateMigration(drizzleJsonAfter, drizzleJsonBefore);
57
- if (!sqlStatementsUp.length && !sqlStatementsDown.length && !forceAcceptWarning) {
58
- const { confirm: shouldCreateBlankMigration } = await prompts({
59
- name: 'confirm',
60
- type: 'confirm',
61
- initial: false,
62
- message: 'No schema changes detected. Would you like to create a blank migration file?'
63
- }, {
64
- onCancel: ()=>{
41
+ if (!upSQL) {
42
+ // Get latest migration snapshot
43
+ const latestSnapshot = fs.readdirSync(dir).filter((file)=>file.endsWith('.json')).sort().reverse()?.[0];
44
+ if (latestSnapshot) {
45
+ drizzleJsonBefore = JSON.parse(fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'));
46
+ if (drizzleJsonBefore.version < drizzleJsonAfter.version) {
47
+ drizzleJsonBefore = upPgSnapshot(drizzleJsonBefore);
48
+ }
49
+ }
50
+ const sqlStatementsUp = await generateMigration(drizzleJsonBefore, drizzleJsonAfter);
51
+ const sqlStatementsDown = await generateMigration(drizzleJsonAfter, drizzleJsonBefore);
52
+ const sqlExecute = 'await payload.db.drizzle.execute(sql`';
53
+ if (sqlStatementsUp?.length) {
54
+ upSQL = `${sqlExecute}\n ${sqlStatementsUp?.join('\n')}\`)`;
55
+ }
56
+ if (sqlStatementsDown?.length) {
57
+ downSQL = `${sqlExecute}\n ${sqlStatementsDown?.join('\n')}\`)`;
58
+ }
59
+ if (!upSQL?.length && !downSQL?.length && !forceAcceptWarning) {
60
+ const { confirm: shouldCreateBlankMigration } = await prompts({
61
+ name: 'confirm',
62
+ type: 'confirm',
63
+ initial: false,
64
+ message: 'No schema changes detected. Would you like to create a blank migration file?'
65
+ }, {
66
+ onCancel: ()=>{
67
+ process.exit(0);
68
+ }
69
+ });
70
+ if (!shouldCreateBlankMigration) {
65
71
  process.exit(0);
66
72
  }
67
- });
68
- if (!shouldCreateBlankMigration) {
69
- process.exit(0);
70
73
  }
74
+ // write schema
75
+ fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2));
71
76
  }
72
- // write schema
73
- fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2));
74
77
  // write migration
75
- fs.writeFileSync(`${filePath}.ts`, migrationTemplate(sqlStatementsUp.length ? sqlStatementsUp?.join('\n') : undefined, sqlStatementsDown.length ? sqlStatementsDown?.join('\n') : undefined));
78
+ fs.writeFileSync(`${filePath}.ts`, getMigrationTemplate({
79
+ downSQL: downSQL || ` // Migration code`,
80
+ imports,
81
+ upSQL: upSQL || ` // Migration code`
82
+ }));
83
+ writeMigrationIndex({
84
+ migrationsDir: payload.db.migrationDir
85
+ });
76
86
  payload.logger.info({
77
87
  msg: `Migration created at ${filePath}.ts`
78
88
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { DrizzleSnapshotJSON } from 'drizzle-kit/payload'\nimport type { CreateMigration } from 'payload/database'\n\nimport fs from 'fs'\nimport { createRequire } from 'module'\nimport prompts from 'prompts'\n\nimport type { PostgresAdapter } from './types.js'\n\nconst require = createRequire(import.meta.url)\n\nconst migrationTemplate = (\n upSQL?: string,\n downSQL?: string,\n) => `import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'\n\nexport async function up({ payload }: MigrateUpArgs): Promise<void> {\n${\n upSQL\n ? `await payload.db.drizzle.execute(sql\\`\n\n${upSQL}\\`);\n`\n : '// Migration code'\n}\n};\n\nexport async function down({ payload }: MigrateDownArgs): Promise<void> {\n${\n downSQL\n ? `await payload.db.drizzle.execute(sql\\`\n\n${downSQL}\\`);\n`\n : '// Migration code'\n}\n};\n`\n\nconst getDefaultDrizzleSnapshot = (): DrizzleSnapshotJSON => ({\n id: '00000000-0000-0000-0000-000000000000',\n _meta: {\n columns: {},\n schemas: {},\n tables: {},\n },\n dialect: 'pg',\n enums: {},\n prevId: '00000000-0000-0000-0000-00000000000',\n schemas: {},\n tables: {},\n version: '5',\n})\n\nexport const createMigration: CreateMigration = async function createMigration(\n this: PostgresAdapter,\n { forceAcceptWarning, migrationName, payload },\n) {\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n\n const { generateDrizzleJson, generateMigration } = require('drizzle-kit/payload')\n\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n const formattedDate = yyymmdd.replace(/\\D/g, '')\n const formattedTime = hhmmss.split('.')[0].replace(/\\D/g, '')\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const fileName = migrationName\n ? `${timestamp}_${migrationName.replace(/\\W/g, '_')}`\n : `${timestamp}`\n\n const filePath = `${dir}/${fileName}`\n\n let drizzleJsonBefore = getDefaultDrizzleSnapshot()\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 const latestSnapshotJSON = JSON.parse(\n fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'),\n ) as DrizzleSnapshotJSON\n\n drizzleJsonBefore = latestSnapshotJSON\n }\n\n const drizzleJsonAfter = generateDrizzleJson(this.schema)\n const sqlStatementsUp = await generateMigration(drizzleJsonBefore, drizzleJsonAfter)\n const sqlStatementsDown = await generateMigration(drizzleJsonAfter, drizzleJsonBefore)\n\n if (!sqlStatementsUp.length && !sqlStatementsDown.length && !forceAcceptWarning) {\n const { confirm: shouldCreateBlankMigration } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: 'No schema changes detected. Would you like to create a blank migration file?',\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!shouldCreateBlankMigration) {\n process.exit(0)\n }\n }\n\n // write schema\n fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2))\n\n // write migration\n fs.writeFileSync(\n `${filePath}.ts`,\n migrationTemplate(\n sqlStatementsUp.length ? sqlStatementsUp?.join('\\n') : undefined,\n sqlStatementsDown.length ? sqlStatementsDown?.join('\\n') : undefined,\n ),\n )\n payload.logger.info({ msg: `Migration created at ${filePath}.ts` })\n}\n"],"names":["fs","createRequire","prompts","require","url","migrationTemplate","upSQL","downSQL","getDefaultDrizzleSnapshot","id","_meta","columns","schemas","tables","dialect","enums","prevId","version","createMigration","forceAcceptWarning","migrationName","payload","dir","db","migrationDir","existsSync","mkdirSync","generateDrizzleJson","generateMigration","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","timestamp","fileName","filePath","drizzleJsonBefore","latestSnapshot","readdirSync","filter","file","endsWith","sort","reverse","latestSnapshotJSON","JSON","parse","readFileSync","drizzleJsonAfter","schema","sqlStatementsUp","sqlStatementsDown","length","confirm","shouldCreateBlankMigration","name","type","initial","message","onCancel","process","exit","writeFileSync","stringify","join","undefined","logger","info","msg"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,yDAAyD,GAIzD,OAAOA,QAAQ,KAAI;AACnB,SAASC,aAAa,QAAQ,SAAQ;AACtC,OAAOC,aAAa,UAAS;AAI7B,MAAMC,UAAUF,cAAc,YAAYG,GAAG;AAE7C,MAAMC,oBAAoB,CACxBC,OACAC,UACG,CAAC;;;AAGN,EACED,QACI,CAAC;;AAEP,EAAEA,MAAM;AACR,CAAC,GACK,oBACL;;;;AAID,EACEC,UACI,CAAC;;AAEP,EAAEA,QAAQ;AACV,CAAC,GACK,oBACL;;AAED,CAAC;AAED,MAAMC,4BAA4B,IAA4B,CAAA;QAC5DC,IAAI;QACJC,OAAO;YACLC,SAAS,CAAC;YACVC,SAAS,CAAC;YACVC,QAAQ,CAAC;QACX;QACAC,SAAS;QACTC,OAAO,CAAC;QACRC,QAAQ;QACRJ,SAAS,CAAC;QACVC,QAAQ,CAAC;QACTI,SAAS;IACX,CAAA;AAEA,OAAO,MAAMC,kBAAmC,eAAeA,gBAE7D,EAAEC,kBAAkB,EAAEC,aAAa,EAAEC,OAAO,EAAE;IAE9C,MAAMC,MAAMD,QAAQE,EAAE,CAACC,YAAY;IACnC,IAAI,CAACxB,GAAGyB,UAAU,CAACH,MAAM;QACvBtB,GAAG0B,SAAS,CAACJ;IACf;IAEA,MAAM,EAAEK,mBAAmB,EAAEC,iBAAiB,EAAE,GAAGzB,QAAQ;IAE3D,MAAM,CAAC0B,SAASC,OAAO,GAAG,IAAIC,OAAOC,WAAW,GAAGC,KAAK,CAAC;IACzD,MAAMC,gBAAgBL,QAAQM,OAAO,CAAC,OAAO;IAC7C,MAAMC,gBAAgBN,OAAOG,KAAK,CAAC,IAAI,CAAC,EAAE,CAACE,OAAO,CAAC,OAAO;IAE1D,MAAME,YAAY,CAAC,EAAEH,cAAc,CAAC,EAAEE,cAAc,CAAC;IAErD,MAAME,WAAWlB,gBACb,CAAC,EAAEiB,UAAU,CAAC,EAAEjB,cAAce,OAAO,CAAC,OAAO,KAAK,CAAC,GACnD,CAAC,EAAEE,UAAU,CAAC;IAElB,MAAME,WAAW,CAAC,EAAEjB,IAAI,CAAC,EAAEgB,SAAS,CAAC;IAErC,IAAIE,oBAAoBhC;IAExB,gCAAgC;IAChC,MAAMiC,iBAAiBzC,GACpB0C,WAAW,CAACpB,KACZqB,MAAM,CAAC,CAACC,OAASA,KAAKC,QAAQ,CAAC,UAC/BC,IAAI,GACJC,OAAO,IAAI,CAAC,EAAE;IAEjB,IAAIN,gBAAgB;QAClB,MAAMO,qBAAqBC,KAAKC,KAAK,CACnClD,GAAGmD,YAAY,CAAC,CAAC,EAAE7B,IAAI,CAAC,EAAEmB,eAAe,CAAC,EAAE;QAG9CD,oBAAoBQ;IACtB;IAEA,MAAMI,mBAAmBzB,oBAAoB,IAAI,CAAC0B,MAAM;IACxD,MAAMC,kBAAkB,MAAM1B,kBAAkBY,mBAAmBY;IACnE,MAAMG,oBAAoB,MAAM3B,kBAAkBwB,kBAAkBZ;IAEpE,IAAI,CAACc,gBAAgBE,MAAM,IAAI,CAACD,kBAAkBC,MAAM,IAAI,CAACrC,oBAAoB;QAC/E,MAAM,EAAEsC,SAASC,0BAA0B,EAAE,GAAG,MAAMxD,QACpD;YACEyD,MAAM;YACNC,MAAM;YACNC,SAAS;YACTC,SAAS;QACX,GACA;YACEC,UAAU;gBACRC,QAAQC,IAAI,CAAC;YACf;QACF;QAGF,IAAI,CAACP,4BAA4B;YAC/BM,QAAQC,IAAI,CAAC;QACf;IACF;IAEA,eAAe;IACfjE,GAAGkE,aAAa,CAAC,CAAC,EAAE3B,SAAS,KAAK,CAAC,EAAEU,KAAKkB,SAAS,CAACf,kBAAkB,MAAM;IAE5E,kBAAkB;IAClBpD,GAAGkE,aAAa,CACd,CAAC,EAAE3B,SAAS,GAAG,CAAC,EAChBlC,kBACEiD,gBAAgBE,MAAM,GAAGF,iBAAiBc,KAAK,QAAQC,WACvDd,kBAAkBC,MAAM,GAAGD,mBAAmBa,KAAK,QAAQC;IAG/DhD,QAAQiD,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK,CAAC,qBAAqB,EAAEjC,SAAS,GAAG,CAAC;IAAC;AACnE,EAAC"}
1
+ {"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["import type { DrizzleSnapshotJSON } from 'drizzle-kit/api'\nimport type { CreateMigration } from 'payload'\n\nimport fs from 'fs'\nimport { createRequire } from 'module'\nimport path from 'path'\nimport { getPredefinedMigration, writeMigrationIndex } from 'payload'\nimport prompts from 'prompts'\nimport { fileURLToPath } from 'url'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { defaultDrizzleSnapshot } from './defaultSnapshot.js'\nimport { getMigrationTemplate } from './getMigrationTemplate.js'\n\nconst require = createRequire(import.meta.url)\n\nexport const createMigration: CreateMigration = async function createMigration(\n this: PostgresAdapter,\n { file, forceAcceptWarning, migrationName, payload },\n) {\n const filename = fileURLToPath(import.meta.url)\n const dirname = path.dirname(filename)\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n const { generateDrizzleJson, generateMigration, upPgSnapshot } = require('drizzle-kit/api')\n const drizzleJsonAfter = generateDrizzleJson(this.schema)\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n const formattedDate = yyymmdd.replace(/\\D/g, '')\n const formattedTime = hhmmss.split('.')[0].replace(/\\D/g, '')\n let imports: string = ''\n let downSQL: string\n let upSQL: string\n ;({ downSQL, imports, upSQL } = await getPredefinedMigration({\n dirname,\n file,\n migrationName,\n payload,\n }))\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const name = migrationName || file?.split('/').slice(2).join('/')\n const fileName = `${timestamp}${name ? `_${name.replace(/\\W/g, '_')}` : ''}`\n\n const filePath = `${dir}/${fileName}`\n\n let drizzleJsonBefore = defaultDrizzleSnapshot\n\n if (this.schemaName) {\n drizzleJsonBefore.schemas = {\n [this.schemaName]: this.schemaName,\n }\n }\n\n if (!upSQL) {\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 drizzleJsonBefore = JSON.parse(fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'))\n\n if (drizzleJsonBefore.version < drizzleJsonAfter.version) {\n drizzleJsonBefore = upPgSnapshot(drizzleJsonBefore)\n }\n }\n\n const sqlStatementsUp = await generateMigration(drizzleJsonBefore, drizzleJsonAfter)\n const sqlStatementsDown = await generateMigration(drizzleJsonAfter, drizzleJsonBefore)\n const sqlExecute = 'await payload.db.drizzle.execute(sql`'\n\n if (sqlStatementsUp?.length) {\n upSQL = `${sqlExecute}\\n ${sqlStatementsUp?.join('\\n')}\\`)`\n }\n if (sqlStatementsDown?.length) {\n downSQL = `${sqlExecute}\\n ${sqlStatementsDown?.join('\\n')}\\`)`\n }\n\n if (!upSQL?.length && !downSQL?.length && !forceAcceptWarning) {\n const { confirm: shouldCreateBlankMigration } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: 'No schema changes detected. Would you like to create a blank migration file?',\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!shouldCreateBlankMigration) {\n process.exit(0)\n }\n }\n\n // write schema\n fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2))\n }\n\n // write migration\n fs.writeFileSync(\n `${filePath}.ts`,\n getMigrationTemplate({\n downSQL: downSQL || ` // Migration code`,\n imports,\n upSQL: upSQL || ` // Migration code`,\n }),\n )\n\n writeMigrationIndex({ migrationsDir: payload.db.migrationDir })\n\n payload.logger.info({ msg: `Migration created at ${filePath}.ts` })\n}\n"],"names":["fs","createRequire","path","getPredefinedMigration","writeMigrationIndex","prompts","fileURLToPath","defaultDrizzleSnapshot","getMigrationTemplate","require","url","createMigration","file","forceAcceptWarning","migrationName","payload","filename","dirname","dir","db","migrationDir","existsSync","mkdirSync","generateDrizzleJson","generateMigration","upPgSnapshot","drizzleJsonAfter","schema","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","imports","downSQL","upSQL","timestamp","name","slice","join","fileName","filePath","drizzleJsonBefore","schemaName","schemas","latestSnapshot","readdirSync","filter","endsWith","sort","reverse","JSON","parse","readFileSync","version","sqlStatementsUp","sqlStatementsDown","sqlExecute","length","confirm","shouldCreateBlankMigration","type","initial","message","onCancel","process","exit","writeFileSync","stringify","migrationsDir","logger","info","msg"],"mappings":"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"}
@@ -0,0 +1,3 @@
1
+ import type { DrizzleSnapshotJSON } from 'drizzle-kit/api';
2
+ export declare const defaultDrizzleSnapshot: DrizzleSnapshotJSON;
3
+ //# sourceMappingURL=defaultSnapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultSnapshot.d.ts","sourceRoot":"","sources":["../src/defaultSnapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAE1D,eAAO,MAAM,sBAAsB,EAAE,mBAcpC,CAAA"}
@@ -0,0 +1,17 @@
1
+ export const defaultDrizzleSnapshot = {
2
+ id: '00000000-0000-0000-0000-000000000000',
3
+ _meta: {
4
+ columns: {},
5
+ schemas: {},
6
+ tables: {}
7
+ },
8
+ dialect: 'postgresql',
9
+ enums: {},
10
+ prevId: '00000000-0000-0000-0000-00000000000',
11
+ schemas: {},
12
+ sequences: {},
13
+ tables: {},
14
+ version: '7'
15
+ };
16
+
17
+ //# sourceMappingURL=defaultSnapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/defaultSnapshot.ts"],"sourcesContent":["import type { DrizzleSnapshotJSON } from 'drizzle-kit/api'\n\nexport const defaultDrizzleSnapshot: DrizzleSnapshotJSON = {\n id: '00000000-0000-0000-0000-000000000000',\n _meta: {\n columns: {},\n schemas: {},\n tables: {},\n },\n dialect: 'postgresql',\n enums: {},\n prevId: '00000000-0000-0000-0000-00000000000',\n schemas: {},\n sequences: {},\n tables: {},\n version: '7',\n}\n"],"names":["defaultDrizzleSnapshot","id","_meta","columns","schemas","tables","dialect","enums","prevId","sequences","version"],"mappings":"AAEA,OAAO,MAAMA,yBAA8C;IACzDC,IAAI;IACJC,OAAO;QACLC,SAAS,CAAC;QACVC,SAAS,CAAC;QACVC,QAAQ,CAAC;IACX;IACAC,SAAS;IACTC,OAAO,CAAC;IACRC,QAAQ;IACRJ,SAAS,CAAC;IACVK,WAAW,CAAC;IACZJ,QAAQ,CAAC;IACTK,SAAS;AACX,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { DeleteWhere } from './types.js';
2
+ export declare const deleteWhere: DeleteWhere;
3
+ //# sourceMappingURL=deleteWhere.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteWhere.d.ts","sourceRoot":"","sources":["../src/deleteWhere.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,eAAO,MAAM,WAAW,EAAE,WAGzB,CAAA"}
@@ -0,0 +1,6 @@
1
+ export const deleteWhere = async function deleteWhere({ db, tableName, where }) {
2
+ const table = this.tables[tableName];
3
+ await db.delete(table).where(where);
4
+ };
5
+
6
+ //# sourceMappingURL=deleteWhere.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/deleteWhere.ts"],"sourcesContent":["import type { TransactionPg } from '@payloadcms/drizzle/types'\n\nimport type { DeleteWhere } from './types.js'\n\nexport const deleteWhere: DeleteWhere = async function deleteWhere({ db, tableName, where }) {\n const table = this.tables[tableName]\n await (db as TransactionPg).delete(table).where(where)\n}\n"],"names":["deleteWhere","db","tableName","where","table","tables","delete"],"mappings":"AAIA,OAAO,MAAMA,cAA2B,eAAeA,YAAY,EAAEC,EAAE,EAAEC,SAAS,EAAEC,KAAK,EAAE;IACzF,MAAMC,QAAQ,IAAI,CAACC,MAAM,CAACH,UAAU;IACpC,MAAM,AAACD,GAAqBK,MAAM,CAACF,OAAOD,KAAK,CAACA;AAClD,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { DropDatabase } from './types.js';
2
+ export declare const dropDatabase: DropDatabase;
3
+ //# sourceMappingURL=dropDatabase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dropDatabase.d.ts","sourceRoot":"","sources":["../src/dropDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,eAAO,MAAM,YAAY,EAAE,YAM1B,CAAA"}
@@ -0,0 +1,9 @@
1
+ export const dropDatabase = async function dropDatabase({ adapter }) {
2
+ await adapter.execute({
3
+ drizzle: adapter.drizzle,
4
+ raw: `drop schema if exists ${this.schemaName || 'public'} cascade;
5
+ create schema ${this.schemaName || 'public'};`
6
+ });
7
+ };
8
+
9
+ //# sourceMappingURL=dropDatabase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/dropDatabase.ts"],"sourcesContent":["import type { DropDatabase } from './types.js'\n\nexport const dropDatabase: DropDatabase = async function dropDatabase({ adapter }) {\n await adapter.execute({\n drizzle: adapter.drizzle,\n raw: `drop schema if exists ${this.schemaName || 'public'} cascade;\n create schema ${this.schemaName || 'public'};`,\n })\n}\n"],"names":["dropDatabase","adapter","execute","drizzle","raw","schemaName"],"mappings":"AAEA,OAAO,MAAMA,eAA6B,eAAeA,aAAa,EAAEC,OAAO,EAAE;IAC/E,MAAMA,QAAQC,OAAO,CAAC;QACpBC,SAASF,QAAQE,OAAO;QACxBC,KAAK,CAAC,sBAAsB,EAAE,IAAI,CAACC,UAAU,IAAI,SAAS;kBAC5C,EAAE,IAAI,CAACA,UAAU,IAAI,SAAS,CAAC,CAAC;IAChD;AACF,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Execute } from './types.js';
2
+ export declare const execute: Execute<any>;
3
+ //# sourceMappingURL=execute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,eAAO,MAAM,OAAO,EAAE,OAAO,CAAC,GAAG,CAQhC,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { sql } from 'drizzle-orm';
2
+ export const execute = function execute({ db, drizzle, raw, sql: statement }) {
3
+ const executeFrom = db ?? drizzle;
4
+ if (raw) {
5
+ return executeFrom.execute(sql.raw(raw));
6
+ } else {
7
+ return executeFrom.execute(sql`${statement}`);
8
+ }
9
+ };
10
+
11
+ //# sourceMappingURL=execute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/execute.ts"],"sourcesContent":["import { sql } from 'drizzle-orm'\n\nimport type { Execute } from './types.js'\n\nexport const execute: Execute<any> = function execute({ db, drizzle, raw, sql: statement }) {\n const executeFrom = db ?? drizzle\n\n if (raw) {\n return executeFrom.execute(sql.raw(raw))\n } else {\n return executeFrom.execute(sql`${statement}`)\n }\n}\n"],"names":["sql","execute","db","drizzle","raw","statement","executeFrom"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAa;AAIjC,OAAO,MAAMC,UAAwB,SAASA,QAAQ,EAAEC,EAAE,EAAEC,OAAO,EAAEC,GAAG,EAAEJ,KAAKK,SAAS,EAAE;IACxF,MAAMC,cAAcJ,MAAMC;IAE1B,IAAIC,KAAK;QACP,OAAOE,YAAYL,OAAO,CAACD,IAAII,GAAG,CAACA;IACrC,OAAO;QACL,OAAOE,YAAYL,OAAO,CAACD,GAAG,CAAC,EAAEK,UAAU,CAAC;IAC9C;AACF,EAAC"}
@@ -0,0 +1,2 @@
1
+ export { migratePostgresV2toV3 } from '../predefinedMigrations/v2-v3/index.js';
2
+ //# sourceMappingURL=migration-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-utils.d.ts","sourceRoot":"","sources":["../../src/exports/migration-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { migratePostgresV2toV3 } from '../predefinedMigrations/v2-v3/index.js';
2
+
3
+ //# sourceMappingURL=migration-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/exports/migration-utils.ts"],"sourcesContent":["export { migratePostgresV2toV3 } from '../predefinedMigrations/v2-v3/index.js'\n"],"names":["migratePostgresV2toV3"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,yCAAwC"}
@@ -0,0 +1,4 @@
1
+ import type { MigrationTemplateArgs } from 'payload';
2
+ export declare const indent: (text: string) => string;
3
+ export declare const getMigrationTemplate: ({ downSQL, imports, upSQL, }: MigrationTemplateArgs) => string;
4
+ //# sourceMappingURL=getMigrationTemplate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getMigrationTemplate.d.ts","sourceRoot":"","sources":["../src/getMigrationTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,eAAO,MAAM,MAAM,SAAU,MAAM,WAIpB,CAAA;AAEf,eAAO,MAAM,oBAAoB,iCAI9B,qBAAqB,KAAG,MAS1B,CAAA"}
@@ -0,0 +1,13 @@
1
+ export const indent = (text)=>text.split('\n').map((line)=>` ${line}`).join('\n');
2
+ export const getMigrationTemplate = ({ downSQL, imports, upSQL })=>`import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
3
+ ${imports ? `${imports}\n` : ''}
4
+ export async function up({ payload, req }: MigrateUpArgs): Promise<void> {
5
+ ${indent(upSQL)}
6
+ }
7
+
8
+ export async function down({ payload, req }: MigrateDownArgs): Promise<void> {
9
+ ${indent(downSQL)}
10
+ }
11
+ `;
12
+
13
+ //# sourceMappingURL=getMigrationTemplate.js.map