@contember/engine-system-api 2.1.0-beta.2 → 2.2.0-alpha.2

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 (618) hide show
  1. package/CLAUDE.md +16 -2
  2. package/dist/development/src/SystemContainer.cjs.map +1 -1
  3. package/dist/development/src/SystemContainer.js.map +1 -1
  4. package/dist/development/src/migrations/2020-03-27-130000-project-migrations.cjs.map +1 -1
  5. package/dist/development/src/migrations/2020-03-27-130000-project-migrations.js.map +1 -1
  6. package/dist/development/src/migrations/2020-05-06-150000-composed-primary.cjs.map +1 -1
  7. package/dist/development/src/migrations/2020-05-06-150000-composed-primary.js.map +1 -1
  8. package/dist/development/src/migrations/2020-06-01-103000-event-trigger-perf.cjs.map +1 -1
  9. package/dist/development/src/migrations/2020-06-01-103000-event-trigger-perf.js.map +1 -1
  10. package/dist/development/src/migrations/2021-05-07-155800-event-log-rework.cjs.map +1 -1
  11. package/dist/development/src/migrations/2021-05-07-155800-event-log-rework.js.map +1 -1
  12. package/dist/development/src/migrations/2021-05-19-1232000-event-log-fix-constraint.cjs.map +1 -1
  13. package/dist/development/src/migrations/2021-05-19-1232000-event-log-fix-constraint.js.map +1 -1
  14. package/dist/development/src/migrations/2022-10-03-110000-table-on-delete.cjs.map +1 -1
  15. package/dist/development/src/migrations/2022-10-03-110000-table-on-delete.js.map +1 -1
  16. package/dist/development/src/migrations/2023-09-11-174000-fix-on-delete.cjs.map +1 -1
  17. package/dist/development/src/migrations/2023-09-11-174000-fix-on-delete.js.map +1 -1
  18. package/dist/development/src/migrations/2023-10-19-173000-fix-unique.cjs.map +1 -1
  19. package/dist/development/src/migrations/2023-10-19-173000-fix-unique.js.map +1 -1
  20. package/dist/development/src/migrations/2024-06-28-153001-schema-init.cjs.map +1 -1
  21. package/dist/development/src/migrations/2024-06-28-153001-schema-init.js.map +1 -1
  22. package/dist/development/src/migrations/2025-03-14-110000-fix-missing-index.cjs.map +1 -1
  23. package/dist/development/src/migrations/2025-03-14-110000-fix-missing-index.js.map +1 -1
  24. package/dist/development/src/migrations/2026-06-01-120000-event-truncate.cjs +13 -0
  25. package/dist/development/src/migrations/2026-06-01-120000-event-truncate.cjs.map +1 -0
  26. package/dist/development/src/migrations/2026-06-01-120000-event-truncate.js +14 -0
  27. package/dist/development/src/migrations/2026-06-01-120000-event-truncate.js.map +1 -0
  28. package/dist/development/src/migrations/runner.cjs +3 -1
  29. package/dist/development/src/migrations/runner.cjs.map +1 -1
  30. package/dist/development/src/migrations/runner.js +3 -1
  31. package/dist/development/src/migrations/runner.js.map +1 -1
  32. package/dist/development/src/migrations/snapshot-factory.cjs.map +1 -1
  33. package/dist/development/src/migrations/snapshot-factory.js.map +1 -1
  34. package/dist/development/src/migrations/snapshot.cjs +5 -4
  35. package/dist/development/src/migrations/snapshot.cjs.map +1 -1
  36. package/dist/development/src/migrations/snapshot.js +5 -4
  37. package/dist/development/src/migrations/snapshot.js.map +1 -1
  38. package/dist/development/src/model/ProjectInitializer.cjs.map +1 -1
  39. package/dist/development/src/model/ProjectInitializer.js.map +1 -1
  40. package/dist/development/src/model/ProjectTruncateExecutor.cjs +3 -3
  41. package/dist/development/src/model/ProjectTruncateExecutor.cjs.map +1 -1
  42. package/dist/development/src/model/ProjectTruncateExecutor.js +3 -3
  43. package/dist/development/src/model/ProjectTruncateExecutor.js.map +1 -1
  44. package/dist/development/src/model/authorization/PermissionsFactory.cjs.map +1 -1
  45. package/dist/development/src/model/authorization/PermissionsFactory.js.map +1 -1
  46. package/dist/development/src/model/authorization/StagePermissionsFactory.cjs.map +1 -1
  47. package/dist/development/src/model/authorization/StagePermissionsFactory.js.map +1 -1
  48. package/dist/development/src/model/authorization/StageScope.cjs.map +1 -1
  49. package/dist/development/src/model/authorization/StageScope.js.map +1 -1
  50. package/dist/development/src/model/commands/CommandBus.cjs.map +1 -1
  51. package/dist/development/src/model/commands/CommandBus.js.map +1 -1
  52. package/dist/development/src/model/commands/events/TruncateEventsCommand.cjs +25 -2
  53. package/dist/development/src/model/commands/events/TruncateEventsCommand.cjs.map +1 -1
  54. package/dist/development/src/model/commands/events/TruncateEventsCommand.js +26 -3
  55. package/dist/development/src/model/commands/events/TruncateEventsCommand.js.map +1 -1
  56. package/dist/development/src/model/commands/migrations/DeleteMigrationCommand.cjs.map +1 -1
  57. package/dist/development/src/model/commands/migrations/DeleteMigrationCommand.js.map +1 -1
  58. package/dist/development/src/model/commands/migrations/ModifyMigrationCommand.cjs.map +1 -1
  59. package/dist/development/src/model/commands/migrations/ModifyMigrationCommand.js.map +1 -1
  60. package/dist/development/src/model/commands/migrations/SaveMigrationCommand.cjs.map +1 -1
  61. package/dist/development/src/model/commands/migrations/SaveMigrationCommand.js.map +1 -1
  62. package/dist/development/src/model/commands/schema/SaveSchemaCommand.cjs.map +1 -1
  63. package/dist/development/src/model/commands/schema/SaveSchemaCommand.js.map +1 -1
  64. package/dist/development/src/model/commands/stages/CreateStageCommand.cjs.map +1 -1
  65. package/dist/development/src/model/commands/stages/CreateStageCommand.js.map +1 -1
  66. package/dist/development/src/model/database/DatabaseContext.cjs.map +1 -1
  67. package/dist/development/src/model/database/DatabaseContext.js.map +1 -1
  68. package/dist/development/src/model/events/EventResponseBuilder.cjs +6 -1
  69. package/dist/development/src/model/events/EventResponseBuilder.cjs.map +1 -1
  70. package/dist/development/src/model/events/EventResponseBuilder.js +6 -1
  71. package/dist/development/src/model/events/EventResponseBuilder.js.map +1 -1
  72. package/dist/development/src/model/events/EventResponseHelper.cjs.map +1 -1
  73. package/dist/development/src/model/events/EventResponseHelper.js.map +1 -1
  74. package/dist/development/src/model/events/identityUtils.cjs.map +1 -1
  75. package/dist/development/src/model/events/identityUtils.js.map +1 -1
  76. package/dist/development/src/model/events/types.cjs +17 -0
  77. package/dist/development/src/model/events/types.cjs.map +1 -1
  78. package/dist/development/src/model/events/types.js +17 -0
  79. package/dist/development/src/model/events/types.js.map +1 -1
  80. package/dist/development/src/model/helpers/stageHelpers.cjs.map +1 -1
  81. package/dist/development/src/model/helpers/stageHelpers.js.map +1 -1
  82. package/dist/development/src/model/metadata/SchemaDatabaseMetadataResolverStore.cjs.map +1 -1
  83. package/dist/development/src/model/metadata/SchemaDatabaseMetadataResolverStore.js.map +1 -1
  84. package/dist/development/src/model/migrations/ExecutedMigrationsResolver.cjs.map +1 -1
  85. package/dist/development/src/model/migrations/ExecutedMigrationsResolver.js.map +1 -1
  86. package/dist/development/src/model/migrations/MigrationAlterer.cjs.map +1 -1
  87. package/dist/development/src/model/migrations/MigrationAlterer.js.map +1 -1
  88. package/dist/development/src/model/migrations/ProjectMigrator.cjs +94 -5
  89. package/dist/development/src/model/migrations/ProjectMigrator.cjs.map +1 -1
  90. package/dist/development/src/model/migrations/ProjectMigrator.js +96 -7
  91. package/dist/development/src/model/migrations/ProjectMigrator.js.map +1 -1
  92. package/dist/development/src/model/migrations/SchemaProvider.cjs.map +1 -1
  93. package/dist/development/src/model/migrations/SchemaProvider.js.map +1 -1
  94. package/dist/development/src/model/queries/events/EventQueryHelpers.cjs +16 -8
  95. package/dist/development/src/model/queries/events/EventQueryHelpers.cjs.map +1 -1
  96. package/dist/development/src/model/queries/events/EventQueryHelpers.js +17 -9
  97. package/dist/development/src/model/queries/events/EventQueryHelpers.js.map +1 -1
  98. package/dist/development/src/model/queries/events/EventsQuery.cjs.map +1 -1
  99. package/dist/development/src/model/queries/events/EventsQuery.js.map +1 -1
  100. package/dist/development/src/model/queries/migrations/ExecutedMigrationByVersionQuery.cjs.map +1 -1
  101. package/dist/development/src/model/queries/migrations/ExecutedMigrationByVersionQuery.js.map +1 -1
  102. package/dist/development/src/model/queries/migrations/ExecutedMigrationsQuery.cjs.map +1 -1
  103. package/dist/development/src/model/queries/migrations/ExecutedMigrationsQuery.js.map +1 -1
  104. package/dist/development/src/model/queries/migrations/ExecutedMigrationsQueryHelper.cjs.map +1 -1
  105. package/dist/development/src/model/queries/migrations/ExecutedMigrationsQueryHelper.js.map +1 -1
  106. package/dist/development/src/model/queries/schema/SchemaQuery.cjs.map +1 -1
  107. package/dist/development/src/model/queries/schema/SchemaQuery.js.map +1 -1
  108. package/dist/development/src/model/queries/stages/StageBySlugQuery.cjs.map +1 -1
  109. package/dist/development/src/model/queries/stages/StageBySlugQuery.js.map +1 -1
  110. package/dist/development/src/model/queries/stages/StageQueryFactory.cjs.map +1 -1
  111. package/dist/development/src/model/queries/stages/StageQueryFactory.js.map +1 -1
  112. package/dist/development/src/model/queries/stages/StagesQuery.cjs.map +1 -1
  113. package/dist/development/src/model/queries/stages/StagesQuery.js.map +1 -1
  114. package/dist/development/src/model/stages/StageCreator.cjs.map +1 -1
  115. package/dist/development/src/model/stages/StageCreator.js.map +1 -1
  116. package/dist/development/src/resolvers/ResolverFactory.cjs +4 -1
  117. package/dist/development/src/resolvers/ResolverFactory.cjs.map +1 -1
  118. package/dist/development/src/resolvers/ResolverFactory.js +4 -1
  119. package/dist/development/src/resolvers/ResolverFactory.js.map +1 -1
  120. package/dist/development/src/resolvers/SystemResolverContext.cjs.map +1 -1
  121. package/dist/development/src/resolvers/SystemResolverContext.js.map +1 -1
  122. package/dist/development/src/resolvers/mutation/MigrateMutationResolver.cjs +49 -1
  123. package/dist/development/src/resolvers/mutation/MigrateMutationResolver.cjs.map +1 -1
  124. package/dist/development/src/resolvers/mutation/MigrateMutationResolver.js +49 -1
  125. package/dist/development/src/resolvers/mutation/MigrateMutationResolver.js.map +1 -1
  126. package/dist/development/src/resolvers/mutation/MigrationAlterMutationResolver.cjs.map +1 -1
  127. package/dist/development/src/resolvers/mutation/MigrationAlterMutationResolver.js.map +1 -1
  128. package/dist/development/src/resolvers/mutation/TruncateMutationResolver.cjs +1 -1
  129. package/dist/development/src/resolvers/mutation/TruncateMutationResolver.cjs.map +1 -1
  130. package/dist/development/src/resolvers/mutation/TruncateMutationResolver.js +1 -1
  131. package/dist/development/src/resolvers/mutation/TruncateMutationResolver.js.map +1 -1
  132. package/dist/development/src/resolvers/query/EventsQueryResolver.cjs.map +1 -1
  133. package/dist/development/src/resolvers/query/EventsQueryResolver.js.map +1 -1
  134. package/dist/development/src/resolvers/query/ExecutedMigrationsQueryResolver.cjs.map +1 -1
  135. package/dist/development/src/resolvers/query/ExecutedMigrationsQueryResolver.js.map +1 -1
  136. package/dist/development/src/resolvers/query/SchemaQueryResolver.cjs.map +1 -1
  137. package/dist/development/src/resolvers/query/SchemaQueryResolver.js.map +1 -1
  138. package/dist/development/src/resolvers/query/StagesQueryResolver.cjs.map +1 -1
  139. package/dist/development/src/resolvers/query/StagesQueryResolver.js.map +1 -1
  140. package/dist/development/src/resolvers/types/EventOldValuesResolver.cjs.map +1 -1
  141. package/dist/development/src/resolvers/types/EventOldValuesResolver.js.map +1 -1
  142. package/dist/development/src/resolvers/types/OldValuesHelpers.cjs.map +1 -1
  143. package/dist/development/src/resolvers/types/OldValuesHelpers.js.map +1 -1
  144. package/dist/development/src/schema/dev.graphql.cjs +1 -1
  145. package/dist/development/src/schema/dev.graphql.cjs.map +1 -1
  146. package/dist/development/src/schema/dev.graphql.js +1 -1
  147. package/dist/development/src/schema/dev.graphql.js.map +1 -1
  148. package/dist/development/src/schema/system.graphql.cjs +39 -3
  149. package/dist/development/src/schema/system.graphql.cjs.map +1 -1
  150. package/dist/development/src/schema/system.graphql.js +39 -3
  151. package/dist/development/src/schema/system.graphql.js.map +1 -1
  152. package/dist/development/src/schema/types.cjs +2 -0
  153. package/dist/development/src/schema/types.cjs.map +1 -1
  154. package/dist/development/src/schema/types.js +2 -0
  155. package/dist/development/src/schema/types.js.map +1 -1
  156. package/dist/development/src/utils/batchQuery.cjs.map +1 -1
  157. package/dist/development/src/utils/batchQuery.js.map +1 -1
  158. package/dist/production/src/SystemContainer.cjs.map +1 -1
  159. package/dist/production/src/SystemContainer.js.map +1 -1
  160. package/dist/production/src/migrations/2020-03-27-130000-project-migrations.cjs.map +1 -1
  161. package/dist/production/src/migrations/2020-03-27-130000-project-migrations.js.map +1 -1
  162. package/dist/production/src/migrations/2020-05-06-150000-composed-primary.cjs.map +1 -1
  163. package/dist/production/src/migrations/2020-05-06-150000-composed-primary.js.map +1 -1
  164. package/dist/production/src/migrations/2020-06-01-103000-event-trigger-perf.cjs.map +1 -1
  165. package/dist/production/src/migrations/2020-06-01-103000-event-trigger-perf.js.map +1 -1
  166. package/dist/production/src/migrations/2021-05-07-155800-event-log-rework.cjs.map +1 -1
  167. package/dist/production/src/migrations/2021-05-07-155800-event-log-rework.js.map +1 -1
  168. package/dist/production/src/migrations/2021-05-19-1232000-event-log-fix-constraint.cjs.map +1 -1
  169. package/dist/production/src/migrations/2021-05-19-1232000-event-log-fix-constraint.js.map +1 -1
  170. package/dist/production/src/migrations/2022-10-03-110000-table-on-delete.cjs.map +1 -1
  171. package/dist/production/src/migrations/2022-10-03-110000-table-on-delete.js.map +1 -1
  172. package/dist/production/src/migrations/2023-09-11-174000-fix-on-delete.cjs.map +1 -1
  173. package/dist/production/src/migrations/2023-09-11-174000-fix-on-delete.js.map +1 -1
  174. package/dist/production/src/migrations/2023-10-19-173000-fix-unique.cjs.map +1 -1
  175. package/dist/production/src/migrations/2023-10-19-173000-fix-unique.js.map +1 -1
  176. package/dist/production/src/migrations/2024-06-28-153001-schema-init.cjs.map +1 -1
  177. package/dist/production/src/migrations/2024-06-28-153001-schema-init.js.map +1 -1
  178. package/dist/production/src/migrations/2025-03-14-110000-fix-missing-index.cjs.map +1 -1
  179. package/dist/production/src/migrations/2025-03-14-110000-fix-missing-index.js.map +1 -1
  180. package/dist/production/src/migrations/2026-06-01-120000-event-truncate.cjs +13 -0
  181. package/dist/production/src/migrations/2026-06-01-120000-event-truncate.cjs.map +1 -0
  182. package/dist/production/src/migrations/2026-06-01-120000-event-truncate.js +14 -0
  183. package/dist/production/src/migrations/2026-06-01-120000-event-truncate.js.map +1 -0
  184. package/dist/production/src/migrations/runner.cjs +3 -1
  185. package/dist/production/src/migrations/runner.cjs.map +1 -1
  186. package/dist/production/src/migrations/runner.js +3 -1
  187. package/dist/production/src/migrations/runner.js.map +1 -1
  188. package/dist/production/src/migrations/snapshot-factory.cjs.map +1 -1
  189. package/dist/production/src/migrations/snapshot-factory.js.map +1 -1
  190. package/dist/production/src/migrations/snapshot.cjs +5 -4
  191. package/dist/production/src/migrations/snapshot.cjs.map +1 -1
  192. package/dist/production/src/migrations/snapshot.js +5 -4
  193. package/dist/production/src/migrations/snapshot.js.map +1 -1
  194. package/dist/production/src/model/ProjectInitializer.cjs.map +1 -1
  195. package/dist/production/src/model/ProjectInitializer.js.map +1 -1
  196. package/dist/production/src/model/ProjectTruncateExecutor.cjs +3 -3
  197. package/dist/production/src/model/ProjectTruncateExecutor.cjs.map +1 -1
  198. package/dist/production/src/model/ProjectTruncateExecutor.js +3 -3
  199. package/dist/production/src/model/ProjectTruncateExecutor.js.map +1 -1
  200. package/dist/production/src/model/authorization/PermissionsFactory.cjs.map +1 -1
  201. package/dist/production/src/model/authorization/PermissionsFactory.js.map +1 -1
  202. package/dist/production/src/model/authorization/StagePermissionsFactory.cjs.map +1 -1
  203. package/dist/production/src/model/authorization/StagePermissionsFactory.js.map +1 -1
  204. package/dist/production/src/model/authorization/StageScope.cjs.map +1 -1
  205. package/dist/production/src/model/authorization/StageScope.js.map +1 -1
  206. package/dist/production/src/model/commands/CommandBus.cjs.map +1 -1
  207. package/dist/production/src/model/commands/CommandBus.js.map +1 -1
  208. package/dist/production/src/model/commands/events/TruncateEventsCommand.cjs +25 -2
  209. package/dist/production/src/model/commands/events/TruncateEventsCommand.cjs.map +1 -1
  210. package/dist/production/src/model/commands/events/TruncateEventsCommand.js +26 -3
  211. package/dist/production/src/model/commands/events/TruncateEventsCommand.js.map +1 -1
  212. package/dist/production/src/model/commands/migrations/DeleteMigrationCommand.cjs.map +1 -1
  213. package/dist/production/src/model/commands/migrations/DeleteMigrationCommand.js.map +1 -1
  214. package/dist/production/src/model/commands/migrations/ModifyMigrationCommand.cjs.map +1 -1
  215. package/dist/production/src/model/commands/migrations/ModifyMigrationCommand.js.map +1 -1
  216. package/dist/production/src/model/commands/migrations/SaveMigrationCommand.cjs.map +1 -1
  217. package/dist/production/src/model/commands/migrations/SaveMigrationCommand.js.map +1 -1
  218. package/dist/production/src/model/commands/schema/SaveSchemaCommand.cjs.map +1 -1
  219. package/dist/production/src/model/commands/schema/SaveSchemaCommand.js.map +1 -1
  220. package/dist/production/src/model/commands/stages/CreateStageCommand.cjs.map +1 -1
  221. package/dist/production/src/model/commands/stages/CreateStageCommand.js.map +1 -1
  222. package/dist/production/src/model/database/DatabaseContext.cjs.map +1 -1
  223. package/dist/production/src/model/database/DatabaseContext.js.map +1 -1
  224. package/dist/production/src/model/events/EventResponseBuilder.cjs +6 -1
  225. package/dist/production/src/model/events/EventResponseBuilder.cjs.map +1 -1
  226. package/dist/production/src/model/events/EventResponseBuilder.js +6 -1
  227. package/dist/production/src/model/events/EventResponseBuilder.js.map +1 -1
  228. package/dist/production/src/model/events/EventResponseHelper.cjs.map +1 -1
  229. package/dist/production/src/model/events/EventResponseHelper.js.map +1 -1
  230. package/dist/production/src/model/events/identityUtils.cjs.map +1 -1
  231. package/dist/production/src/model/events/identityUtils.js.map +1 -1
  232. package/dist/production/src/model/events/types.cjs +17 -0
  233. package/dist/production/src/model/events/types.cjs.map +1 -1
  234. package/dist/production/src/model/events/types.js +17 -0
  235. package/dist/production/src/model/events/types.js.map +1 -1
  236. package/dist/production/src/model/helpers/stageHelpers.cjs.map +1 -1
  237. package/dist/production/src/model/helpers/stageHelpers.js.map +1 -1
  238. package/dist/production/src/model/metadata/SchemaDatabaseMetadataResolverStore.cjs.map +1 -1
  239. package/dist/production/src/model/metadata/SchemaDatabaseMetadataResolverStore.js.map +1 -1
  240. package/dist/production/src/model/migrations/ExecutedMigrationsResolver.cjs.map +1 -1
  241. package/dist/production/src/model/migrations/ExecutedMigrationsResolver.js.map +1 -1
  242. package/dist/production/src/model/migrations/MigrationAlterer.cjs.map +1 -1
  243. package/dist/production/src/model/migrations/MigrationAlterer.js.map +1 -1
  244. package/dist/production/src/model/migrations/ProjectMigrator.cjs +94 -5
  245. package/dist/production/src/model/migrations/ProjectMigrator.cjs.map +1 -1
  246. package/dist/production/src/model/migrations/ProjectMigrator.js +96 -7
  247. package/dist/production/src/model/migrations/ProjectMigrator.js.map +1 -1
  248. package/dist/production/src/model/migrations/SchemaProvider.cjs.map +1 -1
  249. package/dist/production/src/model/migrations/SchemaProvider.js.map +1 -1
  250. package/dist/production/src/model/queries/events/EventQueryHelpers.cjs +16 -8
  251. package/dist/production/src/model/queries/events/EventQueryHelpers.cjs.map +1 -1
  252. package/dist/production/src/model/queries/events/EventQueryHelpers.js +17 -9
  253. package/dist/production/src/model/queries/events/EventQueryHelpers.js.map +1 -1
  254. package/dist/production/src/model/queries/events/EventsQuery.cjs.map +1 -1
  255. package/dist/production/src/model/queries/events/EventsQuery.js.map +1 -1
  256. package/dist/production/src/model/queries/migrations/ExecutedMigrationByVersionQuery.cjs.map +1 -1
  257. package/dist/production/src/model/queries/migrations/ExecutedMigrationByVersionQuery.js.map +1 -1
  258. package/dist/production/src/model/queries/migrations/ExecutedMigrationsQuery.cjs.map +1 -1
  259. package/dist/production/src/model/queries/migrations/ExecutedMigrationsQuery.js.map +1 -1
  260. package/dist/production/src/model/queries/migrations/ExecutedMigrationsQueryHelper.cjs.map +1 -1
  261. package/dist/production/src/model/queries/migrations/ExecutedMigrationsQueryHelper.js.map +1 -1
  262. package/dist/production/src/model/queries/schema/SchemaQuery.cjs.map +1 -1
  263. package/dist/production/src/model/queries/schema/SchemaQuery.js.map +1 -1
  264. package/dist/production/src/model/queries/stages/StageBySlugQuery.cjs.map +1 -1
  265. package/dist/production/src/model/queries/stages/StageBySlugQuery.js.map +1 -1
  266. package/dist/production/src/model/queries/stages/StageQueryFactory.cjs.map +1 -1
  267. package/dist/production/src/model/queries/stages/StageQueryFactory.js.map +1 -1
  268. package/dist/production/src/model/queries/stages/StagesQuery.cjs.map +1 -1
  269. package/dist/production/src/model/queries/stages/StagesQuery.js.map +1 -1
  270. package/dist/production/src/model/stages/StageCreator.cjs.map +1 -1
  271. package/dist/production/src/model/stages/StageCreator.js.map +1 -1
  272. package/dist/production/src/resolvers/ResolverFactory.cjs +4 -1
  273. package/dist/production/src/resolvers/ResolverFactory.cjs.map +1 -1
  274. package/dist/production/src/resolvers/ResolverFactory.js +4 -1
  275. package/dist/production/src/resolvers/ResolverFactory.js.map +1 -1
  276. package/dist/production/src/resolvers/SystemResolverContext.cjs.map +1 -1
  277. package/dist/production/src/resolvers/SystemResolverContext.js.map +1 -1
  278. package/dist/production/src/resolvers/mutation/MigrateMutationResolver.cjs +49 -1
  279. package/dist/production/src/resolvers/mutation/MigrateMutationResolver.cjs.map +1 -1
  280. package/dist/production/src/resolvers/mutation/MigrateMutationResolver.js +49 -1
  281. package/dist/production/src/resolvers/mutation/MigrateMutationResolver.js.map +1 -1
  282. package/dist/production/src/resolvers/mutation/MigrationAlterMutationResolver.cjs.map +1 -1
  283. package/dist/production/src/resolvers/mutation/MigrationAlterMutationResolver.js.map +1 -1
  284. package/dist/production/src/resolvers/mutation/TruncateMutationResolver.cjs +1 -1
  285. package/dist/production/src/resolvers/mutation/TruncateMutationResolver.cjs.map +1 -1
  286. package/dist/production/src/resolvers/mutation/TruncateMutationResolver.js +1 -1
  287. package/dist/production/src/resolvers/mutation/TruncateMutationResolver.js.map +1 -1
  288. package/dist/production/src/resolvers/query/EventsQueryResolver.cjs.map +1 -1
  289. package/dist/production/src/resolvers/query/EventsQueryResolver.js.map +1 -1
  290. package/dist/production/src/resolvers/query/ExecutedMigrationsQueryResolver.cjs.map +1 -1
  291. package/dist/production/src/resolvers/query/ExecutedMigrationsQueryResolver.js.map +1 -1
  292. package/dist/production/src/resolvers/query/SchemaQueryResolver.cjs.map +1 -1
  293. package/dist/production/src/resolvers/query/SchemaQueryResolver.js.map +1 -1
  294. package/dist/production/src/resolvers/query/StagesQueryResolver.cjs.map +1 -1
  295. package/dist/production/src/resolvers/query/StagesQueryResolver.js.map +1 -1
  296. package/dist/production/src/resolvers/types/EventOldValuesResolver.cjs.map +1 -1
  297. package/dist/production/src/resolvers/types/EventOldValuesResolver.js.map +1 -1
  298. package/dist/production/src/resolvers/types/OldValuesHelpers.cjs.map +1 -1
  299. package/dist/production/src/resolvers/types/OldValuesHelpers.js.map +1 -1
  300. package/dist/production/src/schema/dev.graphql.cjs +1 -1
  301. package/dist/production/src/schema/dev.graphql.cjs.map +1 -1
  302. package/dist/production/src/schema/dev.graphql.js +1 -1
  303. package/dist/production/src/schema/dev.graphql.js.map +1 -1
  304. package/dist/production/src/schema/system.graphql.cjs +39 -3
  305. package/dist/production/src/schema/system.graphql.cjs.map +1 -1
  306. package/dist/production/src/schema/system.graphql.js +39 -3
  307. package/dist/production/src/schema/system.graphql.js.map +1 -1
  308. package/dist/production/src/schema/types.cjs +2 -0
  309. package/dist/production/src/schema/types.cjs.map +1 -1
  310. package/dist/production/src/schema/types.js +2 -0
  311. package/dist/production/src/schema/types.js.map +1 -1
  312. package/dist/production/src/utils/batchQuery.cjs.map +1 -1
  313. package/dist/production/src/utils/batchQuery.js.map +1 -1
  314. package/dist/tests/cases/unit/projectMigratorSchemaState.test.d.ts +2 -0
  315. package/dist/tests/cases/unit/projectMigratorSchemaState.test.d.ts.map +1 -0
  316. package/dist/tests/cases/unit/truncateEventsCommand.test.d.ts +2 -0
  317. package/dist/tests/cases/unit/truncateEventsCommand.test.d.ts.map +1 -0
  318. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  319. package/dist/types/SystemContainer.d.ts +6 -6
  320. package/dist/types/SystemContainer.d.ts.map +1 -1
  321. package/dist/types/index.d.ts +7 -7
  322. package/dist/types/index.d.ts.map +1 -1
  323. package/dist/types/migrations/2020-03-27-130000-project-migrations.d.ts +1 -1
  324. package/dist/types/migrations/2020-03-27-130000-project-migrations.d.ts.map +1 -1
  325. package/dist/types/migrations/2020-05-06-150000-composed-primary.d.ts +1 -1
  326. package/dist/types/migrations/2020-05-06-150000-composed-primary.d.ts.map +1 -1
  327. package/dist/types/migrations/2020-06-01-103000-event-trigger-perf.d.ts +1 -1
  328. package/dist/types/migrations/2020-06-01-103000-event-trigger-perf.d.ts.map +1 -1
  329. package/dist/types/migrations/2021-05-07-155800-event-log-rework.d.ts +1 -1
  330. package/dist/types/migrations/2021-05-07-155800-event-log-rework.d.ts.map +1 -1
  331. package/dist/types/migrations/2021-05-19-1232000-event-log-fix-constraint.d.ts +1 -1
  332. package/dist/types/migrations/2021-05-19-1232000-event-log-fix-constraint.d.ts.map +1 -1
  333. package/dist/types/migrations/2022-10-03-110000-table-on-delete.d.ts +1 -1
  334. package/dist/types/migrations/2022-10-03-110000-table-on-delete.d.ts.map +1 -1
  335. package/dist/types/migrations/2023-09-11-174000-fix-on-delete.d.ts +1 -1
  336. package/dist/types/migrations/2023-09-11-174000-fix-on-delete.d.ts.map +1 -1
  337. package/dist/types/migrations/2023-10-19-173000-fix-unique.d.ts +1 -1
  338. package/dist/types/migrations/2023-10-19-173000-fix-unique.d.ts.map +1 -1
  339. package/dist/types/migrations/2024-06-28-153001-schema-init.d.ts +1 -1
  340. package/dist/types/migrations/2024-06-28-153001-schema-init.d.ts.map +1 -1
  341. package/dist/types/migrations/2025-03-14-110000-fix-missing-index.d.ts +1 -1
  342. package/dist/types/migrations/2025-03-14-110000-fix-missing-index.d.ts.map +1 -1
  343. package/dist/types/migrations/2026-06-01-120000-event-truncate.d.ts +3 -0
  344. package/dist/types/migrations/2026-06-01-120000-event-truncate.d.ts.map +1 -0
  345. package/dist/types/migrations/index.d.ts +2 -2
  346. package/dist/types/migrations/index.d.ts.map +1 -1
  347. package/dist/types/migrations/runner.d.ts +2 -2
  348. package/dist/types/migrations/runner.d.ts.map +1 -1
  349. package/dist/types/migrations/snapshot-factory.d.ts +1 -1
  350. package/dist/types/migrations/snapshot-factory.d.ts.map +1 -1
  351. package/dist/types/migrations/snapshot.d.ts +1 -1
  352. package/dist/types/migrations/snapshot.d.ts.map +1 -1
  353. package/dist/types/migrations/types.d.ts +2 -2
  354. package/dist/types/migrations/types.d.ts.map +1 -1
  355. package/dist/types/model/ProjectInitializer.d.ts +4 -4
  356. package/dist/types/model/ProjectInitializer.d.ts.map +1 -1
  357. package/dist/types/model/ProjectTruncateExecutor.d.ts +3 -3
  358. package/dist/types/model/ProjectTruncateExecutor.d.ts.map +1 -1
  359. package/dist/types/model/authorization/StagePermissionsFactory.d.ts +1 -1
  360. package/dist/types/model/authorization/StagePermissionsFactory.d.ts.map +1 -1
  361. package/dist/types/model/authorization/StageScope.d.ts +2 -2
  362. package/dist/types/model/authorization/StageScope.d.ts.map +1 -1
  363. package/dist/types/model/authorization/index.d.ts +3 -3
  364. package/dist/types/model/authorization/index.d.ts.map +1 -1
  365. package/dist/types/model/commands/Command.d.ts +2 -2
  366. package/dist/types/model/commands/Command.d.ts.map +1 -1
  367. package/dist/types/model/commands/CommandBus.d.ts +2 -2
  368. package/dist/types/model/commands/CommandBus.d.ts.map +1 -1
  369. package/dist/types/model/commands/events/TruncateEventsCommand.d.ts +12 -3
  370. package/dist/types/model/commands/events/TruncateEventsCommand.d.ts.map +1 -1
  371. package/dist/types/model/commands/events/index.d.ts +1 -1
  372. package/dist/types/model/commands/events/index.d.ts.map +1 -1
  373. package/dist/types/model/commands/index.d.ts +5 -5
  374. package/dist/types/model/commands/index.d.ts.map +1 -1
  375. package/dist/types/model/commands/migrations/DeleteMigrationCommand.d.ts +1 -1
  376. package/dist/types/model/commands/migrations/DeleteMigrationCommand.d.ts.map +1 -1
  377. package/dist/types/model/commands/migrations/ModifyMigrationCommand.d.ts +1 -1
  378. package/dist/types/model/commands/migrations/ModifyMigrationCommand.d.ts.map +1 -1
  379. package/dist/types/model/commands/migrations/SaveMigrationCommand.d.ts +2 -2
  380. package/dist/types/model/commands/migrations/SaveMigrationCommand.d.ts.map +1 -1
  381. package/dist/types/model/commands/migrations/index.d.ts +2 -2
  382. package/dist/types/model/commands/migrations/index.d.ts.map +1 -1
  383. package/dist/types/model/commands/schema/SaveSchemaCommand.d.ts +2 -2
  384. package/dist/types/model/commands/schema/SaveSchemaCommand.d.ts.map +1 -1
  385. package/dist/types/model/commands/stages/CreateStageCommand.d.ts +2 -2
  386. package/dist/types/model/commands/stages/CreateStageCommand.d.ts.map +1 -1
  387. package/dist/types/model/commands/stages/TruncateStagesCommand.d.ts +1 -1
  388. package/dist/types/model/commands/stages/TruncateStagesCommand.d.ts.map +1 -1
  389. package/dist/types/model/commands/stages/index.d.ts +2 -2
  390. package/dist/types/model/commands/stages/index.d.ts.map +1 -1
  391. package/dist/types/model/database/DatabaseContext.d.ts +2 -2
  392. package/dist/types/model/database/DatabaseContext.d.ts.map +1 -1
  393. package/dist/types/model/database/index.d.ts +1 -1
  394. package/dist/types/model/database/index.d.ts.map +1 -1
  395. package/dist/types/model/dependencies/content/ContentQueryExecutor.d.ts +2 -2
  396. package/dist/types/model/dependencies/content/ContentQueryExecutor.d.ts.map +1 -1
  397. package/dist/types/model/dependencies/index.d.ts +2 -2
  398. package/dist/types/model/dependencies/index.d.ts.map +1 -1
  399. package/dist/types/model/dependencies/tenant/index.d.ts +1 -1
  400. package/dist/types/model/dependencies/tenant/index.d.ts.map +1 -1
  401. package/dist/types/model/dtos/index.d.ts +2 -2
  402. package/dist/types/model/dtos/index.d.ts.map +1 -1
  403. package/dist/types/model/events/EventResponseBuilder.d.ts +4 -4
  404. package/dist/types/model/events/EventResponseBuilder.d.ts.map +1 -1
  405. package/dist/types/model/events/EventResponseHelper.d.ts +1 -1
  406. package/dist/types/model/events/EventResponseHelper.d.ts.map +1 -1
  407. package/dist/types/model/events/identityUtils.d.ts +1 -1
  408. package/dist/types/model/events/identityUtils.d.ts.map +1 -1
  409. package/dist/types/model/events/index.d.ts +2 -2
  410. package/dist/types/model/events/index.d.ts.map +1 -1
  411. package/dist/types/model/events/types.d.ts +12 -2
  412. package/dist/types/model/events/types.d.ts.map +1 -1
  413. package/dist/types/model/helpers/index.d.ts +2 -2
  414. package/dist/types/model/helpers/index.d.ts.map +1 -1
  415. package/dist/types/model/helpers/stageHelpers.d.ts +1 -1
  416. package/dist/types/model/helpers/stageHelpers.d.ts.map +1 -1
  417. package/dist/types/model/index.d.ts +13 -13
  418. package/dist/types/model/index.d.ts.map +1 -1
  419. package/dist/types/model/metadata/SchemaDatabaseMetadataResolverStore.d.ts +1 -1
  420. package/dist/types/model/metadata/SchemaDatabaseMetadataResolverStore.d.ts.map +1 -1
  421. package/dist/types/model/metadata/index.d.ts +1 -1
  422. package/dist/types/model/metadata/index.d.ts.map +1 -1
  423. package/dist/types/model/migrations/ExecutedMigrationsResolver.d.ts +2 -2
  424. package/dist/types/model/migrations/ExecutedMigrationsResolver.d.ts.map +1 -1
  425. package/dist/types/model/migrations/MigrationAlterer.d.ts +3 -3
  426. package/dist/types/model/migrations/MigrationAlterer.d.ts.map +1 -1
  427. package/dist/types/model/migrations/MigrationInput.d.ts +6 -0
  428. package/dist/types/model/migrations/MigrationInput.d.ts.map +1 -1
  429. package/dist/types/model/migrations/ProjectMigrator.d.ts +28 -10
  430. package/dist/types/model/migrations/ProjectMigrator.d.ts.map +1 -1
  431. package/dist/types/model/migrations/SchemaProvider.d.ts +2 -2
  432. package/dist/types/model/migrations/SchemaProvider.d.ts.map +1 -1
  433. package/dist/types/model/migrations/index.d.ts +4 -4
  434. package/dist/types/model/migrations/index.d.ts.map +1 -1
  435. package/dist/types/model/queries/events/EventQueryHelpers.d.ts +4 -4
  436. package/dist/types/model/queries/events/EventQueryHelpers.d.ts.map +1 -1
  437. package/dist/types/model/queries/events/EventsQuery.d.ts +2 -2
  438. package/dist/types/model/queries/events/EventsQuery.d.ts.map +1 -1
  439. package/dist/types/model/queries/events/index.d.ts +3 -3
  440. package/dist/types/model/queries/events/index.d.ts.map +1 -1
  441. package/dist/types/model/queries/index.d.ts +4 -4
  442. package/dist/types/model/queries/index.d.ts.map +1 -1
  443. package/dist/types/model/queries/migrations/ExecutedMigrationByVersionQuery.d.ts +1 -1
  444. package/dist/types/model/queries/migrations/ExecutedMigrationByVersionQuery.d.ts.map +1 -1
  445. package/dist/types/model/queries/migrations/ExecutedMigrationsQuery.d.ts +1 -1
  446. package/dist/types/model/queries/migrations/ExecutedMigrationsQuery.d.ts.map +1 -1
  447. package/dist/types/model/queries/migrations/ExecutedMigrationsQueryHelper.d.ts +1 -1
  448. package/dist/types/model/queries/migrations/ExecutedMigrationsQueryHelper.d.ts.map +1 -1
  449. package/dist/types/model/queries/migrations/index.d.ts +3 -3
  450. package/dist/types/model/queries/migrations/index.d.ts.map +1 -1
  451. package/dist/types/model/queries/schema/SchemaQuery.d.ts +1 -1
  452. package/dist/types/model/queries/schema/SchemaQuery.d.ts.map +1 -1
  453. package/dist/types/model/queries/schema/index.d.ts +1 -1
  454. package/dist/types/model/queries/schema/index.d.ts.map +1 -1
  455. package/dist/types/model/queries/stages/StageBySlugQuery.d.ts +1 -1
  456. package/dist/types/model/queries/stages/StageBySlugQuery.d.ts.map +1 -1
  457. package/dist/types/model/queries/stages/StageQueryFactory.d.ts +1 -1
  458. package/dist/types/model/queries/stages/StageQueryFactory.d.ts.map +1 -1
  459. package/dist/types/model/queries/stages/StagesQuery.d.ts +1 -1
  460. package/dist/types/model/queries/stages/StagesQuery.d.ts.map +1 -1
  461. package/dist/types/model/queries/stages/index.d.ts +3 -3
  462. package/dist/types/model/queries/stages/index.d.ts.map +1 -1
  463. package/dist/types/model/stages/StageCreator.d.ts +2 -2
  464. package/dist/types/model/stages/StageCreator.d.ts.map +1 -1
  465. package/dist/types/model/stages/index.d.ts +1 -1
  466. package/dist/types/model/stages/index.d.ts.map +1 -1
  467. package/dist/types/resolvers/Resolver.d.ts +1 -1
  468. package/dist/types/resolvers/Resolver.d.ts.map +1 -1
  469. package/dist/types/resolvers/ResolverFactory.d.ts +5 -5
  470. package/dist/types/resolvers/ResolverFactory.d.ts.map +1 -1
  471. package/dist/types/resolvers/SystemResolverContext.d.ts +4 -4
  472. package/dist/types/resolvers/SystemResolverContext.d.ts.map +1 -1
  473. package/dist/types/resolvers/index.d.ts +5 -5
  474. package/dist/types/resolvers/index.d.ts.map +1 -1
  475. package/dist/types/resolvers/mutation/MigrateMutationResolver.d.ts +6 -4
  476. package/dist/types/resolvers/mutation/MigrateMutationResolver.d.ts.map +1 -1
  477. package/dist/types/resolvers/mutation/MigrationAlterMutationResolver.d.ts +4 -4
  478. package/dist/types/resolvers/mutation/MigrationAlterMutationResolver.d.ts.map +1 -1
  479. package/dist/types/resolvers/mutation/TruncateMutationResolver.d.ts +4 -4
  480. package/dist/types/resolvers/mutation/TruncateMutationResolver.d.ts.map +1 -1
  481. package/dist/types/resolvers/mutation/index.d.ts +3 -3
  482. package/dist/types/resolvers/mutation/index.d.ts.map +1 -1
  483. package/dist/types/resolvers/query/EventsQueryResolver.d.ts +4 -4
  484. package/dist/types/resolvers/query/EventsQueryResolver.d.ts.map +1 -1
  485. package/dist/types/resolvers/query/ExecutedMigrationsQueryResolver.d.ts +3 -3
  486. package/dist/types/resolvers/query/ExecutedMigrationsQueryResolver.d.ts.map +1 -1
  487. package/dist/types/resolvers/query/SchemaQueryResolver.d.ts +2 -2
  488. package/dist/types/resolvers/query/SchemaQueryResolver.d.ts.map +1 -1
  489. package/dist/types/resolvers/query/StagesQueryResolver.d.ts +3 -3
  490. package/dist/types/resolvers/query/StagesQueryResolver.d.ts.map +1 -1
  491. package/dist/types/resolvers/query/index.d.ts +3 -3
  492. package/dist/types/resolvers/query/index.d.ts.map +1 -1
  493. package/dist/types/resolvers/types/EventOldValuesResolver.d.ts +2 -2
  494. package/dist/types/resolvers/types/EventOldValuesResolver.d.ts.map +1 -1
  495. package/dist/types/resolvers/types/OldValuesHelpers.d.ts +2 -2
  496. package/dist/types/resolvers/types/OldValuesHelpers.d.ts.map +1 -1
  497. package/dist/types/resolvers/types/index.d.ts +1 -1
  498. package/dist/types/resolvers/types/index.d.ts.map +1 -1
  499. package/dist/types/schema/index.d.ts +2 -2
  500. package/dist/types/schema/index.d.ts.map +1 -1
  501. package/dist/types/schema/system.graphql.d.ts.map +1 -1
  502. package/dist/types/schema/types.d.ts +80 -54
  503. package/dist/types/schema/types.d.ts.map +1 -1
  504. package/dist/types/tsconfig.tsbuildinfo +1 -1
  505. package/dist/types/utils/index.d.ts +7 -7
  506. package/dist/types/utils/index.d.ts.map +1 -1
  507. package/dist/types/utils/providers.d.ts +1 -1
  508. package/dist/types/utils/providers.d.ts.map +1 -1
  509. package/package.json +12 -12
  510. package/src/SystemContainer.ts +6 -6
  511. package/src/bin/runMigrations.ts +2 -2
  512. package/src/index.ts +7 -7
  513. package/src/migrations/2020-03-27-130000-project-migrations.ts +1 -1
  514. package/src/migrations/2020-05-06-150000-composed-primary.ts +2 -2
  515. package/src/migrations/2020-06-01-103000-event-trigger-perf.ts +2 -2
  516. package/src/migrations/2021-05-07-155800-event-log-rework.ts +2 -2
  517. package/src/migrations/2021-05-19-1232000-event-log-fix-constraint.ts +2 -2
  518. package/src/migrations/2022-10-03-110000-table-on-delete.ts +1 -1
  519. package/src/migrations/2023-09-11-174000-fix-on-delete.ts +1 -1
  520. package/src/migrations/2023-10-19-173000-fix-unique.ts +1 -1
  521. package/src/migrations/2024-06-28-153001-schema-init.ts +1 -1
  522. package/src/migrations/2025-03-14-110000-fix-missing-index.ts +1 -1
  523. package/src/migrations/2026-06-01-120000-event-truncate.ts +18 -0
  524. package/src/migrations/index.ts +2 -2
  525. package/src/migrations/runner.ts +31 -29
  526. package/src/migrations/snapshot-factory.ts +1 -1
  527. package/src/migrations/snapshot-template-start.txt +1 -1
  528. package/src/migrations/snapshot.ts +6 -5
  529. package/src/migrations/types.ts +2 -2
  530. package/src/model/ProjectInitializer.ts +4 -4
  531. package/src/model/ProjectTruncateExecutor.ts +8 -8
  532. package/src/model/authorization/PermissionsFactory.ts +1 -1
  533. package/src/model/authorization/StagePermissionsFactory.ts +2 -2
  534. package/src/model/authorization/StageScope.ts +3 -3
  535. package/src/model/authorization/index.ts +3 -3
  536. package/src/model/commands/Command.ts +2 -2
  537. package/src/model/commands/CommandBus.ts +2 -2
  538. package/src/model/commands/events/TruncateEventsCommand.ts +45 -5
  539. package/src/model/commands/events/index.ts +1 -1
  540. package/src/model/commands/index.ts +5 -5
  541. package/src/model/commands/migrations/DeleteMigrationCommand.ts +1 -1
  542. package/src/model/commands/migrations/ModifyMigrationCommand.ts +2 -2
  543. package/src/model/commands/migrations/SaveMigrationCommand.ts +2 -2
  544. package/src/model/commands/migrations/index.ts +2 -2
  545. package/src/model/commands/schema/SaveSchemaCommand.ts +2 -2
  546. package/src/model/commands/stages/CreateStageCommand.ts +3 -3
  547. package/src/model/commands/stages/TruncateStagesCommand.ts +1 -1
  548. package/src/model/commands/stages/index.ts +2 -2
  549. package/src/model/database/DatabaseContext.ts +2 -2
  550. package/src/model/database/index.ts +1 -1
  551. package/src/model/dependencies/content/ContentQueryExecutor.ts +2 -2
  552. package/src/model/dependencies/index.ts +2 -2
  553. package/src/model/dependencies/tenant/index.ts +1 -1
  554. package/src/model/dtos/index.ts +2 -2
  555. package/src/model/events/EventResponseBuilder.ts +12 -7
  556. package/src/model/events/EventResponseHelper.ts +1 -1
  557. package/src/model/events/identityUtils.ts +2 -2
  558. package/src/model/events/index.ts +2 -2
  559. package/src/model/events/types.ts +15 -1
  560. package/src/model/helpers/index.ts +2 -2
  561. package/src/model/helpers/stageHelpers.ts +1 -1
  562. package/src/model/index.ts +13 -13
  563. package/src/model/metadata/SchemaDatabaseMetadataResolverStore.ts +1 -1
  564. package/src/model/metadata/index.ts +1 -1
  565. package/src/model/migrations/ExecutedMigrationsResolver.ts +3 -3
  566. package/src/model/migrations/MigrationAlterer.ts +6 -6
  567. package/src/model/migrations/MigrationInput.ts +7 -0
  568. package/src/model/migrations/ProjectMigrator.ts +133 -17
  569. package/src/model/migrations/SchemaProvider.ts +3 -3
  570. package/src/model/migrations/index.ts +4 -4
  571. package/src/model/queries/events/EventQueryHelpers.ts +21 -13
  572. package/src/model/queries/events/EventsQuery.ts +3 -3
  573. package/src/model/queries/events/index.ts +3 -3
  574. package/src/model/queries/index.ts +4 -4
  575. package/src/model/queries/migrations/ExecutedMigrationByVersionQuery.ts +2 -2
  576. package/src/model/queries/migrations/ExecutedMigrationsQuery.ts +2 -2
  577. package/src/model/queries/migrations/ExecutedMigrationsQueryHelper.ts +1 -1
  578. package/src/model/queries/migrations/index.ts +3 -3
  579. package/src/model/queries/schema/SchemaQuery.ts +1 -1
  580. package/src/model/queries/schema/index.ts +1 -1
  581. package/src/model/queries/stages/StageBySlugQuery.ts +2 -2
  582. package/src/model/queries/stages/StageQueryFactory.ts +1 -1
  583. package/src/model/queries/stages/StagesQuery.ts +2 -2
  584. package/src/model/queries/stages/index.ts +3 -3
  585. package/src/model/stages/StageCreator.ts +4 -4
  586. package/src/model/stages/index.ts +1 -1
  587. package/src/resolvers/Resolver.ts +1 -1
  588. package/src/resolvers/ResolverFactory.ts +9 -6
  589. package/src/resolvers/SystemResolverContext.ts +6 -6
  590. package/src/resolvers/index.ts +5 -5
  591. package/src/resolvers/mutation/MigrateMutationResolver.ts +64 -7
  592. package/src/resolvers/mutation/MigrationAlterMutationResolver.ts +4 -4
  593. package/src/resolvers/mutation/TruncateMutationResolver.ts +5 -5
  594. package/src/resolvers/mutation/index.ts +3 -3
  595. package/src/resolvers/query/EventsQueryResolver.ts +4 -4
  596. package/src/resolvers/query/ExecutedMigrationsQueryResolver.ts +4 -4
  597. package/src/resolvers/query/SchemaQueryResolver.ts +3 -3
  598. package/src/resolvers/query/StagesQueryResolver.ts +4 -4
  599. package/src/resolvers/query/index.ts +3 -3
  600. package/src/resolvers/types/EventOldValuesResolver.ts +3 -3
  601. package/src/resolvers/types/OldValuesHelpers.ts +3 -3
  602. package/src/resolvers/types/index.ts +1 -1
  603. package/src/schema/dev.graphql.ts +1 -1
  604. package/src/schema/index.ts +4 -2
  605. package/src/schema/system.graphql.ts +39 -3
  606. package/src/schema/types.ts +108 -38
  607. package/src/utils/batchQuery.ts +1 -1
  608. package/src/utils/index.ts +7 -7
  609. package/src/utils/providers.ts +1 -1
  610. package/tests/cases/migrations/2020-05-06-150000-composed-primary.test.ts +1 -1
  611. package/tests/cases/migrations/2020-06-01-103000-event-trigger-perf.test.ts +1 -1
  612. package/tests/cases/migrations/2022-10-03-110000-table-on-delete.test.ts +1 -1
  613. package/tests/cases/migrations/2023-09-11-174000-fix-on-delete.test.ts +1 -1
  614. package/tests/cases/migrations/2023-10-19-173000-fix-unique.test.ts +1 -1
  615. package/tests/cases/migrations/2025-03-14-110000-fix-missing-index.test.ts +1 -1
  616. package/tests/cases/unit/eventsQuery.test.ts +3 -3
  617. package/tests/cases/unit/projectMigratorSchemaState.test.ts +48 -0
  618. package/tests/cases/unit/truncateEventsCommand.test.ts +54 -0
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sources":["../../../../../../packages/engine-system-api/src/model/events/types.ts"],"sourcesContent":["export enum EventType {\n\tdelete = 'delete',\n\tupdate = 'update',\n\tcreate = 'create',\n}\n\nexport type ContentEvent = UpdateEvent | CreateEvent | DeleteEvent\n\nexport interface Event {\n\treadonly type: EventType\n\treadonly id: string\n\treadonly createdAt: Date\n\treadonly transactionId: string\n\t// readonly errors?: string[]\n}\n\nexport class UpdateEvent implements Event {\n\tpublic readonly type = EventType.update\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\tpublic readonly createdAt: Date,\n\t\tpublic readonly appliedAt: Date,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tpublic readonly rowId: string[],\n\t\tpublic readonly tableName: string,\n\t\tpublic readonly values: { [column: string]: any },\n\t) {\n\t}\n}\n\nexport class CreateEvent implements Event {\n\tpublic readonly type = EventType.create\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\tpublic readonly createdAt: Date,\n\t\tpublic readonly appliedAt: Date,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tpublic readonly rowId: string[],\n\t\tpublic readonly tableName: string,\n\t\tpublic readonly values: { [column: string]: any },\n\t) {\n\t}\n}\n\nexport class DeleteEvent implements Event {\n\tpublic readonly type = EventType.delete\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\tpublic readonly createdAt: Date,\n\t\tpublic readonly appliedAt: Date,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tpublic readonly rowId: string[],\n\t\tpublic readonly tableName: string,\n\t) {\n\t}\n}\n"],"names":["EventType"],"mappings":";;;;;AAAO,IAAK,8BAAAA,eAAL;AACNA,aAAA,QAAA,IAAS;AACTA,aAAA,QAAA,IAAS;AACTA,aAAA,QAAA,IAAS;AAHE,SAAAA;AAAA,GAAA,aAAA,CAAA,CAAA;AAgBL,MAAM,YAA6B;AAAA,EAGzC,YACiB,IACA,WACA,WACA,YACA,eACA,OACA,WACA,QACf;AARe,SAAA,KAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACA,SAAA,QAAA;AACA,SAAA,YAAA;AACA,SAAA,SAAA;AAVjB;AAAA,MAAA;AAAA,MAAgB;AAAA,MAAO;AAAA;AAAA,IAAA;AAAA,EAYvB;AACD;AAEO,MAAM,YAA6B;AAAA,EAGzC,YACiB,IACA,WACA,WACA,YACA,eACA,OACA,WACA,QACf;AARe,SAAA,KAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACA,SAAA,QAAA;AACA,SAAA,YAAA;AACA,SAAA,SAAA;AAVjB;AAAA,MAAA;AAAA,MAAgB;AAAA,MAAO;AAAA;AAAA,IAAA;AAAA,EAYvB;AACD;AAEO,MAAM,YAA6B;AAAA,EAGzC,YACiB,IACA,WACA,WACA,YACA,eACA,OACA,WACf;AAPe,SAAA,KAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACA,SAAA,QAAA;AACA,SAAA,YAAA;AATjB;AAAA,MAAA;AAAA,MAAgB;AAAA,MAAO;AAAA;AAAA,IAAA;AAAA,EAWvB;AACD;;;;;"}
1
+ {"version":3,"file":"types.cjs","sources":["../../../../../../packages/engine-system-api/src/model/events/types.ts"],"sourcesContent":["export enum EventType {\n\tdelete = 'delete',\n\tupdate = 'update',\n\tcreate = 'create',\n\ttruncate = 'truncate',\n}\n\nexport type ContentEvent = UpdateEvent | CreateEvent | DeleteEvent | TruncateEvent\n\nexport interface Event {\n\treadonly type: EventType\n\treadonly id: string\n\treadonly createdAt: Date\n\treadonly transactionId: string\n\t// readonly errors?: string[]\n}\n\nexport class UpdateEvent implements Event {\n\tpublic readonly type = EventType.update\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\tpublic readonly createdAt: Date,\n\t\tpublic readonly appliedAt: Date,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tpublic readonly rowId: string[],\n\t\tpublic readonly tableName: string,\n\t\tpublic readonly values: { [column: string]: any },\n\t) {\n\t}\n}\n\nexport class CreateEvent implements Event {\n\tpublic readonly type = EventType.create\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\tpublic readonly createdAt: Date,\n\t\tpublic readonly appliedAt: Date,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tpublic readonly rowId: string[],\n\t\tpublic readonly tableName: string,\n\t\tpublic readonly values: { [column: string]: any },\n\t) {\n\t}\n}\n\nexport class DeleteEvent implements Event {\n\tpublic readonly type = EventType.delete\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\tpublic readonly createdAt: Date,\n\t\tpublic readonly appliedAt: Date,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tpublic readonly rowId: string[],\n\t\tpublic readonly tableName: string,\n\t) {\n\t}\n}\n\nexport class TruncateEvent implements Event {\n\tpublic readonly type = EventType.truncate\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\tpublic readonly createdAt: Date,\n\t\tpublic readonly appliedAt: Date,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t) {\n\t}\n}\n"],"names":["EventType"],"mappings":";;;;;AAAO,IAAK,8BAAAA,eAAL;AACNA,aAAA,QAAA,IAAS;AACTA,aAAA,QAAA,IAAS;AACTA,aAAA,QAAA,IAAS;AACTA,aAAA,UAAA,IAAW;AAJA,SAAAA;AAAA,GAAA,aAAA,CAAA,CAAA;AAiBL,MAAM,YAA6B;AAAA,EAGzC,YACiB,IACA,WACA,WACA,YACA,eACA,OACA,WACA,QACf;AARe,SAAA,KAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACA,SAAA,QAAA;AACA,SAAA,YAAA;AACA,SAAA,SAAA;AAVjB;AAAA,MAAA;AAAA,MAAgB;AAAA,MAAO;AAAA;AAAA,IAAA;AAAA,EAYvB;AACD;AAEO,MAAM,YAA6B;AAAA,EAGzC,YACiB,IACA,WACA,WACA,YACA,eACA,OACA,WACA,QACf;AARe,SAAA,KAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACA,SAAA,QAAA;AACA,SAAA,YAAA;AACA,SAAA,SAAA;AAVjB;AAAA,MAAA;AAAA,MAAgB;AAAA,MAAO;AAAA;AAAA,IAAA;AAAA,EAYvB;AACD;AAEO,MAAM,YAA6B;AAAA,EAGzC,YACiB,IACA,WACA,WACA,YACA,eACA,OACA,WACf;AAPe,SAAA,KAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACA,SAAA,QAAA;AACA,SAAA,YAAA;AATjB;AAAA,MAAA;AAAA,MAAgB;AAAA,MAAO;AAAA;AAAA,IAAA;AAAA,EAWvB;AACD;AAEO,MAAM,cAA+B;AAAA,EAG3C,YACiB,IACA,WACA,WACA,YACA,eACf;AALe,SAAA,KAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AAPjB;AAAA,MAAA;AAAA,MAAgB;AAAA,MAAO;AAAA;AAAA,IAAA;AAAA,EASvB;AACD;;;;;;"}
@@ -5,6 +5,7 @@ var EventType = /* @__PURE__ */ ((EventType2) => {
5
5
  EventType2["delete"] = "delete";
6
6
  EventType2["update"] = "update";
7
7
  EventType2["create"] = "create";
8
+ EventType2["truncate"] = "truncate";
8
9
  return EventType2;
9
10
  })(EventType || {});
10
11
  class UpdateEvent {
@@ -60,10 +61,26 @@ class DeleteEvent {
60
61
  );
61
62
  }
62
63
  }
64
+ class TruncateEvent {
65
+ constructor(id, createdAt, appliedAt, identityId, transactionId) {
66
+ this.id = id;
67
+ this.createdAt = createdAt;
68
+ this.appliedAt = appliedAt;
69
+ this.identityId = identityId;
70
+ this.transactionId = transactionId;
71
+ __publicField(
72
+ this,
73
+ "type",
74
+ "truncate"
75
+ /* truncate */
76
+ );
77
+ }
78
+ }
63
79
  export {
64
80
  CreateEvent,
65
81
  DeleteEvent,
66
82
  EventType,
83
+ TruncateEvent,
67
84
  UpdateEvent
68
85
  };
69
86
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../../../../../packages/engine-system-api/src/model/events/types.ts"],"sourcesContent":["export enum EventType {\n\tdelete = 'delete',\n\tupdate = 'update',\n\tcreate = 'create',\n}\n\nexport type ContentEvent = UpdateEvent | CreateEvent | DeleteEvent\n\nexport interface Event {\n\treadonly type: EventType\n\treadonly id: string\n\treadonly createdAt: Date\n\treadonly transactionId: string\n\t// readonly errors?: string[]\n}\n\nexport class UpdateEvent implements Event {\n\tpublic readonly type = EventType.update\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\tpublic readonly createdAt: Date,\n\t\tpublic readonly appliedAt: Date,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tpublic readonly rowId: string[],\n\t\tpublic readonly tableName: string,\n\t\tpublic readonly values: { [column: string]: any },\n\t) {\n\t}\n}\n\nexport class CreateEvent implements Event {\n\tpublic readonly type = EventType.create\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\tpublic readonly createdAt: Date,\n\t\tpublic readonly appliedAt: Date,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tpublic readonly rowId: string[],\n\t\tpublic readonly tableName: string,\n\t\tpublic readonly values: { [column: string]: any },\n\t) {\n\t}\n}\n\nexport class DeleteEvent implements Event {\n\tpublic readonly type = EventType.delete\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\tpublic readonly createdAt: Date,\n\t\tpublic readonly appliedAt: Date,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tpublic readonly rowId: string[],\n\t\tpublic readonly tableName: string,\n\t) {\n\t}\n}\n"],"names":["EventType"],"mappings":";;;AAAO,IAAK,8BAAAA,eAAL;AACNA,aAAA,QAAA,IAAS;AACTA,aAAA,QAAA,IAAS;AACTA,aAAA,QAAA,IAAS;AAHE,SAAAA;AAAA,GAAA,aAAA,CAAA,CAAA;AAgBL,MAAM,YAA6B;AAAA,EAGzC,YACiB,IACA,WACA,WACA,YACA,eACA,OACA,WACA,QACf;AARe,SAAA,KAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACA,SAAA,QAAA;AACA,SAAA,YAAA;AACA,SAAA,SAAA;AAVjB;AAAA,MAAA;AAAA,MAAgB;AAAA,MAAO;AAAA;AAAA,IAAA;AAAA,EAYvB;AACD;AAEO,MAAM,YAA6B;AAAA,EAGzC,YACiB,IACA,WACA,WACA,YACA,eACA,OACA,WACA,QACf;AARe,SAAA,KAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACA,SAAA,QAAA;AACA,SAAA,YAAA;AACA,SAAA,SAAA;AAVjB;AAAA,MAAA;AAAA,MAAgB;AAAA,MAAO;AAAA;AAAA,IAAA;AAAA,EAYvB;AACD;AAEO,MAAM,YAA6B;AAAA,EAGzC,YACiB,IACA,WACA,WACA,YACA,eACA,OACA,WACf;AAPe,SAAA,KAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACA,SAAA,QAAA;AACA,SAAA,YAAA;AATjB;AAAA,MAAA;AAAA,MAAgB;AAAA,MAAO;AAAA;AAAA,IAAA;AAAA,EAWvB;AACD;"}
1
+ {"version":3,"file":"types.js","sources":["../../../../../../packages/engine-system-api/src/model/events/types.ts"],"sourcesContent":["export enum EventType {\n\tdelete = 'delete',\n\tupdate = 'update',\n\tcreate = 'create',\n\ttruncate = 'truncate',\n}\n\nexport type ContentEvent = UpdateEvent | CreateEvent | DeleteEvent | TruncateEvent\n\nexport interface Event {\n\treadonly type: EventType\n\treadonly id: string\n\treadonly createdAt: Date\n\treadonly transactionId: string\n\t// readonly errors?: string[]\n}\n\nexport class UpdateEvent implements Event {\n\tpublic readonly type = EventType.update\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\tpublic readonly createdAt: Date,\n\t\tpublic readonly appliedAt: Date,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tpublic readonly rowId: string[],\n\t\tpublic readonly tableName: string,\n\t\tpublic readonly values: { [column: string]: any },\n\t) {\n\t}\n}\n\nexport class CreateEvent implements Event {\n\tpublic readonly type = EventType.create\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\tpublic readonly createdAt: Date,\n\t\tpublic readonly appliedAt: Date,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tpublic readonly rowId: string[],\n\t\tpublic readonly tableName: string,\n\t\tpublic readonly values: { [column: string]: any },\n\t) {\n\t}\n}\n\nexport class DeleteEvent implements Event {\n\tpublic readonly type = EventType.delete\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\tpublic readonly createdAt: Date,\n\t\tpublic readonly appliedAt: Date,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tpublic readonly rowId: string[],\n\t\tpublic readonly tableName: string,\n\t) {\n\t}\n}\n\nexport class TruncateEvent implements Event {\n\tpublic readonly type = EventType.truncate\n\n\tconstructor(\n\t\tpublic readonly id: string,\n\t\tpublic readonly createdAt: Date,\n\t\tpublic readonly appliedAt: Date,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t) {\n\t}\n}\n"],"names":["EventType"],"mappings":";;;AAAO,IAAK,8BAAAA,eAAL;AACNA,aAAA,QAAA,IAAS;AACTA,aAAA,QAAA,IAAS;AACTA,aAAA,QAAA,IAAS;AACTA,aAAA,UAAA,IAAW;AAJA,SAAAA;AAAA,GAAA,aAAA,CAAA,CAAA;AAiBL,MAAM,YAA6B;AAAA,EAGzC,YACiB,IACA,WACA,WACA,YACA,eACA,OACA,WACA,QACf;AARe,SAAA,KAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACA,SAAA,QAAA;AACA,SAAA,YAAA;AACA,SAAA,SAAA;AAVjB;AAAA,MAAA;AAAA,MAAgB;AAAA,MAAO;AAAA;AAAA,IAAA;AAAA,EAYvB;AACD;AAEO,MAAM,YAA6B;AAAA,EAGzC,YACiB,IACA,WACA,WACA,YACA,eACA,OACA,WACA,QACf;AARe,SAAA,KAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACA,SAAA,QAAA;AACA,SAAA,YAAA;AACA,SAAA,SAAA;AAVjB;AAAA,MAAA;AAAA,MAAgB;AAAA,MAAO;AAAA;AAAA,IAAA;AAAA,EAYvB;AACD;AAEO,MAAM,YAA6B;AAAA,EAGzC,YACiB,IACA,WACA,WACA,YACA,eACA,OACA,WACf;AAPe,SAAA,KAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACA,SAAA,QAAA;AACA,SAAA,YAAA;AATjB;AAAA,MAAA;AAAA,MAAgB;AAAA,MAAO;AAAA;AAAA,IAAA;AAAA,EAWvB;AACD;AAEO,MAAM,cAA+B;AAAA,EAG3C,YACiB,IACA,WACA,WACA,YACA,eACf;AALe,SAAA,KAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AAPjB;AAAA,MAAA;AAAA,MAAgB;AAAA,MAAO;AAAA;AAAA,IAAA;AAAA,EASvB;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"stageHelpers.cjs","sources":["../../../../../../packages/engine-system-api/src/model/helpers/stageHelpers.ts"],"sourcesContent":["import { Stage } from '../dtos'\n\nexport function formatSchemaName(stage: Pick<Stage, 'slug'>): string {\n\treturn 'stage_' + stage.slug\n}\n"],"names":[],"mappings":";;AAEO,SAAS,iBAAiB,OAAoC;AACpE,SAAO,WAAW,MAAM;AACzB;;"}
1
+ {"version":3,"file":"stageHelpers.cjs","sources":["../../../../../../packages/engine-system-api/src/model/helpers/stageHelpers.ts"],"sourcesContent":["import { Stage } from '../dtos/index.js'\n\nexport function formatSchemaName(stage: Pick<Stage, 'slug'>): string {\n\treturn 'stage_' + stage.slug\n}\n"],"names":[],"mappings":";;AAEO,SAAS,iBAAiB,OAAoC;AACpE,SAAO,WAAW,MAAM;AACzB;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"stageHelpers.js","sources":["../../../../../../packages/engine-system-api/src/model/helpers/stageHelpers.ts"],"sourcesContent":["import { Stage } from '../dtos'\n\nexport function formatSchemaName(stage: Pick<Stage, 'slug'>): string {\n\treturn 'stage_' + stage.slug\n}\n"],"names":[],"mappings":"AAEO,SAAS,iBAAiB,OAAoC;AACpE,SAAO,WAAW,MAAM;AACzB;"}
1
+ {"version":3,"file":"stageHelpers.js","sources":["../../../../../../packages/engine-system-api/src/model/helpers/stageHelpers.ts"],"sourcesContent":["import { Stage } from '../dtos/index.js'\n\nexport function formatSchemaName(stage: Pick<Stage, 'slug'>): string {\n\treturn 'stage_' + stage.slug\n}\n"],"names":[],"mappings":"AAEO,SAAS,iBAAiB,OAAoC;AACpE,SAAO,WAAW,MAAM;AACzB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaDatabaseMetadataResolverStore.cjs","sources":["../../../../../../packages/engine-system-api/src/model/metadata/SchemaDatabaseMetadataResolverStore.ts"],"sourcesContent":["import { DatabaseContext } from '../database'\nimport { DatabaseMetadata, DatabaseMetadataResolver } from '@contember/database'\n\nexport class SchemaDatabaseMetadataResolverStore {\n\tprivate cache: Map<string, DatabaseMetadata> = new Map()\n\n\tconstructor(\n\t\tprivate resolver: DatabaseMetadataResolver,\n\t\tprivate db: DatabaseContext,\n\t) {\n\t}\n\n\tpublic async getMetadata(schema: string): Promise<DatabaseMetadata> {\n\t\tconst cached = this.cache.get(schema)\n\t\tif (cached) {\n\t\t\treturn cached\n\t\t}\n\n\t\tconst newValue = await this.resolver.resolveMetadata(this.db.client, schema)\n\t\tthis.cache.set(schema, newValue)\n\t\treturn newValue\n\t}\n\n\tpublic invalidate(schema: string): void {\n\t\tthis.cache.delete(schema)\n\t}\n}\n\nexport class MigrationsDatabaseMetadataResolverStoreFactory {\n\tconstructor(\n\t\tprivate resolver: DatabaseMetadataResolver,\n\t) {\n\t}\n\n\tpublic create(db: DatabaseContext) {\n\t\treturn new SchemaDatabaseMetadataResolverStore(this.resolver, db)\n\t}\n}\n"],"names":[],"mappings":";;;;;AAGO,MAAM,oCAAoC;AAAA,EAGhD,YACS,UACA,IACP;AAFO,SAAA,WAAA;AACA,SAAA,KAAA;AAJT,kBAAA,MAAQ,6BAA2C,IAAA,CAAI;AAAA,EAMvD;AAAA,EAEA,MAAa,YAAY,QAA2C;AACnE,UAAM,SAAS,KAAK,MAAM,IAAI,MAAM;AACpC,QAAI,QAAQ;AACX,aAAO;AAAA,IACR;AAEA,UAAM,WAAW,MAAM,KAAK,SAAS,gBAAgB,KAAK,GAAG,QAAQ,MAAM;AAC3E,SAAK,MAAM,IAAI,QAAQ,QAAQ;AAC/B,WAAO;AAAA,EACR;AAAA,EAEO,WAAW,QAAsB;AACvC,SAAK,MAAM,OAAO,MAAM;AAAA,EACzB;AACD;AAEO,MAAM,+CAA+C;AAAA,EAC3D,YACS,UACP;AADO,SAAA,WAAA;AAAA,EAET;AAAA,EAEO,OAAO,IAAqB;AAClC,WAAO,IAAI,oCAAoC,KAAK,UAAU,EAAE;AAAA,EACjE;AACD;;;"}
1
+ {"version":3,"file":"SchemaDatabaseMetadataResolverStore.cjs","sources":["../../../../../../packages/engine-system-api/src/model/metadata/SchemaDatabaseMetadataResolverStore.ts"],"sourcesContent":["import { DatabaseContext } from '../database/index.js'\nimport { DatabaseMetadata, DatabaseMetadataResolver } from '@contember/database'\n\nexport class SchemaDatabaseMetadataResolverStore {\n\tprivate cache: Map<string, DatabaseMetadata> = new Map()\n\n\tconstructor(\n\t\tprivate resolver: DatabaseMetadataResolver,\n\t\tprivate db: DatabaseContext,\n\t) {\n\t}\n\n\tpublic async getMetadata(schema: string): Promise<DatabaseMetadata> {\n\t\tconst cached = this.cache.get(schema)\n\t\tif (cached) {\n\t\t\treturn cached\n\t\t}\n\n\t\tconst newValue = await this.resolver.resolveMetadata(this.db.client, schema)\n\t\tthis.cache.set(schema, newValue)\n\t\treturn newValue\n\t}\n\n\tpublic invalidate(schema: string): void {\n\t\tthis.cache.delete(schema)\n\t}\n}\n\nexport class MigrationsDatabaseMetadataResolverStoreFactory {\n\tconstructor(\n\t\tprivate resolver: DatabaseMetadataResolver,\n\t) {\n\t}\n\n\tpublic create(db: DatabaseContext) {\n\t\treturn new SchemaDatabaseMetadataResolverStore(this.resolver, db)\n\t}\n}\n"],"names":[],"mappings":";;;;;AAGO,MAAM,oCAAoC;AAAA,EAGhD,YACS,UACA,IACP;AAFO,SAAA,WAAA;AACA,SAAA,KAAA;AAJT,kBAAA,MAAQ,6BAA2C,IAAA,CAAI;AAAA,EAMvD;AAAA,EAEA,MAAa,YAAY,QAA2C;AACnE,UAAM,SAAS,KAAK,MAAM,IAAI,MAAM;AACpC,QAAI,QAAQ;AACX,aAAO;AAAA,IACR;AAEA,UAAM,WAAW,MAAM,KAAK,SAAS,gBAAgB,KAAK,GAAG,QAAQ,MAAM;AAC3E,SAAK,MAAM,IAAI,QAAQ,QAAQ;AAC/B,WAAO;AAAA,EACR;AAAA,EAEO,WAAW,QAAsB;AACvC,SAAK,MAAM,OAAO,MAAM;AAAA,EACzB;AACD;AAEO,MAAM,+CAA+C;AAAA,EAC3D,YACS,UACP;AADO,SAAA,WAAA;AAAA,EAET;AAAA,EAEO,OAAO,IAAqB;AAClC,WAAO,IAAI,oCAAoC,KAAK,UAAU,EAAE;AAAA,EACjE;AACD;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaDatabaseMetadataResolverStore.js","sources":["../../../../../../packages/engine-system-api/src/model/metadata/SchemaDatabaseMetadataResolverStore.ts"],"sourcesContent":["import { DatabaseContext } from '../database'\nimport { DatabaseMetadata, DatabaseMetadataResolver } from '@contember/database'\n\nexport class SchemaDatabaseMetadataResolverStore {\n\tprivate cache: Map<string, DatabaseMetadata> = new Map()\n\n\tconstructor(\n\t\tprivate resolver: DatabaseMetadataResolver,\n\t\tprivate db: DatabaseContext,\n\t) {\n\t}\n\n\tpublic async getMetadata(schema: string): Promise<DatabaseMetadata> {\n\t\tconst cached = this.cache.get(schema)\n\t\tif (cached) {\n\t\t\treturn cached\n\t\t}\n\n\t\tconst newValue = await this.resolver.resolveMetadata(this.db.client, schema)\n\t\tthis.cache.set(schema, newValue)\n\t\treturn newValue\n\t}\n\n\tpublic invalidate(schema: string): void {\n\t\tthis.cache.delete(schema)\n\t}\n}\n\nexport class MigrationsDatabaseMetadataResolverStoreFactory {\n\tconstructor(\n\t\tprivate resolver: DatabaseMetadataResolver,\n\t) {\n\t}\n\n\tpublic create(db: DatabaseContext) {\n\t\treturn new SchemaDatabaseMetadataResolverStore(this.resolver, db)\n\t}\n}\n"],"names":[],"mappings":";;;AAGO,MAAM,oCAAoC;AAAA,EAGhD,YACS,UACA,IACP;AAFO,SAAA,WAAA;AACA,SAAA,KAAA;AAJT,kBAAA,MAAQ,6BAA2C,IAAA,CAAI;AAAA,EAMvD;AAAA,EAEA,MAAa,YAAY,QAA2C;AACnE,UAAM,SAAS,KAAK,MAAM,IAAI,MAAM;AACpC,QAAI,QAAQ;AACX,aAAO;AAAA,IACR;AAEA,UAAM,WAAW,MAAM,KAAK,SAAS,gBAAgB,KAAK,GAAG,QAAQ,MAAM;AAC3E,SAAK,MAAM,IAAI,QAAQ,QAAQ;AAC/B,WAAO;AAAA,EACR;AAAA,EAEO,WAAW,QAAsB;AACvC,SAAK,MAAM,OAAO,MAAM;AAAA,EACzB;AACD;AAEO,MAAM,+CAA+C;AAAA,EAC3D,YACS,UACP;AADO,SAAA,WAAA;AAAA,EAET;AAAA,EAEO,OAAO,IAAqB;AAClC,WAAO,IAAI,oCAAoC,KAAK,UAAU,EAAE;AAAA,EACjE;AACD;"}
1
+ {"version":3,"file":"SchemaDatabaseMetadataResolverStore.js","sources":["../../../../../../packages/engine-system-api/src/model/metadata/SchemaDatabaseMetadataResolverStore.ts"],"sourcesContent":["import { DatabaseContext } from '../database/index.js'\nimport { DatabaseMetadata, DatabaseMetadataResolver } from '@contember/database'\n\nexport class SchemaDatabaseMetadataResolverStore {\n\tprivate cache: Map<string, DatabaseMetadata> = new Map()\n\n\tconstructor(\n\t\tprivate resolver: DatabaseMetadataResolver,\n\t\tprivate db: DatabaseContext,\n\t) {\n\t}\n\n\tpublic async getMetadata(schema: string): Promise<DatabaseMetadata> {\n\t\tconst cached = this.cache.get(schema)\n\t\tif (cached) {\n\t\t\treturn cached\n\t\t}\n\n\t\tconst newValue = await this.resolver.resolveMetadata(this.db.client, schema)\n\t\tthis.cache.set(schema, newValue)\n\t\treturn newValue\n\t}\n\n\tpublic invalidate(schema: string): void {\n\t\tthis.cache.delete(schema)\n\t}\n}\n\nexport class MigrationsDatabaseMetadataResolverStoreFactory {\n\tconstructor(\n\t\tprivate resolver: DatabaseMetadataResolver,\n\t) {\n\t}\n\n\tpublic create(db: DatabaseContext) {\n\t\treturn new SchemaDatabaseMetadataResolverStore(this.resolver, db)\n\t}\n}\n"],"names":[],"mappings":";;;AAGO,MAAM,oCAAoC;AAAA,EAGhD,YACS,UACA,IACP;AAFO,SAAA,WAAA;AACA,SAAA,KAAA;AAJT,kBAAA,MAAQ,6BAA2C,IAAA,CAAI;AAAA,EAMvD;AAAA,EAEA,MAAa,YAAY,QAA2C;AACnE,UAAM,SAAS,KAAK,MAAM,IAAI,MAAM;AACpC,QAAI,QAAQ;AACX,aAAO;AAAA,IACR;AAEA,UAAM,WAAW,MAAM,KAAK,SAAS,gBAAgB,KAAK,GAAG,QAAQ,MAAM;AAC3E,SAAK,MAAM,IAAI,QAAQ,QAAQ;AAC/B,WAAO;AAAA,EACR;AAAA,EAEO,WAAW,QAAsB;AACvC,SAAK,MAAM,OAAO,MAAM;AAAA,EACzB;AACD;AAEO,MAAM,+CAA+C;AAAA,EAC3D,YACS,UACP;AADO,SAAA,WAAA;AAAA,EAET;AAAA,EAEO,OAAO,IAAqB;AAClC,WAAO,IAAI,oCAAoC,KAAK,UAAU,EAAE;AAAA,EACjE;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ExecutedMigrationsResolver.cjs","sources":["../../../../../../packages/engine-system-api/src/model/migrations/ExecutedMigrationsResolver.ts"],"sourcesContent":["import { ExecutedMigration } from '../dtos'\nimport { ExecutedMigrationByVersionQuery, ExecutedMigrationsQuery } from '../queries'\nimport { DatabaseContext } from '../database'\n\nexport class ExecutedMigrationsResolver {\n\tasync getMigrations(db: DatabaseContext, afterVersion?: string): Promise<ExecutedMigration[]> {\n\t\treturn db.queryHandler.fetch(new ExecutedMigrationsQuery(afterVersion))\n\t}\n\n\tasync getMigrationByVersion(db: DatabaseContext, version: string): Promise<ExecutedMigration | null> {\n\t\treturn db.queryHandler.fetch(new ExecutedMigrationByVersionQuery(version))\n\t}\n}\n"],"names":["ExecutedMigrationsQuery","ExecutedMigrationByVersionQuery"],"mappings":";;;;;;;AAIO,MAAM,2BAA2B;AAAA,EACvC,MAAM,cAAc,IAAqB,cAAqD;AAC7F,WAAO,GAAG,aAAa,MAAM,IAAIA,wBAAAA,wBAAwB,YAAY,CAAC;AAAA,EACvE;AAAA,EAEA,MAAM,sBAAsB,IAAqB,SAAoD;AACpG,WAAO,GAAG,aAAa,MAAM,IAAIC,gCAAAA,gCAAgC,OAAO,CAAC;AAAA,EAC1E;AACD;;"}
1
+ {"version":3,"file":"ExecutedMigrationsResolver.cjs","sources":["../../../../../../packages/engine-system-api/src/model/migrations/ExecutedMigrationsResolver.ts"],"sourcesContent":["import { ExecutedMigration } from '../dtos/index.js'\nimport { ExecutedMigrationByVersionQuery, ExecutedMigrationsQuery } from '../queries/index.js'\nimport { DatabaseContext } from '../database/index.js'\n\nexport class ExecutedMigrationsResolver {\n\tasync getMigrations(db: DatabaseContext, afterVersion?: string): Promise<ExecutedMigration[]> {\n\t\treturn db.queryHandler.fetch(new ExecutedMigrationsQuery(afterVersion))\n\t}\n\n\tasync getMigrationByVersion(db: DatabaseContext, version: string): Promise<ExecutedMigration | null> {\n\t\treturn db.queryHandler.fetch(new ExecutedMigrationByVersionQuery(version))\n\t}\n}\n"],"names":["ExecutedMigrationsQuery","ExecutedMigrationByVersionQuery"],"mappings":";;;;;;;AAIO,MAAM,2BAA2B;AAAA,EACvC,MAAM,cAAc,IAAqB,cAAqD;AAC7F,WAAO,GAAG,aAAa,MAAM,IAAIA,wBAAAA,wBAAwB,YAAY,CAAC;AAAA,EACvE;AAAA,EAEA,MAAM,sBAAsB,IAAqB,SAAoD;AACpG,WAAO,GAAG,aAAa,MAAM,IAAIC,gCAAAA,gCAAgC,OAAO,CAAC;AAAA,EAC1E;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ExecutedMigrationsResolver.js","sources":["../../../../../../packages/engine-system-api/src/model/migrations/ExecutedMigrationsResolver.ts"],"sourcesContent":["import { ExecutedMigration } from '../dtos'\nimport { ExecutedMigrationByVersionQuery, ExecutedMigrationsQuery } from '../queries'\nimport { DatabaseContext } from '../database'\n\nexport class ExecutedMigrationsResolver {\n\tasync getMigrations(db: DatabaseContext, afterVersion?: string): Promise<ExecutedMigration[]> {\n\t\treturn db.queryHandler.fetch(new ExecutedMigrationsQuery(afterVersion))\n\t}\n\n\tasync getMigrationByVersion(db: DatabaseContext, version: string): Promise<ExecutedMigration | null> {\n\t\treturn db.queryHandler.fetch(new ExecutedMigrationByVersionQuery(version))\n\t}\n}\n"],"names":[],"mappings":";;;;;AAIO,MAAM,2BAA2B;AAAA,EACvC,MAAM,cAAc,IAAqB,cAAqD;AAC7F,WAAO,GAAG,aAAa,MAAM,IAAI,wBAAwB,YAAY,CAAC;AAAA,EACvE;AAAA,EAEA,MAAM,sBAAsB,IAAqB,SAAoD;AACpG,WAAO,GAAG,aAAa,MAAM,IAAI,gCAAgC,OAAO,CAAC;AAAA,EAC1E;AACD;"}
1
+ {"version":3,"file":"ExecutedMigrationsResolver.js","sources":["../../../../../../packages/engine-system-api/src/model/migrations/ExecutedMigrationsResolver.ts"],"sourcesContent":["import { ExecutedMigration } from '../dtos/index.js'\nimport { ExecutedMigrationByVersionQuery, ExecutedMigrationsQuery } from '../queries/index.js'\nimport { DatabaseContext } from '../database/index.js'\n\nexport class ExecutedMigrationsResolver {\n\tasync getMigrations(db: DatabaseContext, afterVersion?: string): Promise<ExecutedMigration[]> {\n\t\treturn db.queryHandler.fetch(new ExecutedMigrationsQuery(afterVersion))\n\t}\n\n\tasync getMigrationByVersion(db: DatabaseContext, version: string): Promise<ExecutedMigration | null> {\n\t\treturn db.queryHandler.fetch(new ExecutedMigrationByVersionQuery(version))\n\t}\n}\n"],"names":[],"mappings":";;;;;AAIO,MAAM,2BAA2B;AAAA,EACvC,MAAM,cAAc,IAAqB,cAAqD;AAC7F,WAAO,GAAG,aAAa,MAAM,IAAI,wBAAwB,YAAY,CAAC;AAAA,EACvE;AAAA,EAEA,MAAM,sBAAsB,IAAqB,SAAoD;AACpG,WAAO,GAAG,aAAa,MAAM,IAAI,gCAAgC,OAAO,CAAC;AAAA,EAC1E;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationAlterer.cjs","sources":["../../../../../../packages/engine-system-api/src/model/migrations/MigrationAlterer.ts"],"sourcesContent":["import { DatabaseContext } from '../database'\nimport { DeleteMigrationCommand } from '../commands'\nimport { Response, ResponseError, ResponseOk } from '../../utils'\nimport { Migration } from '@contember/schema-migrations'\nimport { ModifyMigrationCommand } from '../commands/migrations/ModifyMigrationCommand'\nimport { SchemaProvider } from './SchemaProvider'\nimport { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand'\n\nexport class MigrationAlterer {\n\tconstructor(\n\t\tprivate readonly schemaProvider: SchemaProvider,\n\t) {\n\t}\n\n\tpublic async deleteMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t): Promise<Response<undefined, DeleteMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new DeleteMigrationCommand(version))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(DeleteMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tpublic async modifyMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t\tmigration: Partial<Migration>,\n\t): Promise<Response<undefined, UpdateMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new ModifyMigrationCommand(version, migration))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(UpdateMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tprivate async refreshSchema(db: DatabaseContext): Promise<void> {\n\t\tconst schemaWithMeta = await this.schemaProvider.buildSchemaFromMigrations(db)\n\t\tawait db.commandBus.execute(new SaveSchemaCommand(schemaWithMeta))\n\t}\n}\n\nexport enum DeleteMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n\nexport enum UpdateMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n"],"names":["db","DeleteMigrationCommand","ResponseError","ResponseOk","ModifyMigrationCommand","SaveSchemaCommand","DeleteMigrationErrorCode","UpdateMigrationErrorCode"],"mappings":";;;;;;;;;AAQO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,gBAChB;AADgB,SAAA,iBAAA;AAAA,EAElB;AAAA,EAEA,MAAa,gBACZ,IACA,SACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMA,QAAM;AACvC,YAAM,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAIC,uBAAAA,uBAAuB,OAAO,CAAC;AAC9E,UAAI,CAAC,QAAQ;AACZ,cAAMD,IAAG,OAAO,WAAW,SAAA;AAC3B,eAAO,IAAIE,SAAAA,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MACjG;AACA,YAAM,KAAK,cAAcF,GAAE;AAC3B,aAAO,IAAIG,SAAAA,WAAW,MAAS;AAAA,IAChC,CAAC;AAAA,EACF;AAAA,EAEA,MAAa,gBACZ,IACA,SACA,WACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMH,QAAM;AACvC,YAAM,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAII,uBAAAA,uBAAuB,SAAS,SAAS,CAAC;AACzF,UAAI,CAAC,QAAQ;AACZ,cAAMJ,IAAG,OAAO,WAAW,SAAA;AAC3B,eAAO,IAAIE,SAAAA,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MACjG;AACA,YAAM,KAAK,cAAcF,GAAE;AAC3B,aAAO,IAAIG,SAAAA,WAAW,MAAS;AAAA,IAChC,CAAC;AAAA,EACF;AAAA,EAEA,MAAc,cAAc,IAAoC;AAC/D,UAAM,iBAAiB,MAAM,KAAK,eAAe,0BAA0B,EAAE;AAC7E,UAAM,GAAG,WAAW,QAAQ,IAAIE,kBAAAA,kBAAkB,cAAc,CAAC;AAAA,EAClE;AACD;AAEO,IAAK,6CAAAC,8BAAL;AACNA,4BAAA,UAAA,IAAW;AADA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;AAIL,IAAK,6CAAAC,8BAAL;AACNA,4BAAA,UAAA,IAAW;AADA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"MigrationAlterer.cjs","sources":["../../../../../../packages/engine-system-api/src/model/migrations/MigrationAlterer.ts"],"sourcesContent":["import { DatabaseContext } from '../database/index.js'\nimport { DeleteMigrationCommand } from '../commands/index.js'\nimport { Response, ResponseError, ResponseOk } from '../../utils/index.js'\nimport { Migration } from '@contember/schema-migrations'\nimport { ModifyMigrationCommand } from '../commands/migrations/ModifyMigrationCommand.js'\nimport { SchemaProvider } from './SchemaProvider.js'\nimport { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand.js'\n\nexport class MigrationAlterer {\n\tconstructor(\n\t\tprivate readonly schemaProvider: SchemaProvider,\n\t) {\n\t}\n\n\tpublic async deleteMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t): Promise<Response<undefined, DeleteMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new DeleteMigrationCommand(version))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(DeleteMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tpublic async modifyMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t\tmigration: Partial<Migration>,\n\t): Promise<Response<undefined, UpdateMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new ModifyMigrationCommand(version, migration))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(UpdateMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tprivate async refreshSchema(db: DatabaseContext): Promise<void> {\n\t\tconst schemaWithMeta = await this.schemaProvider.buildSchemaFromMigrations(db)\n\t\tawait db.commandBus.execute(new SaveSchemaCommand(schemaWithMeta))\n\t}\n}\n\nexport enum DeleteMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n\nexport enum UpdateMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n"],"names":["db","DeleteMigrationCommand","ResponseError","ResponseOk","ModifyMigrationCommand","SaveSchemaCommand","DeleteMigrationErrorCode","UpdateMigrationErrorCode"],"mappings":";;;;;;;;;AAQO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,gBAChB;AADgB,SAAA,iBAAA;AAAA,EAElB;AAAA,EAEA,MAAa,gBACZ,IACA,SACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMA,QAAM;AACvC,YAAM,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAIC,uBAAAA,uBAAuB,OAAO,CAAC;AAC9E,UAAI,CAAC,QAAQ;AACZ,cAAMD,IAAG,OAAO,WAAW,SAAA;AAC3B,eAAO,IAAIE,SAAAA,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MACjG;AACA,YAAM,KAAK,cAAcF,GAAE;AAC3B,aAAO,IAAIG,SAAAA,WAAW,MAAS;AAAA,IAChC,CAAC;AAAA,EACF;AAAA,EAEA,MAAa,gBACZ,IACA,SACA,WACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMH,QAAM;AACvC,YAAM,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAII,uBAAAA,uBAAuB,SAAS,SAAS,CAAC;AACzF,UAAI,CAAC,QAAQ;AACZ,cAAMJ,IAAG,OAAO,WAAW,SAAA;AAC3B,eAAO,IAAIE,SAAAA,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MACjG;AACA,YAAM,KAAK,cAAcF,GAAE;AAC3B,aAAO,IAAIG,SAAAA,WAAW,MAAS;AAAA,IAChC,CAAC;AAAA,EACF;AAAA,EAEA,MAAc,cAAc,IAAoC;AAC/D,UAAM,iBAAiB,MAAM,KAAK,eAAe,0BAA0B,EAAE;AAC7E,UAAM,GAAG,WAAW,QAAQ,IAAIE,kBAAAA,kBAAkB,cAAc,CAAC;AAAA,EAClE;AACD;AAEO,IAAK,6CAAAC,8BAAL;AACNA,4BAAA,UAAA,IAAW;AADA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;AAIL,IAAK,6CAAAC,8BAAL;AACNA,4BAAA,UAAA,IAAW;AADA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationAlterer.js","sources":["../../../../../../packages/engine-system-api/src/model/migrations/MigrationAlterer.ts"],"sourcesContent":["import { DatabaseContext } from '../database'\nimport { DeleteMigrationCommand } from '../commands'\nimport { Response, ResponseError, ResponseOk } from '../../utils'\nimport { Migration } from '@contember/schema-migrations'\nimport { ModifyMigrationCommand } from '../commands/migrations/ModifyMigrationCommand'\nimport { SchemaProvider } from './SchemaProvider'\nimport { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand'\n\nexport class MigrationAlterer {\n\tconstructor(\n\t\tprivate readonly schemaProvider: SchemaProvider,\n\t) {\n\t}\n\n\tpublic async deleteMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t): Promise<Response<undefined, DeleteMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new DeleteMigrationCommand(version))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(DeleteMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tpublic async modifyMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t\tmigration: Partial<Migration>,\n\t): Promise<Response<undefined, UpdateMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new ModifyMigrationCommand(version, migration))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(UpdateMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tprivate async refreshSchema(db: DatabaseContext): Promise<void> {\n\t\tconst schemaWithMeta = await this.schemaProvider.buildSchemaFromMigrations(db)\n\t\tawait db.commandBus.execute(new SaveSchemaCommand(schemaWithMeta))\n\t}\n}\n\nexport enum DeleteMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n\nexport enum UpdateMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n"],"names":["db","DeleteMigrationErrorCode","UpdateMigrationErrorCode"],"mappings":";;;;;;;AAQO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,gBAChB;AADgB,SAAA,iBAAA;AAAA,EAElB;AAAA,EAEA,MAAa,gBACZ,IACA,SACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMA,QAAM;AACvC,YAAM,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAI,uBAAuB,OAAO,CAAC;AAC9E,UAAI,CAAC,QAAQ;AACZ,cAAMA,IAAG,OAAO,WAAW,SAAA;AAC3B,eAAO,IAAI,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MACjG;AACA,YAAM,KAAK,cAAcA,GAAE;AAC3B,aAAO,IAAI,WAAW,MAAS;AAAA,IAChC,CAAC;AAAA,EACF;AAAA,EAEA,MAAa,gBACZ,IACA,SACA,WACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMA,QAAM;AACvC,YAAM,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAI,uBAAuB,SAAS,SAAS,CAAC;AACzF,UAAI,CAAC,QAAQ;AACZ,cAAMA,IAAG,OAAO,WAAW,SAAA;AAC3B,eAAO,IAAI,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MACjG;AACA,YAAM,KAAK,cAAcA,GAAE;AAC3B,aAAO,IAAI,WAAW,MAAS;AAAA,IAChC,CAAC;AAAA,EACF;AAAA,EAEA,MAAc,cAAc,IAAoC;AAC/D,UAAM,iBAAiB,MAAM,KAAK,eAAe,0BAA0B,EAAE;AAC7E,UAAM,GAAG,WAAW,QAAQ,IAAI,kBAAkB,cAAc,CAAC;AAAA,EAClE;AACD;AAEO,IAAK,6CAAAC,8BAAL;AACNA,4BAAA,UAAA,IAAW;AADA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;AAIL,IAAK,6CAAAC,8BAAL;AACNA,4BAAA,UAAA,IAAW;AADA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;"}
1
+ {"version":3,"file":"MigrationAlterer.js","sources":["../../../../../../packages/engine-system-api/src/model/migrations/MigrationAlterer.ts"],"sourcesContent":["import { DatabaseContext } from '../database/index.js'\nimport { DeleteMigrationCommand } from '../commands/index.js'\nimport { Response, ResponseError, ResponseOk } from '../../utils/index.js'\nimport { Migration } from '@contember/schema-migrations'\nimport { ModifyMigrationCommand } from '../commands/migrations/ModifyMigrationCommand.js'\nimport { SchemaProvider } from './SchemaProvider.js'\nimport { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand.js'\n\nexport class MigrationAlterer {\n\tconstructor(\n\t\tprivate readonly schemaProvider: SchemaProvider,\n\t) {\n\t}\n\n\tpublic async deleteMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t): Promise<Response<undefined, DeleteMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new DeleteMigrationCommand(version))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(DeleteMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tpublic async modifyMigration(\n\t\tdb: DatabaseContext,\n\t\tversion: string,\n\t\tmigration: Partial<Migration>,\n\t): Promise<Response<undefined, UpdateMigrationErrorCode>> {\n\t\treturn await db.transaction(async db => {\n\t\t\tconst result = await db.commandBus.execute(new ModifyMigrationCommand(version, migration))\n\t\t\tif (!result) {\n\t\t\t\tawait db.client.connection.rollback()\n\t\t\t\treturn new ResponseError(UpdateMigrationErrorCode.notFound, `Migration ${version} was not found`)\n\t\t\t}\n\t\t\tawait this.refreshSchema(db)\n\t\t\treturn new ResponseOk(undefined)\n\t\t})\n\t}\n\n\tprivate async refreshSchema(db: DatabaseContext): Promise<void> {\n\t\tconst schemaWithMeta = await this.schemaProvider.buildSchemaFromMigrations(db)\n\t\tawait db.commandBus.execute(new SaveSchemaCommand(schemaWithMeta))\n\t}\n}\n\nexport enum DeleteMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n\nexport enum UpdateMigrationErrorCode {\n\tnotFound = 'notFound',\n}\n"],"names":["db","DeleteMigrationErrorCode","UpdateMigrationErrorCode"],"mappings":";;;;;;;AAQO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,gBAChB;AADgB,SAAA,iBAAA;AAAA,EAElB;AAAA,EAEA,MAAa,gBACZ,IACA,SACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMA,QAAM;AACvC,YAAM,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAI,uBAAuB,OAAO,CAAC;AAC9E,UAAI,CAAC,QAAQ;AACZ,cAAMA,IAAG,OAAO,WAAW,SAAA;AAC3B,eAAO,IAAI,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MACjG;AACA,YAAM,KAAK,cAAcA,GAAE;AAC3B,aAAO,IAAI,WAAW,MAAS;AAAA,IAChC,CAAC;AAAA,EACF;AAAA,EAEA,MAAa,gBACZ,IACA,SACA,WACyD;AACzD,WAAO,MAAM,GAAG,YAAY,OAAMA,QAAM;AACvC,YAAM,SAAS,MAAMA,IAAG,WAAW,QAAQ,IAAI,uBAAuB,SAAS,SAAS,CAAC;AACzF,UAAI,CAAC,QAAQ;AACZ,cAAMA,IAAG,OAAO,WAAW,SAAA;AAC3B,eAAO,IAAI,cAAc,YAAmC,aAAa,OAAO,gBAAgB;AAAA,MACjG;AACA,YAAM,KAAK,cAAcA,GAAE;AAC3B,aAAO,IAAI,WAAW,MAAS;AAAA,IAChC,CAAC;AAAA,EACF;AAAA,EAEA,MAAc,cAAc,IAAoC;AAC/D,UAAM,iBAAiB,MAAM,KAAK,eAAe,0BAA0B,EAAE;AAC7E,UAAM,GAAG,WAAW,QAAQ,IAAI,kBAAkB,cAAc,CAAC;AAAA,EAClE;AACD;AAEO,IAAK,6CAAAC,8BAAL;AACNA,4BAAA,UAAA,IAAW;AADA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;AAIL,IAAK,6CAAAC,8BAAL;AACNA,4BAAA,UAAA,IAAW;AADA,SAAAA;AAAA,GAAA,4BAAA,CAAA,CAAA;"}
@@ -21,15 +21,15 @@ class ProjectMigrator {
21
21
  this.migrationsDatabaseMetadataResolverStoreFactory = migrationsDatabaseMetadataResolverStoreFactory;
22
22
  this.contentQueryExecutor = contentQueryExecutor;
23
23
  }
24
- async migrate({ db, project, identity, options: { ignoreOrder = false, skipExecuted = false }, migrationsToExecute, stages }) {
25
- if (migrationsToExecute.length === 0) {
24
+ async migrate({ db, project, identity, options: { ignoreOrder = false, skipExecuted = false }, migrationsToExecute, stages, schemaState }) {
25
+ if (migrationsToExecute.length === 0 && !schemaState) {
26
26
  return;
27
27
  }
28
28
  const schemaWithMeta = await this.schemaProvider.fetch({ db });
29
29
  let schema = schemaWithMeta.schema;
30
30
  let id = schemaWithMeta.meta.id;
31
31
  const validated = await this.validateMigrations(db, schema, schemaWithMeta.meta.version ?? null, migrationsToExecute, { ignoreOrder, skipExecuted });
32
- if (validated.length === 0) {
32
+ if (validated.length === 0 && !schemaState) {
33
33
  return;
34
34
  }
35
35
  const sorted = [...validated].sort((a, b) => a.version.localeCompare(b.version));
@@ -71,16 +71,98 @@ class ProjectMigrator {
71
71
  }
72
72
  id = await db.commandBus.execute(new SaveMigrationCommand.SaveMigrationCommand(migration));
73
73
  }
74
+ const latestVersion = sorted.length > 0 ? sorted[sorted.length - 1].version : schemaWithMeta.meta.version;
75
+ if (schemaState) {
76
+ schema = {
77
+ ...schema,
78
+ acl: schemaState.acl,
79
+ validation: schemaState.validation,
80
+ actions: schemaState.actions,
81
+ settings: schemaState.settings
82
+ };
83
+ const errors = schemaUtils.SchemaValidator.validate(schema);
84
+ if (errors.length > 0) {
85
+ throw new InvalidSchemaError(
86
+ latestVersion ?? "(schema state)",
87
+ "Schema state is invalid: \n" + errors.map((it) => `${it.path.join(".")}: [${it.code}] ${it.message}`).join("\n")
88
+ );
89
+ }
90
+ }
91
+ if (!latestVersion) {
92
+ if (schemaState) {
93
+ return;
94
+ }
95
+ throw new exceptions.ImplementationException();
96
+ }
97
+ if (!id) {
98
+ throw new exceptions.ImplementationException();
99
+ }
100
+ await db.commandBus.execute(
101
+ new SaveSchemaCommand.SaveSchemaCommand({
102
+ schema,
103
+ meta: {
104
+ id,
105
+ updatedAt: /* @__PURE__ */ new Date(),
106
+ version: latestVersion,
107
+ checksum: schemaUtils.calculateSchemaChecksum(schema)
108
+ }
109
+ })
110
+ );
111
+ }
112
+ async migrateFromSnapshot({ db, project, stages, snapshot, covers, schemaState }) {
113
+ const sortedCovers = [...covers].sort((a, b) => a.version.localeCompare(b.version));
114
+ const latestVersion = sortedCovers.length > 0 ? sortedCovers[sortedCovers.length - 1].version : null;
115
+ if (!latestVersion) {
116
+ throw new exceptions.ImplementationException("Snapshot must cover at least one migration");
117
+ }
118
+ const executedMigrations = await this.executedMigrationsResolver.getMigrations(db);
119
+ if (executedMigrations.length > 0) {
120
+ throw new ProjectNotEmptyError(latestVersion, "Cannot apply snapshot: project already has executed migrations");
121
+ }
122
+ const metadataStore = this.migrationsDatabaseMetadataResolverStoreFactory.create(db);
123
+ let schema = schemaUtils.emptySchema;
124
+ for (const modification of snapshot.modifications) {
125
+ [schema] = await this.applyModification(
126
+ db.client,
127
+ stages,
128
+ schema,
129
+ modification,
130
+ snapshot.formatVersion,
131
+ latestVersion,
132
+ project,
133
+ metadataStore
134
+ );
135
+ }
136
+ const errors = schemaUtils.SchemaValidator.validate(schema);
137
+ if (errors.length > 0) {
138
+ throw new InvalidSchemaError(
139
+ latestVersion,
140
+ "Snapshot generates invalid schema: \n" + errors.map((it) => `${it.path.join(".")}: [${it.code}] ${it.message}`).join("\n")
141
+ );
142
+ }
143
+ let id;
144
+ for (const migration of sortedCovers) {
145
+ id = await db.commandBus.execute(new SaveMigrationCommand.SaveMigrationCommand(migration));
146
+ }
74
147
  if (!id) {
75
148
  throw new exceptions.ImplementationException();
76
149
  }
150
+ if (schemaState) {
151
+ schema = {
152
+ ...schema,
153
+ acl: schemaState.acl,
154
+ validation: schemaState.validation,
155
+ actions: schemaState.actions,
156
+ settings: schemaState.settings
157
+ };
158
+ }
77
159
  await db.commandBus.execute(
78
160
  new SaveSchemaCommand.SaveSchemaCommand({
79
161
  schema,
80
162
  meta: {
81
163
  id,
82
164
  updatedAt: /* @__PURE__ */ new Date(),
83
- version: sorted[sorted.length - 1].version,
165
+ version: latestVersion,
84
166
  checksum: schemaUtils.calculateSchemaChecksum(schema)
85
167
  }
86
168
  })
@@ -146,7 +228,7 @@ class ProjectMigrator {
146
228
  const errors = schemaUtils.SchemaValidator.validate(schema);
147
229
  if (errors.length > 0) {
148
230
  throw new InvalidSchemaError(
149
- toExecute[toExecute.length - 1].version,
231
+ toExecute[toExecute.length - 1]?.version ?? version ?? "(schema)",
150
232
  "Migration generates invalid schema: \n" + errors.map((it) => it.path.join(".") + ": " + it.message).join("\n")
151
233
  );
152
234
  }
@@ -234,6 +316,12 @@ class NotSuccessfulContentMigrationError extends MigrationError {
234
316
  __publicField(this, "code", types.MigrateErrorCode.ContentMigrationNotSuccessful);
235
317
  }
236
318
  }
319
+ class ProjectNotEmptyError extends MigrationError {
320
+ constructor() {
321
+ super(...arguments);
322
+ __publicField(this, "code", types.MigrateErrorCode.ProjectNotEmpty);
323
+ }
324
+ }
237
325
  exports.AlreadyExecutedMigrationError = AlreadyExecutedMigrationError;
238
326
  exports.FailedContentMigrationError = FailedContentMigrationError;
239
327
  exports.InvalidSchemaError = InvalidSchemaError;
@@ -242,4 +330,5 @@ exports.MigrationFailedError = MigrationFailedError;
242
330
  exports.MustFollowLatestMigrationError = MustFollowLatestMigrationError;
243
331
  exports.NotSuccessfulContentMigrationError = NotSuccessfulContentMigrationError;
244
332
  exports.ProjectMigrator = ProjectMigrator;
333
+ exports.ProjectNotEmptyError = ProjectNotEmptyError;
245
334
  //# sourceMappingURL=ProjectMigrator.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ProjectMigrator.cjs","sources":["../../../../../../packages/engine-system-api/src/model/migrations/ProjectMigrator.ts"],"sourcesContent":["import { calculateMigrationChecksum, Migration, MigrationDescriber, MigrationVersionHelper } from '@contember/schema-migrations'\nimport { Client, DatabaseMetadata, QueryError, wrapIdentifier } from '@contember/database'\nimport { Schema } from '@contember/schema'\nimport { SaveMigrationCommand } from '../commands'\nimport { Stage } from '../dtos'\nimport { DatabaseContext } from '../database'\nimport { ExecutedMigrationsResolver } from './ExecutedMigrationsResolver'\nimport { MigrateErrorCode } from '../../schema'\nimport { calculateSchemaChecksum, SchemaValidator, SchemaValidatorSkippedErrors } from '@contember/schema-utils'\nimport { logger } from '@contember/logger'\nimport { MigrationsDatabaseMetadataResolverStoreFactory, SchemaDatabaseMetadataResolverStore } from '../metadata'\nimport { ContentMigrationQuery, MigrationInput } from './MigrationInput'\nimport { ContentQueryExecutor } from '../dependencies'\nimport { SchemaProvider } from './SchemaProvider'\nimport { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand'\nimport { ImplementationException } from '../../utils'\n\ntype MigrationVariables = {\n\tsystem_schema: string\n\tproject_slug: string\n}\n\nexport class ProjectMigrator {\n\tconstructor(\n\t\tprivate readonly migrationDescriber: MigrationDescriber,\n\t\tprivate readonly schemaProvider: SchemaProvider,\n\t\tprivate readonly executedMigrationsResolver: ExecutedMigrationsResolver,\n\t\tprivate readonly migrationsDatabaseMetadataResolverStoreFactory: MigrationsDatabaseMetadataResolverStoreFactory,\n\t\tprivate readonly contentQueryExecutor: ContentQueryExecutor,\n\t) {}\n\n\tpublic async migrate({ db, project, identity, options: { ignoreOrder = false, skipExecuted = false }, migrationsToExecute, stages }: {\n\t\tdb: DatabaseContext\n\t\tproject: { slug: string; systemSchema: string }\n\t\tidentity: { id: string }\n\t\tstages: Stage[]\n\t\tmigrationsToExecute: readonly MigrationInput[]\n\t\toptions: {\n\t\t\tignoreOrder?: boolean\n\t\t\tskipExecuted?: boolean\n\t\t}\n\t}) {\n\t\tif (migrationsToExecute.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst schemaWithMeta = await this.schemaProvider.fetch({ db })\n\t\tlet schema = schemaWithMeta.schema\n\t\tlet id = schemaWithMeta.meta.id\n\n\t\tconst validated = await this.validateMigrations(db, schema, schemaWithMeta.meta.version ?? null, migrationsToExecute, { ignoreOrder, skipExecuted })\n\t\tif (validated.length === 0) {\n\t\t\treturn\n\t\t}\n\n\t\tconst sorted = [...validated].sort((a, b) => a.version.localeCompare(b.version))\n\n\t\tconst metadataStore = this.migrationsDatabaseMetadataResolverStoreFactory.create(db)\n\n\t\tfor (const migration of sorted) {\n\t\t\tif (migration.type === 'schema') {\n\t\t\t\tconst formatVersion = migration.formatVersion\n\n\t\t\t\tfor (const modification of migration.modifications) {\n\t\t\t\t\t;[schema] = await this.applyModification(\n\t\t\t\t\t\tdb.client,\n\t\t\t\t\t\tstages,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tmodification,\n\t\t\t\t\t\tformatVersion,\n\t\t\t\t\t\tmigration.version,\n\t\t\t\t\t\tproject,\n\t\t\t\t\t\tmetadataStore,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (migration.type === 'content') {\n\t\t\t\tif (!id) {\n\t\t\t\t\tthrow new FailedContentMigrationError(migration.version, `Cannot execute content migration without schema`)\n\t\t\t\t}\n\t\t\t\tfor (const query of migration.queries) {\n\t\t\t\t\tawait this.executeContentMigration({\n\t\t\t\t\t\tversion: migration.version,\n\t\t\t\t\t\tquery,\n\t\t\t\t\t\tdb,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tschemaMeta: { id },\n\t\t\t\t\t\tstages,\n\t\t\t\t\t\tdatabaseMetadata: await metadataStore.getMetadata(db.client.schema),\n\t\t\t\t\t\tidentity,\n\t\t\t\t\t\tproject,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\t// event log uses deferred constraint triggers, we need to fire them before ALTER\n\t\t\t\tawait db.client.query(`SET CONSTRAINTS ALL IMMEDIATE`)\n\t\t\t\tawait db.client.query(`SET CONSTRAINTS ALL DEFERRED`)\n\t\t\t}\n\t\t\tid = await db.commandBus.execute(new SaveMigrationCommand(migration))\n\t\t}\n\t\tif (!id) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\n\t\tawait db.commandBus.execute(\n\t\t\tnew SaveSchemaCommand({\n\t\t\t\tschema,\n\t\t\t\tmeta: {\n\t\t\t\t\tid,\n\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\tversion: sorted[sorted.length - 1].version,\n\t\t\t\t\tchecksum: calculateSchemaChecksum(schema),\n\t\t\t\t},\n\t\t\t}),\n\t\t)\n\t}\n\n\tprivate async executeContentMigration({ query, stages, version, ...ctx }: {\n\t\tversion: string\n\t\tdb: DatabaseContext\n\t\tquery: ContentMigrationQuery\n\t\tstages: Stage[]\n\t\tschema: Schema\n\t\tschemaMeta: { id: number }\n\t\tproject: { slug: string; systemSchema: string }\n\t\tidentity: { id: string }\n\t\tdatabaseMetadata: DatabaseMetadata\n\t}) {\n\t\tconst queryStages = query.stage ? stages.filter(it => it.slug === query.stage) : stages\n\t\tfor (const stage of queryStages) {\n\t\t\tconst response = await this.contentQueryExecutor.execute({\n\t\t\t\tstage,\n\t\t\t\t...ctx,\n\t\t\t}, query)\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new FailedContentMigrationError(version, response.errors.join(', '))\n\t\t\t}\n\t\t\tif (query.checkMutationResult !== false) {\n\t\t\t\tfor (const [key, value] of Object.entries(response.result.data ?? {})) {\n\t\t\t\t\tif (typeof value === 'object' && value !== null && 'ok' in value && !value.ok) {\n\t\t\t\t\t\tconst errorDetails = 'errorMessage' in value ? value.errorMessage : 'No details available. Please fetch errorMessage field.'\n\t\t\t\t\t\tthrow new NotSuccessfulContentMigrationError(version, `Mutation ${key} failed: ${errorDetails}`)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async validateMigrations(\n\t\tdb: DatabaseContext,\n\t\tschema: Schema,\n\t\tversion: string | null,\n\t\tmigrationsToExecute: readonly MigrationInput[],\n\t\t{ ignoreOrder, skipExecuted }: {\n\t\t\tignoreOrder: boolean\n\t\t\tskipExecuted: boolean\n\t\t},\n\t): Promise<readonly MigrationInput[]> {\n\t\tconst executedMigrations = await this.executedMigrationsResolver.getMigrations(db)\n\t\tconst toExecute: MigrationInput[] = []\n\t\tlet skippedErrors: SchemaValidatorSkippedErrors[] = []\n\t\tfor (const migration of migrationsToExecute) {\n\t\t\tconst executedMigration = executedMigrations.find(it => it.version === migration.version)\n\t\t\tif (executedMigration) {\n\t\t\t\tif (skipExecuted && (migration.type !== 'schema' || executedMigration.checksum === calculateMigrationChecksum(migration))) {\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tthrow new AlreadyExecutedMigrationError(migration.version, `Migration is already executed`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (version && migration.version < version && !ignoreOrder) {\n\t\t\t\tthrow new MustFollowLatestMigrationError(migration.version, `Must follow latest executed migration ${version}`)\n\t\t\t}\n\t\t\tif (migration.type === 'schema') {\n\t\t\t\tconst described = this.migrationDescriber.describeModifications(schema, migration)\n\t\t\t\tif (described.length === 0) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst latestModification = described[described.length - 1]\n\t\t\t\tschema = latestModification.schema\n\t\t\t\tskippedErrors = [\n\t\t\t\t\t...skippedErrors.filter(it => it.skipUntil && MigrationVersionHelper.extractVersion(it.skipUntil) >= migration.version),\n\t\t\t\t\t...migration.skippedErrors ?? [],\n\t\t\t\t]\n\t\t\t\tconst errors = SchemaValidator.validate(schema, skippedErrors)\n\t\t\t\tif (errors.length > 0) {\n\t\t\t\t\tthrow new InvalidSchemaError(\n\t\t\t\t\t\tmigration.version,\n\t\t\t\t\t\t'Migration generates invalid schema: \\n'\n\t\t\t\t\t\t\t+ errors.map(it => `${it.path.join('.')}: [${it.code}] ${it.message}`).join('\\n'),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\ttoExecute.push(migration)\n\t\t}\n\t\t// intentionally not using skippedErrors here\n\t\tconst errors = SchemaValidator.validate(schema)\n\t\tif (errors.length > 0) {\n\t\t\tthrow new InvalidSchemaError(\n\t\t\t\ttoExecute[toExecute.length - 1].version,\n\t\t\t\t'Migration generates invalid schema: \\n'\n\t\t\t\t\t+ errors.map(it => it.path.join('.') + ': ' + it.message).join('\\n'),\n\t\t\t)\n\t\t}\n\t\treturn toExecute\n\t}\n\n\tprivate sqlPreprocessor(text: string, variables: MigrationVariables): string {\n\t\treturn Object.entries(variables).reduce(\n\t\t\t(content, [key, value]) => content.replace(new RegExp(`\\\\{\\\\{${key}\\\\}\\\\}`, 'g'), value),\n\t\t\ttext,\n\t\t)\n\t}\n\n\tprivate async applyModification(\n\t\tdb: Client,\n\t\tstages: Stage[],\n\t\tschema: Schema,\n\t\tmodification: Migration.Modification,\n\t\tformatVersion: number,\n\t\tmigrationVersion: string,\n\t\tproject: { slug: string; systemSchema: string },\n\t\tmetadataStore: SchemaDatabaseMetadataResolverStore,\n\t): Promise<[Schema]> {\n\t\tconst {\n\t\t\tgetSql,\n\t\t\tschema: newSchema,\n\t\t} = this.migrationDescriber.describeModification(schema, modification, { formatVersion })\n\t\tfor (const stage of stages) {\n\t\t\tconst databaseMetadata = await metadataStore.getMetadata(stage.schema)\n\t\t\tconst sql = getSql({\n\t\t\t\tsystemSchema: project.systemSchema,\n\t\t\t\tdatabaseMetadata,\n\t\t\t\tinvalidateDatabaseMetadata: () => metadataStore.invalidate(stage.schema),\n\t\t\t})\n\t\t\tconst processedSql = this.sqlPreprocessor(sql, {\n\t\t\t\tproject_slug: project.slug,\n\t\t\t\tsystem_schema: project.systemSchema,\n\t\t\t})\n\t\t\tawait this.executeOnStage(db, stage, processedSql, migrationVersion)\n\t\t}\n\t\treturn [newSchema]\n\t}\n\n\tprivate async executeOnStage(db: Client, stage: Stage, sql: string, migrationVersion: string) {\n\t\tawait db.query('SET LOCAL search_path TO ' + wrapIdentifier(stage.schema))\n\t\ttry {\n\t\t\tawait db.query(sql)\n\t\t} catch (e) {\n\t\t\tif (e instanceof QueryError) {\n\t\t\t\tlogger.error(e, { message: 'Migration failed' })\n\t\t\t\tthrow new MigrationFailedError(migrationVersion, e.message)\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n}\n\nexport abstract class MigrationError extends Error {\n\tpublic abstract code: MigrateErrorCode\n\n\tconstructor(public readonly version: string, public readonly migrationError: string) {\n\t\tsuper(`${version}: ${migrationError}`)\n\t}\n}\n\nexport class MustFollowLatestMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.MustFollowLatest\n}\n\nexport class AlreadyExecutedMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.AlreadyExecuted\n}\n\nexport class MigrationFailedError extends MigrationError {\n\tcode = MigrateErrorCode.MigrationFailed\n}\n\nexport class InvalidSchemaError extends MigrationError {\n\tcode = MigrateErrorCode.InvalidSchema\n}\n\nexport class FailedContentMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.ContentMigrationFailed\n}\n\nexport class NotSuccessfulContentMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.ContentMigrationNotSuccessful\n}\n"],"names":["SaveMigrationCommand","ImplementationException","SaveSchemaCommand","calculateSchemaChecksum","calculateMigrationChecksum","MigrationVersionHelper","errors","SchemaValidator","wrapIdentifier","QueryError","logger","MigrateErrorCode"],"mappings":";;;;;;;;;;;;;;;AAsBO,MAAM,gBAAgB;AAAA,EAC5B,YACkB,oBACA,gBACA,4BACA,gDACA,sBAChB;AALgB,SAAA,qBAAA;AACA,SAAA,iBAAA;AACA,SAAA,6BAAA;AACA,SAAA,iDAAA;AACA,SAAA,uBAAA;AAAA,EACf;AAAA,EAEH,MAAa,QAAQ,EAAE,IAAI,SAAS,UAAU,SAAS,EAAE,cAAc,OAAO,eAAe,MAAA,GAAS,qBAAqB,UAUxH;AACF,QAAI,oBAAoB,WAAW,GAAG;AACrC;AAAA,IACD;AACA,UAAM,iBAAiB,MAAM,KAAK,eAAe,MAAM,EAAE,IAAI;AAC7D,QAAI,SAAS,eAAe;AAC5B,QAAI,KAAK,eAAe,KAAK;AAE7B,UAAM,YAAY,MAAM,KAAK,mBAAmB,IAAI,QAAQ,eAAe,KAAK,WAAW,MAAM,qBAAqB,EAAE,aAAa,cAAc;AACnJ,QAAI,UAAU,WAAW,GAAG;AAC3B;AAAA,IACD;AAEA,UAAM,SAAS,CAAC,GAA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A,EAA5D,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOC,MAAAA,iBAAiB,gBAAA;AAAA,EAAA;AACzB;AAEO,MAAM,sCAAsC,eAAe;AAAA,EAA3D,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,eAAA;AAAA,EAAA;AACzB;AAEO,MAAM,6BAA6B,eAAe;AAAA,EAAlD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,eAAA;AAAA,EAAA;AACzB;AAEO,MAAM,2BAA2B,eAAe;AAAA,EAAhD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,aAAA;AAAA,EAAA;AACzB;AAEO,MAAM,oCAAoC,eAAe;AAAA,EAAzD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,sBAAA;AAAA,EAAA;AACzB;AAEO,MAAM,2CAA2C,eAAe;AAAA,EAAhE,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,6BAAA;AAAA,EAAA;AACzB;;;;;;;;;"}
1
+ {"version":3,"file":"ProjectMigrator.cjs","sources":["../../../../../../packages/engine-system-api/src/model/migrations/ProjectMigrator.ts"],"sourcesContent":["import { calculateMigrationChecksum, Migration, MigrationDescriber, MigrationVersionHelper } from '@contember/schema-migrations'\nimport { Client, DatabaseMetadata, QueryError, wrapIdentifier } from '@contember/database'\nimport { Schema } from '@contember/schema'\nimport { SaveMigrationCommand } from '../commands/index.js'\nimport { Stage } from '../dtos/index.js'\nimport { DatabaseContext } from '../database/index.js'\nimport { ExecutedMigrationsResolver } from './ExecutedMigrationsResolver.js'\nimport { MigrateErrorCode } from '../../schema/index.js'\nimport { calculateSchemaChecksum, emptySchema, SchemaValidator, SchemaValidatorSkippedErrors } from '@contember/schema-utils'\nimport { logger } from '@contember/logger'\nimport { MigrationsDatabaseMetadataResolverStoreFactory, SchemaDatabaseMetadataResolverStore } from '../metadata/index.js'\nimport { ContentMigrationQuery, MigrationInput, SchemaStateInput } from './MigrationInput.js'\nimport { ContentQueryExecutor } from '../dependencies/index.js'\nimport { SchemaProvider } from './SchemaProvider.js'\nimport { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand.js'\nimport { ImplementationException } from '../../utils/index.js'\n\ntype MigrationVariables = {\n\tsystem_schema: string\n\tproject_slug: string\n}\n\nexport class ProjectMigrator {\n\tconstructor(\n\t\tprivate readonly migrationDescriber: MigrationDescriber,\n\t\tprivate readonly schemaProvider: SchemaProvider,\n\t\tprivate readonly executedMigrationsResolver: ExecutedMigrationsResolver,\n\t\tprivate readonly migrationsDatabaseMetadataResolverStoreFactory: MigrationsDatabaseMetadataResolverStoreFactory,\n\t\tprivate readonly contentQueryExecutor: ContentQueryExecutor,\n\t) {}\n\n\tpublic async migrate({ db, project, identity, options: { ignoreOrder = false, skipExecuted = false }, migrationsToExecute, stages, schemaState }: {\n\t\tdb: DatabaseContext\n\t\tproject: { slug: string; systemSchema: string }\n\t\tidentity: { id: string }\n\t\tstages: Stage[]\n\t\tmigrationsToExecute: readonly MigrationInput[]\n\t\tschemaState?: SchemaStateInput\n\t\toptions: {\n\t\t\tignoreOrder?: boolean\n\t\t\tskipExecuted?: boolean\n\t\t}\n\t}) {\n\t\tif (migrationsToExecute.length === 0 && !schemaState) {\n\t\t\treturn\n\t\t}\n\t\tconst schemaWithMeta = await this.schemaProvider.fetch({ db })\n\t\tlet schema = schemaWithMeta.schema\n\t\tlet id = schemaWithMeta.meta.id\n\n\t\tconst validated = await this.validateMigrations(db, schema, schemaWithMeta.meta.version ?? null, migrationsToExecute, { ignoreOrder, skipExecuted })\n\n\t\tif (validated.length === 0 && !schemaState) {\n\t\t\treturn\n\t\t}\n\n\t\tconst sorted = [...validated].sort((a, b) => a.version.localeCompare(b.version))\n\n\t\tconst metadataStore = this.migrationsDatabaseMetadataResolverStoreFactory.create(db)\n\n\t\tfor (const migration of sorted) {\n\t\t\tif (migration.type === 'schema') {\n\t\t\t\tconst formatVersion = migration.formatVersion\n\n\t\t\t\tfor (const modification of migration.modifications) {\n\t\t\t\t\t;[schema] = await this.applyModification(\n\t\t\t\t\t\tdb.client,\n\t\t\t\t\t\tstages,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tmodification,\n\t\t\t\t\t\tformatVersion,\n\t\t\t\t\t\tmigration.version,\n\t\t\t\t\t\tproject,\n\t\t\t\t\t\tmetadataStore,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (migration.type === 'content') {\n\t\t\t\tif (!id) {\n\t\t\t\t\tthrow new FailedContentMigrationError(migration.version, `Cannot execute content migration without schema`)\n\t\t\t\t}\n\t\t\t\tfor (const query of migration.queries) {\n\t\t\t\t\tawait this.executeContentMigration({\n\t\t\t\t\t\tversion: migration.version,\n\t\t\t\t\t\tquery,\n\t\t\t\t\t\tdb,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tschemaMeta: { id },\n\t\t\t\t\t\tstages,\n\t\t\t\t\t\tdatabaseMetadata: await metadataStore.getMetadata(db.client.schema),\n\t\t\t\t\t\tidentity,\n\t\t\t\t\t\tproject,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\t// event log uses deferred constraint triggers, we need to fire them before ALTER\n\t\t\t\tawait db.client.query(`SET CONSTRAINTS ALL IMMEDIATE`)\n\t\t\t\tawait db.client.query(`SET CONSTRAINTS ALL DEFERRED`)\n\t\t\t}\n\t\t\tid = await db.commandBus.execute(new SaveMigrationCommand(migration))\n\t\t}\n\n\t\tconst latestVersion = sorted.length > 0\n\t\t\t? sorted[sorted.length - 1].version\n\t\t\t: schemaWithMeta.meta.version\n\n\t\tif (schemaState) {\n\t\t\tschema = {\n\t\t\t\t...schema,\n\t\t\t\tacl: schemaState.acl as Schema['acl'],\n\t\t\t\tvalidation: schemaState.validation as Schema['validation'],\n\t\t\t\tactions: schemaState.actions as Schema['actions'],\n\t\t\t\tsettings: schemaState.settings as Schema['settings'],\n\t\t\t}\n\t\t\t// Client-supplied state is otherwise saved blindly; validate it as the normal migration flow would.\n\t\t\tconst errors = SchemaValidator.validate(schema)\n\t\t\tif (errors.length > 0) {\n\t\t\t\tthrow new InvalidSchemaError(\n\t\t\t\t\tlatestVersion ?? '(schema state)',\n\t\t\t\t\t'Schema state is invalid: \\n'\n\t\t\t\t\t\t+ errors.map(it => `${it.path.join('.')}: [${it.code}] ${it.message}`).join('\\n'),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tif (!latestVersion) {\n\t\t\tif (schemaState) {\n\t\t\t\t// State-only update on a fresh project with no migrations — there is no schema\n\t\t\t\t// row to attach the state to yet, so there is nothing to save.\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow new ImplementationException()\n\t\t}\n\n\t\tif (!id) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\n\t\tawait db.commandBus.execute(\n\t\t\tnew SaveSchemaCommand({\n\t\t\t\tschema,\n\t\t\t\tmeta: {\n\t\t\t\t\tid,\n\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\tversion: latestVersion,\n\t\t\t\t\tchecksum: calculateSchemaChecksum(schema),\n\t\t\t\t},\n\t\t\t}),\n\t\t)\n\t}\n\n\tpublic async migrateFromSnapshot({ db, project, stages, snapshot, covers, schemaState }: {\n\t\tdb: DatabaseContext\n\t\tproject: { slug: string; systemSchema: string }\n\t\tstages: Stage[]\n\t\tsnapshot: { formatVersion: number; modifications: Migration.Modification[] }\n\t\tcovers: readonly MigrationInput[]\n\t\tschemaState?: SchemaStateInput\n\t}) {\n\t\tconst sortedCovers = [...covers].sort((a, b) => a.version.localeCompare(b.version))\n\t\tconst latestVersion = sortedCovers.length > 0 ? sortedCovers[sortedCovers.length - 1].version : null\n\t\tif (!latestVersion) {\n\t\t\tthrow new ImplementationException('Snapshot must cover at least one migration')\n\t\t}\n\n\t\t// Hard safety gate: a snapshot may only bootstrap a project that has executed nothing yet.\n\t\tconst executedMigrations = await this.executedMigrationsResolver.getMigrations(db)\n\t\tif (executedMigrations.length > 0) {\n\t\t\tthrow new ProjectNotEmptyError(latestVersion, 'Cannot apply snapshot: project already has executed migrations')\n\t\t}\n\n\t\tconst metadataStore = this.migrationsDatabaseMetadataResolverStoreFactory.create(db)\n\t\tlet schema = emptySchema\n\t\tfor (const modification of snapshot.modifications) {\n\t\t\t;[schema] = await this.applyModification(\n\t\t\t\tdb.client,\n\t\t\t\tstages,\n\t\t\t\tschema,\n\t\t\t\tmodification,\n\t\t\t\tsnapshot.formatVersion,\n\t\t\t\tlatestVersion,\n\t\t\t\tproject,\n\t\t\t\tmetadataStore,\n\t\t\t)\n\t\t}\n\n\t\tconst errors = SchemaValidator.validate(schema)\n\t\tif (errors.length > 0) {\n\t\t\tthrow new InvalidSchemaError(\n\t\t\t\tlatestVersion,\n\t\t\t\t'Snapshot generates invalid schema: \\n'\n\t\t\t\t\t+ errors.map(it => `${it.path.join('.')}: [${it.code}] ${it.message}`).join('\\n'),\n\t\t\t)\n\t\t}\n\n\t\t// Record covered migrations as executed without replaying their SQL, so the registry\n\t\t// ends up identical to a full replay (status, checksums and schema rebuild stay correct).\n\t\tlet id: number | undefined\n\t\tfor (const migration of sortedCovers) {\n\t\t\tid = await db.commandBus.execute(new SaveMigrationCommand(migration))\n\t\t}\n\t\tif (!id) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\n\t\tif (schemaState) {\n\t\t\tschema = {\n\t\t\t\t...schema,\n\t\t\t\tacl: schemaState.acl as Schema['acl'],\n\t\t\t\tvalidation: schemaState.validation as Schema['validation'],\n\t\t\t\tactions: schemaState.actions as Schema['actions'],\n\t\t\t\tsettings: schemaState.settings as Schema['settings'],\n\t\t\t}\n\t\t}\n\n\t\tawait db.commandBus.execute(\n\t\t\tnew SaveSchemaCommand({\n\t\t\t\tschema,\n\t\t\t\tmeta: {\n\t\t\t\t\tid,\n\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\tversion: latestVersion,\n\t\t\t\t\tchecksum: calculateSchemaChecksum(schema),\n\t\t\t\t},\n\t\t\t}),\n\t\t)\n\t}\n\n\tprivate async executeContentMigration({ query, stages, version, ...ctx }: {\n\t\tversion: string\n\t\tdb: DatabaseContext\n\t\tquery: ContentMigrationQuery\n\t\tstages: Stage[]\n\t\tschema: Schema\n\t\tschemaMeta: { id: number }\n\t\tproject: { slug: string; systemSchema: string }\n\t\tidentity: { id: string }\n\t\tdatabaseMetadata: DatabaseMetadata\n\t}) {\n\t\tconst queryStages = query.stage ? stages.filter(it => it.slug === query.stage) : stages\n\t\tfor (const stage of queryStages) {\n\t\t\tconst response = await this.contentQueryExecutor.execute({\n\t\t\t\tstage,\n\t\t\t\t...ctx,\n\t\t\t}, query)\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new FailedContentMigrationError(version, response.errors.join(', '))\n\t\t\t}\n\t\t\tif (query.checkMutationResult !== false) {\n\t\t\t\tfor (const [key, value] of Object.entries(response.result.data ?? {})) {\n\t\t\t\t\tif (typeof value === 'object' && value !== null && 'ok' in value && !value.ok) {\n\t\t\t\t\t\tconst errorDetails = 'errorMessage' in value ? value.errorMessage : 'No details available. Please fetch errorMessage field.'\n\t\t\t\t\t\tthrow new NotSuccessfulContentMigrationError(version, `Mutation ${key} failed: ${errorDetails}`)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async validateMigrations(\n\t\tdb: DatabaseContext,\n\t\tschema: Schema,\n\t\tversion: string | null,\n\t\tmigrationsToExecute: readonly MigrationInput[],\n\t\t{ ignoreOrder, skipExecuted }: {\n\t\t\tignoreOrder: boolean\n\t\t\tskipExecuted: boolean\n\t\t},\n\t): Promise<readonly MigrationInput[]> {\n\t\tconst executedMigrations = await this.executedMigrationsResolver.getMigrations(db)\n\t\tconst toExecute: MigrationInput[] = []\n\t\tlet skippedErrors: SchemaValidatorSkippedErrors[] = []\n\t\tfor (const migration of migrationsToExecute) {\n\t\t\tconst executedMigration = executedMigrations.find(it => it.version === migration.version)\n\t\t\tif (executedMigration) {\n\t\t\t\tif (skipExecuted && (migration.type !== 'schema' || executedMigration.checksum === calculateMigrationChecksum(migration))) {\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tthrow new AlreadyExecutedMigrationError(migration.version, `Migration is already executed`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (version && migration.version < version && !ignoreOrder) {\n\t\t\t\tthrow new MustFollowLatestMigrationError(migration.version, `Must follow latest executed migration ${version}`)\n\t\t\t}\n\t\t\tif (migration.type === 'schema') {\n\t\t\t\tconst described = this.migrationDescriber.describeModifications(schema, migration)\n\t\t\t\tif (described.length === 0) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst latestModification = described[described.length - 1]\n\t\t\t\tschema = latestModification.schema\n\t\t\t\tskippedErrors = [\n\t\t\t\t\t...skippedErrors.filter(it => it.skipUntil && MigrationVersionHelper.extractVersion(it.skipUntil) >= migration.version),\n\t\t\t\t\t...migration.skippedErrors ?? [],\n\t\t\t\t]\n\t\t\t\tconst errors = SchemaValidator.validate(schema, skippedErrors)\n\t\t\t\tif (errors.length > 0) {\n\t\t\t\t\tthrow new InvalidSchemaError(\n\t\t\t\t\t\tmigration.version,\n\t\t\t\t\t\t'Migration generates invalid schema: \\n'\n\t\t\t\t\t\t\t+ errors.map(it => `${it.path.join('.')}: [${it.code}] ${it.message}`).join('\\n'),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\ttoExecute.push(migration)\n\t\t}\n\t\t// intentionally not using skippedErrors here\n\t\tconst errors = SchemaValidator.validate(schema)\n\t\tif (errors.length > 0) {\n\t\t\tthrow new InvalidSchemaError(\n\t\t\t\ttoExecute[toExecute.length - 1]?.version ?? version ?? '(schema)',\n\t\t\t\t'Migration generates invalid schema: \\n'\n\t\t\t\t\t+ errors.map(it => it.path.join('.') + ': ' + it.message).join('\\n'),\n\t\t\t)\n\t\t}\n\t\treturn toExecute\n\t}\n\n\tprivate sqlPreprocessor(text: string, variables: MigrationVariables): string {\n\t\treturn Object.entries(variables).reduce(\n\t\t\t(content, [key, value]) => content.replace(new RegExp(`\\\\{\\\\{${key}\\\\}\\\\}`, 'g'), value),\n\t\t\ttext,\n\t\t)\n\t}\n\n\tprivate async applyModification(\n\t\tdb: Client,\n\t\tstages: Stage[],\n\t\tschema: Schema,\n\t\tmodification: Migration.Modification,\n\t\tformatVersion: number,\n\t\tmigrationVersion: string,\n\t\tproject: { slug: string; systemSchema: string },\n\t\tmetadataStore: SchemaDatabaseMetadataResolverStore,\n\t): Promise<[Schema]> {\n\t\tconst {\n\t\t\tgetSql,\n\t\t\tschema: newSchema,\n\t\t} = this.migrationDescriber.describeModification(schema, modification, { formatVersion })\n\t\tfor (const stage of stages) {\n\t\t\tconst databaseMetadata = await metadataStore.getMetadata(stage.schema)\n\t\t\tconst sql = getSql({\n\t\t\t\tsystemSchema: project.systemSchema,\n\t\t\t\tdatabaseMetadata,\n\t\t\t\tinvalidateDatabaseMetadata: () => metadataStore.invalidate(stage.schema),\n\t\t\t})\n\t\t\tconst processedSql = this.sqlPreprocessor(sql, {\n\t\t\t\tproject_slug: project.slug,\n\t\t\t\tsystem_schema: project.systemSchema,\n\t\t\t})\n\t\t\tawait this.executeOnStage(db, stage, processedSql, migrationVersion)\n\t\t}\n\t\treturn [newSchema]\n\t}\n\n\tprivate async executeOnStage(db: Client, stage: Stage, sql: string, migrationVersion: string) {\n\t\tawait db.query('SET LOCAL search_path TO ' + wrapIdentifier(stage.schema))\n\t\ttry {\n\t\t\tawait db.query(sql)\n\t\t} catch (e) {\n\t\t\tif (e instanceof QueryError) {\n\t\t\t\tlogger.error(e, { message: 'Migration failed' })\n\t\t\t\tthrow new MigrationFailedError(migrationVersion, e.message)\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n}\n\nexport abstract class MigrationError extends Error {\n\tpublic abstract code: MigrateErrorCode\n\n\tconstructor(public readonly version: string, public readonly migrationError: string) {\n\t\tsuper(`${version}: ${migrationError}`)\n\t}\n}\n\nexport class MustFollowLatestMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.MustFollowLatest\n}\n\nexport class AlreadyExecutedMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.AlreadyExecuted\n}\n\nexport class MigrationFailedError extends MigrationError {\n\tcode = MigrateErrorCode.MigrationFailed\n}\n\nexport class InvalidSchemaError extends MigrationError {\n\tcode = MigrateErrorCode.InvalidSchema\n}\n\nexport class FailedContentMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.ContentMigrationFailed\n}\n\nexport class NotSuccessfulContentMigrationError extends MigrationError {\n\tcode = MigrateErrorCode.ContentMigrationNotSuccessful\n}\n\nexport class ProjectNotEmptyError extends MigrationError {\n\tcode = MigrateErrorCode.ProjectNotEmpty\n}\n"],"names":["SaveMigrationCommand","SchemaValidator","ImplementationException","SaveSchemaCommand","calculateSchemaChecksum","emptySchema","calculateMigrationChecksum","MigrationVersionHelper","errors","wrapIdentifier","QueryError","logger","MigrateErrorCode"],"mappings":";;;;;;;;;;;;;;;AAsBO,MAAM,gBAAgB;AAAA,EAC5B,YACkB,oBACA,gBACA,4BACA,gDACA,sBAChB;AALgB,SAAA,qBAAA;AACA,SAAA,iBAAA;AACA,SAAA,6BAAA;AACA,SAAA,iDAAA;AACA,SAAA,uBAAA;AAAA,EACf;AAAA,EAEH,MAAa,QAAQ,EAAE,IAAI,SAAS,UAAU,SAAS,EAAE,cAAc,OAAO,eAAe,MAAA,GAAS,qBAAqB,QAAQ,eAWhI;AACF,QAAI,oBAAoB,WAAW,KAAK,CAAC,aAAa;AACrD;AAAA,IACD;AACA,UAAM,iBAAiB,MAAM,KAAK,eAAe,MAAM,EAAE,IAAI;AAC7D,QAAI,SAAS,eAAe;AAC5B,QAAI,KAAK,eAAe,KAA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,gBAAA;AAAA,EAAA;AACzB;AAEO,MAAM,sCAAsC,eAAe;AAAA,EAA3D,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,eAAA;AAAA,EAAA;AACzB;AAEO,MAAM,6BAA6B,eAAe;AAAA,EAAlD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,eAAA;AAAA,EAAA;AACzB;AAEO,MAAM,2BAA2B,eAAe;AAAA,EAAhD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,aAAA;AAAA,EAAA;AACzB;AAEO,MAAM,oCAAoC,eAAe;AAAA,EAAzD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,sBAAA;AAAA,EAAA;AACzB;AAEO,MAAM,2CAA2C,eAAe;AAAA,EAAhE,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,6BAAA;AAAA,EAAA;AACzB;AAEO,MAAM,6BAA6B,eAAe;AAAA,EAAlD,cAAA;AAAA,UAAA,GAAA,SAAA;AACN,kBAAA,MAAA,QAAOA,MAAAA,iBAAiB,eAAA;AAAA,EAAA;AACzB;;;;;;;;;;"}
@@ -1,7 +1,7 @@
1
1
  import { calculateMigrationChecksum, MigrationVersionHelper } from "@contember/schema-migrations";
2
2
  import { wrapIdentifier, QueryError } from "@contember/database";
3
3
  import { SaveMigrationCommand } from "../commands/migrations/SaveMigrationCommand.js";
4
- import { calculateSchemaChecksum, SchemaValidator } from "@contember/schema-utils";
4
+ import { SchemaValidator, calculateSchemaChecksum, emptySchema } from "@contember/schema-utils";
5
5
  import { MigrateErrorCode } from "../../schema/types.js";
6
6
  import "../../schema/dev.graphql.js";
7
7
  import "../../schema/system.graphql.js";
@@ -19,15 +19,15 @@ class ProjectMigrator {
19
19
  this.migrationsDatabaseMetadataResolverStoreFactory = migrationsDatabaseMetadataResolverStoreFactory;
20
20
  this.contentQueryExecutor = contentQueryExecutor;
21
21
  }
22
- async migrate({ db, project, identity, options: { ignoreOrder = false, skipExecuted = false }, migrationsToExecute, stages }) {
23
- if (migrationsToExecute.length === 0) {
22
+ async migrate({ db, project, identity, options: { ignoreOrder = false, skipExecuted = false }, migrationsToExecute, stages, schemaState }) {
23
+ if (migrationsToExecute.length === 0 && !schemaState) {
24
24
  return;
25
25
  }
26
26
  const schemaWithMeta = await this.schemaProvider.fetch({ db });
27
27
  let schema = schemaWithMeta.schema;
28
28
  let id = schemaWithMeta.meta.id;
29
29
  const validated = await this.validateMigrations(db, schema, schemaWithMeta.meta.version ?? null, migrationsToExecute, { ignoreOrder, skipExecuted });
30
- if (validated.length === 0) {
30
+ if (validated.length === 0 && !schemaState) {
31
31
  return;
32
32
  }
33
33
  const sorted = [...validated].sort((a, b) => a.version.localeCompare(b.version));
@@ -69,16 +69,98 @@ class ProjectMigrator {
69
69
  }
70
70
  id = await db.commandBus.execute(new SaveMigrationCommand(migration));
71
71
  }
72
+ const latestVersion = sorted.length > 0 ? sorted[sorted.length - 1].version : schemaWithMeta.meta.version;
73
+ if (schemaState) {
74
+ schema = {
75
+ ...schema,
76
+ acl: schemaState.acl,
77
+ validation: schemaState.validation,
78
+ actions: schemaState.actions,
79
+ settings: schemaState.settings
80
+ };
81
+ const errors = SchemaValidator.validate(schema);
82
+ if (errors.length > 0) {
83
+ throw new InvalidSchemaError(
84
+ latestVersion ?? "(schema state)",
85
+ "Schema state is invalid: \n" + errors.map((it) => `${it.path.join(".")}: [${it.code}] ${it.message}`).join("\n")
86
+ );
87
+ }
88
+ }
89
+ if (!latestVersion) {
90
+ if (schemaState) {
91
+ return;
92
+ }
93
+ throw new ImplementationException();
94
+ }
95
+ if (!id) {
96
+ throw new ImplementationException();
97
+ }
98
+ await db.commandBus.execute(
99
+ new SaveSchemaCommand({
100
+ schema,
101
+ meta: {
102
+ id,
103
+ updatedAt: /* @__PURE__ */ new Date(),
104
+ version: latestVersion,
105
+ checksum: calculateSchemaChecksum(schema)
106
+ }
107
+ })
108
+ );
109
+ }
110
+ async migrateFromSnapshot({ db, project, stages, snapshot, covers, schemaState }) {
111
+ const sortedCovers = [...covers].sort((a, b) => a.version.localeCompare(b.version));
112
+ const latestVersion = sortedCovers.length > 0 ? sortedCovers[sortedCovers.length - 1].version : null;
113
+ if (!latestVersion) {
114
+ throw new ImplementationException("Snapshot must cover at least one migration");
115
+ }
116
+ const executedMigrations = await this.executedMigrationsResolver.getMigrations(db);
117
+ if (executedMigrations.length > 0) {
118
+ throw new ProjectNotEmptyError(latestVersion, "Cannot apply snapshot: project already has executed migrations");
119
+ }
120
+ const metadataStore = this.migrationsDatabaseMetadataResolverStoreFactory.create(db);
121
+ let schema = emptySchema;
122
+ for (const modification of snapshot.modifications) {
123
+ [schema] = await this.applyModification(
124
+ db.client,
125
+ stages,
126
+ schema,
127
+ modification,
128
+ snapshot.formatVersion,
129
+ latestVersion,
130
+ project,
131
+ metadataStore
132
+ );
133
+ }
134
+ const errors = SchemaValidator.validate(schema);
135
+ if (errors.length > 0) {
136
+ throw new InvalidSchemaError(
137
+ latestVersion,
138
+ "Snapshot generates invalid schema: \n" + errors.map((it) => `${it.path.join(".")}: [${it.code}] ${it.message}`).join("\n")
139
+ );
140
+ }
141
+ let id;
142
+ for (const migration of sortedCovers) {
143
+ id = await db.commandBus.execute(new SaveMigrationCommand(migration));
144
+ }
72
145
  if (!id) {
73
146
  throw new ImplementationException();
74
147
  }
148
+ if (schemaState) {
149
+ schema = {
150
+ ...schema,
151
+ acl: schemaState.acl,
152
+ validation: schemaState.validation,
153
+ actions: schemaState.actions,
154
+ settings: schemaState.settings
155
+ };
156
+ }
75
157
  await db.commandBus.execute(
76
158
  new SaveSchemaCommand({
77
159
  schema,
78
160
  meta: {
79
161
  id,
80
162
  updatedAt: /* @__PURE__ */ new Date(),
81
- version: sorted[sorted.length - 1].version,
163
+ version: latestVersion,
82
164
  checksum: calculateSchemaChecksum(schema)
83
165
  }
84
166
  })
@@ -144,7 +226,7 @@ class ProjectMigrator {
144
226
  const errors = SchemaValidator.validate(schema);
145
227
  if (errors.length > 0) {
146
228
  throw new InvalidSchemaError(
147
- toExecute[toExecute.length - 1].version,
229
+ toExecute[toExecute.length - 1]?.version ?? version ?? "(schema)",
148
230
  "Migration generates invalid schema: \n" + errors.map((it) => it.path.join(".") + ": " + it.message).join("\n")
149
231
  );
150
232
  }
@@ -232,6 +314,12 @@ class NotSuccessfulContentMigrationError extends MigrationError {
232
314
  __publicField(this, "code", MigrateErrorCode.ContentMigrationNotSuccessful);
233
315
  }
234
316
  }
317
+ class ProjectNotEmptyError extends MigrationError {
318
+ constructor() {
319
+ super(...arguments);
320
+ __publicField(this, "code", MigrateErrorCode.ProjectNotEmpty);
321
+ }
322
+ }
235
323
  export {
236
324
  AlreadyExecutedMigrationError,
237
325
  FailedContentMigrationError,
@@ -240,6 +328,7 @@ export {
240
328
  MigrationFailedError,
241
329
  MustFollowLatestMigrationError,
242
330
  NotSuccessfulContentMigrationError,
243
- ProjectMigrator
331
+ ProjectMigrator,
332
+ ProjectNotEmptyError
244
333
  };
245
334
  //# sourceMappingURL=ProjectMigrator.js.map