@payloadcms/db-postgres 3.0.0-beta.7 → 3.0.0-canary.0017c67

Sign up to get free protection for your applications and to get access to all the features.
Files changed (301) 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 +3 -0
  7. package/dist/count.d.ts.map +1 -0
  8. package/dist/count.js +41 -0
  9. package/dist/count.js.map +1 -0
  10. package/dist/create.d.ts +1 -1
  11. package/dist/create.d.ts.map +1 -1
  12. package/dist/create.js +3 -5
  13. package/dist/create.js.map +1 -1
  14. package/dist/createGlobal.d.ts +2 -3
  15. package/dist/createGlobal.d.ts.map +1 -1
  16. package/dist/createGlobal.js +3 -5
  17. package/dist/createGlobal.js.map +1 -1
  18. package/dist/createGlobalVersion.d.ts +3 -4
  19. package/dist/createGlobalVersion.d.ts.map +1 -1
  20. package/dist/createGlobalVersion.js +3 -7
  21. package/dist/createGlobalVersion.js.map +1 -1
  22. package/dist/createMigration.d.ts +1 -1
  23. package/dist/createMigration.d.ts.map +1 -1
  24. package/dist/createMigration.js +56 -35
  25. package/dist/createMigration.js.map +1 -1
  26. package/dist/createVersion.d.ts +1 -2
  27. package/dist/createVersion.d.ts.map +1 -1
  28. package/dist/createVersion.js +11 -19
  29. package/dist/createVersion.js.map +1 -1
  30. package/dist/deleteMany.d.ts +1 -1
  31. package/dist/deleteMany.d.ts.map +1 -1
  32. package/dist/deleteMany.js +2 -5
  33. package/dist/deleteMany.js.map +1 -1
  34. package/dist/deleteOne.d.ts +1 -1
  35. package/dist/deleteOne.d.ts.map +1 -1
  36. package/dist/deleteOne.js +4 -7
  37. package/dist/deleteOne.js.map +1 -1
  38. package/dist/deleteVersions.d.ts +1 -1
  39. package/dist/deleteVersions.d.ts.map +1 -1
  40. package/dist/deleteVersions.js +3 -7
  41. package/dist/deleteVersions.js.map +1 -1
  42. package/dist/destroy.d.ts +1 -1
  43. package/dist/destroy.d.ts.map +1 -1
  44. package/dist/destroy.js +11 -7
  45. package/dist/destroy.js.map +1 -1
  46. package/dist/exports/migration-utils.d.ts +2 -0
  47. package/dist/exports/migration-utils.d.ts.map +1 -0
  48. package/dist/exports/migration-utils.js +3 -0
  49. package/dist/exports/migration-utils.js.map +1 -0
  50. package/dist/find/buildFindManyArgs.d.ts +6 -2
  51. package/dist/find/buildFindManyArgs.d.ts.map +1 -1
  52. package/dist/find/buildFindManyArgs.js +4 -3
  53. package/dist/find/buildFindManyArgs.js.map +1 -1
  54. package/dist/find/chainMethods.d.ts.map +1 -1
  55. package/dist/find/chainMethods.js.map +1 -1
  56. package/dist/find/findMany.d.ts +1 -2
  57. package/dist/find/findMany.d.ts.map +1 -1
  58. package/dist/find/findMany.js +5 -16
  59. package/dist/find/findMany.js.map +1 -1
  60. package/dist/find/traverseFields.d.ts +4 -3
  61. package/dist/find/traverseFields.d.ts.map +1 -1
  62. package/dist/find/traverseFields.js +27 -25
  63. package/dist/find/traverseFields.js.map +1 -1
  64. package/dist/find.d.ts +1 -1
  65. package/dist/find.d.ts.map +1 -1
  66. package/dist/find.js +2 -5
  67. package/dist/find.js.map +1 -1
  68. package/dist/findGlobal.d.ts +1 -1
  69. package/dist/findGlobal.d.ts.map +1 -1
  70. package/dist/findGlobal.js +2 -5
  71. package/dist/findGlobal.js.map +1 -1
  72. package/dist/findGlobalVersions.d.ts +1 -1
  73. package/dist/findGlobalVersions.d.ts.map +1 -1
  74. package/dist/findGlobalVersions.js +3 -7
  75. package/dist/findGlobalVersions.js.map +1 -1
  76. package/dist/findOne.d.ts +1 -2
  77. package/dist/findOne.d.ts.map +1 -1
  78. package/dist/findOne.js +2 -5
  79. package/dist/findOne.js.map +1 -1
  80. package/dist/findVersions.d.ts +1 -1
  81. package/dist/findVersions.d.ts.map +1 -1
  82. package/dist/findVersions.js +3 -7
  83. package/dist/findVersions.js.map +1 -1
  84. package/dist/index.d.ts +1 -1
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.js +18 -9
  87. package/dist/index.js.map +1 -1
  88. package/dist/init.d.ts +1 -1
  89. package/dist/init.d.ts.map +1 -1
  90. package/dist/init.js +20 -23
  91. package/dist/init.js.map +1 -1
  92. package/dist/migrate.d.ts.map +1 -1
  93. package/dist/migrate.js +1 -1
  94. package/dist/migrate.js.map +1 -1
  95. package/dist/migrateDown.js +1 -1
  96. package/dist/migrateDown.js.map +1 -1
  97. package/dist/migrateFresh.d.ts.map +1 -1
  98. package/dist/migrateFresh.js +1 -1
  99. package/dist/migrateFresh.js.map +1 -1
  100. package/dist/migrateRefresh.js +1 -1
  101. package/dist/migrateRefresh.js.map +1 -1
  102. package/dist/migrateReset.js +1 -1
  103. package/dist/migrateReset.js.map +1 -1
  104. package/dist/migrateStatus.js +1 -1
  105. package/dist/migrateStatus.js.map +1 -1
  106. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  107. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  108. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  109. package/dist/predefinedMigrations/relationships-v2-v3.mjs +11 -0
  110. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +19 -0
  111. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
  112. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +169 -0
  113. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
  114. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
  115. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
  116. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +191 -0
  117. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
  118. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
  119. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
  120. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js +56 -0
  121. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
  122. package/dist/predefinedMigrations/v2-v3/index.d.ts +23 -0
  123. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
  124. package/dist/predefinedMigrations/v2-v3/index.js +211 -0
  125. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -0
  126. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +19 -0
  127. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
  128. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +57 -0
  129. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
  130. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +22 -0
  131. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
  132. package/dist/predefinedMigrations/v2-v3/traverseFields.js +85 -0
  133. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
  134. package/dist/predefinedMigrations/v2-v3/types.d.ts +9 -0
  135. package/dist/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
  136. package/dist/predefinedMigrations/v2-v3/types.js +6 -0
  137. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -0
  138. package/dist/queries/buildAndOrConditions.d.ts +4 -5
  139. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  140. package/dist/queries/buildAndOrConditions.js +1 -2
  141. package/dist/queries/buildAndOrConditions.js.map +1 -1
  142. package/dist/queries/buildQuery.d.ts +2 -3
  143. package/dist/queries/buildQuery.d.ts.map +1 -1
  144. package/dist/queries/buildQuery.js +1 -5
  145. package/dist/queries/buildQuery.js.map +1 -1
  146. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +1 -1
  147. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +1 -1
  148. package/dist/queries/createJSONQuery/index.js.map +1 -1
  149. package/dist/queries/getTableColumnFromPath.d.ts +4 -5
  150. package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
  151. package/dist/queries/getTableColumnFromPath.js +250 -146
  152. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  153. package/dist/queries/operatorMap.js.map +1 -1
  154. package/dist/queries/parseParams.d.ts +4 -5
  155. package/dist/queries/parseParams.d.ts.map +1 -1
  156. package/dist/queries/parseParams.js +9 -8
  157. package/dist/queries/parseParams.js.map +1 -1
  158. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  159. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  160. package/dist/queries/sanitizeQueryValue.js +2 -3
  161. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  162. package/dist/queries/selectDistinct.d.ts +3 -4
  163. package/dist/queries/selectDistinct.d.ts.map +1 -1
  164. package/dist/queries/selectDistinct.js +3 -14
  165. package/dist/queries/selectDistinct.js.map +1 -1
  166. package/dist/queryDrafts.d.ts +1 -1
  167. package/dist/queryDrafts.d.ts.map +1 -1
  168. package/dist/queryDrafts.js +3 -8
  169. package/dist/queryDrafts.js.map +1 -1
  170. package/dist/schema/build.d.ts +12 -7
  171. package/dist/schema/build.d.ts.map +1 -1
  172. package/dist/schema/build.js +208 -124
  173. package/dist/schema/build.js.map +1 -1
  174. package/dist/schema/createIndex.js.map +1 -1
  175. package/dist/schema/{getTableName.d.ts → createTableName.d.ts} +6 -8
  176. package/dist/schema/createTableName.d.ts.map +1 -0
  177. package/dist/schema/createTableName.js +31 -0
  178. package/dist/schema/createTableName.js.map +1 -0
  179. package/dist/schema/idToUUID.d.ts +1 -1
  180. package/dist/schema/idToUUID.d.ts.map +1 -1
  181. package/dist/schema/idToUUID.js.map +1 -1
  182. package/dist/schema/parentIDColumnMap.js.map +1 -1
  183. package/dist/schema/setColumnID.d.ts +1 -1
  184. package/dist/schema/setColumnID.d.ts.map +1 -1
  185. package/dist/schema/setColumnID.js +2 -2
  186. package/dist/schema/setColumnID.js.map +1 -1
  187. package/dist/schema/traverseFields.d.ts +5 -7
  188. package/dist/schema/traverseFields.d.ts.map +1 -1
  189. package/dist/schema/traverseFields.js +147 -63
  190. package/dist/schema/traverseFields.js.map +1 -1
  191. package/dist/schema/validateExistingBlockIsIdentical.d.ts +3 -2
  192. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +1 -1
  193. package/dist/schema/validateExistingBlockIsIdentical.js +15 -9
  194. package/dist/schema/validateExistingBlockIsIdentical.js.map +1 -1
  195. package/dist/transactions/beginTransaction.d.ts +1 -1
  196. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  197. package/dist/transactions/beginTransaction.js +4 -0
  198. package/dist/transactions/beginTransaction.js.map +1 -1
  199. package/dist/transactions/commitTransaction.d.ts +1 -1
  200. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  201. package/dist/transactions/commitTransaction.js.map +1 -1
  202. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  203. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  204. package/dist/transactions/rollbackTransaction.js.map +1 -1
  205. package/dist/transform/read/hasManyNumber.d.ts +1 -1
  206. package/dist/transform/read/hasManyNumber.d.ts.map +1 -1
  207. package/dist/transform/read/hasManyNumber.js.map +1 -1
  208. package/dist/transform/read/hasManyText.d.ts +1 -1
  209. package/dist/transform/read/hasManyText.d.ts.map +1 -1
  210. package/dist/transform/read/hasManyText.js.map +1 -1
  211. package/dist/transform/read/index.d.ts +4 -3
  212. package/dist/transform/read/index.d.ts.map +1 -1
  213. package/dist/transform/read/index.js +2 -1
  214. package/dist/transform/read/index.js.map +1 -1
  215. package/dist/transform/read/relationship.d.ts +1 -1
  216. package/dist/transform/read/relationship.d.ts.map +1 -1
  217. package/dist/transform/read/relationship.js +0 -4
  218. package/dist/transform/read/relationship.js.map +1 -1
  219. package/dist/transform/read/traverseFields.d.ts +8 -3
  220. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  221. package/dist/transform/read/traverseFields.js +70 -56
  222. package/dist/transform/read/traverseFields.js.map +1 -1
  223. package/dist/transform/write/array.d.ts +1 -1
  224. package/dist/transform/write/array.d.ts.map +1 -1
  225. package/dist/transform/write/array.js.map +1 -1
  226. package/dist/transform/write/blocks.d.ts +1 -1
  227. package/dist/transform/write/blocks.d.ts.map +1 -1
  228. package/dist/transform/write/blocks.js +1 -1
  229. package/dist/transform/write/blocks.js.map +1 -1
  230. package/dist/transform/write/index.d.ts +1 -1
  231. package/dist/transform/write/index.d.ts.map +1 -1
  232. package/dist/transform/write/index.js.map +1 -1
  233. package/dist/transform/write/numbers.js.map +1 -1
  234. package/dist/transform/write/relationships.d.ts +1 -1
  235. package/dist/transform/write/relationships.d.ts.map +1 -1
  236. package/dist/transform/write/relationships.js +1 -1
  237. package/dist/transform/write/relationships.js.map +1 -1
  238. package/dist/transform/write/selects.js.map +1 -1
  239. package/dist/transform/write/texts.js.map +1 -1
  240. package/dist/transform/write/traverseFields.d.ts +1 -1
  241. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  242. package/dist/transform/write/traverseFields.js +23 -6
  243. package/dist/transform/write/traverseFields.js.map +1 -1
  244. package/dist/transform/write/types.js.map +1 -1
  245. package/dist/types.d.ts +7 -9
  246. package/dist/types.d.ts.map +1 -1
  247. package/dist/types.js.map +1 -1
  248. package/dist/update.d.ts +1 -1
  249. package/dist/update.d.ts.map +1 -1
  250. package/dist/update.js +3 -7
  251. package/dist/update.js.map +1 -1
  252. package/dist/updateGlobal.d.ts +2 -3
  253. package/dist/updateGlobal.d.ts.map +1 -1
  254. package/dist/updateGlobal.js +2 -5
  255. package/dist/updateGlobal.js.map +1 -1
  256. package/dist/updateGlobalVersion.d.ts +1 -2
  257. package/dist/updateGlobalVersion.d.ts.map +1 -1
  258. package/dist/updateGlobalVersion.js +3 -7
  259. package/dist/updateGlobalVersion.js.map +1 -1
  260. package/dist/updateVersion.d.ts +1 -2
  261. package/dist/updateVersion.d.ts.map +1 -1
  262. package/dist/updateVersion.js +3 -7
  263. package/dist/updateVersion.js.map +1 -1
  264. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +1 -1
  265. package/dist/upsertRow/deleteExistingArrayRows.js.map +1 -1
  266. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
  267. package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
  268. package/dist/upsertRow/index.d.ts +2 -2
  269. package/dist/upsertRow/index.d.ts.map +1 -1
  270. package/dist/upsertRow/index.js +10 -7
  271. package/dist/upsertRow/index.js.map +1 -1
  272. package/dist/upsertRow/insertArrays.d.ts.map +1 -1
  273. package/dist/upsertRow/insertArrays.js +3 -3
  274. package/dist/upsertRow/insertArrays.js.map +1 -1
  275. package/dist/upsertRow/types.d.ts +7 -2
  276. package/dist/upsertRow/types.d.ts.map +1 -1
  277. package/dist/upsertRow/types.js.map +1 -1
  278. package/dist/utilities/appendPrefixToKeys.d.ts.map +1 -1
  279. package/dist/utilities/appendPrefixToKeys.js.map +1 -1
  280. package/dist/utilities/createBlocksMap.d.ts.map +1 -1
  281. package/dist/utilities/createBlocksMap.js.map +1 -1
  282. package/dist/utilities/createMigrationTable.d.ts.map +1 -1
  283. package/dist/utilities/createMigrationTable.js.map +1 -1
  284. package/dist/utilities/createRelationshipMap.d.ts.map +1 -1
  285. package/dist/utilities/createRelationshipMap.js.map +1 -1
  286. package/dist/utilities/hasLocalesTable.d.ts +1 -1
  287. package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
  288. package/dist/utilities/hasLocalesTable.js +1 -1
  289. package/dist/utilities/hasLocalesTable.js.map +1 -1
  290. package/dist/utilities/isArrayOfRows.js.map +1 -1
  291. package/dist/utilities/migrationTableExists.d.ts.map +1 -1
  292. package/dist/utilities/migrationTableExists.js.map +1 -1
  293. package/dist/utilities/parseError.js.map +1 -1
  294. package/dist/utilities/pushDevSchema.d.ts.map +1 -1
  295. package/dist/utilities/pushDevSchema.js +1 -1
  296. package/dist/utilities/pushDevSchema.js.map +1 -1
  297. package/package.json +34 -29
  298. package/dist/schema/getTableName.d.ts.map +0 -1
  299. package/dist/schema/getTableName.js +0 -31
  300. package/dist/schema/getTableName.js.map +0 -1
  301. package/src/index.ts +0 -156
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Convert an "ADD COLUMN" statement to an "ALTER COLUMN" statement
3
+ * example: ALTER TABLE "pages_blocks_my_block" ADD COLUMN "person_id" integer NOT NULL;
4
+ * to: ALTER TABLE "pages_blocks_my_block" ALTER COLUMN "person_id" SET NOT NULL;
5
+ * @param sql
6
+ */ function convertAddColumnToAlterColumn(sql) {
7
+ // Regular expression to match the ADD COLUMN statement with its constraints
8
+ const regex = /ALTER TABLE ("[^"]+") ADD COLUMN ("[^"]+") [\w\s]+ NOT NULL;/;
9
+ // Replace the matched part with "ALTER COLUMN ... SET NOT NULL;"
10
+ return sql.replace(regex, 'ALTER TABLE $1 ALTER COLUMN $2 SET NOT NULL;');
11
+ }
12
+ export const groupUpSQLStatements = (list)=>{
13
+ const groups = {
14
+ addColumn: 'ADD COLUMN',
15
+ // example: ALTER TABLE "posts" ADD COLUMN "category_id" integer
16
+ addConstraint: 'ADD CONSTRAINT',
17
+ //example:
18
+ // DO $$ BEGIN
19
+ // ALTER TABLE "pages_blocks_my_block" ADD CONSTRAINT "pages_blocks_my_block_person_id_users_id_fk" FOREIGN KEY ("person_id") REFERENCES "users"("id") ON DELETE cascade ON UPDATE no action;
20
+ // EXCEPTION
21
+ // WHEN duplicate_object THEN null;
22
+ // END $$;
23
+ dropColumn: 'DROP COLUMN',
24
+ // example: ALTER TABLE "_posts_v_rels" DROP COLUMN IF EXISTS "posts_id";
25
+ dropConstraint: 'DROP CONSTRAINT',
26
+ // example: ALTER TABLE "_posts_v_rels" DROP CONSTRAINT "_posts_v_rels_posts_fk";
27
+ dropTable: 'DROP TABLE',
28
+ // example: DROP TABLE "pages_rels";
29
+ notNull: 'NOT NULL'
30
+ };
31
+ const result = Object.keys(groups).reduce((result, group)=>{
32
+ result[group] = [];
33
+ return result;
34
+ }, {});
35
+ for (const line of list){
36
+ Object.entries(groups).some(([key, value])=>{
37
+ if (line.endsWith('NOT NULL;')) {
38
+ // split up the ADD COLUMN and ALTER COLUMN NOT NULL statements
39
+ // example: ALTER TABLE "pages_blocks_my_block" ADD COLUMN "person_id" integer NOT NULL;
40
+ // becomes two separate statements:
41
+ // 1. ALTER TABLE "pages_blocks_my_block" ADD COLUMN "person_id" integer;
42
+ // 2. ALTER TABLE "pages_blocks_my_block" ALTER COLUMN "person_id" SET NOT NULL;
43
+ result.addColumn.push(line.replace(' NOT NULL;', ';'));
44
+ result.notNull.push(convertAddColumnToAlterColumn(line));
45
+ return true;
46
+ }
47
+ if (line.includes(value)) {
48
+ result[key].push(line);
49
+ return true;
50
+ }
51
+ });
52
+ }
53
+ return result;
54
+ };
55
+
56
+ //# sourceMappingURL=groupUpSQLStatements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/groupUpSQLStatements.ts"],"sourcesContent":["export type Groups =\n | 'addColumn'\n | 'addConstraint'\n | 'dropColumn'\n | 'dropConstraint'\n | 'dropTable'\n | 'notNull'\n\n/**\n * Convert an \"ADD COLUMN\" statement to an \"ALTER COLUMN\" statement\n * example: ALTER TABLE \"pages_blocks_my_block\" ADD COLUMN \"person_id\" integer NOT NULL;\n * to: ALTER TABLE \"pages_blocks_my_block\" ALTER COLUMN \"person_id\" SET NOT NULL;\n * @param sql\n */\nfunction convertAddColumnToAlterColumn(sql) {\n // Regular expression to match the ADD COLUMN statement with its constraints\n const regex = /ALTER TABLE (\"[^\"]+\") ADD COLUMN (\"[^\"]+\") [\\w\\s]+ NOT NULL;/\n\n // Replace the matched part with \"ALTER COLUMN ... SET NOT NULL;\"\n return sql.replace(regex, 'ALTER TABLE $1 ALTER COLUMN $2 SET NOT NULL;')\n}\n\nexport const groupUpSQLStatements = (list: string[]): Record<Groups, string[]> => {\n const groups = {\n addColumn: 'ADD COLUMN',\n // example: ALTER TABLE \"posts\" ADD COLUMN \"category_id\" integer\n\n addConstraint: 'ADD CONSTRAINT',\n //example:\n // DO $$ BEGIN\n // ALTER TABLE \"pages_blocks_my_block\" ADD CONSTRAINT \"pages_blocks_my_block_person_id_users_id_fk\" FOREIGN KEY (\"person_id\") REFERENCES \"users\"(\"id\") ON DELETE cascade ON UPDATE no action;\n // EXCEPTION\n // WHEN duplicate_object THEN null;\n // END $$;\n\n dropColumn: 'DROP COLUMN',\n // example: ALTER TABLE \"_posts_v_rels\" DROP COLUMN IF EXISTS \"posts_id\";\n\n dropConstraint: 'DROP CONSTRAINT',\n // example: ALTER TABLE \"_posts_v_rels\" DROP CONSTRAINT \"_posts_v_rels_posts_fk\";\n\n dropTable: 'DROP TABLE',\n // example: DROP TABLE \"pages_rels\";\n\n notNull: 'NOT NULL',\n // example: ALTER TABLE \"pages_blocks_my_block\" ALTER COLUMN \"person_id\" SET NOT NULL;\n }\n\n const result = Object.keys(groups).reduce((result, group: Groups) => {\n result[group] = []\n return result\n }, {}) as Record<Groups, string[]>\n\n for (const line of list) {\n Object.entries(groups).some(([key, value]) => {\n if (line.endsWith('NOT NULL;')) {\n // split up the ADD COLUMN and ALTER COLUMN NOT NULL statements\n // example: ALTER TABLE \"pages_blocks_my_block\" ADD COLUMN \"person_id\" integer NOT NULL;\n // becomes two separate statements:\n // 1. ALTER TABLE \"pages_blocks_my_block\" ADD COLUMN \"person_id\" integer;\n // 2. ALTER TABLE \"pages_blocks_my_block\" ALTER COLUMN \"person_id\" SET NOT NULL;\n result.addColumn.push(line.replace(' NOT NULL;', ';'))\n result.notNull.push(convertAddColumnToAlterColumn(line))\n return true\n }\n if (line.includes(value)) {\n result[key].push(line)\n return true\n }\n })\n }\n\n return result\n}\n"],"names":["convertAddColumnToAlterColumn","sql","regex","replace","groupUpSQLStatements","list","groups","addColumn","addConstraint","dropColumn","dropConstraint","dropTable","notNull","result","Object","keys","reduce","group","line","entries","some","key","value","endsWith","push","includes"],"mappings":"AAQA;;;;;CAKC,GACD,SAASA,8BAA8BC,GAAG;IACxC,4EAA4E;IAC5E,MAAMC,QAAQ;IAEd,iEAAiE;IACjE,OAAOD,IAAIE,OAAO,CAACD,OAAO;AAC5B;AAEA,OAAO,MAAME,uBAAuB,CAACC;IACnC,MAAMC,SAAS;QACbC,WAAW;QACX,gEAAgE;QAEhEC,eAAe;QACf,UAAU;QACV,cAAc;QACd,8LAA8L;QAC9L,YAAY;QACZ,oCAAoC;QACpC,UAAU;QAEVC,YAAY;QACZ,yEAAyE;QAEzEC,gBAAgB;QAChB,iFAAiF;QAEjFC,WAAW;QACX,oCAAoC;QAEpCC,SAAS;IAEX;IAEA,MAAMC,SAASC,OAAOC,IAAI,CAACT,QAAQU,MAAM,CAAC,CAACH,QAAQI;QACjDJ,MAAM,CAACI,MAAM,GAAG,EAAE;QAClB,OAAOJ;IACT,GAAG,CAAC;IAEJ,KAAK,MAAMK,QAAQb,KAAM;QACvBS,OAAOK,OAAO,CAACb,QAAQc,IAAI,CAAC,CAAC,CAACC,KAAKC,MAAM;YACvC,IAAIJ,KAAKK,QAAQ,CAAC,cAAc;gBAC9B,+DAA+D;gBAC/D,wFAAwF;gBACxF,mCAAmC;gBACnC,0EAA0E;gBAC1E,kFAAkF;gBAClFV,OAAON,SAAS,CAACiB,IAAI,CAACN,KAAKf,OAAO,CAAC,cAAc;gBACjDU,OAAOD,OAAO,CAACY,IAAI,CAACxB,8BAA8BkB;gBAClD,OAAO;YACT;YACA,IAAIA,KAAKO,QAAQ,CAACH,QAAQ;gBACxBT,MAAM,CAACQ,IAAI,CAACG,IAAI,CAACN;gBACjB,OAAO;YACT;QACF;IACF;IAEA,OAAOL;AACT,EAAC"}
@@ -0,0 +1,23 @@
1
+ import type { Payload, PayloadRequestWithData } from 'payload';
2
+ type Args = {
3
+ debug?: boolean;
4
+ payload: Payload;
5
+ req?: Partial<PayloadRequestWithData>;
6
+ };
7
+ /**
8
+ * Moves upload and relationship columns from the join table and into the tables while moving data
9
+ * This is done in the following order:
10
+ * ADD COLUMNs
11
+ * -- manipulate data to move relationships to new columns
12
+ * ADD CONSTRAINTs
13
+ * NOT NULLs
14
+ * DROP TABLEs
15
+ * DROP CONSTRAINTs
16
+ * DROP COLUMNs
17
+ * @param debug
18
+ * @param payload
19
+ * @param req
20
+ */
21
+ export declare const migratePostgresV2toV3: ({ debug, payload, req }: Args) => Promise<void>;
22
+ export {};
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAiB9D,KAAK,IAAI,GAAG;IACV,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAA;CACtC,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,4BAAmC,IAAI,kBA8OxE,CAAA"}
@@ -0,0 +1,211 @@
1
+ import { sql } from 'drizzle-orm';
2
+ import fs from 'fs';
3
+ import { createRequire } from 'module';
4
+ import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
5
+ import toSnakeCase from 'to-snake-case';
6
+ import { groupUpSQLStatements } from './groupUpSQLStatements.js';
7
+ import { migrateRelationships } from './migrateRelationships.js';
8
+ import { traverseFields } from './traverseFields.js';
9
+ const require = createRequire(import.meta.url);
10
+ /**
11
+ * Moves upload and relationship columns from the join table and into the tables while moving data
12
+ * This is done in the following order:
13
+ * ADD COLUMNs
14
+ * -- manipulate data to move relationships to new columns
15
+ * ADD CONSTRAINTs
16
+ * NOT NULLs
17
+ * DROP TABLEs
18
+ * DROP CONSTRAINTs
19
+ * DROP COLUMNs
20
+ * @param debug
21
+ * @param payload
22
+ * @param req
23
+ */ export const migratePostgresV2toV3 = async ({ debug, payload, req })=>{
24
+ const adapter = payload.db;
25
+ const db = adapter.sessions[req.transactionID]?.db;
26
+ const dir = payload.db.migrationDir;
27
+ // get the drizzle migrateUpSQL from drizzle using the last schema
28
+ const { generateDrizzleJson, generateMigration } = require('drizzle-kit/payload');
29
+ const drizzleJsonAfter = generateDrizzleJson(adapter.schema);
30
+ // Get the previous migration snapshot
31
+ const previousSnapshot = fs.readdirSync(dir).filter((file)=>file.endsWith('.json') && !file.endsWith('relationships_v2_v3.json')).sort().reverse()?.[0];
32
+ if (!previousSnapshot) {
33
+ throw new Error(`No previous migration schema file found! A prior migration from v2 is required to migrate to v3.`);
34
+ }
35
+ const drizzleJsonBefore = JSON.parse(fs.readFileSync(`${dir}/${previousSnapshot}`, 'utf8'));
36
+ const generatedSQL = await generateMigration(drizzleJsonBefore, drizzleJsonAfter);
37
+ if (!generatedSQL.length) {
38
+ payload.logger.info(`No schema changes needed.`);
39
+ process.exit(0);
40
+ }
41
+ const sqlUpStatements = groupUpSQLStatements(generatedSQL);
42
+ const addColumnsStatement = sqlUpStatements.addColumn.join('\n');
43
+ if (debug) {
44
+ payload.logger.info('CREATING NEW RELATIONSHIP COLUMNS');
45
+ payload.logger.info(addColumnsStatement);
46
+ }
47
+ await db.execute(sql.raw(addColumnsStatement));
48
+ for (const collection of payload.config.collections){
49
+ const tableName = adapter.tableNameMap.get(toSnakeCase(collection.slug));
50
+ const pathsToQuery = new Set();
51
+ traverseFields({
52
+ adapter,
53
+ collectionSlug: collection.slug,
54
+ columnPrefix: '',
55
+ db,
56
+ disableNotNull: false,
57
+ fields: collection.fields,
58
+ isVersions: false,
59
+ newTableName: tableName,
60
+ parentTableName: tableName,
61
+ path: '',
62
+ pathsToQuery,
63
+ payload,
64
+ rootTableName: tableName
65
+ });
66
+ await migrateRelationships({
67
+ adapter,
68
+ collectionSlug: collection.slug,
69
+ db,
70
+ debug,
71
+ fields: collection.fields,
72
+ isVersions: false,
73
+ pathsToQuery,
74
+ payload,
75
+ req,
76
+ tableName
77
+ });
78
+ if (collection.versions) {
79
+ const versionsTableName = adapter.tableNameMap.get(`_${toSnakeCase(collection.slug)}${adapter.versionsSuffix}`);
80
+ const versionFields = buildVersionCollectionFields(collection);
81
+ const versionPathsToQuery = new Set();
82
+ traverseFields({
83
+ adapter,
84
+ collectionSlug: collection.slug,
85
+ columnPrefix: '',
86
+ db,
87
+ disableNotNull: true,
88
+ fields: versionFields,
89
+ isVersions: true,
90
+ newTableName: versionsTableName,
91
+ parentTableName: versionsTableName,
92
+ path: '',
93
+ pathsToQuery: versionPathsToQuery,
94
+ payload,
95
+ rootTableName: versionsTableName
96
+ });
97
+ await migrateRelationships({
98
+ adapter,
99
+ collectionSlug: collection.slug,
100
+ db,
101
+ debug,
102
+ fields: versionFields,
103
+ isVersions: true,
104
+ pathsToQuery: versionPathsToQuery,
105
+ payload,
106
+ req,
107
+ tableName: versionsTableName
108
+ });
109
+ }
110
+ }
111
+ for (const global of payload.config.globals){
112
+ const tableName = adapter.tableNameMap.get(toSnakeCase(global.slug));
113
+ const pathsToQuery = new Set();
114
+ traverseFields({
115
+ adapter,
116
+ columnPrefix: '',
117
+ db,
118
+ disableNotNull: false,
119
+ fields: global.fields,
120
+ globalSlug: global.slug,
121
+ isVersions: false,
122
+ newTableName: tableName,
123
+ parentTableName: tableName,
124
+ path: '',
125
+ pathsToQuery,
126
+ payload,
127
+ rootTableName: tableName
128
+ });
129
+ await migrateRelationships({
130
+ adapter,
131
+ db,
132
+ debug,
133
+ fields: global.fields,
134
+ globalSlug: global.slug,
135
+ isVersions: false,
136
+ pathsToQuery,
137
+ payload,
138
+ req,
139
+ tableName
140
+ });
141
+ if (global.versions) {
142
+ const versionsTableName = adapter.tableNameMap.get(`_${toSnakeCase(global.slug)}${adapter.versionsSuffix}`);
143
+ const versionFields = buildVersionGlobalFields(global);
144
+ const versionPathsToQuery = new Set();
145
+ traverseFields({
146
+ adapter,
147
+ columnPrefix: '',
148
+ db,
149
+ disableNotNull: true,
150
+ fields: versionFields,
151
+ globalSlug: global.slug,
152
+ isVersions: true,
153
+ newTableName: versionsTableName,
154
+ parentTableName: versionsTableName,
155
+ path: '',
156
+ pathsToQuery: versionPathsToQuery,
157
+ payload,
158
+ rootTableName: versionsTableName
159
+ });
160
+ await migrateRelationships({
161
+ adapter,
162
+ db,
163
+ debug,
164
+ fields: versionFields,
165
+ globalSlug: global.slug,
166
+ isVersions: true,
167
+ pathsToQuery: versionPathsToQuery,
168
+ payload,
169
+ req,
170
+ tableName: versionsTableName
171
+ });
172
+ }
173
+ }
174
+ // ADD CONSTRAINT
175
+ const addConstraintsStatement = sqlUpStatements.addConstraint.join('\n');
176
+ if (debug) {
177
+ payload.logger.info('ADDING CONSTRAINTS');
178
+ payload.logger.info(addConstraintsStatement);
179
+ }
180
+ await db.execute(sql.raw(addConstraintsStatement));
181
+ // NOT NULL
182
+ const notNullStatements = sqlUpStatements.notNull.join('\n');
183
+ if (debug) {
184
+ payload.logger.info('NOT NULL CONSTRAINTS');
185
+ payload.logger.info(notNullStatements);
186
+ }
187
+ await db.execute(sql.raw(notNullStatements));
188
+ // DROP TABLE
189
+ const dropTablesStatement = sqlUpStatements.dropTable.join('\n');
190
+ if (debug) {
191
+ payload.logger.info('DROPPING TABLES');
192
+ payload.logger.info(dropTablesStatement);
193
+ }
194
+ await db.execute(sql.raw(dropTablesStatement));
195
+ // DROP CONSTRAINT
196
+ const dropConstraintsStatement = sqlUpStatements.dropConstraint.join('\n');
197
+ if (debug) {
198
+ payload.logger.info('DROPPING CONSTRAINTS');
199
+ payload.logger.info(dropConstraintsStatement);
200
+ }
201
+ await db.execute(sql.raw(dropConstraintsStatement));
202
+ // DROP COLUMN
203
+ const dropColumnsStatement = sqlUpStatements.dropColumn.join('\n');
204
+ if (debug) {
205
+ payload.logger.info('DROPPING COLUMNS');
206
+ payload.logger.info(dropColumnsStatement);
207
+ }
208
+ await db.execute(sql.raw(dropColumnsStatement));
209
+ };
210
+
211
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/index.ts"],"sourcesContent":["import type { DrizzleSnapshotJSON } from 'drizzle-kit/payload'\nimport type { Payload, PayloadRequestWithData } from 'payload'\n\nimport { sql } from 'drizzle-orm'\nimport fs from 'fs'\nimport { createRequire } from 'module'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { PathsToQuery } from './types.js'\n\nimport { groupUpSQLStatements } from './groupUpSQLStatements.js'\nimport { migrateRelationships } from './migrateRelationships.js'\nimport { traverseFields } from './traverseFields.js'\n\nconst require = createRequire(import.meta.url)\n\ntype Args = {\n debug?: boolean\n payload: Payload\n req?: Partial<PayloadRequestWithData>\n}\n\n/**\n * Moves upload and relationship columns from the join table and into the tables while moving data\n * This is done in the following order:\n * ADD COLUMNs\n * -- manipulate data to move relationships to new columns\n * ADD CONSTRAINTs\n * NOT NULLs\n * DROP TABLEs\n * DROP CONSTRAINTs\n * DROP COLUMNs\n * @param debug\n * @param payload\n * @param req\n */\nexport const migratePostgresV2toV3 = async ({ debug, payload, req }: Args) => {\n const adapter = payload.db as PostgresAdapter\n const db = adapter.sessions[req.transactionID]?.db\n const dir = payload.db.migrationDir\n\n // get the drizzle migrateUpSQL from drizzle using the last schema\n const { generateDrizzleJson, generateMigration } = require('drizzle-kit/payload')\n const drizzleJsonAfter = generateDrizzleJson(adapter.schema)\n\n // Get the previous migration snapshot\n const previousSnapshot = fs\n .readdirSync(dir)\n .filter((file) => file.endsWith('.json') && !file.endsWith('relationships_v2_v3.json'))\n .sort()\n .reverse()?.[0]\n\n if (!previousSnapshot) {\n throw new Error(\n `No previous migration schema file found! A prior migration from v2 is required to migrate to v3.`,\n )\n }\n\n const drizzleJsonBefore = JSON.parse(\n fs.readFileSync(`${dir}/${previousSnapshot}`, 'utf8'),\n ) as DrizzleSnapshotJSON\n\n const generatedSQL = await generateMigration(drizzleJsonBefore, drizzleJsonAfter)\n\n if (!generatedSQL.length) {\n payload.logger.info(`No schema changes needed.`)\n process.exit(0)\n }\n\n const sqlUpStatements = groupUpSQLStatements(generatedSQL)\n\n const addColumnsStatement = sqlUpStatements.addColumn.join('\\n')\n\n if (debug) {\n payload.logger.info('CREATING NEW RELATIONSHIP COLUMNS')\n payload.logger.info(addColumnsStatement)\n }\n\n await db.execute(sql.raw(addColumnsStatement))\n\n for (const collection of payload.config.collections) {\n const tableName = adapter.tableNameMap.get(toSnakeCase(collection.slug))\n const pathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n collectionSlug: collection.slug,\n columnPrefix: '',\n db,\n disableNotNull: false,\n fields: collection.fields,\n isVersions: false,\n newTableName: tableName,\n parentTableName: tableName,\n path: '',\n pathsToQuery,\n payload,\n rootTableName: tableName,\n })\n\n await migrateRelationships({\n adapter,\n collectionSlug: collection.slug,\n db,\n debug,\n fields: collection.fields,\n isVersions: false,\n pathsToQuery,\n payload,\n req,\n tableName,\n })\n\n if (collection.versions) {\n const versionsTableName = adapter.tableNameMap.get(\n `_${toSnakeCase(collection.slug)}${adapter.versionsSuffix}`,\n )\n const versionFields = buildVersionCollectionFields(collection)\n const versionPathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n collectionSlug: collection.slug,\n columnPrefix: '',\n db,\n disableNotNull: true,\n fields: versionFields,\n isVersions: true,\n newTableName: versionsTableName,\n parentTableName: versionsTableName,\n path: '',\n pathsToQuery: versionPathsToQuery,\n payload,\n rootTableName: versionsTableName,\n })\n\n await migrateRelationships({\n adapter,\n collectionSlug: collection.slug,\n db,\n debug,\n fields: versionFields,\n isVersions: true,\n pathsToQuery: versionPathsToQuery,\n payload,\n req,\n tableName: versionsTableName,\n })\n }\n }\n\n for (const global of payload.config.globals) {\n const tableName = adapter.tableNameMap.get(toSnakeCase(global.slug))\n\n const pathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n columnPrefix: '',\n db,\n disableNotNull: false,\n fields: global.fields,\n globalSlug: global.slug,\n isVersions: false,\n newTableName: tableName,\n parentTableName: tableName,\n path: '',\n pathsToQuery,\n payload,\n rootTableName: tableName,\n })\n\n await migrateRelationships({\n adapter,\n db,\n debug,\n fields: global.fields,\n globalSlug: global.slug,\n isVersions: false,\n pathsToQuery,\n payload,\n req,\n tableName,\n })\n\n if (global.versions) {\n const versionsTableName = adapter.tableNameMap.get(\n `_${toSnakeCase(global.slug)}${adapter.versionsSuffix}`,\n )\n\n const versionFields = buildVersionGlobalFields(global)\n\n const versionPathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n columnPrefix: '',\n db,\n disableNotNull: true,\n fields: versionFields,\n globalSlug: global.slug,\n isVersions: true,\n newTableName: versionsTableName,\n parentTableName: versionsTableName,\n path: '',\n pathsToQuery: versionPathsToQuery,\n payload,\n rootTableName: versionsTableName,\n })\n\n await migrateRelationships({\n adapter,\n db,\n debug,\n fields: versionFields,\n globalSlug: global.slug,\n isVersions: true,\n pathsToQuery: versionPathsToQuery,\n payload,\n req,\n tableName: versionsTableName,\n })\n }\n }\n\n // ADD CONSTRAINT\n const addConstraintsStatement = sqlUpStatements.addConstraint.join('\\n')\n\n if (debug) {\n payload.logger.info('ADDING CONSTRAINTS')\n payload.logger.info(addConstraintsStatement)\n }\n\n await db.execute(sql.raw(addConstraintsStatement))\n\n // NOT NULL\n const notNullStatements = sqlUpStatements.notNull.join('\\n')\n\n if (debug) {\n payload.logger.info('NOT NULL CONSTRAINTS')\n payload.logger.info(notNullStatements)\n }\n\n await db.execute(sql.raw(notNullStatements))\n\n // DROP TABLE\n const dropTablesStatement = sqlUpStatements.dropTable.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING TABLES')\n payload.logger.info(dropTablesStatement)\n }\n\n await db.execute(sql.raw(dropTablesStatement))\n\n // DROP CONSTRAINT\n const dropConstraintsStatement = sqlUpStatements.dropConstraint.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING CONSTRAINTS')\n payload.logger.info(dropConstraintsStatement)\n }\n\n await db.execute(sql.raw(dropConstraintsStatement))\n\n // DROP COLUMN\n const dropColumnsStatement = sqlUpStatements.dropColumn.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING COLUMNS')\n payload.logger.info(dropColumnsStatement)\n }\n\n await db.execute(sql.raw(dropColumnsStatement))\n}\n"],"names":["sql","fs","createRequire","buildVersionCollectionFields","buildVersionGlobalFields","toSnakeCase","groupUpSQLStatements","migrateRelationships","traverseFields","require","url","migratePostgresV2toV3","debug","payload","req","adapter","db","sessions","transactionID","dir","migrationDir","generateDrizzleJson","generateMigration","drizzleJsonAfter","schema","previousSnapshot","readdirSync","filter","file","endsWith","sort","reverse","Error","drizzleJsonBefore","JSON","parse","readFileSync","generatedSQL","length","logger","info","process","exit","sqlUpStatements","addColumnsStatement","addColumn","join","execute","raw","collection","config","collections","tableName","tableNameMap","get","slug","pathsToQuery","Set","collectionSlug","columnPrefix","disableNotNull","fields","isVersions","newTableName","parentTableName","path","rootTableName","versions","versionsTableName","versionsSuffix","versionFields","versionPathsToQuery","global","globals","globalSlug","addConstraintsStatement","addConstraint","notNullStatements","notNull","dropTablesStatement","dropTable","dropConstraintsStatement","dropConstraint","dropColumnsStatement","dropColumn"],"mappings":"AAGA,SAASA,GAAG,QAAQ,cAAa;AACjC,OAAOC,QAAQ,KAAI;AACnB,SAASC,aAAa,QAAQ,SAAQ;AACtC,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAChF,OAAOC,iBAAiB,gBAAe;AAKvC,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,cAAc,QAAQ,sBAAqB;AAEpD,MAAMC,UAAUP,cAAc,YAAYQ,GAAG;AAQ7C;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMC,wBAAwB,OAAO,EAAEC,KAAK,EAAEC,OAAO,EAAEC,GAAG,EAAQ;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I,CAAC;IAEvD,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAACqC;IACtB;IAEA,MAAM7D,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAAC6B;IAEzB,aAAa;IACb,MAAME,sBAAsBpC,gBAAgBqC,SAAS,CAAClC,IAAI,CAAC;IAE3D,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAACuC;IACtB;IAEA,MAAM/D,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAAC+B;IAEzB,kBAAkB;IAClB,MAAME,2BAA2BtC,gBAAgBuC,cAAc,CAACpC,IAAI,CAAC;IAErE,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAACyC;IACtB;IAEA,MAAMjE,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAACiC;IAEzB,cAAc;IACd,MAAME,uBAAuBxC,gBAAgByC,UAAU,CAACtC,IAAI,CAAC;IAE7D,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAAC2C;IACtB;IAEA,MAAMnE,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAACmC;AAC3B,EAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Field, Payload, PayloadRequestWithData } from 'payload';
2
+ import type { DrizzleTransaction, PostgresAdapter } from '../../types.js';
3
+ import type { PathsToQuery } from './types.js';
4
+ type Args = {
5
+ adapter: PostgresAdapter;
6
+ collectionSlug?: string;
7
+ db: DrizzleTransaction;
8
+ debug: boolean;
9
+ fields: Field[];
10
+ globalSlug?: string;
11
+ isVersions: boolean;
12
+ pathsToQuery: PathsToQuery;
13
+ payload: Payload;
14
+ req?: Partial<PayloadRequestWithData>;
15
+ tableName: string;
16
+ };
17
+ export declare const migrateRelationships: ({ adapter, collectionSlug, db, debug, fields, globalSlug, isVersions, pathsToQuery, payload, req, tableName, }: Args) => Promise<void>;
18
+ export {};
19
+ //# sourceMappingURL=migrateRelationships.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrateRelationships.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/migrateRelationships.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAIrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,YAAY,CAAA;AAI5D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,kBAAkB,CAAA;IACtB,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,YAAY,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAA;IACrC,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,oBAAoB,mHAY9B,IAAI,kBAkEN,CAAA"}
@@ -0,0 +1,57 @@
1
+ import { sql } from 'drizzle-orm';
2
+ import { fetchAndResave } from './fetchAndResave/index.js';
3
+ export const migrateRelationships = async ({ adapter, collectionSlug, db, debug, fields, globalSlug, isVersions, pathsToQuery, payload, req, tableName })=>{
4
+ if (pathsToQuery.size === 0) return;
5
+ let offset = 0;
6
+ let paginationResult;
7
+ const where = Array.from(pathsToQuery).reduce((statement, path, i)=>{
8
+ return statement += `
9
+ "${tableName}${adapter.relationshipsSuffix}"."path" LIKE '${path}'${pathsToQuery.size !== i + 1 ? ' OR' : ''}
10
+ `;
11
+ }, '');
12
+ while(typeof paginationResult === 'undefined' || paginationResult.rows.length > 0){
13
+ const paginationStatement = `SELECT DISTINCT parent_id FROM ${tableName}${adapter.relationshipsSuffix} WHERE
14
+ ${where} ORDER BY parent_id LIMIT 500 OFFSET ${offset * 500};
15
+ `;
16
+ paginationResult = await adapter.drizzle.execute(sql.raw(`${paginationStatement}`));
17
+ if (paginationResult.rows.length === 0) return;
18
+ offset += 1;
19
+ const statement = `SELECT * FROM ${tableName}${adapter.relationshipsSuffix} WHERE
20
+ (${where}) AND parent_id IN (${paginationResult.rows.map((row)=>row.parent_id).join(', ')});
21
+ `;
22
+ if (debug) {
23
+ payload.logger.info('FINDING ROWS TO MIGRATE');
24
+ payload.logger.info(statement);
25
+ }
26
+ const result = await adapter.drizzle.execute(sql.raw(`${statement}`));
27
+ const docsToResave = {};
28
+ result.rows.forEach((row)=>{
29
+ const parentID = row.parent_id;
30
+ if (typeof parentID === 'string' || typeof parentID === 'number') {
31
+ if (!docsToResave[parentID]) docsToResave[parentID] = [];
32
+ docsToResave[parentID].push(row);
33
+ }
34
+ });
35
+ await fetchAndResave({
36
+ adapter,
37
+ collectionSlug,
38
+ db,
39
+ debug,
40
+ docsToResave,
41
+ fields,
42
+ globalSlug,
43
+ isVersions,
44
+ payload,
45
+ req: req,
46
+ tableName
47
+ });
48
+ }
49
+ const deleteStatement = `DELETE FROM ${tableName}${adapter.relationshipsSuffix} WHERE ${where}`;
50
+ if (debug) {
51
+ payload.logger.info('DELETING ROWS');
52
+ payload.logger.info(deleteStatement);
53
+ }
54
+ await db.execute(sql.raw(`${deleteStatement}`));
55
+ };
56
+
57
+ //# sourceMappingURL=migrateRelationships.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/migrateRelationships.ts"],"sourcesContent":["import type { Field, Payload, PayloadRequestWithData } from 'payload'\n\nimport { sql } from 'drizzle-orm'\n\nimport type { DrizzleTransaction, PostgresAdapter } from '../../types.js'\nimport type { DocsToResave, PathsToQuery } from './types.js'\n\nimport { fetchAndResave } from './fetchAndResave/index.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n db: DrizzleTransaction\n debug: boolean\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n pathsToQuery: PathsToQuery\n payload: Payload\n req?: Partial<PayloadRequestWithData>\n tableName: string\n}\n\nexport const migrateRelationships = async ({\n adapter,\n collectionSlug,\n db,\n debug,\n fields,\n globalSlug,\n isVersions,\n pathsToQuery,\n payload,\n req,\n tableName,\n}: Args) => {\n if (pathsToQuery.size === 0) return\n\n let offset = 0\n\n let paginationResult\n\n const where = Array.from(pathsToQuery).reduce((statement, path, i) => {\n return (statement += `\n\"${tableName}${adapter.relationshipsSuffix}\".\"path\" LIKE '${path}'${pathsToQuery.size !== i + 1 ? ' OR' : ''}\n`)\n }, '')\n\n while (typeof paginationResult === 'undefined' || paginationResult.rows.length > 0) {\n const paginationStatement = `SELECT DISTINCT parent_id FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n ${where} ORDER BY parent_id LIMIT 500 OFFSET ${offset * 500};\n `\n\n paginationResult = await adapter.drizzle.execute(sql.raw(`${paginationStatement}`))\n\n if (paginationResult.rows.length === 0) return\n\n offset += 1\n\n const statement = `SELECT * FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n (${where}) AND parent_id IN (${paginationResult.rows.map((row) => row.parent_id).join(', ')});\n`\n if (debug) {\n payload.logger.info('FINDING ROWS TO MIGRATE')\n payload.logger.info(statement)\n }\n\n const result = await adapter.drizzle.execute(sql.raw(`${statement}`))\n\n const docsToResave: DocsToResave = {}\n\n result.rows.forEach((row) => {\n const parentID = row.parent_id\n\n if (typeof parentID === 'string' || typeof parentID === 'number') {\n if (!docsToResave[parentID]) docsToResave[parentID] = []\n docsToResave[parentID].push(row)\n }\n })\n\n await fetchAndResave({\n adapter,\n collectionSlug,\n db,\n debug,\n docsToResave,\n fields,\n globalSlug,\n isVersions,\n payload,\n req: req as unknown as PayloadRequestWithData,\n tableName,\n })\n }\n\n const deleteStatement = `DELETE FROM ${tableName}${adapter.relationshipsSuffix} WHERE ${where}`\n if (debug) {\n payload.logger.info('DELETING ROWS')\n payload.logger.info(deleteStatement)\n }\n await db.execute(sql.raw(`${deleteStatement}`))\n}\n"],"names":["sql","fetchAndResave","migrateRelationships","adapter","collectionSlug","db","debug","fields","globalSlug","isVersions","pathsToQuery","payload","req","tableName","size","offset","paginationResult","where","Array","from","reduce","statement","path","i","relationshipsSuffix","rows","length","paginationStatement","drizzle","execute","raw","map","row","parent_id","join","logger","info","result","docsToResave","forEach","parentID","push","deleteStatement"],"mappings":"AAEA,SAASA,GAAG,QAAQ,cAAa;AAKjC,SAASC,cAAc,QAAQ,4BAA2B;AAgB1D,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,OAAO,EACPC,cAAc,EACdC,EAAE,EACFC,KAAK,EACLC,MAAM,EACNC,UAAU,EACVC,UAAU,EACVC,YAAY,EACZC,OAAO,EACPC,GAAG,EACHC,SAAS,EACJ;IACL,IAAIH,aAAaI,IAAI,KAAK,GAAG;IAE7B,IAAIC,SAAS;IAEb,IAAIC;IAEJ,MAAMC,QAAQC,MAAMC,IAAI,CAACT,cAAcU,MAAM,CAAC,CAACC,WAAWC,MAAMC;QAC9D,OAAQF,aAAa,CAAC;CACzB,EAAER,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC,eAAe,EAAEF,KAAK,CAAC,EAAEZ,aAAaI,IAAI,KAAKS,IAAI,IAAI,QAAQ,GAAG;AAC7G,CAAC;IACC,GAAG;IAEH,MAAO,OAAOP,qBAAqB,eAAeA,iBAAiBS,IAAI,CAACC,MAAM,GAAG,EAAG;QAClF,MAAMC,sBAAsB,CAAC,+BAA+B,EAAEd,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC;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MAAM,CAACC,IAAI,CAACM;IACtB;IACA,MAAMrC,GAAGwB,OAAO,CAAC7B,IAAI8B,GAAG,CAAC,CAAC,EAAEY,gBAAgB,CAAC;AAC/C,EAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Field, Payload } from 'payload';
2
+ import type { DrizzleTransaction, PostgresAdapter } from '../../types.js';
3
+ import type { PathsToQuery } from './types.js';
4
+ type Args = {
5
+ adapter: PostgresAdapter;
6
+ collectionSlug?: string;
7
+ columnPrefix: string;
8
+ db: DrizzleTransaction;
9
+ disableNotNull: boolean;
10
+ fields: Field[];
11
+ globalSlug?: string;
12
+ isVersions: boolean;
13
+ newTableName: string;
14
+ parentTableName: string;
15
+ path: string;
16
+ pathsToQuery: PathsToQuery;
17
+ payload: Payload;
18
+ rootTableName: string;
19
+ };
20
+ export declare const traverseFields: (args: Args) => void;
21
+ export {};
22
+ //# sourceMappingURL=traverseFields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAK7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,EAAE,EAAE,kBAAkB,CAAA;IACtB,cAAc,EAAE,OAAO,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,YAAY,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,cAAc,SAAU,IAAI,SA0FxC,CAAA"}
@@ -0,0 +1,85 @@
1
+ import { tabHasName } from 'payload/shared';
2
+ import toSnakeCase from 'to-snake-case';
3
+ export const traverseFields = (args)=>{
4
+ args.fields.forEach((field)=>{
5
+ switch(field.type){
6
+ case 'group':
7
+ {
8
+ let newTableName = `${args.newTableName}_${toSnakeCase(field.name)}`;
9
+ if (field.localized && args.payload.config.localization) {
10
+ newTableName += args.adapter.localesSuffix;
11
+ }
12
+ return traverseFields({
13
+ ...args,
14
+ columnPrefix: `${args.columnPrefix}${toSnakeCase(field.name)}_`,
15
+ fields: field.fields,
16
+ newTableName,
17
+ path: `${args.path ? `${args.path}.` : ''}${field.name}`
18
+ });
19
+ }
20
+ case 'row':
21
+ case 'collapsible':
22
+ {
23
+ return traverseFields({
24
+ ...args,
25
+ fields: field.fields
26
+ });
27
+ }
28
+ case 'array':
29
+ {
30
+ const newTableName = args.adapter.tableNameMap.get(`${args.newTableName}_${toSnakeCase(field.name)}`);
31
+ return traverseFields({
32
+ ...args,
33
+ columnPrefix: '',
34
+ fields: field.fields,
35
+ newTableName,
36
+ parentTableName: newTableName,
37
+ path: `${args.path ? `${args.path}.` : ''}${field.name}.%`
38
+ });
39
+ }
40
+ case 'blocks':
41
+ {
42
+ return field.blocks.forEach((block)=>{
43
+ const newTableName = args.adapter.tableNameMap.get(`${args.rootTableName}_blocks_${toSnakeCase(block.slug)}`);
44
+ traverseFields({
45
+ ...args,
46
+ columnPrefix: '',
47
+ fields: block.fields,
48
+ newTableName,
49
+ parentTableName: newTableName,
50
+ path: `${args.path ? `${args.path}.` : ''}${field.name}.%`
51
+ });
52
+ });
53
+ }
54
+ case 'tabs':
55
+ {
56
+ return field.tabs.forEach((tab)=>{
57
+ if (tabHasName(tab)) {
58
+ args.columnPrefix = `${args.columnPrefix}_${toSnakeCase(tab.name)}_`;
59
+ args.path = `${args.path ? `${args.path}.` : ''}${tab.name}`;
60
+ args.newTableName = `${args.newTableName}_${toSnakeCase(tab.name)}`;
61
+ if (tab.localized && args.payload.config.localization) {
62
+ args.newTableName += args.adapter.localesSuffix;
63
+ }
64
+ }
65
+ traverseFields({
66
+ ...args,
67
+ fields: tab.fields
68
+ });
69
+ });
70
+ }
71
+ case 'relationship':
72
+ case 'upload':
73
+ {
74
+ if (typeof field.relationTo === 'string') {
75
+ if (field.type === 'upload' || !field.hasMany) {
76
+ args.pathsToQuery.add(`${args.path ? `${args.path}.` : ''}${field.name}`);
77
+ }
78
+ }
79
+ return null;
80
+ }
81
+ }
82
+ });
83
+ };
84
+
85
+ //# sourceMappingURL=traverseFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/traverseFields.ts"],"sourcesContent":["import type { Field, Payload } from 'payload'\n\nimport { tabHasName } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleTransaction, PostgresAdapter } from '../../types.js'\nimport type { PathsToQuery } from './types.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n columnPrefix: string\n db: DrizzleTransaction\n disableNotNull: boolean\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n newTableName: string\n parentTableName: string\n path: string\n pathsToQuery: PathsToQuery\n payload: Payload\n rootTableName: string\n}\n\nexport const traverseFields = (args: Args) => {\n args.fields.forEach((field) => {\n switch (field.type) {\n case 'group': {\n let newTableName = `${args.newTableName}_${toSnakeCase(field.name)}`\n\n if (field.localized && args.payload.config.localization) {\n newTableName += args.adapter.localesSuffix\n }\n\n return traverseFields({\n ...args,\n columnPrefix: `${args.columnPrefix}${toSnakeCase(field.name)}_`,\n fields: field.fields,\n newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}`,\n })\n }\n\n case 'row':\n case 'collapsible': {\n return traverseFields({\n ...args,\n fields: field.fields,\n })\n }\n\n case 'array': {\n const newTableName = args.adapter.tableNameMap.get(\n `${args.newTableName}_${toSnakeCase(field.name)}`,\n )\n\n return traverseFields({\n ...args,\n columnPrefix: '',\n fields: field.fields,\n newTableName,\n parentTableName: newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}.%`,\n })\n }\n\n case 'blocks': {\n return field.blocks.forEach((block) => {\n const newTableName = args.adapter.tableNameMap.get(\n `${args.rootTableName}_blocks_${toSnakeCase(block.slug)}`,\n )\n\n traverseFields({\n ...args,\n columnPrefix: '',\n fields: block.fields,\n newTableName,\n parentTableName: newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}.%`,\n })\n })\n }\n\n case 'tabs': {\n return field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n args.columnPrefix = `${args.columnPrefix}_${toSnakeCase(tab.name)}_`\n args.path = `${args.path ? `${args.path}.` : ''}${tab.name}`\n args.newTableName = `${args.newTableName}_${toSnakeCase(tab.name)}`\n\n if (tab.localized && args.payload.config.localization) {\n args.newTableName += args.adapter.localesSuffix\n }\n }\n\n traverseFields({\n ...args,\n fields: tab.fields,\n })\n })\n }\n\n case 'relationship':\n case 'upload': {\n if (typeof field.relationTo === 'string') {\n if (field.type === 'upload' || !field.hasMany) {\n args.pathsToQuery.add(`${args.path ? `${args.path}.` : ''}${field.name}`)\n }\n }\n\n return null\n }\n }\n })\n}\n"],"names":["tabHasName","toSnakeCase","traverseFields","args","fields","forEach","field","type","newTableName","name","localized","payload","config","localization","adapter","localesSuffix","columnPrefix","path","tableNameMap","get","parentTableName","blocks","block","rootTableName","slug","tabs","tab","relationTo","hasMany","pathsToQuery","add"],"mappings":"AAEA,SAASA,UAAU,QAAQ,iBAAgB;AAC3C,OAAOC,iBAAiB,gBAAe;AAsBvC,OAAO,MAAMC,iBAAiB,CAACC;IAC7BA,KAAKC,MAAM,CAACC,OAAO,CAAC,CAACC;QACnB,OAAQA,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,EAAE;4BAC7CzB,KAAK0B,YAAY,CAACC,GAAG,CAAC,CAAC,EAAE3B,KAAKc,IAAI,GAAG,CAAC,EAAEd,KAAKc,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,EAAEX,MAAMG,IAAI,CAAC,CAAC;wBAC1E;oBACF;oBAEA,OAAO;gBACT;QACF;IACF;AACF,EAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Set of all paths which should be moved
3
+ * This will be built up into one WHERE query
4
+ */
5
+ export type PathsToQuery = Set<string>;
6
+ export type DocsToResave = {
7
+ [id: number | string]: Record<string, unknown>[];
8
+ };
9
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC,CAAA;AAEtC,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CACjD,CAAA"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Set of all paths which should be moved
3
+ * This will be built up into one WHERE query
4
+ */ export { };
5
+
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/types.ts"],"sourcesContent":["/**\n * Set of all paths which should be moved\n * This will be built up into one WHERE query\n */\nexport type PathsToQuery = Set<string>\n\nexport type DocsToResave = {\n [id: number | string]: Record<string, unknown>[]\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GAGD,WAEC"}
@@ -1,14 +1,13 @@
1
1
  import type { SQL } from 'drizzle-orm';
2
- import type { Field, Where } from 'payload/types';
2
+ import type { Field, Where } from 'payload';
3
3
  import type { GenericColumn, PostgresAdapter } from '../types.js';
4
- import type { BuildQueryJoinAliases, BuildQueryJoins } from './buildQuery.js';
5
- export declare function buildAndOrConditions({ adapter, fields, joinAliases, joins, locale, selectFields, tableName, where, }: {
4
+ import type { BuildQueryJoinAliases } from './buildQuery.js';
5
+ export declare function buildAndOrConditions({ adapter, fields, joins, locale, selectFields, tableName, where, }: {
6
6
  adapter: PostgresAdapter;
7
7
  collectionSlug?: string;
8
8
  fields: Field[];
9
9
  globalSlug?: string;
10
- joinAliases: BuildQueryJoinAliases;
11
- joins: BuildQueryJoins;
10
+ joins: BuildQueryJoinAliases;
12
11
  locale?: string;
13
12
  selectFields: Record<string, GenericColumn>;
14
13
  tableName: string;
@@ -1 +1 @@
1
- {"version":3,"file":"buildAndOrConditions.d.ts","sourceRoot":"","sources":["../../src/queries/buildAndOrConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAI7E,wBAAsB,oBAAoB,CAAC,EACzC,OAAO,EACP,MAAM,EACN,WAAW,EACX,KAAK,EACL,MAAM,EACN,YAAY,EACZ,SAAS,EACT,KAAK,GACN,EAAE;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,qBAAqB,CAAA;IAClC,KAAK,EAAE,eAAe,CAAA;IACtB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAyBjB"}
1
+ {"version":3,"file":"buildAndOrConditions.d.ts","sourceRoot":"","sources":["../../src/queries/buildAndOrConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE3C,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAI5D,wBAAsB,oBAAoB,CAAC,EACzC,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,YAAY,EACZ,SAAS,EACT,KAAK,GACN,EAAE;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,qBAAqB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAwBjB"}
@@ -1,5 +1,5 @@
1
1
  import { parseParams } from './parseParams.js';
2
- export async function buildAndOrConditions({ adapter, fields, joinAliases, joins, locale, selectFields, tableName, where }) {
2
+ export async function buildAndOrConditions({ adapter, fields, joins, locale, selectFields, tableName, where }) {
3
3
  const completedConditions = [];
4
4
  // Loop over all AND / OR operations and add them to the AND / OR query param
5
5
  // Operations should come through as an array
@@ -11,7 +11,6 @@ export async function buildAndOrConditions({ adapter, fields, joinAliases, joins
11
11
  const result = await parseParams({
12
12
  adapter,
13
13
  fields,
14
- joinAliases,
15
14
  joins,
16
15
  locale,
17
16
  selectFields,