@payloadcms/drizzle 3.0.0-canary.a192632 → 3.0.0-canary.a5aaf21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) hide show
  1. package/dist/count.d.ts.map +1 -1
  2. package/dist/count.js +1 -1
  3. package/dist/count.js.map +1 -1
  4. package/dist/createGlobalVersion.d.ts +1 -1
  5. package/dist/createGlobalVersion.d.ts.map +1 -1
  6. package/dist/createGlobalVersion.js +4 -2
  7. package/dist/createGlobalVersion.js.map +1 -1
  8. package/dist/createTableName.d.ts.map +1 -1
  9. package/dist/createTableName.js +6 -2
  10. package/dist/createTableName.js.map +1 -1
  11. package/dist/createVersion.d.ts +1 -1
  12. package/dist/createVersion.d.ts.map +1 -1
  13. package/dist/createVersion.js +22 -14
  14. package/dist/createVersion.js.map +1 -1
  15. package/dist/deleteOne.d.ts.map +1 -1
  16. package/dist/deleteOne.js +5 -3
  17. package/dist/deleteOne.js.map +1 -1
  18. package/dist/deleteVersions.js +1 -1
  19. package/dist/deleteVersions.js.map +1 -1
  20. package/dist/destroy.d.ts.map +1 -1
  21. package/dist/destroy.js +3 -1
  22. package/dist/destroy.js.map +1 -1
  23. package/dist/exports/postgres.d.ts +14 -0
  24. package/dist/exports/postgres.d.ts.map +1 -0
  25. package/dist/exports/postgres.js +15 -0
  26. package/dist/exports/postgres.js.map +1 -0
  27. package/dist/find/buildFindManyArgs.d.ts +13 -7
  28. package/dist/find/buildFindManyArgs.d.ts.map +1 -1
  29. package/dist/find/buildFindManyArgs.js +5 -1
  30. package/dist/find/buildFindManyArgs.js.map +1 -1
  31. package/dist/find/findMany.d.ts +1 -1
  32. package/dist/find/findMany.d.ts.map +1 -1
  33. package/dist/find/findMany.js +6 -3
  34. package/dist/find/findMany.js.map +1 -1
  35. package/dist/find/traverseFields.d.ts +7 -3
  36. package/dist/find/traverseFields.d.ts.map +1 -1
  37. package/dist/find/traverseFields.js +91 -16
  38. package/dist/find/traverseFields.js.map +1 -1
  39. package/dist/find.d.ts.map +1 -1
  40. package/dist/find.js +2 -1
  41. package/dist/find.js.map +1 -1
  42. package/dist/findGlobalVersions.js +1 -1
  43. package/dist/findGlobalVersions.js.map +1 -1
  44. package/dist/findMigrationDir.d.ts.map +1 -1
  45. package/dist/findMigrationDir.js +3 -1
  46. package/dist/findMigrationDir.js.map +1 -1
  47. package/dist/findOne.d.ts +1 -1
  48. package/dist/findOne.d.ts.map +1 -1
  49. package/dist/findOne.js +2 -1
  50. package/dist/findOne.js.map +1 -1
  51. package/dist/findVersions.js +1 -1
  52. package/dist/findVersions.js.map +1 -1
  53. package/dist/migrate.js +1 -0
  54. package/dist/migrate.js.map +1 -1
  55. package/dist/migrateDown.d.ts.map +1 -1
  56. package/dist/migrateDown.js +1 -1
  57. package/dist/migrateDown.js.map +1 -1
  58. package/dist/migrateFresh.d.ts.map +1 -1
  59. package/dist/migrateFresh.js +1 -0
  60. package/dist/migrateFresh.js.map +1 -1
  61. package/dist/migrateRefresh.d.ts.map +1 -1
  62. package/dist/migrateRefresh.js +2 -1
  63. package/dist/migrateRefresh.js.map +1 -1
  64. package/dist/migrateReset.d.ts.map +1 -1
  65. package/dist/migrateReset.js +4 -2
  66. package/dist/migrateReset.js.map +1 -1
  67. package/dist/migrateStatus.js +0 -1
  68. package/dist/migrateStatus.js.map +1 -1
  69. package/dist/postgres/countDistinct.d.ts +3 -0
  70. package/dist/postgres/countDistinct.d.ts.map +1 -0
  71. package/dist/postgres/countDistinct.js +24 -0
  72. package/dist/postgres/countDistinct.js.map +1 -0
  73. package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.d.ts +2 -0
  74. package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -0
  75. package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.js +16 -0
  76. package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.js.map +1 -0
  77. package/dist/postgres/createJSONQuery/formatJSONPathSegment.d.ts +2 -0
  78. package/dist/postgres/createJSONQuery/formatJSONPathSegment.d.ts.map +1 -0
  79. package/dist/postgres/createJSONQuery/formatJSONPathSegment.js +5 -0
  80. package/dist/postgres/createJSONQuery/formatJSONPathSegment.js.map +1 -0
  81. package/dist/postgres/createJSONQuery/index.d.ts +10 -0
  82. package/dist/postgres/createJSONQuery/index.d.ts.map +1 -0
  83. package/dist/postgres/createJSONQuery/index.js +54 -0
  84. package/dist/postgres/createJSONQuery/index.js.map +1 -0
  85. package/dist/postgres/createMigration.d.ts +3 -0
  86. package/dist/postgres/createMigration.d.ts.map +1 -0
  87. package/dist/postgres/createMigration.js +92 -0
  88. package/dist/postgres/createMigration.js.map +1 -0
  89. package/dist/postgres/defaultSnapshot.d.ts +3 -0
  90. package/dist/postgres/defaultSnapshot.d.ts.map +1 -0
  91. package/dist/postgres/defaultSnapshot.js +17 -0
  92. package/dist/postgres/defaultSnapshot.js.map +1 -0
  93. package/dist/postgres/deleteWhere.d.ts +3 -0
  94. package/dist/postgres/deleteWhere.d.ts.map +1 -0
  95. package/dist/postgres/deleteWhere.js +6 -0
  96. package/dist/postgres/deleteWhere.js.map +1 -0
  97. package/dist/postgres/dropDatabase.d.ts +3 -0
  98. package/dist/postgres/dropDatabase.d.ts.map +1 -0
  99. package/dist/postgres/dropDatabase.js +9 -0
  100. package/dist/postgres/dropDatabase.js.map +1 -0
  101. package/dist/postgres/execute.d.ts +3 -0
  102. package/dist/postgres/execute.d.ts.map +1 -0
  103. package/dist/postgres/execute.js +11 -0
  104. package/dist/postgres/execute.js.map +1 -0
  105. package/dist/postgres/getMigrationTemplate.d.ts +4 -0
  106. package/dist/postgres/getMigrationTemplate.d.ts.map +1 -0
  107. package/dist/postgres/getMigrationTemplate.js +13 -0
  108. package/dist/postgres/getMigrationTemplate.js.map +1 -0
  109. package/dist/postgres/init.d.ts +3 -0
  110. package/dist/postgres/init.d.ts.map +1 -0
  111. package/dist/postgres/init.js +95 -0
  112. package/dist/postgres/init.js.map +1 -0
  113. package/dist/postgres/insert.d.ts +3 -0
  114. package/dist/postgres/insert.d.ts.map +1 -0
  115. package/dist/postgres/insert.js +12 -0
  116. package/dist/postgres/insert.js.map +1 -0
  117. package/dist/postgres/requireDrizzleKit.d.ts +3 -0
  118. package/dist/postgres/requireDrizzleKit.d.ts.map +1 -0
  119. package/dist/postgres/requireDrizzleKit.js +5 -0
  120. package/dist/postgres/requireDrizzleKit.js.map +1 -0
  121. package/dist/postgres/schema/build.d.ts +40 -0
  122. package/dist/postgres/schema/build.d.ts.map +1 -0
  123. package/dist/postgres/schema/build.js +378 -0
  124. package/dist/postgres/schema/build.js.map +1 -0
  125. package/dist/postgres/schema/createIndex.d.ts +12 -0
  126. package/dist/postgres/schema/createIndex.d.ts.map +1 -0
  127. package/dist/postgres/schema/createIndex.js +20 -0
  128. package/dist/postgres/schema/createIndex.js.map +1 -0
  129. package/dist/postgres/schema/idToUUID.d.ts +3 -0
  130. package/dist/postgres/schema/idToUUID.d.ts.map +1 -0
  131. package/dist/postgres/schema/idToUUID.js +11 -0
  132. package/dist/postgres/schema/idToUUID.js.map +1 -0
  133. package/dist/postgres/schema/parentIDColumnMap.d.ts +4 -0
  134. package/dist/postgres/schema/parentIDColumnMap.d.ts.map +1 -0
  135. package/dist/postgres/schema/parentIDColumnMap.js +9 -0
  136. package/dist/postgres/schema/parentIDColumnMap.js.map +1 -0
  137. package/dist/postgres/schema/setColumnID.d.ts +11 -0
  138. package/dist/postgres/schema/setColumnID.d.ts.map +1 -0
  139. package/dist/postgres/schema/setColumnID.js +24 -0
  140. package/dist/postgres/schema/setColumnID.js.map +1 -0
  141. package/dist/postgres/schema/traverseFields.d.ts +40 -0
  142. package/dist/postgres/schema/traverseFields.d.ts.map +1 -0
  143. package/dist/postgres/schema/traverseFields.js +733 -0
  144. package/dist/postgres/schema/traverseFields.js.map +1 -0
  145. package/dist/postgres/schema/withDefault.d.ts +4 -0
  146. package/dist/postgres/schema/withDefault.d.ts.map +1 -0
  147. package/dist/postgres/schema/withDefault.js +12 -0
  148. package/dist/postgres/schema/withDefault.js.map +1 -0
  149. package/dist/postgres/types.d.ts +113 -0
  150. package/dist/postgres/types.d.ts.map +1 -0
  151. package/dist/postgres/types.js +3 -0
  152. package/dist/postgres/types.js.map +1 -0
  153. package/dist/queries/buildAndOrConditions.d.ts +1 -1
  154. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  155. package/dist/queries/buildAndOrConditions.js +2 -4
  156. package/dist/queries/buildAndOrConditions.js.map +1 -1
  157. package/dist/queries/buildOrderBy.d.ts +18 -0
  158. package/dist/queries/buildOrderBy.d.ts.map +1 -0
  159. package/dist/queries/buildOrderBy.js +51 -0
  160. package/dist/queries/buildOrderBy.js.map +1 -0
  161. package/dist/queries/buildQuery.d.ts +4 -4
  162. package/dist/queries/buildQuery.d.ts.map +1 -1
  163. package/dist/queries/buildQuery.js +12 -47
  164. package/dist/queries/buildQuery.js.map +1 -1
  165. package/dist/queries/getTableColumnFromPath.d.ts +6 -2
  166. package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
  167. package/dist/queries/getTableColumnFromPath.js +55 -18
  168. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  169. package/dist/queries/operatorMap.d.ts.map +1 -1
  170. package/dist/queries/operatorMap.js.map +1 -1
  171. package/dist/queries/parseParams.d.ts +1 -1
  172. package/dist/queries/parseParams.d.ts.map +1 -1
  173. package/dist/queries/parseParams.js +50 -6
  174. package/dist/queries/parseParams.js.map +1 -1
  175. package/dist/queries/sanitizeQueryValue.d.ts +11 -1
  176. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  177. package/dist/queries/sanitizeQueryValue.js +69 -21
  178. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  179. package/dist/queries/selectDistinct.d.ts +3 -4
  180. package/dist/queries/selectDistinct.d.ts.map +1 -1
  181. package/dist/queries/selectDistinct.js.map +1 -1
  182. package/dist/queryDrafts.d.ts.map +1 -1
  183. package/dist/queryDrafts.js +1 -2
  184. package/dist/queryDrafts.js.map +1 -1
  185. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  186. package/dist/transactions/beginTransaction.js +5 -1
  187. package/dist/transactions/beginTransaction.js.map +1 -1
  188. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  189. package/dist/transactions/commitTransaction.js +3 -1
  190. package/dist/transactions/commitTransaction.js.map +1 -1
  191. package/dist/transform/read/hasManyNumber.d.ts +2 -1
  192. package/dist/transform/read/hasManyNumber.d.ts.map +1 -1
  193. package/dist/transform/read/hasManyNumber.js +12 -2
  194. package/dist/transform/read/hasManyNumber.js.map +1 -1
  195. package/dist/transform/read/hasManyText.d.ts +2 -1
  196. package/dist/transform/read/hasManyText.d.ts.map +1 -1
  197. package/dist/transform/read/hasManyText.js +12 -2
  198. package/dist/transform/read/hasManyText.js.map +1 -1
  199. package/dist/transform/read/index.d.ts +3 -2
  200. package/dist/transform/read/index.d.ts.map +1 -1
  201. package/dist/transform/read/index.js +3 -2
  202. package/dist/transform/read/index.js.map +1 -1
  203. package/dist/transform/read/relationship.d.ts +2 -1
  204. package/dist/transform/read/relationship.d.ts.map +1 -1
  205. package/dist/transform/read/relationship.js +15 -6
  206. package/dist/transform/read/relationship.js.map +1 -1
  207. package/dist/transform/read/traverseFields.d.ts +10 -2
  208. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  209. package/dist/transform/read/traverseFields.js +132 -52
  210. package/dist/transform/read/traverseFields.js.map +1 -1
  211. package/dist/transform/write/array.d.ts +6 -1
  212. package/dist/transform/write/array.d.ts.map +1 -1
  213. package/dist/transform/write/array.js +7 -3
  214. package/dist/transform/write/array.js.map +1 -1
  215. package/dist/transform/write/blocks.d.ts +8 -3
  216. package/dist/transform/write/blocks.d.ts.map +1 -1
  217. package/dist/transform/write/blocks.js +19 -7
  218. package/dist/transform/write/blocks.js.map +1 -1
  219. package/dist/transform/write/index.d.ts.map +1 -1
  220. package/dist/transform/write/index.js +1 -1
  221. package/dist/transform/write/index.js.map +1 -1
  222. package/dist/transform/write/relationships.d.ts.map +1 -1
  223. package/dist/transform/write/relationships.js +6 -2
  224. package/dist/transform/write/relationships.js.map +1 -1
  225. package/dist/transform/write/selects.d.ts.map +1 -1
  226. package/dist/transform/write/selects.js +1 -1
  227. package/dist/transform/write/selects.js.map +1 -1
  228. package/dist/transform/write/traverseFields.d.ts +6 -1
  229. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  230. package/dist/transform/write/traverseFields.js +45 -17
  231. package/dist/transform/write/traverseFields.js.map +1 -1
  232. package/dist/types.d.ts +1 -1
  233. package/dist/types.d.ts.map +1 -1
  234. package/dist/types.js.map +1 -1
  235. package/dist/update.d.ts.map +1 -1
  236. package/dist/update.js +3 -2
  237. package/dist/update.js.map +1 -1
  238. package/dist/updateGlobalVersion.js +2 -2
  239. package/dist/updateGlobalVersion.js.map +1 -1
  240. package/dist/updateVersion.js +2 -2
  241. package/dist/updateVersion.js.map +1 -1
  242. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
  243. package/dist/upsertRow/deleteExistingRowsByPath.js +6 -2
  244. package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
  245. package/dist/upsertRow/index.d.ts +1 -1
  246. package/dist/upsertRow/index.d.ts.map +1 -1
  247. package/dist/upsertRow/index.js +50 -12
  248. package/dist/upsertRow/index.js.map +1 -1
  249. package/dist/upsertRow/insertArrays.d.ts.map +1 -1
  250. package/dist/upsertRow/insertArrays.js +5 -2
  251. package/dist/upsertRow/insertArrays.js.map +1 -1
  252. package/dist/upsertRow/types.d.ts +8 -5
  253. package/dist/upsertRow/types.d.ts.map +1 -1
  254. package/dist/upsertRow/types.js.map +1 -1
  255. package/dist/utilities/createBlocksMap.d.ts.map +1 -1
  256. package/dist/utilities/createBlocksMap.js +4 -2
  257. package/dist/utilities/createBlocksMap.js.map +1 -1
  258. package/dist/utilities/createRelationshipMap.d.ts.map +1 -1
  259. package/dist/utilities/createRelationshipMap.js +3 -1
  260. package/dist/utilities/createRelationshipMap.js.map +1 -1
  261. package/dist/utilities/getCollectionIdType.d.ts +7 -0
  262. package/dist/utilities/getCollectionIdType.d.ts.map +1 -0
  263. package/dist/utilities/getCollectionIdType.js +11 -0
  264. package/dist/utilities/getCollectionIdType.js.map +1 -0
  265. package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
  266. package/dist/utilities/hasLocalesTable.js +12 -4
  267. package/dist/utilities/hasLocalesTable.js.map +1 -1
  268. package/dist/utilities/isPolymorphicRelationship.d.ts +6 -0
  269. package/dist/utilities/isPolymorphicRelationship.d.ts.map +1 -0
  270. package/dist/utilities/isPolymorphicRelationship.js +5 -0
  271. package/dist/utilities/isPolymorphicRelationship.js.map +1 -0
  272. package/package.json +16 -7
@@ -1,4 +1,4 @@
1
- /* eslint-disable no-restricted-syntax, no-await-in-loop */ import { commitTransaction, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload';
1
+ import { commitTransaction, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload';
2
2
  import { migrationTableExists } from './utilities/migrationTableExists.js';
3
3
  /**
4
4
  * Run all migrate down functions
@@ -49,7 +49,9 @@ import { migrationTableExists } from './utilities/migrationTableExists.js';
49
49
  await commitTransaction(req);
50
50
  } catch (err) {
51
51
  let msg = `Error running migration ${migrationFile.name}.`;
52
- if (err instanceof Error) msg += ` ${err.message}`;
52
+ if (err instanceof Error) {
53
+ msg += ` ${err.message}`;
54
+ }
53
55
  await killTransaction(req);
54
56
  payload.logger.error({
55
57
  err,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/migrateReset.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { PayloadRequest } from 'payload'\n\nimport {\n commitTransaction,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\n\n/**\n * Run all migrate down functions\n */\nexport async function migrateReset(this: DrizzleAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations } = await getMigrations({ payload })\n\n if (!existingMigrations?.length) {\n payload.logger.info({ msg: 'No migrations to reset.' })\n return\n }\n\n const req = { payload } as PayloadRequest\n\n // Rollback all migrations in order\n for (const migration of existingMigrations) {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n try {\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n const start = Date.now()\n payload.logger.info({ msg: `Migrating down: ${migrationFile.name}` })\n await initTransaction(req)\n await migrationFile.down({ payload, req })\n payload.logger.info({\n msg: `Migrated down: ${migrationFile.name} (${Date.now() - start}ms)`,\n })\n\n const tableExists = await migrationTableExists(this)\n if (tableExists) {\n await payload.delete({\n id: migration.id,\n collection: 'payload-migrations',\n req,\n })\n }\n\n await commitTransaction(req)\n } catch (err: unknown) {\n let msg = `Error running migration ${migrationFile.name}.`\n\n if (err instanceof Error) msg += ` ${err.message}`\n\n await killTransaction(req)\n payload.logger.error({\n err,\n msg,\n })\n process.exit(1)\n }\n }\n\n // Delete dev migration\n\n const tableExists = await migrationTableExists(this)\n if (tableExists) {\n try {\n await payload.delete({\n collection: 'payload-migrations',\n where: {\n batch: {\n equals: -1,\n },\n },\n })\n } catch (err: unknown) {\n payload.logger.error({ error: err, msg: 'Error deleting dev migration' })\n }\n }\n}\n"],"names":["commitTransaction","getMigrations","initTransaction","killTransaction","readMigrationFiles","migrationTableExists","migrateReset","payload","migrationFiles","existingMigrations","length","logger","info","msg","req","migration","migrationFile","find","m","name","Error","start","Date","now","down","tableExists","delete","id","collection","err","message","error","process","exit","where","batch","equals"],"mappings":"AAAA,yDAAyD,GAGzD,SACEA,iBAAiB,EACjBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,UAAS;AAIhB,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAM,EAAEC,O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AAO,CAAC,CAAC,EAAEgB,IAAIC,OAAO,CAAC,CAAC;YAElD,MAAM3B,gBAAgBW;YACtBP,QAAQI,MAAM,CAACoB,KAAK,CAAC;gBACnBF;gBACAhB;YACF;YACAmB,QAAQC,IAAI,CAAC;QACf;IACF;IAEA,uBAAuB;IAEvB,MAAMR,cAAc,MAAMpB,qBAAqB,IAAI;IACnD,IAAIoB,aAAa;QACf,IAAI;YACF,MAAMlB,QAAQmB,MAAM,CAAC;gBACnBE,YAAY;gBACZM,OAAO;oBACLC,OAAO;wBACLC,QAAQ,CAAC;oBACX;gBACF;YACF;QACF,EAAE,OAAOP,KAAc;YACrBtB,QAAQI,MAAM,CAACoB,KAAK,CAAC;gBAAEA,OAAOF;gBAAKhB,KAAK;YAA+B;QACzE;IACF;AACF"}
1
+ {"version":3,"sources":["../src/migrateReset.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport {\n commitTransaction,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\n\n/**\n * Run all migrate down functions\n */\nexport async function migrateReset(this: DrizzleAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations } = await getMigrations({ payload })\n\n if (!existingMigrations?.length) {\n payload.logger.info({ msg: 'No migrations to reset.' })\n return\n }\n\n const req = { payload } as PayloadRequest\n\n // Rollback all migrations in order\n for (const migration of existingMigrations) {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n try {\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n const start = Date.now()\n payload.logger.info({ msg: `Migrating down: ${migrationFile.name}` })\n await initTransaction(req)\n await migrationFile.down({ payload, req })\n payload.logger.info({\n msg: `Migrated down: ${migrationFile.name} (${Date.now() - start}ms)`,\n })\n\n const tableExists = await migrationTableExists(this)\n if (tableExists) {\n await payload.delete({\n id: migration.id,\n collection: 'payload-migrations',\n req,\n })\n }\n\n await commitTransaction(req)\n } catch (err: unknown) {\n let msg = `Error running migration ${migrationFile.name}.`\n\n if (err instanceof Error) {\n msg += ` ${err.message}`\n }\n\n await killTransaction(req)\n payload.logger.error({\n err,\n msg,\n })\n process.exit(1)\n }\n }\n\n // Delete dev migration\n\n const tableExists = await migrationTableExists(this)\n if (tableExists) {\n try {\n await payload.delete({\n collection: 'payload-migrations',\n where: {\n batch: {\n equals: -1,\n },\n },\n })\n } catch (err: unknown) {\n payload.logger.error({ error: err, msg: 'Error deleting dev migration' })\n }\n }\n}\n"],"names":["commitTransaction","getMigrations","initTransaction","killTransaction","readMigrationFiles","migrationTableExists","migrateReset","payload","migrationFiles","existingMigrations","length","logger","info","msg","req","migration","migrationFile","find","m","name","Error","start","Date","now","down","tableExists","delete","id","collection","err","message","error","process","exit","where","batch","equals"],"mappings":"AAEA,SACEA,iBAAiB,EACjBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,UAAS;AAIhB,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMJ,mBAAmB;QAAEG;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAE,GAAG,MAAMR,cAAc;QAAEM;IAAQ;IAE7D,IAAI,CAACE,oBAAoBC,QAAQ;QAC/BH,QAAQI,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAA0B;QACrD;IACF;IAEA,MAAMC,MAAM;QAAEP;IAAQ;IAEtB,mCAAmC;IACnC,KAAK,MAAMQ,aAAaN,mBAAoB;QAC1C,MAAMO,gBAAgBR,eAAeS,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAC1E,IAAI;YACF,IAAI,CAACH,eAAe;gBAClB,MAAM,IAAII,MAAM,C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QACzE;IACF;AACF"}
@@ -27,7 +27,6 @@ export async function migrateStatus() {
27
27
  const existingMigration = existingMigrations.find((m)=>m.name === migration.name);
28
28
  return {
29
29
  Name: migration.name,
30
- // eslint-disable-next-line perfectionist/sort-objects
31
30
  Batch: existingMigration?.batch,
32
31
  Ran: existingMigration ? 'Yes' : 'No'
33
32
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/migrateStatus.ts"],"sourcesContent":["import { Table } from 'console-table-printer'\nimport { getMigrations, readMigrationFiles } from 'payload'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\n\nexport async function migrateStatus(this: DrizzleAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n let existingMigrations = []\n const hasMigrationTable = await migrationTableExists(this)\n\n if (hasMigrationTable) {\n ;({ existingMigrations } = await getMigrations({ payload }))\n }\n\n if (!migrationFiles.length) {\n payload.logger.info({ msg: 'No migrations found.' })\n return\n }\n\n // Compare migration files to existing migrations\n const statuses = migrationFiles.map((migration) => {\n const existingMigration = existingMigrations.find((m) => m.name === migration.name)\n return {\n Name: migration.name,\n // eslint-disable-next-line perfectionist/sort-objects\n Batch: existingMigration?.batch,\n Ran: existingMigration ? 'Yes' : 'No',\n }\n })\n\n const p = new Table()\n\n statuses.forEach((s) => {\n p.addRow(s, {\n color: s.Ran === 'Yes' ? 'green' : 'red',\n })\n })\n p.printTable()\n}\n"],"names":["Table","getMigrations","readMigrationFiles","migrationTableExists","migrateStatus","payload","migrationFiles","logger","debug","msg","length","existingMigrations","hasMigrationTable","info","statuses","map","migration","existingMigration","find","m","name","Name","Batch","batch","Ran","p","forEach","s","addRow","color","printTable"],"mappings":"AAAA,SAASA,KAAK,QAAQ,wBAAuB;AAC7C,SAASC,aAAa,EAAEC,kBAAkB,QAAQ,UAAS;AAI3D,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMJ,mBAAmB;QAAEG;IAAQ;IAE1DA,QAAQE,MAAM,CAACC,KAAK,CAAC;QACnBC,KAAK,CAAC,MAAM,EAAEH,eAAeI,MAAM,CAAC,iBAAiB,CAAC;IACxD;IAEA,IAAIC,qBAAqB,EAAE;IAC3B,MAAMC,oBAAoB,MAAMT,qBAAqB,IAAI;IAEzD,IAAIS,mBAAmB;QACnB,CAAA,EAAED,kBAAkB,EAAE,GAAG,MAAMV,cAAc;YAAEI;QAAQ,EAAC;IAC5D;IAEA,IAAI,CAACC,eAAeI,MAAM,EAAE;QAC1BL,QAAQE,MAAM,CAACM,IAAI,CAAC;YAAEJ,KAAK;QAAuB;QAClD;IACF;IAEA,iDAAiD;IACjD,MAAMK,WAAWR,eAAeS,GAAG,CAAC,CAACC;QACnC,MAAMC,oBAAoBN,mBAAmBO,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAClF,OAAO;YACLC,MAAML,UAAUI,IAAI;YACpB,sDAAsD;YACtDE,OAAOL,mBAAmBM;YAC1BC,KAAKP,oBAAoB,QAAQ;QACnC;IACF;IAEA,MAAMQ,IAAI,IAAIzB;IAEdc,SAASY,OAAO,CAAC,CAACC;QAChBF,EAAEG,MAAM,CAACD,GAAG;YACVE,OAAOF,EAAEH,GAAG,KAAK,QAAQ,UAAU;QACrC;IACF;IACAC,EAAEK,UAAU;AACd"}
1
+ {"version":3,"sources":["../src/migrateStatus.ts"],"sourcesContent":["import { Table } from 'console-table-printer'\nimport { getMigrations, readMigrationFiles } from 'payload'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\n\nexport async function migrateStatus(this: DrizzleAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n let existingMigrations = []\n const hasMigrationTable = await migrationTableExists(this)\n\n if (hasMigrationTable) {\n ;({ existingMigrations } = await getMigrations({ payload }))\n }\n\n if (!migrationFiles.length) {\n payload.logger.info({ msg: 'No migrations found.' })\n return\n }\n\n // Compare migration files to existing migrations\n const statuses = migrationFiles.map((migration) => {\n const existingMigration = existingMigrations.find((m) => m.name === migration.name)\n return {\n Name: migration.name,\n\n Batch: existingMigration?.batch,\n Ran: existingMigration ? 'Yes' : 'No',\n }\n })\n\n const p = new Table()\n\n statuses.forEach((s) => {\n p.addRow(s, {\n color: s.Ran === 'Yes' ? 'green' : 'red',\n })\n })\n p.printTable()\n}\n"],"names":["Table","getMigrations","readMigrationFiles","migrationTableExists","migrateStatus","payload","migrationFiles","logger","debug","msg","length","existingMigrations","hasMigrationTable","info","statuses","map","migration","existingMigration","find","m","name","Name","Batch","batch","Ran","p","forEach","s","addRow","color","printTable"],"mappings":"AAAA,SAASA,KAAK,QAAQ,wBAAuB;AAC7C,SAASC,aAAa,EAAEC,kBAAkB,QAAQ,UAAS;AAI3D,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMJ,mBAAmB;QAAEG;IAAQ;IAE1DA,QAAQE,MAAM,CAACC,KAAK,CAAC;QACnBC,KAAK,CAAC,MAAM,EAAEH,eAAeI,MAAM,CAAC,iBAAiB,CAAC;IACxD;IAEA,IAAIC,qBAAqB,EAAE;IAC3B,MAAMC,oBAAoB,MAAMT,qBAAqB,IAAI;IAEzD,IAAIS,mBAAmB;QACnB,CAAA,EAAED,kBAAkB,EAAE,GAAG,MAAMV,cAAc;YAAEI;QAAQ,EAAC;IAC5D;IAEA,IAAI,CAACC,eAAeI,MAAM,EAAE;QAC1BL,QAAQE,MAAM,CAACM,IAAI,CAAC;YAAEJ,KAAK;QAAuB;QAClD;IACF;IAEA,iDAAiD;IACjD,MAAMK,WAAWR,eAAeS,GAAG,CAAC,CAACC;QACnC,MAAMC,oBAAoBN,mBAAmBO,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAClF,OAAO;YACLC,MAAML,UAAUI,IAAI;YAEpBE,OAAOL,mBAAmBM;YAC1BC,KAAKP,oBAAoB,QAAQ;QACnC;IACF;IAEA,MAAMQ,IAAI,IAAIzB;IAEdc,SAASY,OAAO,CAAC,CAACC;QAChBF,EAAEG,MAAM,CAACD,GAAG;YACVE,OAAOF,EAAEH,GAAG,KAAK,QAAQ,UAAU;QACrC;IACF;IACAC,EAAEK,UAAU;AACd"}
@@ -0,0 +1,3 @@
1
+ import type { CountDistinct } from './types.js';
2
+ export declare const countDistinct: CountDistinct;
3
+ //# sourceMappingURL=countDistinct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countDistinct.d.ts","sourceRoot":"","sources":["../../src/postgres/countDistinct.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAuB,aAAa,EAAE,MAAM,YAAY,CAAA;AAIpE,eAAO,MAAM,aAAa,EAAE,aA4B3B,CAAA"}
@@ -0,0 +1,24 @@
1
+ import { count, sql } from 'drizzle-orm';
2
+ import { chainMethods } from '../find/chainMethods.js';
3
+ export const countDistinct = async function countDistinct({ db, joins, tableName, where }) {
4
+ const chainedMethods = [];
5
+ joins.forEach(({ condition, table })=>{
6
+ chainedMethods.push({
7
+ args: [
8
+ table,
9
+ condition
10
+ ],
11
+ method: 'leftJoin'
12
+ });
13
+ });
14
+ const countResult = await chainMethods({
15
+ methods: chainedMethods,
16
+ query: db.select({
17
+ count: joins.length > 0 ? sql`count
18
+ (DISTINCT ${this.tables[tableName].id})`.mapWith(Number) : count()
19
+ }).from(this.tables[tableName]).where(where)
20
+ });
21
+ return Number(countResult[0].count);
22
+ };
23
+
24
+ //# sourceMappingURL=countDistinct.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/postgres/countDistinct.ts"],"sourcesContent":["import { count, sql } from 'drizzle-orm'\n\nimport type { ChainedMethods, TransactionPg } from '../types.js'\nimport type { BasePostgresAdapter, CountDistinct } from './types.js'\n\nimport { chainMethods } from '../find/chainMethods.js'\n\nexport const countDistinct: CountDistinct = async function countDistinct(\n this: BasePostgresAdapter,\n { db, joins, tableName, where },\n) {\n const chainedMethods: ChainedMethods = []\n\n joins.forEach(({ condition, table }) => {\n chainedMethods.push({\n args: [table, condition],\n method: 'leftJoin',\n })\n })\n\n const countResult = await chainMethods({\n methods: chainedMethods,\n query: (db as TransactionPg)\n .select({\n count:\n joins.length > 0\n ? sql`count\n (DISTINCT ${this.tables[tableName].id})`.mapWith(Number)\n : count(),\n })\n .from(this.tables[tableName])\n .where(where),\n })\n\n return Number(countResult[0].count)\n}\n"],"names":["count","sql","chainMethods","countDistinct","db","joins","tableName","where","chainedMethods","forEach","condition","table","push","args","method","countResult","methods","query","select","length","tables","id","mapWith","Number","from"],"mappings":"AAAA,SAASA,KAAK,EAAEC,GAAG,QAAQ,cAAa;AAKxC,SAASC,YAAY,QAAQ,0BAAyB;AAEtD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,KAAK,EAAEC,SAAS,EAAEC,KAAK,EAAE;IAE/B,MAAMC,iBAAiC,EAAE;IAEzCH,MAAMI,OAAO,CAAC,CAAC,EAAEC,SAAS,EAAEC,KAAK,EAAE;QACjCH,eAAeI,IAAI,CAAC;YAClBC,MAAM;gBAACF;gBAAOD;aAAU;YACxBI,QAAQ;QACV;IACF;IAEA,MAAMC,cAAc,MAAMb,aAAa;QACrCc,SAASR;QACTS,OAAO,AAACb,GACLc,MAAM,CAAC;YACNlB,OACEK,MAAMc,MAAM,GAAG,IACXlB,GAAG,CAAC;gBACF,EAAE,IAAI,CAACmB,MAAM,CAACd,UAAU,CAACe,EAAE,CAAC,CAAC,CAAC,CAACC,OAAO,CAACC,UACzCvB;QACR,GACCwB,IAAI,CAAC,IAAI,CAACJ,MAAM,CAACd,UAAU,EAC3BC,KAAK,CAACA;IACX;IAEA,OAAOgB,OAAOR,WAAW,CAAC,EAAE,CAACf,KAAK;AACpC,EAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const convertPathToJSONTraversal: (incomingSegments: string[]) => string;
2
+ //# sourceMappingURL=convertPathToJSONTraversal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertPathToJSONTraversal.d.ts","sourceRoot":"","sources":["../../../src/postgres/createJSONQuery/convertPathToJSONTraversal.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,0BAA0B,qBAAsB,MAAM,EAAE,WAYpE,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { formatJSONPathSegment } from './formatJSONPathSegment.js';
2
+ export const convertPathToJSONTraversal = (incomingSegments)=>{
3
+ const segments = [
4
+ ...incomingSegments
5
+ ];
6
+ segments.shift();
7
+ return segments.reduce((res, segment, i)=>{
8
+ const formattedSegment = formatJSONPathSegment(segment);
9
+ if (i + 1 === segments.length) {
10
+ return `${res}->>${formattedSegment}`;
11
+ }
12
+ return `${res}->${formattedSegment}`;
13
+ }, '');
14
+ };
15
+
16
+ //# sourceMappingURL=convertPathToJSONTraversal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/postgres/createJSONQuery/convertPathToJSONTraversal.ts"],"sourcesContent":["import { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nexport const convertPathToJSONTraversal = (incomingSegments: string[]) => {\n const segments = [...incomingSegments]\n segments.shift()\n\n return segments.reduce((res, segment, i) => {\n const formattedSegment = formatJSONPathSegment(segment)\n\n if (i + 1 === segments.length) {\n return `${res}->>${formattedSegment}`\n }\n return `${res}->${formattedSegment}`\n }, '')\n}\n"],"names":["formatJSONPathSegment","convertPathToJSONTraversal","incomingSegments","segments","shift","reduce","res","segment","i","formattedSegment","length"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,6BAA4B;AAElE,OAAO,MAAMC,6BAA6B,CAACC;IACzC,MAAMC,WAAW;WAAID;KAAiB;IACtCC,SAASC,KAAK;IAEd,OAAOD,SAASE,MAAM,CAAC,CAACC,KAAKC,SAASC;QACpC,MAAMC,mBAAmBT,sBAAsBO;QAE/C,IAAIC,IAAI,MAAML,SAASO,MAAM,EAAE;YAC7B,OAAO,CAAC,EAAEJ,IAAI,GAAG,EAAEG,iBAAiB,CAAC;QACvC;QACA,OAAO,CAAC,EAAEH,IAAI,EAAE,EAAEG,iBAAiB,CAAC;IACtC,GAAG;AACL,EAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const formatJSONPathSegment: (segment: string) => string;
2
+ //# sourceMappingURL=formatJSONPathSegment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatJSONPathSegment.d.ts","sourceRoot":"","sources":["../../../src/postgres/createJSONQuery/formatJSONPathSegment.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,YAAa,MAAM,WAEpD,CAAA"}
@@ -0,0 +1,5 @@
1
+ export const formatJSONPathSegment = (segment)=>{
2
+ return Number.isNaN(parseInt(segment)) ? `'${segment}'` : segment;
3
+ };
4
+
5
+ //# sourceMappingURL=formatJSONPathSegment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/postgres/createJSONQuery/formatJSONPathSegment.ts"],"sourcesContent":["export const formatJSONPathSegment = (segment: string) => {\n return Number.isNaN(parseInt(segment)) ? `'${segment}'` : segment\n}\n"],"names":["formatJSONPathSegment","segment","Number","isNaN","parseInt"],"mappings":"AAAA,OAAO,MAAMA,wBAAwB,CAACC;IACpC,OAAOC,OAAOC,KAAK,CAACC,SAASH,YAAY,CAAC,CAAC,EAAEA,QAAQ,CAAC,CAAC,GAAGA;AAC5D,EAAC"}
@@ -0,0 +1,10 @@
1
+ type Args = {
2
+ operator: string;
3
+ pathSegments: string[];
4
+ treatAsArray?: string[];
5
+ treatRootAsArray?: boolean;
6
+ value: unknown;
7
+ };
8
+ export declare const createJSONQuery: ({ operator, pathSegments, treatAsArray, treatRootAsArray, value, }: Args) => string;
9
+ export {};
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/postgres/createJSONQuery/index.ts"],"names":[],"mappings":"AAmDA,KAAK,IAAI,GAAG;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,eAAO,MAAM,eAAe,uEAMzB,IAAI,KAAG,MAqBT,CAAA"}
@@ -0,0 +1,54 @@
1
+ import { convertPathToJSONTraversal } from './convertPathToJSONTraversal.js';
2
+ import { formatJSONPathSegment } from './formatJSONPathSegment.js';
3
+ const operatorMap = {
4
+ contains: '~*',
5
+ equals: '=',
6
+ like: '~*'
7
+ };
8
+ const fromArray = ({ isRoot, operator, pathSegments, treatAsArray, value })=>{
9
+ const newPathSegments = pathSegments.slice(isRoot ? 1 : 2);
10
+ const alias = `${pathSegments[isRoot ? 0 : 1]}_alias_${newPathSegments.length}`;
11
+ newPathSegments.unshift(alias);
12
+ const arrayElements = isRoot ? pathSegments[0] : `${pathSegments[0]} -> ${formatJSONPathSegment(pathSegments[1])}`;
13
+ return `EXISTS (
14
+ SELECT 1
15
+ FROM jsonb_array_elements(${arrayElements}) AS ${alias}
16
+ WHERE ${createJSONQuery({
17
+ operator,
18
+ pathSegments: newPathSegments,
19
+ treatAsArray,
20
+ value
21
+ })}
22
+ )`;
23
+ };
24
+ const createConstraint = ({ operator, pathSegments, value })=>{
25
+ const jsonQuery = convertPathToJSONTraversal(pathSegments);
26
+ return `${pathSegments[0]}${jsonQuery} ${operatorMap[operator]} '${value}'`;
27
+ };
28
+ export const createJSONQuery = ({ operator, pathSegments, treatAsArray, treatRootAsArray, value })=>{
29
+ if (treatRootAsArray) {
30
+ return fromArray({
31
+ isRoot: true,
32
+ operator,
33
+ pathSegments,
34
+ treatAsArray,
35
+ value
36
+ });
37
+ }
38
+ if (treatAsArray.includes(pathSegments[1])) {
39
+ return fromArray({
40
+ operator,
41
+ pathSegments,
42
+ treatAsArray,
43
+ value
44
+ });
45
+ }
46
+ return createConstraint({
47
+ operator,
48
+ pathSegments,
49
+ treatAsArray,
50
+ value
51
+ });
52
+ };
53
+
54
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/postgres/createJSONQuery/index.ts"],"sourcesContent":["import { convertPathToJSONTraversal } from './convertPathToJSONTraversal.js'\nimport { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nconst operatorMap = {\n contains: '~*',\n equals: '=',\n like: '~*',\n}\n\ntype FromArrayArgs = {\n isRoot?: true\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst fromArray = ({ isRoot, operator, pathSegments, treatAsArray, value }: FromArrayArgs) => {\n const newPathSegments = pathSegments.slice(isRoot ? 1 : 2)\n const alias = `${pathSegments[isRoot ? 0 : 1]}_alias_${newPathSegments.length}`\n\n newPathSegments.unshift(alias)\n\n const arrayElements = isRoot\n ? pathSegments[0]\n : `${pathSegments[0]} -> ${formatJSONPathSegment(pathSegments[1])}`\n\n return `EXISTS (\n SELECT 1\n FROM jsonb_array_elements(${arrayElements}) AS ${alias}\n WHERE ${createJSONQuery({\n operator,\n pathSegments: newPathSegments,\n treatAsArray,\n value,\n })}\n )`\n}\n\ntype CreateConstraintArgs = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst createConstraint = ({ operator, pathSegments, value }: CreateConstraintArgs): string => {\n const jsonQuery = convertPathToJSONTraversal(pathSegments)\n return `${pathSegments[0]}${jsonQuery} ${operatorMap[operator]} '${value}'`\n}\n\ntype Args = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n treatRootAsArray?: boolean\n value: unknown\n}\n\nexport const createJSONQuery = ({\n operator,\n pathSegments,\n treatAsArray,\n treatRootAsArray,\n value,\n}: Args): string => {\n if (treatRootAsArray) {\n return fromArray({\n isRoot: true,\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n if (treatAsArray.includes(pathSegments[1])) {\n return fromArray({\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n return createConstraint({ operator, pathSegments, treatAsArray, value })\n}\n"],"names":["convertPathToJSONTraversal","formatJSONPathSegment","operatorMap","contains","equals","like","fromArray","isRoot","operator","pathSegments","treatAsArray","value","newPathSegments","slice","alias","length","unshift","arrayElements","createJSONQuery","createConstraint","jsonQuery","treatRootAsArray","includes"],"mappings":"AAAA,SAASA,0BAA0B,QAAQ,kCAAiC;AAC5E,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,MAAMC,cAAc;IAClBC,UAAU;IACVC,QAAQ;IACRC,MAAM;AACR;AAUA,MAAMC,YAAY,CAAC,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,YAAY,EAAEC,KAAK,EAAiB;IACvF,MAAMC,kBAAkBH,aAAaI,KAAK,CAACN,SAAS,IAAI;IACxD,MAAMO,QAAQ,CAAC,EAAEL,YAAY,CAACF,SAAS,IAAI,EAAE,CAAC,OAAO,EAAEK,gBAAgBG,MAAM,CAAC,CAAC;IAE/EH,gBAAgBI,OAAO,CAACF;IAExB,MAAMG,gBAAgBV,SAClBE,YAAY,CAAC,EAAE,GACf,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,IAAI,EAAER,sBAAsBQ,YAAY,CAAC,EAAE,EAAE,CAAC;IAErE,OAAO,CAAC;;8BAEoB,EAAEQ,cAAc,KAAK,EAAEH,MAAM;UACjD,EAAEI,gBAAgB;QACtBV;QACAC,cAAcG;QACdF;QACAC;IACF,GAAG;GACJ,CAAC;AACJ;AASA,MAAMQ,mBAAmB,CAAC,EAAEX,QAAQ,EAAEC,YAAY,EAAEE,KAAK,EAAwB;IAC/E,MAAMS,YAAYpB,2BAA2BS;IAC7C,OAAO,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,EAAEW,UAAU,CAAC,EAAElB,WAAW,CAACM,SAAS,CAAC,EAAE,EAAEG,MAAM,CAAC,CAAC;AAC7E;AAUA,OAAO,MAAMO,kBAAkB,CAAC,EAC9BV,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZW,gBAAgB,EAChBV,KAAK,EACA;IACL,IAAIU,kBAAkB;QACpB,OAAOf,UAAU;YACfC,QAAQ;YACRC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,IAAID,aAAaY,QAAQ,CAACb,YAAY,CAAC,EAAE,GAAG;QAC1C,OAAOH,UAAU;YACfE;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAOQ,iBAAiB;QAAEX;QAAUC;QAAcC;QAAcC;IAAM;AACxE,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { CreateMigration } from 'payload';
2
+ export declare const createMigration: CreateMigration;
3
+ //# sourceMappingURL=createMigration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../../src/postgres/createMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAgB9C,eAAO,MAAM,eAAe,EAAE,eAyG7B,CAAA"}
@@ -0,0 +1,92 @@
1
+ import fs from 'fs';
2
+ import { createRequire } from 'module';
3
+ import path from 'path';
4
+ import { getPredefinedMigration, writeMigrationIndex } from 'payload';
5
+ import prompts from 'prompts';
6
+ import { fileURLToPath } from 'url';
7
+ import { defaultDrizzleSnapshot } from './defaultSnapshot.js';
8
+ import { getMigrationTemplate } from './getMigrationTemplate.js';
9
+ const require = createRequire(import.meta.url);
10
+ export const createMigration = async function createMigration({ file, forceAcceptWarning, migrationName, payload }) {
11
+ const filename = fileURLToPath(import.meta.url);
12
+ const dirname = path.dirname(filename);
13
+ const dir = payload.db.migrationDir;
14
+ if (!fs.existsSync(dir)) {
15
+ fs.mkdirSync(dir);
16
+ }
17
+ const { generateDrizzleJson, generateMigration, upPgSnapshot } = require('drizzle-kit/api');
18
+ const drizzleJsonAfter = generateDrizzleJson(this.schema);
19
+ const [yyymmdd, hhmmss] = new Date().toISOString().split('T');
20
+ const formattedDate = yyymmdd.replace(/\D/g, '');
21
+ const formattedTime = hhmmss.split('.')[0].replace(/\D/g, '');
22
+ let imports = '';
23
+ let downSQL;
24
+ let upSQL;
25
+ ({ downSQL, imports, upSQL } = await getPredefinedMigration({
26
+ dirname,
27
+ file,
28
+ migrationName,
29
+ payload
30
+ }));
31
+ const timestamp = `${formattedDate}_${formattedTime}`;
32
+ const name = migrationName || file?.split('/').slice(2).join('/');
33
+ const fileName = `${timestamp}${name ? `_${name.replace(/\W/g, '_')}` : ''}`;
34
+ const filePath = `${dir}/${fileName}`;
35
+ let drizzleJsonBefore = defaultDrizzleSnapshot;
36
+ if (this.schemaName) {
37
+ drizzleJsonBefore.schemas = {
38
+ [this.schemaName]: this.schemaName
39
+ };
40
+ }
41
+ if (!upSQL) {
42
+ // Get latest migration snapshot
43
+ const latestSnapshot = fs.readdirSync(dir).filter((file)=>file.endsWith('.json')).sort().reverse()?.[0];
44
+ if (latestSnapshot) {
45
+ drizzleJsonBefore = JSON.parse(fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'));
46
+ if (drizzleJsonBefore.version < drizzleJsonAfter.version) {
47
+ drizzleJsonBefore = upPgSnapshot(drizzleJsonBefore);
48
+ }
49
+ }
50
+ const sqlStatementsUp = await generateMigration(drizzleJsonBefore, drizzleJsonAfter);
51
+ const sqlStatementsDown = await generateMigration(drizzleJsonAfter, drizzleJsonBefore);
52
+ const sqlExecute = 'await payload.db.drizzle.execute(sql`';
53
+ if (sqlStatementsUp?.length) {
54
+ upSQL = `${sqlExecute}\n ${sqlStatementsUp?.join('\n')}\`)`;
55
+ }
56
+ if (sqlStatementsDown?.length) {
57
+ downSQL = `${sqlExecute}\n ${sqlStatementsDown?.join('\n')}\`)`;
58
+ }
59
+ if (!upSQL?.length && !downSQL?.length && !forceAcceptWarning) {
60
+ const { confirm: shouldCreateBlankMigration } = await prompts({
61
+ name: 'confirm',
62
+ type: 'confirm',
63
+ initial: false,
64
+ message: 'No schema changes detected. Would you like to create a blank migration file?'
65
+ }, {
66
+ onCancel: ()=>{
67
+ process.exit(0);
68
+ }
69
+ });
70
+ if (!shouldCreateBlankMigration) {
71
+ process.exit(0);
72
+ }
73
+ }
74
+ // write schema
75
+ fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2));
76
+ }
77
+ // write migration
78
+ fs.writeFileSync(`${filePath}.ts`, getMigrationTemplate({
79
+ downSQL: downSQL || ` // Migration code`,
80
+ imports,
81
+ packageName: payload.db.packageName,
82
+ upSQL: upSQL || ` // Migration code`
83
+ }));
84
+ writeMigrationIndex({
85
+ migrationsDir: payload.db.migrationDir
86
+ });
87
+ payload.logger.info({
88
+ msg: `Migration created at ${filePath}.ts`
89
+ });
90
+ };
91
+
92
+ //# sourceMappingURL=createMigration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/postgres/createMigration.ts"],"sourcesContent":["import type { CreateMigration } from 'payload'\n\nimport fs from 'fs'\nimport { createRequire } from 'module'\nimport path from 'path'\nimport { getPredefinedMigration, writeMigrationIndex } from 'payload'\nimport prompts from 'prompts'\nimport { fileURLToPath } from 'url'\n\nimport type { BasePostgresAdapter } from './types.js'\n\nimport { defaultDrizzleSnapshot } from './defaultSnapshot.js'\nimport { getMigrationTemplate } from './getMigrationTemplate.js'\n\nconst require = createRequire(import.meta.url)\n\nexport const createMigration: CreateMigration = async function createMigration(\n this: BasePostgresAdapter,\n { file, forceAcceptWarning, migrationName, payload },\n) {\n const filename = fileURLToPath(import.meta.url)\n const dirname = path.dirname(filename)\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n const { generateDrizzleJson, generateMigration, upPgSnapshot } = require('drizzle-kit/api')\n const drizzleJsonAfter = generateDrizzleJson(this.schema)\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n const formattedDate = yyymmdd.replace(/\\D/g, '')\n const formattedTime = hhmmss.split('.')[0].replace(/\\D/g, '')\n let imports: string = ''\n let downSQL: string\n let upSQL: string\n ;({ downSQL, imports, upSQL } = await getPredefinedMigration({\n dirname,\n file,\n migrationName,\n payload,\n }))\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const name = migrationName || file?.split('/').slice(2).join('/')\n const fileName = `${timestamp}${name ? `_${name.replace(/\\W/g, '_')}` : ''}`\n\n const filePath = `${dir}/${fileName}`\n\n let drizzleJsonBefore = defaultDrizzleSnapshot\n\n if (this.schemaName) {\n drizzleJsonBefore.schemas = {\n [this.schemaName]: this.schemaName,\n }\n }\n\n if (!upSQL) {\n // Get latest migration snapshot\n const latestSnapshot = fs\n .readdirSync(dir)\n .filter((file) => file.endsWith('.json'))\n .sort()\n .reverse()?.[0]\n\n if (latestSnapshot) {\n drizzleJsonBefore = JSON.parse(fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'))\n\n if (drizzleJsonBefore.version < drizzleJsonAfter.version) {\n drizzleJsonBefore = upPgSnapshot(drizzleJsonBefore)\n }\n }\n\n const sqlStatementsUp = await generateMigration(drizzleJsonBefore, drizzleJsonAfter)\n const sqlStatementsDown = await generateMigration(drizzleJsonAfter, drizzleJsonBefore)\n const sqlExecute = 'await payload.db.drizzle.execute(sql`'\n\n if (sqlStatementsUp?.length) {\n upSQL = `${sqlExecute}\\n ${sqlStatementsUp?.join('\\n')}\\`)`\n }\n if (sqlStatementsDown?.length) {\n downSQL = `${sqlExecute}\\n ${sqlStatementsDown?.join('\\n')}\\`)`\n }\n\n if (!upSQL?.length && !downSQL?.length && !forceAcceptWarning) {\n const { confirm: shouldCreateBlankMigration } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: 'No schema changes detected. Would you like to create a blank migration file?',\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!shouldCreateBlankMigration) {\n process.exit(0)\n }\n }\n\n // write schema\n fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2))\n }\n\n // write migration\n fs.writeFileSync(\n `${filePath}.ts`,\n getMigrationTemplate({\n downSQL: downSQL || ` // Migration code`,\n imports,\n packageName: payload.db.packageName,\n upSQL: upSQL || ` // Migration code`,\n }),\n )\n\n writeMigrationIndex({ migrationsDir: payload.db.migrationDir })\n\n payload.logger.info({ msg: `Migration created at ${filePath}.ts` })\n}\n"],"names":["fs","createRequire","path","getPredefinedMigration","writeMigrationIndex","prompts","fileURLToPath","defaultDrizzleSnapshot","getMigrationTemplate","require","url","createMigration","file","forceAcceptWarning","migrationName","payload","filename","dirname","dir","db","migrationDir","existsSync","mkdirSync","generateDrizzleJson","generateMigration","upPgSnapshot","drizzleJsonAfter","schema","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","imports","downSQL","upSQL","timestamp","name","slice","join","fileName","filePath","drizzleJsonBefore","schemaName","schemas","latestSnapshot","readdirSync","filter","endsWith","sort","reverse","JSON","parse","readFileSync","version","sqlStatementsUp","sqlStatementsDown","sqlExecute","length","confirm","shouldCreateBlankMigration","type","initial","message","onCancel","process","exit","writeFileSync","stringify","packageName","migrationsDir","logger","info","msg"],"mappings":"AAEA,OAAOA,QAAQ,KAAI;AACnB,SAASC,aAAa,QAAQ,SAAQ;AACtC,OAAOC,UAAU,OAAM;AACvB,SAASC,sBAAsB,EAAEC,mBAAmB,QAAQ,UAAS;AACrE,OAAOC,aAAa,UAAS;AAC7B,SAASC,aAAa,QAAQ,MAAK;AAInC,SAASC,sBAAsB,QAAQ,uBAAsB;AAC7D,SAASC,oBAAoB,QAAQ,4BAA2B;AAEhE,MAAMC,UAAUR,cAAc,YA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AE1B,SAAS,KAAK,CAAC,EAAEU,KAAKiB,SAAS,CAAC7C,kBAAkB,MAAM;IAC9E;IAEA,kBAAkB;IAClB1B,GAAGsE,aAAa,CACd,CAAC,EAAE1B,SAAS,GAAG,CAAC,EAChBpC,qBAAqB;QACnB6B,SAASA,WAAW,CAAC,mBAAmB,CAAC;QACzCD;QACAoC,aAAazD,QAAQI,EAAE,CAACqD,WAAW;QACnClC,OAAOA,SAAS,CAAC,mBAAmB,CAAC;IACvC;IAGFlC,oBAAoB;QAAEqE,eAAe1D,QAAQI,EAAE,CAACC,YAAY;IAAC;IAE7DL,QAAQ2D,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK,CAAC,qBAAqB,EAAEhC,SAAS,GAAG,CAAC;IAAC;AACnE,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { DrizzleSnapshotJSON } from 'drizzle-kit/api';
2
+ export declare const defaultDrizzleSnapshot: DrizzleSnapshotJSON;
3
+ //# sourceMappingURL=defaultSnapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultSnapshot.d.ts","sourceRoot":"","sources":["../../src/postgres/defaultSnapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAE1D,eAAO,MAAM,sBAAsB,EAAE,mBAcpC,CAAA"}
@@ -0,0 +1,17 @@
1
+ export const defaultDrizzleSnapshot = {
2
+ id: '00000000-0000-0000-0000-000000000000',
3
+ _meta: {
4
+ columns: {},
5
+ schemas: {},
6
+ tables: {}
7
+ },
8
+ dialect: 'postgresql',
9
+ enums: {},
10
+ prevId: '00000000-0000-0000-0000-00000000000',
11
+ schemas: {},
12
+ sequences: {},
13
+ tables: {},
14
+ version: '7'
15
+ };
16
+
17
+ //# sourceMappingURL=defaultSnapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/postgres/defaultSnapshot.ts"],"sourcesContent":["import type { DrizzleSnapshotJSON } from 'drizzle-kit/api'\n\nexport const defaultDrizzleSnapshot: DrizzleSnapshotJSON = {\n id: '00000000-0000-0000-0000-000000000000',\n _meta: {\n columns: {},\n schemas: {},\n tables: {},\n },\n dialect: 'postgresql',\n enums: {},\n prevId: '00000000-0000-0000-0000-00000000000',\n schemas: {},\n sequences: {},\n tables: {},\n version: '7',\n}\n"],"names":["defaultDrizzleSnapshot","id","_meta","columns","schemas","tables","dialect","enums","prevId","sequences","version"],"mappings":"AAEA,OAAO,MAAMA,yBAA8C;IACzDC,IAAI;IACJC,OAAO;QACLC,SAAS,CAAC;QACVC,SAAS,CAAC;QACVC,QAAQ,CAAC;IACX;IACAC,SAAS;IACTC,OAAO,CAAC;IACRC,QAAQ;IACRJ,SAAS,CAAC;IACVK,WAAW,CAAC;IACZJ,QAAQ,CAAC;IACTK,SAAS;AACX,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { DeleteWhere } from './types.js';
2
+ export declare const deleteWhere: DeleteWhere;
3
+ //# sourceMappingURL=deleteWhere.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteWhere.d.ts","sourceRoot":"","sources":["../../src/postgres/deleteWhere.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,eAAO,MAAM,WAAW,EAAE,WAGzB,CAAA"}
@@ -0,0 +1,6 @@
1
+ export const deleteWhere = async function deleteWhere({ db, tableName, where }) {
2
+ const table = this.tables[tableName];
3
+ await db.delete(table).where(where);
4
+ };
5
+
6
+ //# sourceMappingURL=deleteWhere.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/postgres/deleteWhere.ts"],"sourcesContent":["import type { TransactionPg } from '../types.js'\nimport type { DeleteWhere } from './types.js'\n\nexport const deleteWhere: DeleteWhere = async function deleteWhere({ db, tableName, where }) {\n const table = this.tables[tableName]\n await (db as TransactionPg).delete(table).where(where)\n}\n"],"names":["deleteWhere","db","tableName","where","table","tables","delete"],"mappings":"AAGA,OAAO,MAAMA,cAA2B,eAAeA,YAAY,EAAEC,EAAE,EAAEC,SAAS,EAAEC,KAAK,EAAE;IACzF,MAAMC,QAAQ,IAAI,CAACC,MAAM,CAACH,UAAU;IACpC,MAAM,AAACD,GAAqBK,MAAM,CAACF,OAAOD,KAAK,CAACA;AAClD,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { DropDatabase } from './types.js';
2
+ export declare const dropDatabase: DropDatabase;
3
+ //# sourceMappingURL=dropDatabase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dropDatabase.d.ts","sourceRoot":"","sources":["../../src/postgres/dropDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,eAAO,MAAM,YAAY,EAAE,YAM1B,CAAA"}
@@ -0,0 +1,9 @@
1
+ export const dropDatabase = async function dropDatabase({ adapter }) {
2
+ await adapter.execute({
3
+ drizzle: adapter.drizzle,
4
+ raw: `drop schema if exists ${this.schemaName || 'public'} cascade;
5
+ create schema ${this.schemaName || 'public'};`
6
+ });
7
+ };
8
+
9
+ //# sourceMappingURL=dropDatabase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/postgres/dropDatabase.ts"],"sourcesContent":["import type { DropDatabase } from './types.js'\n\nexport const dropDatabase: DropDatabase = async function dropDatabase({ adapter }) {\n await adapter.execute({\n drizzle: adapter.drizzle,\n raw: `drop schema if exists ${this.schemaName || 'public'} cascade;\n create schema ${this.schemaName || 'public'};`,\n })\n}\n"],"names":["dropDatabase","adapter","execute","drizzle","raw","schemaName"],"mappings":"AAEA,OAAO,MAAMA,eAA6B,eAAeA,aAAa,EAAEC,OAAO,EAAE;IAC/E,MAAMA,QAAQC,OAAO,CAAC;QACpBC,SAASF,QAAQE,OAAO;QACxBC,KAAK,CAAC,sBAAsB,EAAE,IAAI,CAACC,UAAU,IAAI,SAAS;kBAC5C,EAAE,IAAI,CAACA,UAAU,IAAI,SAAS,CAAC,CAAC;IAChD;AACF,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Execute } from './types.js';
2
+ export declare const execute: Execute<any>;
3
+ //# sourceMappingURL=execute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/postgres/execute.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,eAAO,MAAM,OAAO,EAAE,OAAO,CAAC,GAAG,CAQhC,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { sql } from 'drizzle-orm';
2
+ export const execute = function execute({ db, drizzle, raw, sql: statement }) {
3
+ const executeFrom = db ?? drizzle;
4
+ if (raw) {
5
+ return executeFrom.execute(sql.raw(raw));
6
+ } else {
7
+ return executeFrom.execute(sql`${statement}`);
8
+ }
9
+ };
10
+
11
+ //# sourceMappingURL=execute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/postgres/execute.ts"],"sourcesContent":["import { sql } from 'drizzle-orm'\n\nimport type { Execute } from './types.js'\n\nexport const execute: Execute<any> = function execute({ db, drizzle, raw, sql: statement }) {\n const executeFrom = db ?? drizzle\n\n if (raw) {\n return executeFrom.execute(sql.raw(raw))\n } else {\n return executeFrom.execute(sql`${statement}`)\n }\n}\n"],"names":["sql","execute","db","drizzle","raw","statement","executeFrom"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAa;AAIjC,OAAO,MAAMC,UAAwB,SAASA,QAAQ,EAAEC,EAAE,EAAEC,OAAO,EAAEC,GAAG,EAAEJ,KAAKK,SAAS,EAAE;IACxF,MAAMC,cAAcJ,MAAMC;IAE1B,IAAIC,KAAK;QACP,OAAOE,YAAYL,OAAO,CAACD,IAAII,GAAG,CAACA;IACrC,OAAO;QACL,OAAOE,YAAYL,OAAO,CAACD,GAAG,CAAC,EAAEK,UAAU,CAAC;IAC9C;AACF,EAAC"}
@@ -0,0 +1,4 @@
1
+ import type { MigrationTemplateArgs } from 'payload';
2
+ export declare const indent: (text: string) => string;
3
+ export declare const getMigrationTemplate: ({ downSQL, imports, packageName, upSQL, }: MigrationTemplateArgs) => string;
4
+ //# sourceMappingURL=getMigrationTemplate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getMigrationTemplate.d.ts","sourceRoot":"","sources":["../../src/postgres/getMigrationTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,eAAO,MAAM,MAAM,SAAU,MAAM,WAIpB,CAAA;AAEf,eAAO,MAAM,oBAAoB,8CAK9B,qBAAqB,KAAG,MAS1B,CAAA"}
@@ -0,0 +1,13 @@
1
+ export const indent = (text)=>text.split('\n').map((line)=>` ${line}`).join('\n');
2
+ export const getMigrationTemplate = ({ downSQL, imports, packageName, upSQL })=>`import { MigrateUpArgs, MigrateDownArgs, sql } from '${packageName}'
3
+ ${imports ? `${imports}\n` : ''}
4
+ export async function up({ payload, req }: MigrateUpArgs): Promise<void> {
5
+ ${indent(upSQL)}
6
+ }
7
+
8
+ export async function down({ payload, req }: MigrateDownArgs): Promise<void> {
9
+ ${indent(downSQL)}
10
+ }
11
+ `;
12
+
13
+ //# sourceMappingURL=getMigrationTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/postgres/getMigrationTemplate.ts"],"sourcesContent":["import type { MigrationTemplateArgs } from 'payload'\n\nexport const indent = (text: string) =>\n text\n .split('\\n')\n .map((line) => ` ${line}`)\n .join('\\n')\n\nexport const getMigrationTemplate = ({\n downSQL,\n imports,\n packageName,\n upSQL,\n}: MigrationTemplateArgs): string => `import { MigrateUpArgs, MigrateDownArgs, sql } from '${packageName}'\n${imports ? `${imports}\\n` : ''}\nexport async function up({ payload, req }: MigrateUpArgs): Promise<void> {\n${indent(upSQL)}\n}\n\nexport async function down({ payload, req }: MigrateDownArgs): Promise<void> {\n${indent(downSQL)}\n}\n`\n"],"names":["indent","text","split","map","line","join","getMigrationTemplate","downSQL","imports","packageName","upSQL"],"mappings":"AAEA,OAAO,MAAMA,SAAS,CAACC,OACrBA,KACGC,KAAK,CAAC,MACNC,GAAG,CAAC,CAACC,OAAS,CAAC,EAAE,EAAEA,KAAK,CAAC,EACzBC,IAAI,CAAC,MAAK;AAEf,OAAO,MAAMC,uBAAuB,CAAC,EACnCC,OAAO,EACPC,OAAO,EACPC,WAAW,EACXC,KAAK,EACiB,GAAa,CAAC,qDAAqD,EAAED,YAAY;AACzG,EAAED,UAAU,CAAC,EAAEA,QAAQ,EAAE,CAAC,GAAG,GAAG;;AAEhC,EAAER,OAAOU,OAAO;;;;AAIhB,EAAEV,OAAOO,SAAS;;AAElB,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Init } from 'payload';
2
+ export declare const init: Init;
3
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/postgres/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;AAW9D,eAAO,MAAM,IAAI,EAAE,IAqGlB,CAAA"}
@@ -0,0 +1,95 @@
1
+ import { uniqueIndex } from 'drizzle-orm/pg-core';
2
+ import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
3
+ import toSnakeCase from 'to-snake-case';
4
+ import { createTableName } from '../createTableName.js';
5
+ import { buildTable } from './schema/build.js';
6
+ export const init = function init() {
7
+ if (this.payload.config.localization) {
8
+ this.enums.enum__locales = this.pgSchema.enum('_locales', this.payload.config.localization.locales.map(({ code })=>code));
9
+ }
10
+ this.payload.config.collections.forEach((collection)=>{
11
+ createTableName({
12
+ adapter: this,
13
+ config: collection
14
+ });
15
+ if (collection.versions) {
16
+ createTableName({
17
+ adapter: this,
18
+ config: collection,
19
+ versions: true,
20
+ versionsCustomName: true
21
+ });
22
+ }
23
+ });
24
+ this.payload.config.collections.forEach((collection)=>{
25
+ const tableName = this.tableNameMap.get(toSnakeCase(collection.slug));
26
+ const baseExtraConfig = {};
27
+ if (collection.upload.filenameCompoundIndex) {
28
+ const indexName = `${tableName}_filename_compound_idx`;
29
+ baseExtraConfig.filename_compound_index = (cols)=>{
30
+ const colsConstraint = collection.upload.filenameCompoundIndex.map((f)=>{
31
+ return cols[f];
32
+ });
33
+ return uniqueIndex(indexName).on(colsConstraint[0], ...colsConstraint.slice(1));
34
+ };
35
+ }
36
+ buildTable({
37
+ adapter: this,
38
+ baseExtraConfig,
39
+ disableNotNull: !!collection?.versions?.drafts,
40
+ disableUnique: false,
41
+ fields: collection.fields,
42
+ tableName,
43
+ timestamps: collection.timestamps,
44
+ versions: false
45
+ });
46
+ if (collection.versions) {
47
+ const versionsTableName = this.tableNameMap.get(`_${toSnakeCase(collection.slug)}${this.versionsSuffix}`);
48
+ const versionFields = buildVersionCollectionFields(this.payload.config, collection);
49
+ buildTable({
50
+ adapter: this,
51
+ disableNotNull: !!collection.versions?.drafts,
52
+ disableUnique: true,
53
+ fields: versionFields,
54
+ tableName: versionsTableName,
55
+ timestamps: true,
56
+ versions: true
57
+ });
58
+ }
59
+ });
60
+ this.payload.config.globals.forEach((global)=>{
61
+ const tableName = createTableName({
62
+ adapter: this,
63
+ config: global
64
+ });
65
+ buildTable({
66
+ adapter: this,
67
+ disableNotNull: !!global?.versions?.drafts,
68
+ disableUnique: false,
69
+ fields: global.fields,
70
+ tableName,
71
+ timestamps: false,
72
+ versions: false
73
+ });
74
+ if (global.versions) {
75
+ const versionsTableName = createTableName({
76
+ adapter: this,
77
+ config: global,
78
+ versions: true,
79
+ versionsCustomName: true
80
+ });
81
+ const versionFields = buildVersionGlobalFields(this.payload.config, global);
82
+ buildTable({
83
+ adapter: this,
84
+ disableNotNull: !!global.versions?.drafts,
85
+ disableUnique: true,
86
+ fields: versionFields,
87
+ tableName: versionsTableName,
88
+ timestamps: true,
89
+ versions: true
90
+ });
91
+ }
92
+ });
93
+ };
94
+
95
+ //# sourceMappingURL=init.js.map