@payloadcms/db-postgres 3.0.0-beta.4 → 3.0.0-beta.41

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +12 -7
  3. package/dist/connect.js.map +1 -1
  4. package/dist/count.d.ts +3 -0
  5. package/dist/count.d.ts.map +1 -0
  6. package/dist/count.js +41 -0
  7. package/dist/count.js.map +1 -0
  8. package/dist/create.d.ts.map +1 -1
  9. package/dist/create.js +3 -5
  10. package/dist/create.js.map +1 -1
  11. package/dist/createGlobal.d.ts.map +1 -1
  12. package/dist/createGlobal.js +3 -5
  13. package/dist/createGlobal.js.map +1 -1
  14. package/dist/createGlobalVersion.d.ts +1 -1
  15. package/dist/createGlobalVersion.d.ts.map +1 -1
  16. package/dist/createGlobalVersion.js +2 -6
  17. package/dist/createGlobalVersion.js.map +1 -1
  18. package/dist/createMigration.d.ts.map +1 -1
  19. package/dist/createMigration.js +56 -35
  20. package/dist/createMigration.js.map +1 -1
  21. package/dist/createVersion.d.ts.map +1 -1
  22. package/dist/createVersion.js +10 -18
  23. package/dist/createVersion.js.map +1 -1
  24. package/dist/deleteMany.d.ts.map +1 -1
  25. package/dist/deleteMany.js +2 -5
  26. package/dist/deleteMany.js.map +1 -1
  27. package/dist/deleteOne.d.ts.map +1 -1
  28. package/dist/deleteOne.js +4 -7
  29. package/dist/deleteOne.js.map +1 -1
  30. package/dist/deleteVersions.d.ts.map +1 -1
  31. package/dist/deleteVersions.js +2 -6
  32. package/dist/deleteVersions.js.map +1 -1
  33. package/dist/destroy.d.ts.map +1 -1
  34. package/dist/destroy.js +11 -7
  35. package/dist/destroy.js.map +1 -1
  36. package/dist/exports/migration-utils.d.ts +2 -0
  37. package/dist/exports/migration-utils.d.ts.map +1 -0
  38. package/dist/exports/migration-utils.js +3 -0
  39. package/dist/exports/migration-utils.js.map +1 -0
  40. package/dist/find/buildFindManyArgs.d.ts +5 -1
  41. package/dist/find/buildFindManyArgs.d.ts.map +1 -1
  42. package/dist/find/buildFindManyArgs.js +4 -3
  43. package/dist/find/buildFindManyArgs.js.map +1 -1
  44. package/dist/find/findMany.d.ts.map +1 -1
  45. package/dist/find/findMany.js +5 -16
  46. package/dist/find/findMany.js.map +1 -1
  47. package/dist/find/traverseFields.d.ts +3 -2
  48. package/dist/find/traverseFields.d.ts.map +1 -1
  49. package/dist/find/traverseFields.js +26 -24
  50. package/dist/find/traverseFields.js.map +1 -1
  51. package/dist/find.d.ts.map +1 -1
  52. package/dist/find.js +2 -5
  53. package/dist/find.js.map +1 -1
  54. package/dist/findGlobal.d.ts.map +1 -1
  55. package/dist/findGlobal.js +2 -5
  56. package/dist/findGlobal.js.map +1 -1
  57. package/dist/findGlobalVersions.d.ts.map +1 -1
  58. package/dist/findGlobalVersions.js +2 -6
  59. package/dist/findGlobalVersions.js.map +1 -1
  60. package/dist/findOne.d.ts.map +1 -1
  61. package/dist/findOne.js +2 -5
  62. package/dist/findOne.js.map +1 -1
  63. package/dist/findVersions.d.ts.map +1 -1
  64. package/dist/findVersions.js +2 -6
  65. package/dist/findVersions.js.map +1 -1
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +17 -8
  68. package/dist/index.js.map +1 -1
  69. package/dist/init.d.ts.map +1 -1
  70. package/dist/init.js +19 -22
  71. package/dist/init.js.map +1 -1
  72. package/dist/migrate.js.map +1 -1
  73. package/dist/migrateDown.js.map +1 -1
  74. package/dist/migrateFresh.js.map +1 -1
  75. package/dist/migrateRefresh.js.map +1 -1
  76. package/dist/migrateReset.js.map +1 -1
  77. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  78. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  79. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  80. package/dist/predefinedMigrations/relationships-v2-v3.mjs +11 -0
  81. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +20 -0
  82. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
  83. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +170 -0
  84. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
  85. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
  86. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
  87. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +191 -0
  88. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
  89. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
  90. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
  91. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js +56 -0
  92. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
  93. package/dist/predefinedMigrations/v2-v3/index.d.ts +24 -0
  94. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
  95. package/dist/predefinedMigrations/v2-v3/index.js +211 -0
  96. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -0
  97. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +19 -0
  98. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
  99. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +57 -0
  100. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
  101. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +23 -0
  102. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
  103. package/dist/predefinedMigrations/v2-v3/traverseFields.js +85 -0
  104. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
  105. package/dist/predefinedMigrations/v2-v3/types.d.ts +9 -0
  106. package/dist/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
  107. package/dist/predefinedMigrations/v2-v3/types.js +6 -0
  108. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -0
  109. package/dist/queries/buildAndOrConditions.d.ts +3 -4
  110. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  111. package/dist/queries/buildAndOrConditions.js +1 -2
  112. package/dist/queries/buildAndOrConditions.js.map +1 -1
  113. package/dist/queries/buildQuery.d.ts +1 -2
  114. package/dist/queries/buildQuery.d.ts.map +1 -1
  115. package/dist/queries/buildQuery.js +1 -5
  116. package/dist/queries/buildQuery.js.map +1 -1
  117. package/dist/queries/getTableColumnFromPath.d.ts +3 -4
  118. package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
  119. package/dist/queries/getTableColumnFromPath.js +248 -143
  120. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  121. package/dist/queries/parseParams.d.ts +3 -4
  122. package/dist/queries/parseParams.d.ts.map +1 -1
  123. package/dist/queries/parseParams.js +7 -6
  124. package/dist/queries/parseParams.js.map +1 -1
  125. package/dist/queries/selectDistinct.d.ts +3 -4
  126. package/dist/queries/selectDistinct.d.ts.map +1 -1
  127. package/dist/queries/selectDistinct.js +3 -14
  128. package/dist/queries/selectDistinct.js.map +1 -1
  129. package/dist/queryDrafts.d.ts.map +1 -1
  130. package/dist/queryDrafts.js +2 -6
  131. package/dist/queryDrafts.js.map +1 -1
  132. package/dist/schema/build.d.ts +11 -6
  133. package/dist/schema/build.d.ts.map +1 -1
  134. package/dist/schema/build.js +208 -124
  135. package/dist/schema/build.js.map +1 -1
  136. package/dist/schema/{getTableName.d.ts → createTableName.d.ts} +5 -7
  137. package/dist/schema/createTableName.d.ts.map +1 -0
  138. package/dist/schema/createTableName.js +31 -0
  139. package/dist/schema/createTableName.js.map +1 -0
  140. package/dist/schema/traverseFields.d.ts +4 -6
  141. package/dist/schema/traverseFields.d.ts.map +1 -1
  142. package/dist/schema/traverseFields.js +145 -61
  143. package/dist/schema/traverseFields.js.map +1 -1
  144. package/dist/schema/validateExistingBlockIsIdentical.d.ts +2 -1
  145. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +1 -1
  146. package/dist/schema/validateExistingBlockIsIdentical.js +13 -7
  147. package/dist/schema/validateExistingBlockIsIdentical.js.map +1 -1
  148. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  149. package/dist/transactions/beginTransaction.js +4 -0
  150. package/dist/transactions/beginTransaction.js.map +1 -1
  151. package/dist/transform/read/index.d.ts +3 -1
  152. package/dist/transform/read/index.d.ts.map +1 -1
  153. package/dist/transform/read/index.js +2 -1
  154. package/dist/transform/read/index.js.map +1 -1
  155. package/dist/transform/read/relationship.d.ts.map +1 -1
  156. package/dist/transform/read/relationship.js +0 -4
  157. package/dist/transform/read/relationship.js.map +1 -1
  158. package/dist/transform/read/traverseFields.d.ts +6 -1
  159. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  160. package/dist/transform/read/traverseFields.js +69 -55
  161. package/dist/transform/read/traverseFields.js.map +1 -1
  162. package/dist/transform/write/array.d.ts.map +1 -1
  163. package/dist/transform/write/array.js.map +1 -1
  164. package/dist/transform/write/blocks.js +1 -1
  165. package/dist/transform/write/blocks.js.map +1 -1
  166. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  167. package/dist/transform/write/traverseFields.js +22 -5
  168. package/dist/transform/write/traverseFields.js.map +1 -1
  169. package/dist/types.d.ts +7 -7
  170. package/dist/types.d.ts.map +1 -1
  171. package/dist/types.js.map +1 -1
  172. package/dist/update.d.ts.map +1 -1
  173. package/dist/update.js +3 -7
  174. package/dist/update.js.map +1 -1
  175. package/dist/updateGlobal.d.ts.map +1 -1
  176. package/dist/updateGlobal.js +2 -5
  177. package/dist/updateGlobal.js.map +1 -1
  178. package/dist/updateGlobalVersion.d.ts.map +1 -1
  179. package/dist/updateGlobalVersion.js +2 -6
  180. package/dist/updateGlobalVersion.js.map +1 -1
  181. package/dist/updateVersion.d.ts.map +1 -1
  182. package/dist/updateVersion.js +2 -6
  183. package/dist/updateVersion.js.map +1 -1
  184. package/dist/upsertRow/index.d.ts +1 -1
  185. package/dist/upsertRow/index.d.ts.map +1 -1
  186. package/dist/upsertRow/index.js +9 -6
  187. package/dist/upsertRow/index.js.map +1 -1
  188. package/dist/upsertRow/insertArrays.d.ts.map +1 -1
  189. package/dist/upsertRow/insertArrays.js +3 -3
  190. package/dist/upsertRow/insertArrays.js.map +1 -1
  191. package/dist/upsertRow/types.d.ts +7 -2
  192. package/dist/upsertRow/types.d.ts.map +1 -1
  193. package/dist/upsertRow/types.js.map +1 -1
  194. package/dist/utilities/pushDevSchema.d.ts.map +1 -1
  195. package/dist/utilities/pushDevSchema.js +1 -1
  196. package/dist/utilities/pushDevSchema.js.map +1 -1
  197. package/package.json +29 -27
  198. package/dist/schema/getTableName.d.ts.map +0 -1
  199. package/dist/schema/getTableName.js +0 -31
  200. package/dist/schema/getTableName.js.map +0 -1
  201. package/src/index.ts +0 -156
@@ -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/versions';
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 } from 'payload'\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport { sql } from 'drizzle-orm'\nimport fs from 'fs'\nimport { createRequire } from 'module'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { PathsToQuery } from './types.js'\n\nimport { groupUpSQLStatements } from './groupUpSQLStatements.js'\nimport { migrateRelationships } from './migrateRelationships.js'\nimport { traverseFields } from './traverseFields.js'\n\nconst require = createRequire(import.meta.url)\n\ntype Args = {\n debug?: boolean\n payload: Payload\n req?: Partial<PayloadRequestWithData>\n}\n\n/**\n * Moves upload and relationship columns from the join table and into the tables while moving data\n * This is done in the following order:\n * ADD COLUMNs\n * -- manipulate data to move relationships to new columns\n * ADD CONSTRAINTs\n * NOT NULLs\n * DROP TABLEs\n * DROP CONSTRAINTs\n * DROP COLUMNs\n * @param debug\n * @param payload\n * @param req\n */\nexport const migratePostgresV2toV3 = async ({ debug, payload, req }: Args) => {\n const adapter = payload.db as PostgresAdapter\n const db = adapter.sessions[req.transactionID]?.db\n const dir = payload.db.migrationDir\n\n // get the drizzle migrateUpSQL from drizzle using the last schema\n const { generateDrizzleJson, generateMigration } = require('drizzle-kit/payload')\n const drizzleJsonAfter = generateDrizzleJson(adapter.schema)\n\n // Get 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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,GAAG,QAAQ,cAAa;AACjC,OAAOC,QAAQ,KAAI;AACnB,SAASC,aAAa,QAAQ,SAAQ;AACtC,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,mBAAkB;AACzF,OAAOC,iBAAiB,gBAAe;AAKvC,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,cAAc,QAAQ,sBAAqB;AAEpD,MAAMC,UAAUP,cAAc,Y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AEA,MAAM3D,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAAC2B;IAEzB,WAAW;IACX,MAAME,oBAAoBlC,gBAAgBmC,OAAO,CAAChC,IAAI,CAAC;IAEvD,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAACqC;IACtB;IAEA,MAAM7D,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAAC6B;IAEzB,aAAa;IACb,MAAME,sBAAsBpC,gBAAgBqC,SAAS,CAAClC,IAAI,CAAC;IAE3D,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAACuC;IACtB;IAEA,MAAM/D,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAAC+B;IAEzB,kBAAkB;IAClB,MAAME,2BAA2BtC,gBAAgBuC,cAAc,CAACpC,IAAI,CAAC;IAErE,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAACyC;IACtB;IAEA,MAAMjE,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAACiC;IAEzB,cAAc;IACd,MAAME,uBAAuBxC,gBAAgByC,UAAU,CAACtC,IAAI,CAAC;IAE7D,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAAC2C;IACtB;IAEA,MAAMnE,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAACmC;AAC3B,EAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Field, Payload, PayloadRequestWithData } from 'payload/types';
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,eAAe,CAAA;AAI3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,YAAY,CAAA;AAI5D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,kBAAkB,CAAA;IACtB,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,YAAY,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAA;IACrC,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,oBAAoB,mHAY9B,IAAI,kBAkEN,CAAA"}
@@ -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/types'\n\nimport { sql } from 'drizzle-orm'\n\nimport type { DrizzleTransaction, PostgresAdapter } from '../../types.js'\nimport type { DocsToResave, PathsToQuery } from './types.js'\n\nimport { fetchAndResave } from './fetchAndResave/index.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n db: DrizzleTransaction\n debug: boolean\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n pathsToQuery: PathsToQuery\n payload: Payload\n req?: Partial<PayloadRequestWithData>\n tableName: string\n}\n\nexport const migrateRelationships = async ({\n adapter,\n collectionSlug,\n db,\n debug,\n fields,\n globalSlug,\n isVersions,\n pathsToQuery,\n payload,\n req,\n tableName,\n}: Args) => {\n if (pathsToQuery.size === 0) return\n\n let offset = 0\n\n let paginationResult\n\n const where = Array.from(pathsToQuery).reduce((statement, path, i) => {\n return (statement += `\n\"${tableName}${adapter.relationshipsSuffix}\".\"path\" LIKE '${path}'${pathsToQuery.size !== i + 1 ? ' OR' : ''}\n`)\n }, '')\n\n while (typeof paginationResult === 'undefined' || paginationResult.rows.length > 0) {\n const paginationStatement = `SELECT DISTINCT parent_id FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n ${where} ORDER BY parent_id LIMIT 500 OFFSET ${offset * 500};\n `\n\n paginationResult = await adapter.drizzle.execute(sql.raw(`${paginationStatement}`))\n\n if (paginationResult.rows.length === 0) return\n\n offset += 1\n\n const statement = `SELECT * FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n (${where}) AND parent_id IN (${paginationResult.rows.map((row) => row.parent_id).join(', ')});\n`\n if (debug) {\n payload.logger.info('FINDING ROWS TO MIGRATE')\n payload.logger.info(statement)\n }\n\n const result = await adapter.drizzle.execute(sql.raw(`${statement}`))\n\n const docsToResave: DocsToResave = {}\n\n result.rows.forEach((row) => {\n const parentID = row.parent_id\n\n if (typeof parentID === 'string' || typeof parentID === 'number') {\n if (!docsToResave[parentID]) docsToResave[parentID] = []\n docsToResave[parentID].push(row)\n }\n })\n\n await fetchAndResave({\n adapter,\n collectionSlug,\n db,\n debug,\n docsToResave,\n fields,\n globalSlug,\n isVersions,\n payload,\n req: req as PayloadRequestWithData,\n tableName,\n })\n }\n\n const deleteStatement = `DELETE FROM ${tableName}${adapter.relationshipsSuffix} WHERE ${where}`\n if (debug) {\n payload.logger.info('DELETING ROWS')\n payload.logger.info(deleteStatement)\n }\n await db.execute(sql.raw(`${deleteStatement}`))\n}\n"],"names":["sql","fetchAndResave","migrateRelationships","adapter","collectionSlug","db","debug","fields","globalSlug","isVersions","pathsToQuery","payload","req","tableName","size","offset","paginationResult","where","Array","from","reduce","statement","path","i","relationshipsSuffix","rows","length","paginationStatement","drizzle","execute","raw","map","row","parent_id","join","logger","info","result","docsToResave","forEach","parentID","push","deleteStatement"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,GAAG,QAAQ,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,I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YACLC;QACF;IACF;IAEA,MAAM6B,kBAAkB,CAAC,YAAY,EAAE7B,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC,OAAO,EAAEP,MAAM,CAAC;IAC/F,IAAIX,OAAO;QACTK,QAAQwB,MAAM,CAACC,IAAI,CAAC;QACpBzB,QAAQwB,MAAM,CAACC,IAAI,CAACM;IACtB;IACA,MAAMrC,GAAGwB,OAAO,CAAC7B,IAAI8B,GAAG,CAAC,CAAC,EAAEY,gBAAgB,CAAC;AAC/C,EAAC"}
@@ -0,0 +1,23 @@
1
+ import type { Payload } from 'payload';
2
+ import { type Field } from 'payload/types';
3
+ import type { DrizzleTransaction, PostgresAdapter } from '../../types.js';
4
+ import type { PathsToQuery } from './types.js';
5
+ type Args = {
6
+ adapter: PostgresAdapter;
7
+ collectionSlug?: string;
8
+ columnPrefix: string;
9
+ db: DrizzleTransaction;
10
+ disableNotNull: boolean;
11
+ fields: Field[];
12
+ globalSlug?: string;
13
+ isVersions: boolean;
14
+ newTableName: string;
15
+ parentTableName: string;
16
+ path: string;
17
+ pathsToQuery: PathsToQuery;
18
+ payload: Payload;
19
+ rootTableName: string;
20
+ };
21
+ export declare const traverseFields: (args: Args) => void;
22
+ export {};
23
+ //# 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,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,EAAE,KAAK,KAAK,EAAc,MAAM,eAAe,CAAA;AAGtD,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/types';
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 { Payload } from 'payload'\n\nimport { type Field, tabHasName } from 'payload/types'\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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAAqBA,UAAU,QAAQ,gBAAe;AACtD,OAAOC,iBAAiB,gBAAe;AAsBvC,OAAO,MAAMC,iBAAiB,CAACC;IAC7BA,KAAKC,MAAM,CAACC,OAAO,CAAC,CAACC;QACnB,OAAQA,MAAMC,IAAI;YAChB,KAAK;gBAAS;oBACZ,IAAIC,eAAe,CAAC,EAAEL,KAAKK,YAAY,CAAC,CAAC,EAAEP,YAAYK,MAAMG,IAAI,EAAE,CAAC;oBAEpE,IAAIH,MAAMI,SAAS,IAAIP,KAAKQ,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;wBACvDL,gBAAgBL,KAAKW,OAAO,CAACC,aAAa;oBAC5C;oBAEA,OAAOb,eAAe;wBACpB,GAAGC,IAAI;wBACPa,cAAc,CAAC,EAAEb,KAAKa,YAAY,CAAC,EAAEf,YAAYK,MAAMG,IAAI,EAAE,CAAC,CAAC;wBAC/DL,QAAQE,MAAMF,MAAM;wBACpBI;wBACAS,MAAM,CAAC,EAAEd,KAAKc,IAAI,GAAG,CAAC,EAAEd,KAAKc,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,EAAEX,MAAMG,IAAI,CAAC,CAAC;oBAC1D;gBACF;YAEA,KAAK;YACL,KAAK;gBAAe;oBAClB,OAAOP,eAAe;wBACpB,GAAGC,IAAI;wBACPC,QAAQE,MAAMF,MAAM;oBACtB;gBACF;YAEA,KAAK;gBAAS;oBACZ,MAAMI,eAAeL,KAAKW,OAAO,CAACI,YAAY,CAACC,GAAG,CAChD,CAAC,EAAEhB,KAAKK,YAAY,CAAC,CAAC,EAAEP,YAAYK,MAAMG,IAAI,EAAE,CAAC;oBAGnD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AEnE,IAAIiB,IAAIhB,SAAS,IAAIP,KAAKQ,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;gCACrDV,KAAKK,YAAY,IAAIL,KAAKW,OAAO,CAACC,aAAa;4BACjD;wBACF;wBAEAb,eAAe;4BACb,GAAGC,IAAI;4BACPC,QAAQsB,IAAItB,MAAM;wBACpB;oBACF;gBACF;YAEA,KAAK;YACL,KAAK;gBAAU;oBACb,IAAI,OAAOE,MAAMqB,UAAU,KAAK,UAAU;wBACxC,IAAIrB,MAAMC,IAAI,KAAK,YAAY,CAACD,MAAMsB,OAAO,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":[],"rangeMappings":";;;","mappings":"AAAA;;;CAGC,GAGD,WAEC"}
@@ -1,14 +1,13 @@
1
1
  import type { SQL } from 'drizzle-orm';
2
2
  import type { Field, Where } from 'payload/types';
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,G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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,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { Field, Where } from 'payload/types'\n\nimport type { GenericColumn, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases, BuildQueryJoins } from './buildQuery.js'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\n adapter,\n fields,\n joinAliases,\n joins,\n locale,\n selectFields,\n tableName,\n where,\n}: {\n adapter: PostgresAdapter\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n joinAliases: BuildQueryJoinAliases\n joins: BuildQueryJoins\n locale?: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: Where[]\n}): Promise<SQL[]> {\n const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n // eslint-disable-next-line no-restricted-syntax\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n // eslint-disable-next-line no-await-in-loop\n const result = await parseParams({\n adapter,\n fields,\n joinAliases,\n joins,\n locale,\n selectFields,\n tableName,\n where: condition,\n })\n if (result && Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","adapter","fields","joinAliases","joins","locale","selectFields","tableName","where","completedConditions","condition","result","Object","keys","length","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAMA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,qBAAqB,EACzCC,OAAO,EACPC,MAAM,EACNC,WAAW,EACXC,KAAK,EACLC,MAAM,EACNC,YAAY,EACZC,SAAS,EACTC,KAAK,EAYN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAC7C,gDAAgD;IAChD,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,4CAA4C;YAC5C,MAAMC,SAAS,MAAMZ,YAAY;gBAC/BE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOE;YACT;YACA,IAAIC,UAAUC,OAAOC,IAAI,CAACF,QAAQG,MAAM,GAAG,GAAG;gBAC5CL,oBAAoBM,IAAI,CAACJ;YAC3B;QACF;IACF;IACA,OAAOF;AACT"}
1
+ {"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { Field, Where } from 'payload/types'\n\nimport type { GenericColumn, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where,\n}: {\n adapter: PostgresAdapter\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n joins: BuildQueryJoinAliases\n locale?: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: Where[]\n}): Promise<SQL[]> {\n const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n // eslint-disable-next-line no-restricted-syntax\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n // eslint-disable-next-line no-await-in-loop\n const result = await parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: condition,\n })\n if (result && Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","adapter","fields","joins","locale","selectFields","tableName","where","completedConditions","condition","result","Object","keys","length","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAMA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,qBAAqB,EACzCC,OAAO,EACPC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,YAAY,EACZC,SAAS,EACTC,KAAK,EAWN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAC7C,gDAAgD;IAChD,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,4CAA4C;YAC5C,MAAMC,SAAS,MAAMX,YAAY;gBAC/BE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOE;YACT;YACA,IAAIC,UAAUC,OAAOC,IAAI,CAACF,QAAQG,MAAM,GAAG,GAAG;gBAC5CL,oBAAoBM,IAAI,CAACJ;YAC3B;QACF;IACF;IACA,OAAOF;AACT"}
@@ -17,8 +17,7 @@ type BuildQueryArgs = {
17
17
  where: Where;
18
18
  };
19
19
  type Result = {
20
- joinAliases: BuildQueryJoinAliases;
21
- joins: BuildQueryJoins;
20
+ joins: BuildQueryJoinAliases;
22
21
  orderBy: {
23
22
  column: GenericColumn;
24
23
  order: typeof asc | typeof desc;
@@ -1 +1 @@
1
- {"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAA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,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAK/E,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAEjD,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,GAAG,CAAA;IACd,KAAK,EAAE,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;CAC9C,EAAE,CAAA;AAEH,KAAK,cAAc,GAAG;IACpB,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,KAAK,EAAE,qBAAqB,CAAA;IAC5B,OAAO,EAAE;QACP,MAAM,EAAE,aAAa,CAAA;QACrB,KAAK,EAAE,OAAO,GAAG,GAAG,OAAO,IAAI,CAAA;KAChC,CAAA;IACD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,KAAK,EAAE,GAAG,CAAA;CACX,CAAA;AACD,QAAA,MAAM,UAAU,wEAOb,cAAc,KAAG,QAAQ,MAAM,CA2EjC,CAAA;AAED,eAAe,UAAU,CAAA"}
@@ -5,8 +5,7 @@ const buildQuery = async function buildQuery({ adapter, fields, locale, sort, ta
5
5
  const selectFields = {
6
6
  id: adapter.tables[tableName].id
7
7
  };
8
- const joins = {};
9
- const joinAliases = [];
8
+ const joins = [];
10
9
  const orderBy = {
11
10
  column: null,
12
11
  order: null
@@ -25,7 +24,6 @@ const buildQuery = async function buildQuery({ adapter, fields, locale, sort, ta
25
24
  adapter,
26
25
  collectionPath: sortPath,
27
26
  fields,
28
- joinAliases,
29
27
  joins,
30
28
  locale,
31
29
  pathSegments: sortPath.replace(/__/g, '.').split('.'),
@@ -55,7 +53,6 @@ const buildQuery = async function buildQuery({ adapter, fields, locale, sort, ta
55
53
  where = await parseParams({
56
54
  adapter,
57
55
  fields,
58
- joinAliases,
59
56
  joins,
60
57
  locale,
61
58
  selectFields,
@@ -64,7 +61,6 @@ const buildQuery = async function buildQuery({ adapter, fields, locale, sort, ta
64
61
  });
65
62
  }
66
63
  return {
67
- joinAliases,
68
64
  joins,
69
65
  orderBy,
70
66
  selectFields,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, Where } from 'payload/types'\n\nimport { asc, desc } from 'drizzle-orm'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\n\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { parseParams } from './parseParams.js'\n\nexport type BuildQueryJoins = Record<string, SQL>\n\nexport type BuildQueryJoinAliases = {\n condition: SQL\n table: GenericTable | PgTableWithColumns<any>\n}[]\n\ntype BuildQueryArgs = {\n adapter: PostgresAdapter\n fields: Field[]\n locale?: string\n sort?: string\n tableName: string\n where: Where\n}\n\ntype Result = {\n joinAliases: BuildQueryJoinAliases\n joins: BuildQueryJoins\n orderBy: {\n column: GenericColumn\n order: typeof asc | typeof desc\n }\n selectFields: Record<string, GenericColumn>\n where: SQL\n}\nconst buildQuery = async function buildQuery({\n adapter,\n fields,\n locale,\n sort,\n tableName,\n where: incomingWhere,\n}: BuildQueryArgs): Promise<Result> {\n const selectFields: Record<string, GenericColumn> = {\n id: adapter.tables[tableName].id,\n }\n const joins: BuildQueryJoins = {}\n const joinAliases: BuildQueryJoinAliases = []\n\n const orderBy: Result['orderBy'] = {\n column: null,\n order: null,\n }\n\n if (sort) {\n let sortPath\n\n if (sort[0] === '-') {\n sortPath = sort.substring(1)\n orderBy.order = desc\n } else {\n sortPath = sort\n orderBy.order = asc\n }\n\n try {\n const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({\n adapter,\n collectionPath: sortPath,\n fields,\n joinAliases,\n joins,\n locale,\n pathSegments: sortPath.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n value: sortPath,\n })\n orderBy.column = sortTable?.[sortTableColumnName]\n } catch (err) {\n // continue\n }\n }\n\n if (!orderBy?.column) {\n orderBy.order = desc\n const createdAt = adapter.tables[tableName]?.createdAt\n\n if (createdAt) {\n orderBy.column = createdAt\n } else {\n orderBy.column = adapter.tables[tableName].id\n }\n }\n\n if (orderBy.column) {\n selectFields.sort = orderBy.column\n }\n\n let where: SQL\n\n if (incomingWhere && Object.keys(incomingWhere).length > 0) {\n where = await parseParams({\n adapter,\n fields,\n joinAliases,\n joins,\n locale,\n selectFields,\n tableName,\n where: incomingWhere,\n })\n }\n\n return {\n joinAliases,\n joins,\n orderBy,\n selectFields,\n where,\n }\n}\n\nexport default buildQuery\n"],"names":["asc","desc","getTableColumnFromPath","parseParams","buildQuery","adapter","fields","locale","sort","tableName","where","incomingWhere","selectFields","id","tables","joins","joinAliases","orderBy","column","order","sortPath","substring","columnName","sortTableColumnName","table","sortTable","collectionPath","pathSegments","replace","split","value","err","createdAt","Object","keys","length"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,GAAG,EAAEC,IAAI,QAAQ,cAAa;AAIvC,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,WAAW,QAAQ,mBAAkB;AA4B9C,MAAMC,aAAa,eAAeA,WAAW,EAC3CC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,OAAOC,aAAa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QACT;IACF;IAEA,OAAO;QACLK;QACAD;QACAE;QACAL;QACAF;IACF;AACF;AAEA,eAAeN,WAAU"}
1
+ {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, Where } from 'payload/types'\n\nimport { asc, desc } from 'drizzle-orm'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\n\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { parseParams } from './parseParams.js'\n\nexport type BuildQueryJoins = Record<string, SQL>\n\nexport type BuildQueryJoinAliases = {\n condition: SQL\n table: GenericTable | PgTableWithColumns<any>\n}[]\n\ntype BuildQueryArgs = {\n adapter: PostgresAdapter\n fields: Field[]\n locale?: string\n sort?: string\n tableName: string\n where: Where\n}\n\ntype Result = {\n joins: BuildQueryJoinAliases\n orderBy: {\n column: GenericColumn\n order: typeof asc | typeof desc\n }\n selectFields: Record<string, GenericColumn>\n where: SQL\n}\nconst buildQuery = async function buildQuery({\n adapter,\n fields,\n locale,\n sort,\n tableName,\n where: incomingWhere,\n}: BuildQueryArgs): Promise<Result> {\n const selectFields: Record<string, GenericColumn> = {\n id: adapter.tables[tableName].id,\n }\n const joins: BuildQueryJoinAliases = []\n\n const orderBy: Result['orderBy'] = {\n column: null,\n order: null,\n }\n\n if (sort) {\n let sortPath\n\n if (sort[0] === '-') {\n sortPath = sort.substring(1)\n orderBy.order = desc\n } else {\n sortPath = sort\n orderBy.order = asc\n }\n\n try {\n const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({\n adapter,\n collectionPath: sortPath,\n fields,\n joins,\n locale,\n pathSegments: sortPath.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n value: sortPath,\n })\n orderBy.column = sortTable?.[sortTableColumnName]\n } catch (err) {\n // continue\n }\n }\n\n if (!orderBy?.column) {\n orderBy.order = desc\n const createdAt = adapter.tables[tableName]?.createdAt\n\n if (createdAt) {\n orderBy.column = createdAt\n } else {\n orderBy.column = adapter.tables[tableName].id\n }\n }\n\n if (orderBy.column) {\n selectFields.sort = orderBy.column\n }\n\n let where: SQL\n\n if (incomingWhere && Object.keys(incomingWhere).length > 0) {\n where = await parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: incomingWhere,\n })\n }\n\n return {\n joins,\n orderBy,\n selectFields,\n where,\n }\n}\n\nexport default buildQuery\n"],"names":["asc","desc","getTableColumnFromPath","parseParams","buildQuery","adapter","fields","locale","sort","tableName","where","incomingWhere","selectFields","id","tables","joins","orderBy","column","order","sortPath","substring","columnName","sortTableColumnName","table","sortTable","collectionPath","pathSegments","replace","split","value","err","createdAt","Object","keys","length"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,GAAG,EAAEC,IAAI,QAAQ,cAAa;AAIvC,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,WAAW,QAAQ,mBAAkB;AA2B9C,MAAMC,aAAa,eAAeA,WAAW,EAC3CC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,OAAOC,aAAa,EACL;IACf,MAAMC,eAA8C;QAClDC,IAAIR,QAAQS,MAAM,CAACL,UAAU,CAACI,EAAE;IAClC;IACA,MAAME,QAA+B,EAAE;IAEvC,MAAMC,UAA6B;QACjCC,QAAQ;QACRC,OAAO;IACT;IAEA,IAAIV,MAAM;QACR,IAAIW;QAEJ,IAAIX,IAAI,CAAC,EAAE,KAAK,KAAK;YACnBW,WAAWX,KAAKY,SAAS,CAAC;YAC1BJ,QAAQE,KAAK,GAAGjB;QAClB,OAAO;YACLkB,WAAWX;YACXQ,QAAQE,KAAK,GAAGlB;QAClB;QAEA,IAAI;YACF,MAAM,EAAEqB,YAAYC,mBAAmB,EAAEC,OAAOC,SAAS,EA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