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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (288) 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 +12 -7
  5. package/dist/connect.js.map +1 -1
  6. package/dist/count.d.ts +1 -1
  7. package/dist/count.d.ts.map +1 -1
  8. package/dist/count.js +1 -10
  9. package/dist/count.js.map +1 -1
  10. package/dist/create.d.ts +1 -1
  11. package/dist/create.d.ts.map +1 -1
  12. package/dist/create.js.map +1 -1
  13. package/dist/createGlobal.d.ts +2 -3
  14. package/dist/createGlobal.d.ts.map +1 -1
  15. package/dist/createGlobal.js.map +1 -1
  16. package/dist/createGlobalVersion.d.ts +2 -3
  17. package/dist/createGlobalVersion.d.ts.map +1 -1
  18. package/dist/createGlobalVersion.js +1 -1
  19. package/dist/createGlobalVersion.js.map +1 -1
  20. package/dist/createMigration.d.ts +1 -1
  21. package/dist/createMigration.d.ts.map +1 -1
  22. package/dist/createMigration.js +56 -35
  23. package/dist/createMigration.js.map +1 -1
  24. package/dist/createVersion.d.ts +1 -2
  25. package/dist/createVersion.d.ts.map +1 -1
  26. package/dist/createVersion.js +3 -7
  27. package/dist/createVersion.js.map +1 -1
  28. package/dist/deleteMany.d.ts +1 -1
  29. package/dist/deleteMany.d.ts.map +1 -1
  30. package/dist/deleteMany.js.map +1 -1
  31. package/dist/deleteOne.d.ts +1 -1
  32. package/dist/deleteOne.d.ts.map +1 -1
  33. package/dist/deleteOne.js +2 -2
  34. package/dist/deleteOne.js.map +1 -1
  35. package/dist/deleteVersions.d.ts +1 -1
  36. package/dist/deleteVersions.d.ts.map +1 -1
  37. package/dist/deleteVersions.js +1 -1
  38. package/dist/deleteVersions.js.map +1 -1
  39. package/dist/destroy.d.ts +1 -1
  40. package/dist/destroy.d.ts.map +1 -1
  41. package/dist/destroy.js +4 -0
  42. package/dist/destroy.js.map +1 -1
  43. package/dist/exports/migration-utils.d.ts +2 -0
  44. package/dist/exports/migration-utils.d.ts.map +1 -0
  45. package/dist/exports/migration-utils.js +3 -0
  46. package/dist/exports/migration-utils.js.map +1 -0
  47. package/dist/find/buildFindManyArgs.d.ts +6 -2
  48. package/dist/find/buildFindManyArgs.d.ts.map +1 -1
  49. package/dist/find/buildFindManyArgs.js +2 -1
  50. package/dist/find/buildFindManyArgs.js.map +1 -1
  51. package/dist/find/chainMethods.d.ts.map +1 -1
  52. package/dist/find/chainMethods.js.map +1 -1
  53. package/dist/find/findMany.d.ts +1 -2
  54. package/dist/find/findMany.d.ts.map +1 -1
  55. package/dist/find/findMany.js +4 -15
  56. package/dist/find/findMany.js.map +1 -1
  57. package/dist/find/traverseFields.d.ts +4 -3
  58. package/dist/find/traverseFields.d.ts.map +1 -1
  59. package/dist/find/traverseFields.js +23 -5
  60. package/dist/find/traverseFields.js.map +1 -1
  61. package/dist/find.d.ts +1 -1
  62. package/dist/find.d.ts.map +1 -1
  63. package/dist/find.js.map +1 -1
  64. package/dist/findGlobal.d.ts +1 -1
  65. package/dist/findGlobal.d.ts.map +1 -1
  66. package/dist/findGlobal.js.map +1 -1
  67. package/dist/findGlobalVersions.d.ts +1 -1
  68. package/dist/findGlobalVersions.d.ts.map +1 -1
  69. package/dist/findGlobalVersions.js +1 -1
  70. package/dist/findGlobalVersions.js.map +1 -1
  71. package/dist/findOne.d.ts +1 -2
  72. package/dist/findOne.d.ts.map +1 -1
  73. package/dist/findOne.js.map +1 -1
  74. package/dist/findVersions.d.ts +1 -1
  75. package/dist/findVersions.d.ts.map +1 -1
  76. package/dist/findVersions.js +1 -1
  77. package/dist/findVersions.js.map +1 -1
  78. package/dist/index.d.ts +1 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +10 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/init.d.ts +1 -1
  83. package/dist/init.d.ts.map +1 -1
  84. package/dist/init.js +15 -20
  85. package/dist/init.js.map +1 -1
  86. package/dist/migrate.d.ts.map +1 -1
  87. package/dist/migrate.js +1 -1
  88. package/dist/migrate.js.map +1 -1
  89. package/dist/migrateDown.js +1 -1
  90. package/dist/migrateDown.js.map +1 -1
  91. package/dist/migrateFresh.d.ts.map +1 -1
  92. package/dist/migrateFresh.js +1 -1
  93. package/dist/migrateFresh.js.map +1 -1
  94. package/dist/migrateRefresh.js +1 -1
  95. package/dist/migrateRefresh.js.map +1 -1
  96. package/dist/migrateReset.js +1 -1
  97. package/dist/migrateReset.js.map +1 -1
  98. package/dist/migrateStatus.js +1 -1
  99. package/dist/migrateStatus.js.map +1 -1
  100. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  101. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  102. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  103. package/dist/predefinedMigrations/relationships-v2-v3.mjs +11 -0
  104. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +19 -0
  105. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
  106. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +169 -0
  107. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
  108. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
  109. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
  110. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +191 -0
  111. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
  112. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
  113. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
  114. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js +56 -0
  115. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
  116. package/dist/predefinedMigrations/v2-v3/index.d.ts +23 -0
  117. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
  118. package/dist/predefinedMigrations/v2-v3/index.js +211 -0
  119. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -0
  120. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +19 -0
  121. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
  122. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +57 -0
  123. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
  124. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +22 -0
  125. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
  126. package/dist/predefinedMigrations/v2-v3/traverseFields.js +85 -0
  127. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
  128. package/dist/predefinedMigrations/v2-v3/types.d.ts +9 -0
  129. package/dist/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
  130. package/dist/predefinedMigrations/v2-v3/types.js +6 -0
  131. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -0
  132. package/dist/queries/buildAndOrConditions.d.ts +4 -5
  133. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  134. package/dist/queries/buildAndOrConditions.js +1 -2
  135. package/dist/queries/buildAndOrConditions.js.map +1 -1
  136. package/dist/queries/buildQuery.d.ts +2 -3
  137. package/dist/queries/buildQuery.d.ts.map +1 -1
  138. package/dist/queries/buildQuery.js +1 -5
  139. package/dist/queries/buildQuery.js.map +1 -1
  140. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +1 -1
  141. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +1 -1
  142. package/dist/queries/createJSONQuery/index.js.map +1 -1
  143. package/dist/queries/getTableColumnFromPath.d.ts +4 -5
  144. package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
  145. package/dist/queries/getTableColumnFromPath.js +170 -99
  146. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  147. package/dist/queries/operatorMap.js.map +1 -1
  148. package/dist/queries/parseParams.d.ts +4 -5
  149. package/dist/queries/parseParams.d.ts.map +1 -1
  150. package/dist/queries/parseParams.js +9 -8
  151. package/dist/queries/parseParams.js.map +1 -1
  152. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  153. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  154. package/dist/queries/sanitizeQueryValue.js +2 -3
  155. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  156. package/dist/queries/selectDistinct.d.ts +3 -4
  157. package/dist/queries/selectDistinct.d.ts.map +1 -1
  158. package/dist/queries/selectDistinct.js +3 -14
  159. package/dist/queries/selectDistinct.js.map +1 -1
  160. package/dist/queryDrafts.d.ts +1 -1
  161. package/dist/queryDrafts.d.ts.map +1 -1
  162. package/dist/queryDrafts.js +1 -2
  163. package/dist/queryDrafts.js.map +1 -1
  164. package/dist/schema/build.d.ts +9 -5
  165. package/dist/schema/build.d.ts.map +1 -1
  166. package/dist/schema/build.js +161 -112
  167. package/dist/schema/build.js.map +1 -1
  168. package/dist/schema/createIndex.js.map +1 -1
  169. package/dist/schema/createTableName.d.ts +1 -1
  170. package/dist/schema/createTableName.d.ts.map +1 -1
  171. package/dist/schema/createTableName.js +1 -1
  172. package/dist/schema/createTableName.js.map +1 -1
  173. package/dist/schema/idToUUID.d.ts +1 -1
  174. package/dist/schema/idToUUID.d.ts.map +1 -1
  175. package/dist/schema/idToUUID.js.map +1 -1
  176. package/dist/schema/parentIDColumnMap.js.map +1 -1
  177. package/dist/schema/setColumnID.d.ts +1 -1
  178. package/dist/schema/setColumnID.d.ts.map +1 -1
  179. package/dist/schema/setColumnID.js +2 -2
  180. package/dist/schema/setColumnID.js.map +1 -1
  181. package/dist/schema/traverseFields.d.ts +5 -7
  182. package/dist/schema/traverseFields.d.ts.map +1 -1
  183. package/dist/schema/traverseFields.js +105 -42
  184. package/dist/schema/traverseFields.js.map +1 -1
  185. package/dist/schema/validateExistingBlockIsIdentical.d.ts +1 -1
  186. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +1 -1
  187. package/dist/schema/validateExistingBlockIsIdentical.js +2 -2
  188. package/dist/schema/validateExistingBlockIsIdentical.js.map +1 -1
  189. package/dist/transactions/beginTransaction.d.ts +1 -1
  190. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  191. package/dist/transactions/beginTransaction.js +4 -0
  192. package/dist/transactions/beginTransaction.js.map +1 -1
  193. package/dist/transactions/commitTransaction.d.ts +1 -1
  194. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  195. package/dist/transactions/commitTransaction.js.map +1 -1
  196. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  197. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  198. package/dist/transactions/rollbackTransaction.js.map +1 -1
  199. package/dist/transform/read/hasManyNumber.d.ts +1 -1
  200. package/dist/transform/read/hasManyNumber.d.ts.map +1 -1
  201. package/dist/transform/read/hasManyNumber.js.map +1 -1
  202. package/dist/transform/read/hasManyText.d.ts +1 -1
  203. package/dist/transform/read/hasManyText.d.ts.map +1 -1
  204. package/dist/transform/read/hasManyText.js.map +1 -1
  205. package/dist/transform/read/index.d.ts +4 -3
  206. package/dist/transform/read/index.d.ts.map +1 -1
  207. package/dist/transform/read/index.js +2 -1
  208. package/dist/transform/read/index.js.map +1 -1
  209. package/dist/transform/read/relationship.d.ts +1 -1
  210. package/dist/transform/read/relationship.d.ts.map +1 -1
  211. package/dist/transform/read/relationship.js +0 -4
  212. package/dist/transform/read/relationship.js.map +1 -1
  213. package/dist/transform/read/traverseFields.d.ts +8 -3
  214. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  215. package/dist/transform/read/traverseFields.js +70 -56
  216. package/dist/transform/read/traverseFields.js.map +1 -1
  217. package/dist/transform/write/array.d.ts +1 -1
  218. package/dist/transform/write/array.d.ts.map +1 -1
  219. package/dist/transform/write/array.js.map +1 -1
  220. package/dist/transform/write/blocks.d.ts +1 -1
  221. package/dist/transform/write/blocks.d.ts.map +1 -1
  222. package/dist/transform/write/blocks.js.map +1 -1
  223. package/dist/transform/write/index.d.ts +1 -1
  224. package/dist/transform/write/index.d.ts.map +1 -1
  225. package/dist/transform/write/index.js.map +1 -1
  226. package/dist/transform/write/numbers.js.map +1 -1
  227. package/dist/transform/write/relationships.d.ts +1 -1
  228. package/dist/transform/write/relationships.d.ts.map +1 -1
  229. package/dist/transform/write/relationships.js +1 -1
  230. package/dist/transform/write/relationships.js.map +1 -1
  231. package/dist/transform/write/selects.js.map +1 -1
  232. package/dist/transform/write/texts.js.map +1 -1
  233. package/dist/transform/write/traverseFields.d.ts +1 -1
  234. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  235. package/dist/transform/write/traverseFields.js +21 -4
  236. package/dist/transform/write/traverseFields.js.map +1 -1
  237. package/dist/transform/write/types.js.map +1 -1
  238. package/dist/types.d.ts +4 -3
  239. package/dist/types.d.ts.map +1 -1
  240. package/dist/types.js.map +1 -1
  241. package/dist/update.d.ts +1 -1
  242. package/dist/update.d.ts.map +1 -1
  243. package/dist/update.js +1 -2
  244. package/dist/update.js.map +1 -1
  245. package/dist/updateGlobal.d.ts +2 -3
  246. package/dist/updateGlobal.d.ts.map +1 -1
  247. package/dist/updateGlobal.js.map +1 -1
  248. package/dist/updateGlobalVersion.d.ts +1 -2
  249. package/dist/updateGlobalVersion.d.ts.map +1 -1
  250. package/dist/updateGlobalVersion.js +1 -1
  251. package/dist/updateGlobalVersion.js.map +1 -1
  252. package/dist/updateVersion.d.ts +1 -2
  253. package/dist/updateVersion.d.ts.map +1 -1
  254. package/dist/updateVersion.js +1 -1
  255. package/dist/updateVersion.js.map +1 -1
  256. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +1 -1
  257. package/dist/upsertRow/deleteExistingArrayRows.js.map +1 -1
  258. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
  259. package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
  260. package/dist/upsertRow/index.d.ts +2 -2
  261. package/dist/upsertRow/index.d.ts.map +1 -1
  262. package/dist/upsertRow/index.js +12 -8
  263. package/dist/upsertRow/index.js.map +1 -1
  264. package/dist/upsertRow/insertArrays.d.ts.map +1 -1
  265. package/dist/upsertRow/insertArrays.js.map +1 -1
  266. package/dist/upsertRow/types.d.ts +6 -1
  267. package/dist/upsertRow/types.d.ts.map +1 -1
  268. package/dist/upsertRow/types.js.map +1 -1
  269. package/dist/utilities/appendPrefixToKeys.d.ts.map +1 -1
  270. package/dist/utilities/appendPrefixToKeys.js.map +1 -1
  271. package/dist/utilities/createBlocksMap.d.ts.map +1 -1
  272. package/dist/utilities/createBlocksMap.js.map +1 -1
  273. package/dist/utilities/createMigrationTable.d.ts.map +1 -1
  274. package/dist/utilities/createMigrationTable.js.map +1 -1
  275. package/dist/utilities/createRelationshipMap.d.ts.map +1 -1
  276. package/dist/utilities/createRelationshipMap.js.map +1 -1
  277. package/dist/utilities/hasLocalesTable.d.ts +1 -1
  278. package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
  279. package/dist/utilities/hasLocalesTable.js +1 -1
  280. package/dist/utilities/hasLocalesTable.js.map +1 -1
  281. package/dist/utilities/isArrayOfRows.js.map +1 -1
  282. package/dist/utilities/migrationTableExists.d.ts.map +1 -1
  283. package/dist/utilities/migrationTableExists.js.map +1 -1
  284. package/dist/utilities/parseError.js.map +1 -1
  285. package/dist/utilities/pushDevSchema.d.ts.map +1 -1
  286. package/dist/utilities/pushDevSchema.js +1 -1
  287. package/dist/utilities/pushDevSchema.js.map +1 -1
  288. package/package.json +20 -11
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { createDatabaseAdapter } from 'payload/database';
3
+ import { createDatabaseAdapter } from 'payload';
4
4
  import { connect } from './connect.js';
5
5
  import { count } from './count.js';
6
6
  import { create } from './create.js';
@@ -38,12 +38,19 @@ export function postgresAdapter(args) {
38
38
  const payloadIDType = postgresIDType === 'serial' ? 'number' : 'text';
39
39
  function adapter({ payload }) {
40
40
  const migrationDir = findMigrationDir(args.migrationDir);
41
+ let resolveInitializing;
42
+ let rejectInitializing;
43
+ const initializing = new Promise((res, rej)=>{
44
+ resolveInitializing = res;
45
+ rejectInitializing = rej;
46
+ });
41
47
  return createDatabaseAdapter({
42
48
  name: 'postgres',
43
49
  drizzle: undefined,
44
50
  enums: {},
45
51
  fieldConstraints: {},
46
52
  idType: postgresIDType,
53
+ initializing,
47
54
  localesSuffix: args.localesSuffix || '_locales',
48
55
  logger: args.logger,
49
56
  pgSchema: undefined,
@@ -88,6 +95,8 @@ export function postgresAdapter(args) {
88
95
  migrationDir,
89
96
  payload,
90
97
  queryDrafts,
98
+ rejectInitializing,
99
+ resolveInitializing,
91
100
  rollbackTransaction,
92
101
  updateGlobal,
93
102
  updateGlobalVersion,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type { DatabaseAdapterObj } from 'payload/database'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { createDatabaseAdapter } from 'payload/database'\n\nimport type { Args, PostgresAdapter } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrate } from './migrate.js'\nimport { migrateDown } from './migrateDown.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { migrateRefresh } from './migrateRefresh.js'\nimport { migrateReset } from './migrateReset.js'\nimport { migrateStatus } from './migrateStatus.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateOne } from './update.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateVersion } from './updateVersion.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport { sql } from 'drizzle-orm'\n\nexport function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter> {\n const postgresIDType = args.idType || 'serial'\n const payloadIDType = postgresIDType === 'serial' ? 'number' : 'text'\n\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(args.migrationDir)\n\n return createDatabaseAdapter<PostgresAdapter>({\n name: 'postgres',\n drizzle: undefined,\n enums: {},\n fieldConstraints: {},\n idType: postgresIDType,\n localesSuffix: args.localesSuffix || '_locales',\n logger: args.logger,\n pgSchema: undefined,\n pool: undefined,\n poolOptions: args.pool,\n push: args.push,\n relations: {},\n relationshipsSuffix: args.relationshipsSuffix || '_rels',\n schema: {},\n schemaName: args.schemaName,\n sessions: {},\n tableNameMap: new Map<string, string>(),\n tables: {},\n versionsSuffix: args.versionsSuffix || '_v',\n\n // DatabaseAdapter\n beginTransaction,\n commitTransaction,\n connect,\n count,\n create,\n createGlobal,\n createGlobalVersion,\n createMigration,\n createVersion,\n defaultIDType: payloadIDType,\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n migrate,\n migrateDown,\n migrateFresh,\n migrateRefresh,\n migrateReset,\n migrateStatus,\n migrationDir,\n payload,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: payloadIDType,\n init: adapter,\n }\n}\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nfunction findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) return migrationDir\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","path","createDatabaseAdapter","connect","count","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateOne","updateGlobal","updateGlobalVersion","updateVersion","sql","postgresAdapter","args","postgresIDType","idType","payloadIDType","adapter","payload","migrationDir","findMigrationDir","name","drizzle","undefined","enums","fieldConstraints","localesSuffix","logger","pgSchema","pool","poolOptions","push","relations","relationshipsSuffix","schema","schemaName","sessions","tableNameMap","Map","tables","versionsSuffix","defaultIDType","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AACvB,SAASC,qBAAqB,QAAQ,mBAAkB;AAI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AGuE,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { DatabaseAdapterObj, Payload } from 'payload'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { createDatabaseAdapter } from 'payload'\n\nimport type { Args, PostgresAdapter } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrate } from './migrate.js'\nimport { migrateDown } from './migrateDown.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { migrateRefresh } from './migrateRefresh.js'\nimport { migrateReset } from './migrateReset.js'\nimport { migrateStatus } from './migrateStatus.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateOne } from './update.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateVersion } from './updateVersion.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport { sql } from 'drizzle-orm'\n\nexport function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter> {\n const postgresIDType = args.idType || 'serial'\n const payloadIDType = postgresIDType === 'serial' ? 'number' : 'text'\n\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(args.migrationDir)\n let resolveInitializing\n let rejectInitializing\n\n const initializing = new Promise<void>((res, rej) => {\n resolveInitializing = res\n rejectInitializing = rej\n })\n\n return createDatabaseAdapter<PostgresAdapter>({\n name: 'postgres',\n drizzle: undefined,\n enums: {},\n fieldConstraints: {},\n idType: postgresIDType,\n initializing,\n localesSuffix: args.localesSuffix || '_locales',\n logger: args.logger,\n pgSchema: undefined,\n pool: undefined,\n poolOptions: args.pool,\n push: args.push,\n relations: {},\n relationshipsSuffix: args.relationshipsSuffix || '_rels',\n schema: {},\n schemaName: args.schemaName,\n sessions: {},\n tableNameMap: new Map<string, string>(),\n tables: {},\n versionsSuffix: args.versionsSuffix || '_v',\n\n // DatabaseAdapter\n beginTransaction,\n commitTransaction,\n connect,\n count,\n create,\n createGlobal,\n createGlobalVersion,\n createMigration,\n createVersion,\n defaultIDType: payloadIDType,\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n migrate,\n migrateDown,\n migrateFresh,\n migrateRefresh,\n migrateReset,\n migrateStatus,\n migrationDir,\n payload,\n queryDrafts,\n rejectInitializing,\n resolveInitializing,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: payloadIDType,\n init: adapter,\n }\n}\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nfunction findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) return migrationDir\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","path","createDatabaseAdapter","connect","count","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateOne","updateGlobal","updateGlobalVersion","updateVersion","sql","postgresAdapter","args","postgresIDType","idType","payloadIDType","adapter","payload","migrationDir","findMigrationDir","resolveInitializing","rejectInitializing","initializing","Promise","res","rej","name","drizzle","undefined","enums","fieldConstraints","localesSuffix","logger","pgSchema","pool","poolOptions","push","relations","relationshipsSuffix","schema","schemaName","sessions","tableNameMap","Map","tables","versionsSuffix","defaultIDType","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"mappings":"AAEA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AACvB,SAASC,qBAAqB,QAAQ,UAAS;AAI/C,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,IAAI,QAAQ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,cAAc,IAAIC;YAClBC,QAAQ,CAAC;YACTC,gBAAgBjC,KAAKiC,cAAc,IAAI;YAEvC,kBAAkB;YAClB1C;YACAC;YACAzB;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACA6D,eAAe/B;YACf7B;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAiB;YACAD;YACAf;YACAmB;YACAD;YACAf;YACAE;YACAC;YACAF;YACAG;QACF;IACF;IAEA,OAAO;QACLqC,eAAe/B;QACfpB,MAAMqB;IACR;AACF;AAEA;;;;;;;;;;;;;CAaC,GACD,SAASG,iBAAiBD,YAAqB;IAC7C,MAAM6B,MAAMC,QAAQD,GAAG;IACvB,MAAME,SAASxE,KAAKyE,OAAO,CAACH,KAAK;IACjC,MAAMI,UAAU1E,KAAKyE,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqB3E,KAAKyE,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAI7B,cAAc,OAAOA;IAEzB,+BAA+B;IAC/B,IAAI1C,GAAG6E,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAIzE,GAAG6E,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAI3E,GAAG6E,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
package/dist/init.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { Init } from 'payload/database';
1
+ import type { Init } from 'payload';
2
2
  export declare const init: Init;
3
3
  //# sourceMappingURL=init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAW5C,eAAO,MAAM,IAAI,EAAE,IAgGlB,CAAA"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAWnC,eAAO,MAAM,IAAI,EAAE,IA6FlB,CAAA"}
package/dist/init.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable no-param-reassign */ import { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core';
2
- import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions';
2
+ import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
3
+ import toSnakeCase from 'to-snake-case';
3
4
  import { buildTable } from './schema/build.js';
4
5
  import { createTableName } from './schema/createTableName.js';
5
6
  export const init = function init() {
@@ -14,15 +15,23 @@ export const init = function init() {
14
15
  this.enums.enum__locales = pgEnum('_locales', this.payload.config.localization.locales.map(({ code })=>code));
15
16
  }
16
17
  this.payload.config.collections.forEach((collection)=>{
17
- const tableName = createTableName({
18
+ createTableName({
18
19
  adapter: this,
19
20
  config: collection
20
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));
21
33
  buildTable({
22
34
  adapter: this,
23
- buildNumbers: true,
24
- buildRelationships: true,
25
- buildTexts: true,
26
35
  disableNotNull: !!collection?.versions?.drafts,
27
36
  disableUnique: false,
28
37
  fields: collection.fields,
@@ -31,18 +40,10 @@ export const init = function init() {
31
40
  versions: false
32
41
  });
33
42
  if (collection.versions) {
34
- const versionsTableName = createTableName({
35
- adapter: this,
36
- config: collection,
37
- versions: true,
38
- versionsCustomName: true
39
- });
43
+ const versionsTableName = this.tableNameMap.get(`_${toSnakeCase(collection.slug)}${this.versionsSuffix}`);
40
44
  const versionFields = buildVersionCollectionFields(collection);
41
45
  buildTable({
42
46
  adapter: this,
43
- buildNumbers: true,
44
- buildRelationships: true,
45
- buildTexts: true,
46
47
  disableNotNull: !!collection.versions?.drafts,
47
48
  disableUnique: true,
48
49
  fields: versionFields,
@@ -59,9 +60,6 @@ export const init = function init() {
59
60
  });
60
61
  buildTable({
61
62
  adapter: this,
62
- buildNumbers: true,
63
- buildRelationships: true,
64
- buildTexts: true,
65
63
  disableNotNull: !!global?.versions?.drafts,
66
64
  disableUnique: false,
67
65
  fields: global.fields,
@@ -79,9 +77,6 @@ export const init = function init() {
79
77
  const versionFields = buildVersionGlobalFields(global);
80
78
  buildTable({
81
79
  adapter: this,
82
- buildNumbers: true,
83
- buildRelationships: true,
84
- buildTexts: true,
85
80
  disableNotNull: !!global.versions?.drafts,
86
81
  disableUnique: true,
87
82
  fields: versionFields,
package/dist/init.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/init.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Init } from 'payload/database'\nimport type { SanitizedCollectionConfig } from 'payload/types'\n\nimport { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions'\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 const tableName = createTableName({\n adapter: this,\n config: collection,\n })\n\n buildTable({\n adapter: this,\n buildNumbers: true,\n buildRelationships: true,\n buildTexts: true,\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 = createTableName({\n adapter: this,\n config: collection,\n versions: true,\n versionsCustomName: true,\n })\n const versionFields = buildVersionCollectionFields(collection)\n\n buildTable({\n adapter: this,\n buildNumbers: true,\n buildRelationships: true,\n buildTexts: true,\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 buildNumbers: true,\n buildRelationships: true,\n buildTexts: true,\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 buildNumbers: true,\n buildRelationships: true,\n buildTexts: true,\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","buildTable","createTableName","init","schemaName","table","payload","config","localization","enums","enum__locales","locales","map","code","collections","forEach","collection","tableName","adapter","buildNumbers","buildRelationships","buildTexts","disableNotNull","versions","drafts","disableUnique","fields","timestamps","versionsTableName","versionsCustomName","versionFields","globals","global"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAIpC,SAASA,MAAM,EAAEC,QAAQ,EAAEC,OAAO,QAAQ,sBAAqB;AAC/D,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,mBAAkB;AAIzF,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,eAAe,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AO,CAAC,CAACiB;QACnC,MAAMf,YAAYf,gBAAgB;YAAEgB,SAAS,IAAI;YAAEX,QAAQyB;QAAO;QAElE/B,WAAW;YACTiB,SAAS,IAAI;YACbC,cAAc;YACdC,oBAAoB;YACpBC,YAAY;YACZC,gBAAgB,CAAC,CAACU,QAAQT,UAAUC;YACpCC,eAAe;YACfC,QAAQM,OAAON,MAAM;YACrBT;YACAU,YAAY;YACZJ,UAAU;QACZ;QAEA,IAAIS,OAAOT,QAAQ,EAAE;YACnB,MAAMK,oBAAoB1B,gBAAgB;gBACxCgB,SAAS,IAAI;gBACbX,QAAQyB;gBACRT,UAAU;gBACVM,oBAAoB;YACtB;YACA,MAAMC,gBAAgB9B,yBAAyBgC;YAE/C/B,WAAW;gBACTiB,SAAS,IAAI;gBACbC,cAAc;gBACdC,oBAAoB;gBACpBC,YAAY;gBACZC,gBAAgB,CAAC,CAACU,OAAOT,QAAQ,EAAEC;gBACnCC,eAAe;gBACfC,QAAQI;gBACRb,WAAWW;gBACXD,YAAY;gBACZJ,UAAU;YACZ;QACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/init.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { SanitizedCollectionConfig } from 'payload'\nimport type { Init } from 'payload'\n\nimport { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { buildTable } from './schema/build.js'\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"],"mappings":"AAAA,oCAAoC,GAIpC,SAASA,MAAM,EAAEC,QAAQ,EAAEC,OAAO,QAAQ,sBAAqB;AAC/D,SAASC,4B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AAEtB,YAAYgB,WAAWO,IAAI,EAAE,EAAE,IAAI,CAACO,cAAc,CAAC,CAAC;YAE1D,MAAMC,gBAAgBjC,6BAA6BkB;YAEnDf,WAAW;gBACTgB,SAAS,IAAI;gBACbO,gBAAgB,CAAC,CAACR,WAAWE,QAAQ,EAAEO;gBACvCC,eAAe;gBACfC,QAAQI;gBACRX,WAAWS;gBACXD,YAAY;gBACZV,UAAU;YACZ;QACF;IACF;IAEA,IAAI,CAACZ,OAAO,CAACC,MAAM,CAACyB,OAAO,CAACjB,OAAO,CAAC,CAACkB;QACnC,MAAMb,YAAYlB,gBAAgB;YAAEe,SAAS,IAAI;YAAEV,QAAQ0B;QAAO;QAElEhC,WAAW;YACTgB,SAAS,IAAI;YACbO,gBAAgB,CAAC,CAACS,QAAQf,UAAUO;YACpCC,eAAe;YACfC,QAAQM,OAAON,MAAM;YACrBP;YACAQ,YAAY;YACZV,UAAU;QACZ;QAEA,IAAIe,OAAOf,QAAQ,EAAE;YACnB,MAAMW,oBAAoB3B,gBAAgB;gBACxCe,SAAS,IAAI;gBACbV,QAAQ0B;gBACRf,UAAU;gBACVC,oBAAoB;YACtB;YACA,MAAMY,gBAAgBhC,yBAAyBkC;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"}
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AASA,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 CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-restricted-syntax, no-await-in-loop */ import { createRequire } from 'module';
2
- import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload/database';
2
+ import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload';
3
3
  import prompts from 'prompts';
4
4
  import { createMigrationTable } from './utilities/createMigrationTable.js';
5
5
  import { migrationTableExists } from './utilities/migrationTableExists.js';
@@ -1 +1 @@
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"],"rang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QACtBpC,QAAQG,MAAM,CAAC0C,KAAK,CAAC;YACnBD;YACAvC,KAAKT,WAAWgD,KAAK,CAAC,wBAAwB,EAAEhB,UAAUR,IAAI,CAAC,CAAC;QAClE;IACF;AACF"}
1
+ {"version":3,"sources":["../src/migrate.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { Payload } from 'payload'\nimport type { PayloadRequestWithData } from 'payload'\nimport type { Migration } from 'payload'\n\nimport { createRequire } from 'module'\nimport { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload'\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"],"mappings":"AAAA,yDAAyD,GAKzD,SAASA,aAAa,QAAQ,SAAQ;AACtC,SAASC,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,EAAEC,kBAAkB,QAAQ,UAAS;AACjG,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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B,EAAE4B,SAAoB,EAAEZ,KAAa;IACnF,MAAM,EAAEgB,mBAAmB,EAAE,GAAGnC,QAAQ;IAExC,MAAMoC,QAAQC,KAAKC,GAAG;IACtB,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,4 +1,4 @@
1
- /* eslint-disable no-restricted-syntax, no-await-in-loop */ import { commitTransaction, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload/database';
1
+ /* eslint-disable no-restricted-syntax, no-await-in-loop */ import { commitTransaction, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload';
2
2
  import { migrationTableExists } from './utilities/migrationTableExists.js';
3
3
  import { parseError } from './utilities/parseError.js';
4
4
  export async function migrateDown() {
@@ -1 +1 @@
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,GAGzD,SACEA,iBAAiB,EACjBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,mBAAkB;AAIzB,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,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,wBAAwBN,mBAAmBO,MAAM,CAAC,CAAC,EAAEC,KAAK,EAAE,GAAKA,UAAUP;IAEjF,KAAK,MAAMQ,aAAaH,sBAAuB;QAC7C,MAAMI,gBAAgBX,eAAeY,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAC1E,IAAI,CAACH,eAAe;YAClB,MAAM,IAAII,MAAM,CAAC,UAAU,EAAEL,UAAUI,IAAI,CAAC,mBAAmB,CAAC;QAClE;QAEA,MAAME,QAAQC,KAAKC,GAAG;QACtB,MAAMC,MAAM;YAAEpB;QAAQ;QAEtB,IAAI;YACFA,QAAQK,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,gBAAgB,EAAEK,cAAcG,IAAI,CAAC,CAAC;YAAC;YACnE,MAAMrB,gBAAgB0B;YACtB,MAAMR,cAAcS,IAAI,CAAC;gBAAErB;gBAASoB;YAAI;YACxCpB,QAAQK,MAAM,CAACC,IAAI,CAAC;gBAClBC,KAAK,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
+ {"version":3,"sources":["../src/migrateDown.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { PayloadRequestWithData } from 'payload'\n\nimport {\n commitTransaction,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload'\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"],"mappings":"AAAA,yDAAyD,GAGzD,SACEA,iBAAiB,EACjBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,UAAS;AAIhB,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,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;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,CAAC,eAAe,CAAC;YAClF;YACAc,QAAQC,IAAI,CAAC;QACf;IACF;AACF"}
@@ -1 +1 @@
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
+ {"version":3,"file":"migrateFresh.d.ts","sourceRoot":"","sources":["../src/migrateFresh.ts"],"names":[],"mappings":"AAMA,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,5 +1,5 @@
1
1
  import { sql } from 'drizzle-orm';
2
- import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload/database';
2
+ import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload';
3
3
  import prompts from 'prompts';
4
4
  import { parseError } from './utilities/parseError.js';
5
5
  /**
@@ -1 +1 @@
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,aAAa,UAAS;AAI7B,SAASC,UAAU,QAAQ,4BAA2B;AAEtD;;CAEC,GACD,OAAO,eAAeC,aAEpB,EAAEC,qBAAqB,KAAK,EAAE;I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C,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
+ {"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { PayloadRequestWithData } from 'payload'\n\nimport { sql } from 'drizzle-orm'\nimport { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload'\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"],"mappings":"AAEA,SAASA,GAAG,QAAQ,cAAa;AACjC,SAASC,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,EAAEC,kBAAkB,QAAQ,UAAS;AACjG,OAAOC,aAAa,UAAS;AAI7B,SAASC,UAAU,QAAQ,4BAA2B;AAEtD;;CAEC,GACD,OAAO,eAAeC,aAEpB,EAAEC,qBAAqB,KAAK,EAAE;IAE9B,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IAExB,IAAID,uBAAuB,OAAO;QAChC,MAAM,EAAEE,SAASC,aAAa,EAAE,GAAG,MAAMN,QACvC;YACEO,MAAM;YACNC,MAAM;YACNC,SAAS;YACTC,SAAS,CAAC,+FAA+F,CAAC;QAC5G,GACA;YACEC,UAAU;gBACRC,QAAQC,IAAI,CAAC;YACf;QACF;QAGF,IAAI,CAACP,eAAe;YAClBM,QAAQC,IAAI,CAAC;QACf;IACF;IAEAT,QAAQU,MAAM,CAACC,IAAI,CAAC;QAClBC,KAAK,CAAC,kBAAkB,CAAC;IAC3B;IAEA,MAAM,IAAI,CAACC,OAAO,CAACC,OAAO,CACxBvB,IAAIwB,GAAG,CAAC,CAAC,YAAY,EAAE,IAAI,CAACC,UAAU,IAAI,SAAS;gBACvC,EAAE,IAAI,CAACA,UAAU,IAAI,SAAS,CAAC,CAAC;IAG9C,MAAMC,iBAAiB,MAAMtB,mBAAmB;QAAEK;IAAQ;IAC1DA,QAAQU,MAAM,CAACQ,KAAK,CAAC;QACnBN,KAAK,CAAC,MAAM,EAAEK,eAAeE,MAAM,CAAC,iBAAiB,CAAC;IACxD;IAEA,MAAMC,MAAM;QAAEpB;IAAQ;IACtB,qBAAqB;IACrB,KAAK,MAAMqB,aAAaJ,eAAgB;QACtCjB,QAAQU,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK,CAAC,WAAW,EAAES,UAAUlB,IAAI,CAAC,CAAC;QAAC;QAC1D,IAAI;YACF,MAAMmB,QAAQC,KAAKC,GAAG;YACtB,MAAM/B,gBAAgB2B;YACtB,MAAMC,UAAUI,EAAE,CAAC;gBAAEzB;gBAASoB;YAAI;YAClC,MAAMpB,QAAQ0B,MAAM,CAAC;gBACnBC,YAAY;gBACZC,MAAM;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,4 +1,4 @@
1
- /* eslint-disable no-restricted-syntax, no-await-in-loop */ import { commitTransaction, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload/database';
1
+ /* eslint-disable no-restricted-syntax, no-await-in-loop */ import { commitTransaction, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload';
2
2
  import { migrationTableExists } from './utilities/migrationTableExists.js';
3
3
  import { parseError } from './utilities/parseError.js';
4
4
  /**
@@ -1 +1 @@
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;IAEt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EG,UAAUI,IAAI,CAAC,CAAC;QAAC;QAC1D,IAAI;YACF,MAAME,QAAQC,KAAKC,GAAG;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
+ {"version":3,"sources":["../src/migrateRefresh.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { PayloadRequestWithData } from 'payload'\n\nimport {\n commitTransaction,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload'\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"],"mappings":"AAAA,yDAAyD,GAGzD,SACEA,iBAAiB,EACjBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,UAAS;AAIhB,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC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commitTransaction, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload/database';
1
+ /* eslint-disable no-restricted-syntax, no-await-in-loop */ import { commitTransaction, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload';
2
2
  import { migrationTableExists } from './utilities/migrationTableExists.js';
3
3
  /**
4
4
  * Run all migrate down functions
@@ -1 +1 @@
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,yDAAyD,GAGzD,SACEA,iBAAiB,EACjBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,mBAAkB;AAIzB,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMJ,mBAAmB;QAAEG;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAE,GAAG,MAAMR,cAAc;QAAEM;IAAQ;IAE7D,IAAI,CAACE,oBAAoBC,QAAQ;QAC/BH,QAAQI,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAA0B;QACrD;IACF;IAEA,MAAMC,MAAM;QAAEP;IAAQ;IAEtB,mCAAmC;IACnC,KAAK,MAAMQ,aAAaN,mBAAoB;QAC1C,MAAMO,gBAAgBR,eAAeS,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAC1E,IAAI;YACF,IAAI,CAACH,eAAe;gBAClB,MAAM,IAAII,MAAM,CAAC,UAAU,EAAEL,UAAUI,IAAI,CAAC,mBAAmB,CAAC;YAClE;YAEA,MAAME,QAAQC,KAAKC,GAAG;YAC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, no-await-in-loop */\nimport type { PayloadRequestWithData } from 'payload'\n\nimport {\n commitTransaction,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload'\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"],"mappings":"AAAA,yDAAyD,GAGzD,SACEA,iBAAiB,EACjBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,UAAS;AAIhB,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMJ,mBAAmB;QAAEG;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAE,GAAG,MAAMR,cAAc;QAAEM;IAAQ;IAE7D,IAAI,CAACE,oBAAoBC,QAAQ;QAC/BH,QAAQI,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAA0B;QACrD;IACF;IAEA,MAAMC,MAAM;QAAEP;IAAQ;IAEtB,mCAAmC;IACnC,KAAK,MAAMQ,aAAaN,mBAAoB;QAC1C,MAAMO,gBAAgBR,eAAeS,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAC1E,IAAI;YACF,IAAI,CAACH,eAAe;gBAClB,MAAM,IAAII,MAAM,CAAC,UAAU,EAAEL,UAAUI,IAAI,CAAC,mBAAmB,CAAC;YAClE;YAEA,MAAME,QAAQC,KAAKC,GAAG;YACtBhB,QAAQI,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,gBAAgB,EAAEG,cAAcG,IAAI,CAAC,CAAC;YAAC;YACnE,MAAMjB,gBAAgBY;YACtB,MAAME,cAAcQ,IAAI,CAAC;gBAAEjB;gBAASO;YAAI;YACxCP,QAAQI,MAAM,CAACC,IAAI,CAAC;gBAClBC,KAAK,CAAC,gBAAgB,EAAEG,cAAcG,IAAI,CAAC,EAAE,EAAEG,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YACxE;YAEA,MAAMI,cAAc,MAAMpB,qBAAqB,IAAI,CAACqB,OAAO;YAC3D,IAAID,aAAa;gBACf,MAAMlB,QAAQoB,MAAM,CAAC;oBACnBC,IAAIb,UAAUa,EAAE;oBAChBC,YAAY;oBACZf;gBACF;YACF;YAEA,MAAMd,kBAAkBc;QAC1B,EAAE,OAAOgB,KAAc;YACrB,IAAIjB,MAAM,CAAC,wBAAwB,EAAEG,cAAcG,IAAI,CAAC,CAAC,CAAC;YAE1D,IAAIW,eAAeV,OAAOP,OAAO,CAAC,CAAC,EAAEiB,IAAIC,OAAO,CAAC,CAAC;YAElD,MAAM5B,gBAAgBW;YACtBP,QAAQI,MAAM,CAACqB,KAAK,CAAC;gBACnBF;gBACAjB;YACF;YACAoB,QAAQC,IAAI,CAAC;QACf;IACF;IAEA,uBAAuB;IAEvB,MAAMT,cAAc,MAAMpB,qBAAqB,IAAI,CAACqB,OAAO;IAC3D,IAAID,aAAa;QACf,IAAI;YACF,MAAMlB,QAAQoB,MAAM,CAAC;gBACnBE,YAAY;gBACZM,OAAO;oBACLC,OAAO;wBACLC,QAAQ,CAAC;oBACX;gBACF;YACF;QACF,EAAE,OAAOP,KAAc;YACrBvB,QAAQI,MAAM,CAACqB,KAAK,CAAC;gBAAEA,OAAOF;gBAAKjB,KAAK;YAA+B;QACzE;IACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { Table } from 'console-table-printer';
2
- import { getMigrations, readMigrationFiles } from 'payload/database';
2
+ import { getMigrations, readMigrationFiles } from 'payload';
3
3
  import { migrationTableExists } from './utilities/migrationTableExists.js';
4
4
  export async function migrateStatus() {
5
5
  const { payload } = this;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/migrateStatus.ts"],"sourcesContent":["import { Table } from 'console-table-printer'\nimport { getMigrations, readMigrationFiles } from 'payload/database'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\n\nexport async function migrateStatus(this: PostgresAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n let existingMigrations = []\n const hasMigrationTable = await migrationTableExists(this.drizzle)\n\n if (hasMigrationTable) {\n ;({ existingMigrations } = await getMigrations({ payload }))\n }\n\n if (!migrationFiles.length) {\n payload.logger.info({ msg: 'No migrations found.' })\n return\n }\n\n // Compare migration files to existing migrations\n const statuses = migrationFiles.map((migration) => {\n const existingMigration = existingMigrations.find((m) => m.name === migration.name)\n return {\n Name: migration.name,\n // eslint-disable-next-line perfectionist/sort-objects\n Batch: existingMigration?.batch,\n Ran: existingMigration ? 'Yes' : 'No',\n }\n })\n\n const p = new Table()\n\n statuses.forEach((s) => {\n p.addRow(s, {\n color: s.Ran === 'Yes' ? 'green' : 'red',\n })\n })\n p.printTable()\n}\n"],"names":["Table","getMigrations","readMigrationFiles","migrationTableExists","migrateStatus","payload","migrationFiles","logger","debug","msg","length","existingMigrations","hasMigrationTable","drizzle","info","statuses","map","migration","existingMigration","find","m","name","Name","Batch","batch","Ran","p","forEach","s","addRow","color","printTable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,KAAK,QAAQ,wBAAuB;AAC7C,SAASC,aAAa,EAAEC,kBAAkB,QAAQ,mBAAkB;AAIpE,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMJ,mBAAmB;QAAEG;IAAQ;IAE1DA,QAAQE,MAAM,CAACC,KAAK,CAAC;QACnBC,KAAK,CAAC,MAAM,EAAEH,eAAeI,MAAM,CAAC,iBAAiB,CAAC;IACxD;IAEA,IAAIC,qBAAqB,EAAE;IAC3B,MAAMC,oBAAoB,MAAMT,qBAAqB,IAAI,CAACU,OAAO;IAEjE,IAAID,mBAAmB;QACnB,CAAA,EAAED,kBAAkB,EAAE,GAAG,MAAMV,cAAc;YAAEI;QAAQ,EAAC;IAC5D;IAEA,IAAI,CAACC,eAAeI,MAAM,EAAE;QAC1BL,QAAQE,MAAM,CAACO,IAAI,CAAC;YAAEL,KAAK;QAAuB;QAClD;IACF;IAEA,iDAAiD;IACjD,MAAMM,WAAWT,eAAeU,GAAG,CAAC,CAACC;QACnC,MAAMC,oBAAoBP,mBAAmBQ,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAClF,OAAO;YACLC,MAAML,UAAUI,IAAI;YACpB,sDAAsD;YACtDE,OAAOL,mBAAmBM;YAC1BC,KAAKP,oBAAoB,QAAQ;QACnC;IACF;IAEA,MAAMQ,IAAI,IAAI1B;IAEde,SAASY,OAAO,CAAC,CAACC;QAChBF,EAAEG,MAAM,CAACD,GAAG;YACVE,OAAOF,EAAEH,GAAG,KAAK,QAAQ,UAAU;QACrC;IACF;IACAC,EAAEK,UAAU;AACd"}
1
+ {"version":3,"sources":["../src/migrateStatus.ts"],"sourcesContent":["import { Table } from 'console-table-printer'\nimport { getMigrations, readMigrationFiles } from 'payload'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\n\nexport async function migrateStatus(this: PostgresAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n let existingMigrations = []\n const hasMigrationTable = await migrationTableExists(this.drizzle)\n\n if (hasMigrationTable) {\n ;({ existingMigrations } = await getMigrations({ payload }))\n }\n\n if (!migrationFiles.length) {\n payload.logger.info({ msg: 'No migrations found.' })\n return\n }\n\n // Compare migration files to existing migrations\n const statuses = migrationFiles.map((migration) => {\n const existingMigration = existingMigrations.find((m) => m.name === migration.name)\n return {\n Name: migration.name,\n // eslint-disable-next-line perfectionist/sort-objects\n Batch: existingMigration?.batch,\n Ran: existingMigration ? 'Yes' : 'No',\n }\n })\n\n const p = new Table()\n\n statuses.forEach((s) => {\n p.addRow(s, {\n color: s.Ran === 'Yes' ? 'green' : 'red',\n })\n })\n p.printTable()\n}\n"],"names":["Table","getMigrations","readMigrationFiles","migrationTableExists","migrateStatus","payload","migrationFiles","logger","debug","msg","length","existingMigrations","hasMigrationTable","drizzle","info","statuses","map","migration","existingMigration","find","m","name","Name","Batch","batch","Ran","p","forEach","s","addRow","color","printTable"],"mappings":"AAAA,SAASA,KAAK,QAAQ,wBAAuB;AAC7C,SAASC,aAAa,EAAEC,kBAAkB,QAAQ,UAAS;AAI3D,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMJ,mBAAmB;QAAEG;IAAQ;IAE1DA,QAAQE,MAAM,CAACC,KAAK,CAAC;QACnBC,KAAK,CAAC,MAAM,EAAEH,eAAeI,MAAM,CAAC,iBAAiB,CAAC;IACxD;IAEA,IAAIC,qBAAqB,EAAE;IAC3B,MAAMC,oBAAoB,MAAMT,qBAAqB,IAAI,CAACU,OAAO;IAEjE,IAAID,mBAAmB;QACnB,CAAA,EAAED,kBAAkB,EAAE,GAAG,MAAMV,cAAc;YAAEI;QAAQ,EAAC;IAC5D;IAEA,IAAI,CAACC,eAAeI,MAAM,EAAE;QAC1BL,QAAQE,MAAM,CAACO,IAAI,CAAC;YAAEL,KAAK;QAAuB;QAClD;IACF;IAEA,iDAAiD;IACjD,MAAMM,WAAWT,eAAeU,GAAG,CAAC,CAACC;QACnC,MAAMC,oBAAoBP,mBAAmBQ,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAClF,OAAO;YACLC,MAAML,UAAUI,IAAI;YACpB,sDAAsD;YACtDE,OAAOL,mBAAmBM;YAC1BC,KAAKP,oBAAoB,QAAQ;QACnC;IACF;IAEA,MAAMQ,IAAI,IAAI1B;IAEde,SAASY,OAAO,CAAC,CAACC;QAChBF,EAAEG,MAAM,CAACD,GAAG;YACVE,OAAOF,EAAEH,GAAG,KAAK,QAAQ,UAAU;QACrC;IACF;IACAC,EAAEK,UAAU;AACd"}
@@ -0,0 +1,4 @@
1
+ declare const imports = "import { migratePostgresV2toV3 } from '@payloadcms/db-postgres/migration-utils'";
2
+ declare const upSQL = " await migratePostgresV2toV3({\n // enables logging of changes that will be made to the database\n debug: false,\n payload,\n req,\n })\n";
3
+ export { imports, upSQL };
4
+ //# sourceMappingURL=relationships-v2-v3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relationships-v2-v3.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/relationships-v2-v3.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,oFAAoF,CAAA;AACjG,QAAA,MAAM,KAAK,mLAMV,CAAA;AAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/predefinedMigrations/relationships-v2-v3.ts"],"sourcesContent":["const imports = `import { migratePostgresV2toV3 } from '@payloadcms/db-postgres/migration-utils'`\nconst upSQL = ` await migratePostgresV2toV3({\n // enables logging of changes that will be made to the database\n debug: false,\n payload,\n req,\n })\n`\n\nexport { imports, upSQL }\n"],"names":["imports","upSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,+EAA+E,CAAC;AACjG,MAAMC,QAAQ,CAAC;;;;;;AAMf,CAAC;AAED,SAASD,OAAO,EAAEC,KAAK,GAAE"}
@@ -0,0 +1,11 @@
1
+ const imports = `import { migratePostgresV2toV3 } from '@payloadcms/db-postgres/migration-utils'`;
2
+ const upSQL = ` await migratePostgresV2toV3({
3
+ // enables logging of changes that will be made to the database
4
+ debug: false,
5
+ payload,
6
+ req,
7
+ })
8
+ `;
9
+ export { imports, upSQL };
10
+
11
+ //# sourceMappingURL=relationships-v2-v3.js.map
@@ -0,0 +1,19 @@
1
+ import type { Field, Payload, PayloadRequestWithData } from 'payload';
2
+ import type { DrizzleTransaction, PostgresAdapter } from '../../../types.js';
3
+ import type { DocsToResave } from '../types.js';
4
+ type Args = {
5
+ adapter: PostgresAdapter;
6
+ collectionSlug?: string;
7
+ db: DrizzleTransaction;
8
+ debug: boolean;
9
+ docsToResave: DocsToResave;
10
+ fields: Field[];
11
+ globalSlug?: string;
12
+ isVersions: boolean;
13
+ payload: Payload;
14
+ req: PayloadRequestWithData;
15
+ tableName: string;
16
+ };
17
+ export declare const fetchAndResave: ({ adapter, collectionSlug, db, debug, docsToResave, fields, globalSlug, isVersions, payload, req, tableName, }: Args) => Promise<void>;
18
+ export {};
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAErE,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAK/C,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,kBAAkB,CAAA;IACtB,KAAK,EAAE,OAAO,CAAA;IACd,YAAY,EAAE,YAAY,CAAA;IAC1B,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,sBAAsB,CAAA;IAC3B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,cAAc,mHAYxB,IAAI,kBAwMN,CAAA"}