@contember/cli 2.1.0-beta.1 → 2.2.0-alpha.1

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 (525) hide show
  1. package/CLAUDE.md +14 -1
  2. package/dist/development/index.cjs +5 -0
  3. package/dist/development/index.cjs.map +1 -0
  4. package/dist/development/index.js +5 -0
  5. package/dist/development/index.js.map +1 -0
  6. package/dist/development/run.cjs +3 -3
  7. package/dist/development/run.cjs.map +1 -1
  8. package/dist/development/run.js.map +1 -1
  9. package/dist/development/src/commands/actions/ActionsGetEventCommand.cjs.map +1 -1
  10. package/dist/development/src/commands/actions/ActionsGetEventCommand.js.map +1 -1
  11. package/dist/development/src/commands/actions/ActionsListFailedEventsCommand.cjs.map +1 -1
  12. package/dist/development/src/commands/actions/ActionsListFailedEventsCommand.js.map +1 -1
  13. package/dist/development/src/commands/actions/ActionsListVariablesCommand.cjs.map +1 -1
  14. package/dist/development/src/commands/actions/ActionsListVariablesCommand.js.map +1 -1
  15. package/dist/development/src/commands/actions/ActionsRetryEventCommand.cjs.map +1 -1
  16. package/dist/development/src/commands/actions/ActionsRetryEventCommand.js.map +1 -1
  17. package/dist/development/src/commands/actions/ActionsSetVariablesCommand.cjs.map +1 -1
  18. package/dist/development/src/commands/actions/ActionsSetVariablesCommand.js.map +1 -1
  19. package/dist/development/src/commands/actions/ActionsStopEventCommand.cjs.map +1 -1
  20. package/dist/development/src/commands/actions/ActionsStopEventCommand.js.map +1 -1
  21. package/dist/development/src/commands/deploy/DeployCommand.cjs +3 -1
  22. package/dist/development/src/commands/deploy/DeployCommand.cjs.map +1 -1
  23. package/dist/development/src/commands/deploy/DeployCommand.js +3 -1
  24. package/dist/development/src/commands/deploy/DeployCommand.js.map +1 -1
  25. package/dist/development/src/commands/migrations/MigrationAmendCommand.cjs +26 -4
  26. package/dist/development/src/commands/migrations/MigrationAmendCommand.cjs.map +1 -1
  27. package/dist/development/src/commands/migrations/MigrationAmendCommand.js +26 -4
  28. package/dist/development/src/commands/migrations/MigrationAmendCommand.js.map +1 -1
  29. package/dist/development/src/commands/migrations/MigrationDescribeCommand.cjs.map +1 -1
  30. package/dist/development/src/commands/migrations/MigrationDescribeCommand.js.map +1 -1
  31. package/dist/development/src/commands/migrations/MigrationDiffCommand.cjs +39 -3
  32. package/dist/development/src/commands/migrations/MigrationDiffCommand.cjs.map +1 -1
  33. package/dist/development/src/commands/migrations/MigrationDiffCommand.js +39 -3
  34. package/dist/development/src/commands/migrations/MigrationDiffCommand.js.map +1 -1
  35. package/dist/development/src/commands/migrations/MigrationExecuteCommand.cjs +3 -1
  36. package/dist/development/src/commands/migrations/MigrationExecuteCommand.cjs.map +1 -1
  37. package/dist/development/src/commands/migrations/MigrationExecuteCommand.js +3 -1
  38. package/dist/development/src/commands/migrations/MigrationExecuteCommand.js.map +1 -1
  39. package/dist/development/src/commands/migrations/MigrationInitStateCommand.cjs +26 -0
  40. package/dist/development/src/commands/migrations/MigrationInitStateCommand.cjs.map +1 -0
  41. package/dist/development/src/commands/migrations/MigrationInitStateCommand.js +26 -0
  42. package/dist/development/src/commands/migrations/MigrationInitStateCommand.js.map +1 -0
  43. package/dist/development/src/commands/migrations/MigrationRebaseCommand.cjs.map +1 -1
  44. package/dist/development/src/commands/migrations/MigrationRebaseCommand.js.map +1 -1
  45. package/dist/development/src/commands/migrations/MigrationSnapshotCommand.cjs +28 -0
  46. package/dist/development/src/commands/migrations/MigrationSnapshotCommand.cjs.map +1 -0
  47. package/dist/development/src/commands/migrations/MigrationSnapshotCommand.js +28 -0
  48. package/dist/development/src/commands/migrations/MigrationSnapshotCommand.js.map +1 -0
  49. package/dist/development/src/commands/migrations/MigrationStatusCommand.cjs.map +1 -1
  50. package/dist/development/src/commands/migrations/MigrationStatusCommand.js.map +1 -1
  51. package/dist/development/src/commands/migrations/MigrationVerifySnapshotCommand.cjs +23 -0
  52. package/dist/development/src/commands/migrations/MigrationVerifySnapshotCommand.cjs.map +1 -0
  53. package/dist/development/src/commands/migrations/MigrationVerifySnapshotCommand.js +23 -0
  54. package/dist/development/src/commands/migrations/MigrationVerifySnapshotCommand.js.map +1 -0
  55. package/dist/development/src/commands/project/ProjectGenerateDocumentationCommand.cjs +2 -2
  56. package/dist/development/src/commands/project/ProjectGenerateDocumentationCommand.cjs.map +1 -1
  57. package/dist/development/src/commands/project/ProjectGenerateDocumentationCommand.js.map +1 -1
  58. package/dist/development/src/commands/project/ProjectPrintSchemaCommand.cjs.map +1 -1
  59. package/dist/development/src/commands/project/ProjectPrintSchemaCommand.js.map +1 -1
  60. package/dist/development/src/commands/project/ProjectValidateCommand.cjs.map +1 -1
  61. package/dist/development/src/commands/project/ProjectValidateCommand.js.map +1 -1
  62. package/dist/development/src/commands/tenant/TenantApplyCommand.cjs +39 -0
  63. package/dist/development/src/commands/tenant/TenantApplyCommand.cjs.map +1 -0
  64. package/dist/development/src/commands/tenant/TenantApplyCommand.js +39 -0
  65. package/dist/development/src/commands/tenant/TenantApplyCommand.js.map +1 -0
  66. package/dist/development/src/commands/transfer/ExportCommand.cjs.map +1 -1
  67. package/dist/development/src/commands/transfer/ExportCommand.js.map +1 -1
  68. package/dist/development/src/commands/transfer/ImportCommand.cjs.map +1 -1
  69. package/dist/development/src/commands/transfer/ImportCommand.js.map +1 -1
  70. package/dist/development/src/commands/transfer/TransferCommand.cjs.map +1 -1
  71. package/dist/development/src/commands/transfer/TransferCommand.js.map +1 -1
  72. package/dist/development/src/commands/workspace/WorkspaceUpdateApiCommand.cjs.map +1 -1
  73. package/dist/development/src/commands/workspace/WorkspaceUpdateApiCommand.js.map +1 -1
  74. package/dist/development/src/consts.cjs +2 -2
  75. package/dist/development/src/consts.cjs.map +1 -1
  76. package/dist/development/src/dic.cjs +60 -10
  77. package/dist/development/src/dic.cjs.map +1 -1
  78. package/dist/development/src/dic.js +61 -11
  79. package/dist/development/src/dic.js.map +1 -1
  80. package/dist/development/src/lib/SystemClientProvider.cjs.map +1 -1
  81. package/dist/development/src/lib/SystemClientProvider.js.map +1 -1
  82. package/dist/development/src/lib/TenantClientProvider.cjs.map +1 -1
  83. package/dist/development/src/lib/TenantClientProvider.js.map +1 -1
  84. package/dist/development/src/lib/VersionChecker.cjs +2 -2
  85. package/dist/development/src/lib/VersionChecker.cjs.map +1 -1
  86. package/dist/development/src/lib/VersionChecker.js.map +1 -1
  87. package/dist/development/src/lib/admin/AdminClient.cjs.map +1 -1
  88. package/dist/development/src/lib/admin/AdminClient.js.map +1 -1
  89. package/dist/development/src/lib/admin/AdminDeployer.cjs.map +1 -1
  90. package/dist/development/src/lib/admin/AdminDeployer.js.map +1 -1
  91. package/dist/development/src/lib/fs/DockerComposeManager.cjs +10 -10
  92. package/dist/development/src/lib/fs/DockerComposeManager.cjs.map +1 -1
  93. package/dist/development/src/lib/fs/DockerComposeManager.js.map +1 -1
  94. package/dist/development/src/lib/fs/YamlHandler.cjs.map +1 -1
  95. package/dist/development/src/lib/fs/YamlHandler.js.map +1 -1
  96. package/dist/development/src/lib/js/EsBuildBuilder.cjs.map +1 -1
  97. package/dist/development/src/lib/js/EsBuildBuilder.js.map +1 -1
  98. package/dist/development/src/lib/js/EvalExecutor.cjs.map +1 -1
  99. package/dist/development/src/lib/js/EvalExecutor.js.map +1 -1
  100. package/dist/development/src/lib/js/JsCodeRunner.cjs.map +1 -1
  101. package/dist/development/src/lib/js/JsCodeRunner.js.map +1 -1
  102. package/dist/development/src/lib/migrations/MigrationExecutionFacade.cjs +78 -18
  103. package/dist/development/src/lib/migrations/MigrationExecutionFacade.cjs.map +1 -1
  104. package/dist/development/src/lib/migrations/MigrationExecutionFacade.js +79 -19
  105. package/dist/development/src/lib/migrations/MigrationExecutionFacade.js.map +1 -1
  106. package/dist/development/src/lib/migrations/MigrationPrinter.cjs.map +1 -1
  107. package/dist/development/src/lib/migrations/MigrationPrinter.js.map +1 -1
  108. package/dist/development/src/lib/migrations/MigrationRebaseFacade.cjs +5 -1
  109. package/dist/development/src/lib/migrations/MigrationRebaseFacade.cjs.map +1 -1
  110. package/dist/development/src/lib/migrations/MigrationRebaseFacade.js +5 -1
  111. package/dist/development/src/lib/migrations/MigrationRebaseFacade.js.map +1 -1
  112. package/dist/development/src/lib/migrations/MigrationSnapshotFacade.cjs +171 -0
  113. package/dist/development/src/lib/migrations/MigrationSnapshotFacade.cjs.map +1 -0
  114. package/dist/development/src/lib/migrations/MigrationSnapshotFacade.js +171 -0
  115. package/dist/development/src/lib/migrations/MigrationSnapshotFacade.js.map +1 -0
  116. package/dist/development/src/lib/migrations/MigrationsStatusFacade.cjs.map +1 -1
  117. package/dist/development/src/lib/migrations/MigrationsStatusFacade.js.map +1 -1
  118. package/dist/development/src/lib/migrations/MigrationsValidator.cjs.map +1 -1
  119. package/dist/development/src/lib/migrations/MigrationsValidator.js.map +1 -1
  120. package/dist/development/src/lib/project/RemoteProjectProvider.cjs.map +1 -1
  121. package/dist/development/src/lib/project/RemoteProjectProvider.js.map +1 -1
  122. package/dist/development/src/lib/project/RemoteProjectResolver.cjs.map +1 -1
  123. package/dist/development/src/lib/project/RemoteProjectResolver.js.map +1 -1
  124. package/dist/development/src/lib/project/docs/components/EntityInfo.cjs.map +1 -1
  125. package/dist/development/src/lib/project/docs/components/EntityInfo.js.map +1 -1
  126. package/dist/development/src/lib/project/docs/components/EntityLink.cjs.map +1 -1
  127. package/dist/development/src/lib/project/docs/components/EntityLink.js.map +1 -1
  128. package/dist/development/src/lib/project/docs/components/FieldLink.cjs.map +1 -1
  129. package/dist/development/src/lib/project/docs/components/FieldLink.js.map +1 -1
  130. package/dist/development/src/lib/project/docs/components/FieldPermissions.cjs.map +1 -1
  131. package/dist/development/src/lib/project/docs/components/FieldPermissions.js.map +1 -1
  132. package/dist/development/src/lib/project/docs/components/FieldType.cjs.map +1 -1
  133. package/dist/development/src/lib/project/docs/components/FieldType.js.map +1 -1
  134. package/dist/development/src/lib/project/docs/components/OnDelete.cjs.map +1 -1
  135. package/dist/development/src/lib/project/docs/components/OnDelete.js.map +1 -1
  136. package/dist/development/src/lib/project/docs/components/ProjectInfo.cjs.map +1 -1
  137. package/dist/development/src/lib/project/docs/components/ProjectInfo.js.map +1 -1
  138. package/dist/development/src/lib/project/docs/projectDescribe.cjs.map +1 -1
  139. package/dist/development/src/lib/project/docs/projectDescribe.js.map +1 -1
  140. package/dist/development/src/lib/schema/SchemaLoader.cjs +5 -5
  141. package/dist/development/src/lib/schema/SchemaLoader.cjs.map +1 -1
  142. package/dist/development/src/lib/schema/SchemaLoader.js.map +1 -1
  143. package/dist/development/src/lib/schema/SchemaValidationHelper.cjs.map +1 -1
  144. package/dist/development/src/lib/schema/SchemaValidationHelper.js.map +1 -1
  145. package/dist/development/src/lib/tenant/TenantClient.cjs +75 -12
  146. package/dist/development/src/lib/tenant/TenantClient.cjs.map +1 -1
  147. package/dist/development/src/lib/tenant/TenantClient.js +75 -12
  148. package/dist/development/src/lib/tenant/TenantClient.js.map +1 -1
  149. package/dist/development/src/lib/tenant/TenantConfigApplier.cjs +55 -0
  150. package/dist/development/src/lib/tenant/TenantConfigApplier.cjs.map +1 -0
  151. package/dist/development/src/lib/tenant/TenantConfigApplier.js +55 -0
  152. package/dist/development/src/lib/tenant/TenantConfigApplier.js.map +1 -0
  153. package/dist/development/src/lib/tenant/TenantConfigLoader.cjs +32 -0
  154. package/dist/development/src/lib/tenant/TenantConfigLoader.cjs.map +1 -0
  155. package/dist/development/src/lib/tenant/TenantConfigLoader.js +32 -0
  156. package/dist/development/src/lib/tenant/TenantConfigLoader.js.map +1 -0
  157. package/dist/development/src/lib/tenant/tenantConfig.cjs +5 -0
  158. package/dist/development/src/lib/tenant/tenantConfig.cjs.map +1 -0
  159. package/dist/development/src/lib/tenant/tenantConfig.js +5 -0
  160. package/dist/development/src/lib/tenant/tenantConfig.js.map +1 -0
  161. package/dist/development/src/lib/transfer/DataTransferClient.cjs.map +1 -1
  162. package/dist/development/src/lib/transfer/DataTransferClient.js.map +1 -1
  163. package/dist/development/src/lib/workspace/WorkspaceResolver.cjs +6 -6
  164. package/dist/development/src/lib/workspace/WorkspaceResolver.cjs.map +1 -1
  165. package/dist/development/src/lib/workspace/WorkspaceResolver.js.map +1 -1
  166. package/dist/production/index.cjs +5 -0
  167. package/dist/production/index.cjs.map +1 -0
  168. package/dist/production/index.js +5 -0
  169. package/dist/production/index.js.map +1 -0
  170. package/dist/production/run.cjs +3 -3
  171. package/dist/production/run.cjs.map +1 -1
  172. package/dist/production/run.js.map +1 -1
  173. package/dist/production/src/commands/actions/ActionsGetEventCommand.cjs.map +1 -1
  174. package/dist/production/src/commands/actions/ActionsGetEventCommand.js.map +1 -1
  175. package/dist/production/src/commands/actions/ActionsListFailedEventsCommand.cjs.map +1 -1
  176. package/dist/production/src/commands/actions/ActionsListFailedEventsCommand.js.map +1 -1
  177. package/dist/production/src/commands/actions/ActionsListVariablesCommand.cjs.map +1 -1
  178. package/dist/production/src/commands/actions/ActionsListVariablesCommand.js.map +1 -1
  179. package/dist/production/src/commands/actions/ActionsRetryEventCommand.cjs.map +1 -1
  180. package/dist/production/src/commands/actions/ActionsRetryEventCommand.js.map +1 -1
  181. package/dist/production/src/commands/actions/ActionsSetVariablesCommand.cjs.map +1 -1
  182. package/dist/production/src/commands/actions/ActionsSetVariablesCommand.js.map +1 -1
  183. package/dist/production/src/commands/actions/ActionsStopEventCommand.cjs.map +1 -1
  184. package/dist/production/src/commands/actions/ActionsStopEventCommand.js.map +1 -1
  185. package/dist/production/src/commands/deploy/DeployCommand.cjs +3 -1
  186. package/dist/production/src/commands/deploy/DeployCommand.cjs.map +1 -1
  187. package/dist/production/src/commands/deploy/DeployCommand.js +3 -1
  188. package/dist/production/src/commands/deploy/DeployCommand.js.map +1 -1
  189. package/dist/production/src/commands/migrations/MigrationAmendCommand.cjs +26 -4
  190. package/dist/production/src/commands/migrations/MigrationAmendCommand.cjs.map +1 -1
  191. package/dist/production/src/commands/migrations/MigrationAmendCommand.js +26 -4
  192. package/dist/production/src/commands/migrations/MigrationAmendCommand.js.map +1 -1
  193. package/dist/production/src/commands/migrations/MigrationDescribeCommand.cjs.map +1 -1
  194. package/dist/production/src/commands/migrations/MigrationDescribeCommand.js.map +1 -1
  195. package/dist/production/src/commands/migrations/MigrationDiffCommand.cjs +39 -3
  196. package/dist/production/src/commands/migrations/MigrationDiffCommand.cjs.map +1 -1
  197. package/dist/production/src/commands/migrations/MigrationDiffCommand.js +39 -3
  198. package/dist/production/src/commands/migrations/MigrationDiffCommand.js.map +1 -1
  199. package/dist/production/src/commands/migrations/MigrationExecuteCommand.cjs +3 -1
  200. package/dist/production/src/commands/migrations/MigrationExecuteCommand.cjs.map +1 -1
  201. package/dist/production/src/commands/migrations/MigrationExecuteCommand.js +3 -1
  202. package/dist/production/src/commands/migrations/MigrationExecuteCommand.js.map +1 -1
  203. package/dist/production/src/commands/migrations/MigrationInitStateCommand.cjs +26 -0
  204. package/dist/production/src/commands/migrations/MigrationInitStateCommand.cjs.map +1 -0
  205. package/dist/production/src/commands/migrations/MigrationInitStateCommand.js +26 -0
  206. package/dist/production/src/commands/migrations/MigrationInitStateCommand.js.map +1 -0
  207. package/dist/production/src/commands/migrations/MigrationRebaseCommand.cjs.map +1 -1
  208. package/dist/production/src/commands/migrations/MigrationRebaseCommand.js.map +1 -1
  209. package/dist/production/src/commands/migrations/MigrationSnapshotCommand.cjs +28 -0
  210. package/dist/production/src/commands/migrations/MigrationSnapshotCommand.cjs.map +1 -0
  211. package/dist/production/src/commands/migrations/MigrationSnapshotCommand.js +28 -0
  212. package/dist/production/src/commands/migrations/MigrationSnapshotCommand.js.map +1 -0
  213. package/dist/production/src/commands/migrations/MigrationStatusCommand.cjs.map +1 -1
  214. package/dist/production/src/commands/migrations/MigrationStatusCommand.js.map +1 -1
  215. package/dist/production/src/commands/migrations/MigrationVerifySnapshotCommand.cjs +23 -0
  216. package/dist/production/src/commands/migrations/MigrationVerifySnapshotCommand.cjs.map +1 -0
  217. package/dist/production/src/commands/migrations/MigrationVerifySnapshotCommand.js +23 -0
  218. package/dist/production/src/commands/migrations/MigrationVerifySnapshotCommand.js.map +1 -0
  219. package/dist/production/src/commands/project/ProjectGenerateDocumentationCommand.cjs +2 -2
  220. package/dist/production/src/commands/project/ProjectGenerateDocumentationCommand.cjs.map +1 -1
  221. package/dist/production/src/commands/project/ProjectGenerateDocumentationCommand.js.map +1 -1
  222. package/dist/production/src/commands/project/ProjectPrintSchemaCommand.cjs.map +1 -1
  223. package/dist/production/src/commands/project/ProjectPrintSchemaCommand.js.map +1 -1
  224. package/dist/production/src/commands/project/ProjectValidateCommand.cjs.map +1 -1
  225. package/dist/production/src/commands/project/ProjectValidateCommand.js.map +1 -1
  226. package/dist/production/src/commands/tenant/TenantApplyCommand.cjs +39 -0
  227. package/dist/production/src/commands/tenant/TenantApplyCommand.cjs.map +1 -0
  228. package/dist/production/src/commands/tenant/TenantApplyCommand.js +39 -0
  229. package/dist/production/src/commands/tenant/TenantApplyCommand.js.map +1 -0
  230. package/dist/production/src/commands/transfer/ExportCommand.cjs.map +1 -1
  231. package/dist/production/src/commands/transfer/ExportCommand.js.map +1 -1
  232. package/dist/production/src/commands/transfer/ImportCommand.cjs.map +1 -1
  233. package/dist/production/src/commands/transfer/ImportCommand.js.map +1 -1
  234. package/dist/production/src/commands/transfer/TransferCommand.cjs.map +1 -1
  235. package/dist/production/src/commands/transfer/TransferCommand.js.map +1 -1
  236. package/dist/production/src/commands/workspace/WorkspaceUpdateApiCommand.cjs.map +1 -1
  237. package/dist/production/src/commands/workspace/WorkspaceUpdateApiCommand.js.map +1 -1
  238. package/dist/production/src/consts.cjs +2 -2
  239. package/dist/production/src/consts.cjs.map +1 -1
  240. package/dist/production/src/dic.cjs +60 -10
  241. package/dist/production/src/dic.cjs.map +1 -1
  242. package/dist/production/src/dic.js +61 -11
  243. package/dist/production/src/dic.js.map +1 -1
  244. package/dist/production/src/lib/SystemClientProvider.cjs.map +1 -1
  245. package/dist/production/src/lib/SystemClientProvider.js.map +1 -1
  246. package/dist/production/src/lib/TenantClientProvider.cjs.map +1 -1
  247. package/dist/production/src/lib/TenantClientProvider.js.map +1 -1
  248. package/dist/production/src/lib/VersionChecker.cjs +2 -2
  249. package/dist/production/src/lib/VersionChecker.cjs.map +1 -1
  250. package/dist/production/src/lib/VersionChecker.js.map +1 -1
  251. package/dist/production/src/lib/admin/AdminClient.cjs.map +1 -1
  252. package/dist/production/src/lib/admin/AdminClient.js.map +1 -1
  253. package/dist/production/src/lib/admin/AdminDeployer.cjs.map +1 -1
  254. package/dist/production/src/lib/admin/AdminDeployer.js.map +1 -1
  255. package/dist/production/src/lib/fs/DockerComposeManager.cjs +10 -10
  256. package/dist/production/src/lib/fs/DockerComposeManager.cjs.map +1 -1
  257. package/dist/production/src/lib/fs/DockerComposeManager.js.map +1 -1
  258. package/dist/production/src/lib/fs/YamlHandler.cjs.map +1 -1
  259. package/dist/production/src/lib/fs/YamlHandler.js.map +1 -1
  260. package/dist/production/src/lib/js/EsBuildBuilder.cjs.map +1 -1
  261. package/dist/production/src/lib/js/EsBuildBuilder.js.map +1 -1
  262. package/dist/production/src/lib/js/EvalExecutor.cjs.map +1 -1
  263. package/dist/production/src/lib/js/EvalExecutor.js.map +1 -1
  264. package/dist/production/src/lib/js/JsCodeRunner.cjs.map +1 -1
  265. package/dist/production/src/lib/js/JsCodeRunner.js.map +1 -1
  266. package/dist/production/src/lib/migrations/MigrationExecutionFacade.cjs +78 -18
  267. package/dist/production/src/lib/migrations/MigrationExecutionFacade.cjs.map +1 -1
  268. package/dist/production/src/lib/migrations/MigrationExecutionFacade.js +79 -19
  269. package/dist/production/src/lib/migrations/MigrationExecutionFacade.js.map +1 -1
  270. package/dist/production/src/lib/migrations/MigrationPrinter.cjs.map +1 -1
  271. package/dist/production/src/lib/migrations/MigrationPrinter.js.map +1 -1
  272. package/dist/production/src/lib/migrations/MigrationRebaseFacade.cjs +5 -1
  273. package/dist/production/src/lib/migrations/MigrationRebaseFacade.cjs.map +1 -1
  274. package/dist/production/src/lib/migrations/MigrationRebaseFacade.js +5 -1
  275. package/dist/production/src/lib/migrations/MigrationRebaseFacade.js.map +1 -1
  276. package/dist/production/src/lib/migrations/MigrationSnapshotFacade.cjs +171 -0
  277. package/dist/production/src/lib/migrations/MigrationSnapshotFacade.cjs.map +1 -0
  278. package/dist/production/src/lib/migrations/MigrationSnapshotFacade.js +171 -0
  279. package/dist/production/src/lib/migrations/MigrationSnapshotFacade.js.map +1 -0
  280. package/dist/production/src/lib/migrations/MigrationsStatusFacade.cjs.map +1 -1
  281. package/dist/production/src/lib/migrations/MigrationsStatusFacade.js.map +1 -1
  282. package/dist/production/src/lib/migrations/MigrationsValidator.cjs.map +1 -1
  283. package/dist/production/src/lib/migrations/MigrationsValidator.js.map +1 -1
  284. package/dist/production/src/lib/project/RemoteProjectProvider.cjs.map +1 -1
  285. package/dist/production/src/lib/project/RemoteProjectProvider.js.map +1 -1
  286. package/dist/production/src/lib/project/RemoteProjectResolver.cjs.map +1 -1
  287. package/dist/production/src/lib/project/RemoteProjectResolver.js.map +1 -1
  288. package/dist/production/src/lib/project/docs/components/EntityInfo.cjs.map +1 -1
  289. package/dist/production/src/lib/project/docs/components/EntityInfo.js.map +1 -1
  290. package/dist/production/src/lib/project/docs/components/EntityLink.cjs.map +1 -1
  291. package/dist/production/src/lib/project/docs/components/EntityLink.js.map +1 -1
  292. package/dist/production/src/lib/project/docs/components/FieldLink.cjs.map +1 -1
  293. package/dist/production/src/lib/project/docs/components/FieldLink.js.map +1 -1
  294. package/dist/production/src/lib/project/docs/components/FieldPermissions.cjs.map +1 -1
  295. package/dist/production/src/lib/project/docs/components/FieldPermissions.js.map +1 -1
  296. package/dist/production/src/lib/project/docs/components/FieldType.cjs.map +1 -1
  297. package/dist/production/src/lib/project/docs/components/FieldType.js.map +1 -1
  298. package/dist/production/src/lib/project/docs/components/OnDelete.cjs.map +1 -1
  299. package/dist/production/src/lib/project/docs/components/OnDelete.js.map +1 -1
  300. package/dist/production/src/lib/project/docs/components/ProjectInfo.cjs.map +1 -1
  301. package/dist/production/src/lib/project/docs/components/ProjectInfo.js.map +1 -1
  302. package/dist/production/src/lib/project/docs/projectDescribe.cjs.map +1 -1
  303. package/dist/production/src/lib/project/docs/projectDescribe.js.map +1 -1
  304. package/dist/production/src/lib/schema/SchemaLoader.cjs +5 -5
  305. package/dist/production/src/lib/schema/SchemaLoader.cjs.map +1 -1
  306. package/dist/production/src/lib/schema/SchemaLoader.js.map +1 -1
  307. package/dist/production/src/lib/schema/SchemaValidationHelper.cjs.map +1 -1
  308. package/dist/production/src/lib/schema/SchemaValidationHelper.js.map +1 -1
  309. package/dist/production/src/lib/tenant/TenantClient.cjs +75 -12
  310. package/dist/production/src/lib/tenant/TenantClient.cjs.map +1 -1
  311. package/dist/production/src/lib/tenant/TenantClient.js +75 -12
  312. package/dist/production/src/lib/tenant/TenantClient.js.map +1 -1
  313. package/dist/production/src/lib/tenant/TenantConfigApplier.cjs +55 -0
  314. package/dist/production/src/lib/tenant/TenantConfigApplier.cjs.map +1 -0
  315. package/dist/production/src/lib/tenant/TenantConfigApplier.js +55 -0
  316. package/dist/production/src/lib/tenant/TenantConfigApplier.js.map +1 -0
  317. package/dist/production/src/lib/tenant/TenantConfigLoader.cjs +32 -0
  318. package/dist/production/src/lib/tenant/TenantConfigLoader.cjs.map +1 -0
  319. package/dist/production/src/lib/tenant/TenantConfigLoader.js +32 -0
  320. package/dist/production/src/lib/tenant/TenantConfigLoader.js.map +1 -0
  321. package/dist/production/src/lib/tenant/tenantConfig.cjs +5 -0
  322. package/dist/production/src/lib/tenant/tenantConfig.cjs.map +1 -0
  323. package/dist/production/src/lib/tenant/tenantConfig.js +5 -0
  324. package/dist/production/src/lib/tenant/tenantConfig.js.map +1 -0
  325. package/dist/production/src/lib/transfer/DataTransferClient.cjs.map +1 -1
  326. package/dist/production/src/lib/transfer/DataTransferClient.js.map +1 -1
  327. package/dist/production/src/lib/workspace/WorkspaceResolver.cjs +6 -6
  328. package/dist/production/src/lib/workspace/WorkspaceResolver.cjs.map +1 -1
  329. package/dist/production/src/lib/workspace/WorkspaceResolver.js.map +1 -1
  330. package/dist/types/commands/actions/ActionsGetEventCommand.d.ts +1 -1
  331. package/dist/types/commands/actions/ActionsGetEventCommand.d.ts.map +1 -1
  332. package/dist/types/commands/actions/ActionsListFailedEventsCommand.d.ts +1 -1
  333. package/dist/types/commands/actions/ActionsListFailedEventsCommand.d.ts.map +1 -1
  334. package/dist/types/commands/actions/ActionsListVariablesCommand.d.ts +1 -1
  335. package/dist/types/commands/actions/ActionsListVariablesCommand.d.ts.map +1 -1
  336. package/dist/types/commands/actions/ActionsRetryEventCommand.d.ts +1 -1
  337. package/dist/types/commands/actions/ActionsRetryEventCommand.d.ts.map +1 -1
  338. package/dist/types/commands/actions/ActionsSetVariablesCommand.d.ts +1 -1
  339. package/dist/types/commands/actions/ActionsSetVariablesCommand.d.ts.map +1 -1
  340. package/dist/types/commands/actions/ActionsStopEventCommand.d.ts +1 -1
  341. package/dist/types/commands/actions/ActionsStopEventCommand.d.ts.map +1 -1
  342. package/dist/types/commands/deploy/DeployCommand.d.ts +7 -6
  343. package/dist/types/commands/deploy/DeployCommand.d.ts.map +1 -1
  344. package/dist/types/commands/deploy/index.d.ts +1 -1
  345. package/dist/types/commands/deploy/index.d.ts.map +1 -1
  346. package/dist/types/commands/index.d.ts +6 -5
  347. package/dist/types/commands/index.d.ts.map +1 -1
  348. package/dist/types/commands/migrations/MigrationAmendCommand.d.ts +8 -7
  349. package/dist/types/commands/migrations/MigrationAmendCommand.d.ts.map +1 -1
  350. package/dist/types/commands/migrations/MigrationDescribeCommand.d.ts +1 -1
  351. package/dist/types/commands/migrations/MigrationDescribeCommand.d.ts.map +1 -1
  352. package/dist/types/commands/migrations/MigrationDiffCommand.d.ts +8 -5
  353. package/dist/types/commands/migrations/MigrationDiffCommand.d.ts.map +1 -1
  354. package/dist/types/commands/migrations/MigrationExecuteCommand.d.ts +2 -1
  355. package/dist/types/commands/migrations/MigrationExecuteCommand.d.ts.map +1 -1
  356. package/dist/types/commands/migrations/MigrationInitStateCommand.d.ts +14 -0
  357. package/dist/types/commands/migrations/MigrationInitStateCommand.d.ts.map +1 -0
  358. package/dist/types/commands/migrations/MigrationRebaseCommand.d.ts +1 -1
  359. package/dist/types/commands/migrations/MigrationRebaseCommand.d.ts.map +1 -1
  360. package/dist/types/commands/migrations/MigrationSnapshotCommand.d.ts +12 -0
  361. package/dist/types/commands/migrations/MigrationSnapshotCommand.d.ts.map +1 -0
  362. package/dist/types/commands/migrations/MigrationStatusCommand.d.ts +3 -3
  363. package/dist/types/commands/migrations/MigrationStatusCommand.d.ts.map +1 -1
  364. package/dist/types/commands/migrations/MigrationVerifySnapshotCommand.d.ts +12 -0
  365. package/dist/types/commands/migrations/MigrationVerifySnapshotCommand.d.ts.map +1 -0
  366. package/dist/types/commands/migrations/index.d.ts +10 -7
  367. package/dist/types/commands/migrations/index.d.ts.map +1 -1
  368. package/dist/types/commands/misc/index.d.ts +1 -1
  369. package/dist/types/commands/misc/index.d.ts.map +1 -1
  370. package/dist/types/commands/project/ProjectGenerateDocumentationCommand.d.ts +1 -1
  371. package/dist/types/commands/project/ProjectGenerateDocumentationCommand.d.ts.map +1 -1
  372. package/dist/types/commands/project/ProjectPrintSchemaCommand.d.ts +1 -1
  373. package/dist/types/commands/project/ProjectPrintSchemaCommand.d.ts.map +1 -1
  374. package/dist/types/commands/project/ProjectValidateCommand.d.ts +2 -2
  375. package/dist/types/commands/project/ProjectValidateCommand.d.ts.map +1 -1
  376. package/dist/types/commands/project/index.d.ts +3 -3
  377. package/dist/types/commands/project/index.d.ts.map +1 -1
  378. package/dist/types/commands/tenant/TenantApplyCommand.d.ts +21 -0
  379. package/dist/types/commands/tenant/TenantApplyCommand.d.ts.map +1 -0
  380. package/dist/types/commands/tenant/index.d.ts +2 -0
  381. package/dist/types/commands/tenant/index.d.ts.map +1 -0
  382. package/dist/types/commands/transfer/ExportCommand.d.ts +2 -2
  383. package/dist/types/commands/transfer/ExportCommand.d.ts.map +1 -1
  384. package/dist/types/commands/transfer/ImportCommand.d.ts +2 -2
  385. package/dist/types/commands/transfer/ImportCommand.d.ts.map +1 -1
  386. package/dist/types/commands/transfer/TransferCommand.d.ts +2 -2
  387. package/dist/types/commands/transfer/TransferCommand.d.ts.map +1 -1
  388. package/dist/types/commands/transfer/index.d.ts +3 -3
  389. package/dist/types/commands/transfer/index.d.ts.map +1 -1
  390. package/dist/types/commands/workspace/WorkspaceUpdateApiCommand.d.ts +1 -1
  391. package/dist/types/commands/workspace/WorkspaceUpdateApiCommand.d.ts.map +1 -1
  392. package/dist/types/commands/workspace/index.d.ts +1 -1
  393. package/dist/types/commands/workspace/index.d.ts.map +1 -1
  394. package/dist/types/dic.d.ts +54 -32
  395. package/dist/types/dic.d.ts.map +1 -1
  396. package/dist/types/index.d.ts +2 -0
  397. package/dist/types/index.d.ts.map +1 -0
  398. package/dist/types/lib/SystemClientProvider.d.ts +1 -1
  399. package/dist/types/lib/SystemClientProvider.d.ts.map +1 -1
  400. package/dist/types/lib/TenantClientProvider.d.ts +2 -2
  401. package/dist/types/lib/TenantClientProvider.d.ts.map +1 -1
  402. package/dist/types/lib/VersionChecker.d.ts +1 -1
  403. package/dist/types/lib/VersionChecker.d.ts.map +1 -1
  404. package/dist/types/lib/admin/AdminClient.d.ts +1 -1
  405. package/dist/types/lib/admin/AdminClient.d.ts.map +1 -1
  406. package/dist/types/lib/admin/AdminDeployer.d.ts +3 -3
  407. package/dist/types/lib/admin/AdminDeployer.d.ts.map +1 -1
  408. package/dist/types/lib/fs/DockerComposeManager.d.ts +2 -2
  409. package/dist/types/lib/fs/DockerComposeManager.d.ts.map +1 -1
  410. package/dist/types/lib/fs/YamlHandler.d.ts +2 -2
  411. package/dist/types/lib/fs/YamlHandler.d.ts.map +1 -1
  412. package/dist/types/lib/js/EsBuildBuilder.d.ts +1 -1
  413. package/dist/types/lib/js/EsBuildBuilder.d.ts.map +1 -1
  414. package/dist/types/lib/js/EvalExecutor.d.ts +1 -1
  415. package/dist/types/lib/js/EvalExecutor.d.ts.map +1 -1
  416. package/dist/types/lib/js/JsCodeRunner.d.ts +2 -2
  417. package/dist/types/lib/js/JsCodeRunner.d.ts.map +1 -1
  418. package/dist/types/lib/migrations/MigrationExecutionFacade.d.ts +13 -8
  419. package/dist/types/lib/migrations/MigrationExecutionFacade.d.ts.map +1 -1
  420. package/dist/types/lib/migrations/MigrationRebaseFacade.d.ts +5 -4
  421. package/dist/types/lib/migrations/MigrationRebaseFacade.d.ts.map +1 -1
  422. package/dist/types/lib/migrations/MigrationSnapshotFacade.d.ts +28 -0
  423. package/dist/types/lib/migrations/MigrationSnapshotFacade.d.ts.map +1 -0
  424. package/dist/types/lib/migrations/MigrationsStatusFacade.d.ts +2 -2
  425. package/dist/types/lib/migrations/MigrationsStatusFacade.d.ts.map +1 -1
  426. package/dist/types/lib/project/RemoteProjectProvider.d.ts +1 -1
  427. package/dist/types/lib/project/RemoteProjectProvider.d.ts.map +1 -1
  428. package/dist/types/lib/project/RemoteProjectResolver.d.ts +2 -2
  429. package/dist/types/lib/project/RemoteProjectResolver.d.ts.map +1 -1
  430. package/dist/types/lib/project/docs/components/EntityInfo.d.ts +1 -1
  431. package/dist/types/lib/project/docs/components/EntityInfo.d.ts.map +1 -1
  432. package/dist/types/lib/project/docs/components/OnDelete.d.ts +1 -1
  433. package/dist/types/lib/project/docs/components/OnDelete.d.ts.map +1 -1
  434. package/dist/types/lib/schema/SchemaLoader.d.ts +2 -2
  435. package/dist/types/lib/schema/SchemaLoader.d.ts.map +1 -1
  436. package/dist/types/lib/tenant/TenantClient.d.ts +15 -0
  437. package/dist/types/lib/tenant/TenantClient.d.ts.map +1 -1
  438. package/dist/types/lib/tenant/TenantConfigApplier.d.ts +18 -0
  439. package/dist/types/lib/tenant/TenantConfigApplier.d.ts.map +1 -0
  440. package/dist/types/lib/tenant/TenantConfigLoader.d.ts +16 -0
  441. package/dist/types/lib/tenant/TenantConfigLoader.d.ts.map +1 -0
  442. package/dist/types/lib/tenant/tenantConfig.d.ts +74 -0
  443. package/dist/types/lib/tenant/tenantConfig.d.ts.map +1 -0
  444. package/dist/types/lib/transfer/DataTransferClient.d.ts +1 -1
  445. package/dist/types/lib/transfer/DataTransferClient.d.ts.map +1 -1
  446. package/dist/types/lib/workspace/WorkspaceResolver.d.ts +2 -2
  447. package/dist/types/lib/workspace/WorkspaceResolver.d.ts.map +1 -1
  448. package/dist/types/tsconfig.tsbuildinfo +1 -1
  449. package/package.json +33 -15
  450. package/src/commands/actions/ActionsGetEventCommand.ts +2 -2
  451. package/src/commands/actions/ActionsListFailedEventsCommand.ts +2 -2
  452. package/src/commands/actions/ActionsListVariablesCommand.ts +2 -2
  453. package/src/commands/actions/ActionsRetryEventCommand.ts +2 -2
  454. package/src/commands/actions/ActionsSetVariablesCommand.ts +2 -2
  455. package/src/commands/actions/ActionsStopEventCommand.ts +2 -2
  456. package/src/commands/deploy/DeployCommand.ts +13 -8
  457. package/src/commands/deploy/index.ts +1 -1
  458. package/src/commands/index.ts +6 -5
  459. package/src/commands/migrations/MigrationAmendCommand.ts +38 -10
  460. package/src/commands/migrations/MigrationDescribeCommand.ts +1 -1
  461. package/src/commands/migrations/MigrationDiffCommand.ts +50 -6
  462. package/src/commands/migrations/MigrationExecuteCommand.ts +6 -1
  463. package/src/commands/migrations/MigrationInitStateCommand.ts +34 -0
  464. package/src/commands/migrations/MigrationRebaseCommand.ts +1 -1
  465. package/src/commands/migrations/MigrationSnapshotCommand.ts +34 -0
  466. package/src/commands/migrations/MigrationStatusCommand.ts +3 -3
  467. package/src/commands/migrations/MigrationVerifySnapshotCommand.ts +28 -0
  468. package/src/commands/migrations/index.ts +10 -7
  469. package/src/commands/misc/index.ts +1 -1
  470. package/src/commands/project/ProjectGenerateDocumentationCommand.ts +3 -3
  471. package/src/commands/project/ProjectPrintSchemaCommand.ts +2 -2
  472. package/src/commands/project/ProjectValidateCommand.ts +3 -3
  473. package/src/commands/project/index.ts +3 -3
  474. package/src/commands/tenant/TenantApplyCommand.ts +57 -0
  475. package/src/commands/tenant/index.ts +1 -0
  476. package/src/commands/transfer/ExportCommand.ts +4 -4
  477. package/src/commands/transfer/ImportCommand.ts +6 -6
  478. package/src/commands/transfer/TransferCommand.ts +6 -6
  479. package/src/commands/transfer/index.ts +3 -3
  480. package/src/commands/workspace/WorkspaceUpdateApiCommand.ts +2 -2
  481. package/src/commands/workspace/index.ts +1 -1
  482. package/src/dic.ts +103 -37
  483. package/src/index.ts +1 -0
  484. package/src/lib/SystemClientProvider.ts +1 -1
  485. package/src/lib/TenantClientProvider.ts +2 -2
  486. package/src/lib/VersionChecker.ts +2 -2
  487. package/src/lib/admin/AdminClient.ts +2 -2
  488. package/src/lib/admin/AdminDeployer.ts +3 -3
  489. package/src/lib/fs/DockerComposeManager.ts +2 -2
  490. package/src/lib/fs/YamlHandler.ts +2 -2
  491. package/src/lib/js/EsBuildBuilder.ts +1 -1
  492. package/src/lib/js/EvalExecutor.ts +1 -1
  493. package/src/lib/js/JsCodeRunner.ts +2 -2
  494. package/src/lib/migrations/MigrationExecutionFacade.ts +117 -23
  495. package/src/lib/migrations/MigrationPrinter.ts +1 -1
  496. package/src/lib/migrations/MigrationRebaseFacade.ts +10 -3
  497. package/src/lib/migrations/MigrationSnapshotFacade.ts +218 -0
  498. package/src/lib/migrations/MigrationsStatusFacade.ts +2 -2
  499. package/src/lib/migrations/MigrationsValidator.ts +1 -1
  500. package/src/lib/project/RemoteProjectProvider.ts +1 -1
  501. package/src/lib/project/RemoteProjectResolver.ts +3 -3
  502. package/src/lib/project/docs/components/EntityInfo.tsx +6 -6
  503. package/src/lib/project/docs/components/EntityLink.tsx +1 -1
  504. package/src/lib/project/docs/components/FieldLink.tsx +2 -2
  505. package/src/lib/project/docs/components/FieldPermissions.tsx +1 -1
  506. package/src/lib/project/docs/components/FieldType.tsx +2 -2
  507. package/src/lib/project/docs/components/OnDelete.tsx +3 -3
  508. package/src/lib/project/docs/components/ProjectInfo.tsx +3 -3
  509. package/src/lib/project/docs/projectDescribe.tsx +2 -2
  510. package/src/lib/schema/SchemaLoader.ts +2 -2
  511. package/src/lib/schema/SchemaValidationHelper.ts +1 -1
  512. package/src/lib/tenant/TenantClient.ts +123 -14
  513. package/src/lib/tenant/TenantConfigApplier.ts +72 -0
  514. package/src/lib/tenant/TenantConfigLoader.ts +41 -0
  515. package/src/lib/tenant/tenantConfig.ts +101 -0
  516. package/src/lib/transfer/DataTransferClient.ts +2 -2
  517. package/src/lib/workspace/WorkspaceResolver.ts +2 -2
  518. package/src/run.ts +6 -6
  519. package/src/tsconfig.json +1 -0
  520. package/tenant.config.example.ts +64 -0
  521. package/tests/cases/unit/MigrationAmendCommand.test.ts +156 -0
  522. package/tests/cases/unit/MigrationExecutionFacade.test.ts +81 -0
  523. package/tests/cases/unit/MigrationRebaseFacade.test.ts +87 -0
  524. package/tests/cases/unit/MigrationSnapshotFacade.test.ts +243 -0
  525. package/tests/tenantConfigApplier.test.ts +87 -0
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationExecutionFacade.cjs","sources":["../../../../../../packages/cli/src/lib/migrations/MigrationExecutionFacade.ts"],"sourcesContent":["import prompts from 'prompts'\nimport { MigrationPrinter } from './MigrationPrinter'\nimport { isSchemaMigration, MigrationExecutor, MigrationToExecuteOkStatus, SchemaVersionBuilder } from '@contember/migrations-client'\nimport { MigrationsStatusFacade } from './MigrationsStatusFacade'\nimport { MigrationVersionHelper } from '@contember/engine-common'\nimport { RemoteProject } from '../project/RemoteProject'\nimport { SystemClientProvider } from '../SystemClientProvider'\nimport { TenantClientProvider } from '../TenantClientProvider'\nimport { RemoteProjectProvider } from '../project/RemoteProjectProvider'\n\nexport class MigrationExecutionFacade {\n\tconstructor(\n\t\tprivate readonly systemClientProvider: SystemClientProvider,\n\t\tprivate readonly tenantClientProvider: TenantClientProvider,\n\t\tprivate readonly projectProvider: RemoteProjectProvider,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly migrationExecutor: MigrationExecutor,\n\t\tprivate readonly migrationStatusFacade: MigrationsStatusFacade,\n\t) {\n\t}\n\n\texecute = async ({\n\t\trequireConfirmation,\n\t\tforce,\n\t\tuntil,\n\t\tadditionalMessage,\n\t}: {\n\t\trequireConfirmation: boolean | ((migrations: MigrationToExecuteOkStatus[]) => boolean)\n\t\tforce?: boolean\n\t\tuntil?: string\n\t\tadditionalMessage?: string\n\t}): Promise<boolean> => {\n\t\tconst project = this.projectProvider.get()\n\t\tawait this.tenantClientProvider.get().createProject(project.name, true)\n\n\t\tconst status = await this.migrationStatusFacade.resolveMigrationsStatus({ force })\n\t\tconst migrations = until\n\t\t\t? status.migrationsToExecute.filter(it => it.version <= MigrationVersionHelper.extractVersion(until))\n\t\t\t: status.migrationsToExecute\n\t\tif (migrations.length === 0) {\n\t\t\tconsole.log('No migrations to execute')\n\t\t\treturn true\n\t\t}\n\t\tconsole.log('Will execute following migrations:')\n\t\tmigrations.forEach(it => console.log(it.name))\n\t\tadditionalMessage && console.log(additionalMessage)\n\n\t\tif (typeof requireConfirmation === 'function' ? requireConfirmation(migrations) : requireConfirmation) {\n\t\t\tif (!process.stdin.isTTY) {\n\t\t\t\tthrow 'TTY not available. Pass --yes option to confirm execution.'\n\t\t\t}\n\t\t\tdo {\n\t\t\t\tconst { action } = await prompts({\n\t\t\t\t\ttype: 'select',\n\t\t\t\t\tname: 'action',\n\t\t\t\t\tmessage: 'Do you want to continue?',\n\t\t\t\t\tchoices: [\n\t\t\t\t\t\t{ value: 'yes', title: 'Execute migrations' },\n\t\t\t\t\t\t{ value: 'describe', title: 'Describe migrations' },\n\t\t\t\t\t\t{ value: 'no', title: 'Abort' },\n\t\t\t\t\t],\n\t\t\t\t})\n\t\t\t\tif (action === 'describe') {\n\t\t\t\t\tconst schema = await this.schemaVersionBuilder.buildSchemaUntil(migrations[0].version)\n\t\t\t\t\tfor (const migration of migrations) {\n\t\t\t\t\t\tconst migrationContent = await migration.localMigration.getContent()\n\t\t\t\t\t\tif (!isSchemaMigration(migrationContent)) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait this.migrationPrinter.printMigrationDescription(schema, migrationContent, {\n\t\t\t\t\t\t\tnoSql: true,\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t} else if (action === 'yes') {\n\t\t\t\t\tbreak\n\t\t\t\t} else {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t} while (true)\n\t\t}\n\n\t\tawait this.migrationExecutor.executeMigrations({\n\t\t\tclient: this.systemClientProvider.get(),\n\t\t\tmigrations,\n\t\t\tcontentMigrationFactoryArgs: {\n\t\t\t\tapiToken: project.token,\n\t\t\t\tapiBaseUrl: project.endpoint,\n\t\t\t\tprojectName: project.name,\n\t\t\t\tschemaVersionBuilder: this.schemaVersionBuilder,\n\t\t\t},\n\t\t\tlog: message => console.log(message),\n\t\t\tforce,\n\t\t})\n\t\treturn true\n\t}\n}\n"],"names":["MigrationVersionHelper","isSchemaMigration"],"mappings":";;;;;;;;AAUO,MAAM,yBAAyB;AAAA,EACrC,YACkB,sBACA,sBACA,iBACA,sBACA,kBACA,mBACA,uBAChB;AAPgB,SAAA,uBAAA;AACA,SAAA,uBAAA;AACA,SAAA,kBAAA;AACA,SAAA,uBAAA;AACA,SAAA,mBAAA;AACA,SAAA,oBAAA;AACA,SAAA,wBAAA;AAIlB,kBAAA,MAAA,WAAU,OAAO;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,MAMuB;AACvB,YAAM,UAAU,KAAK,gBAAgB,IAAA;AACrC,YAAM,KAAK,qBAAqB,IAAA,EAAM,cAAc,QAAQ,MAAM,IAAI;AAEtE,YAAM,SAAS,MAAM,KAAK,sBAAsB,wBAAwB,EAAE,OAAO;AACjF,YAAM,aAAa,QAChB,OAAO,oBAAoB,OAAO,CAAA,OAAM,GAAG,WAAWA,aAAAA,uB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Y,QAAQ;AAAA,UACpB,aAAa,QAAQ;AAAA,UACrB,sBAAsB,KAAK;AAAA,QAAA;AAAA,QAE5B,KAAK,CAAA,YAAW,QAAQ,IAAI,OAAO;AAAA,QACnC;AAAA,MAAA,CACA;AACD,aAAO;AAAA,IACR,CAAA;AAAA,EA5EA;AA6ED;;"}
1
+ {"version":3,"file":"MigrationExecutionFacade.cjs","sources":["../../../../../../packages/cli/src/lib/migrations/MigrationExecutionFacade.ts"],"sourcesContent":["import prompts from 'prompts'\nimport { MigrationPrinter } from './MigrationPrinter.js'\nimport {\n\tisSchemaMigration,\n\tMigrateErrorCode,\n\tMigrationExecutor,\n\tMigrationToExecuteOkStatus,\n\tSchemaState,\n\tSchemaStateManager,\n\tSchemaVersionBuilder,\n} from '@contember/migrations-client'\nimport { MigrationsStatusFacade } from './MigrationsStatusFacade.js'\nimport { MigrationSnapshotFacade } from './MigrationSnapshotFacade.js'\nimport { MigrationVersionHelper } from '@contember/engine-common'\nimport { SystemClientProvider } from '../SystemClientProvider.js'\nimport { TenantClientProvider } from '../TenantClientProvider.js'\nimport { RemoteProjectProvider } from '../project/RemoteProjectProvider.js'\n\nexport class MigrationExecutionFacade {\n\tconstructor(\n\t\tprivate readonly systemClientProvider: SystemClientProvider,\n\t\tprivate readonly tenantClientProvider: TenantClientProvider,\n\t\tprivate readonly projectProvider: RemoteProjectProvider,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly migrationExecutor: MigrationExecutor,\n\t\tprivate readonly migrationStatusFacade: MigrationsStatusFacade,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t\tprivate readonly migrationSnapshotFacade: MigrationSnapshotFacade,\n\t) {\n\t}\n\n\texecute = async ({\n\t\trequireConfirmation,\n\t\tforce,\n\t\tuntil,\n\t\tadditionalMessage,\n\t\tuseSnapshot = true,\n\t}: {\n\t\trequireConfirmation: boolean | ((migrations: MigrationToExecuteOkStatus[]) => boolean)\n\t\tforce?: boolean\n\t\tuntil?: string\n\t\tadditionalMessage?: string\n\t\tuseSnapshot?: boolean\n\t}): Promise<boolean> => {\n\t\tconst project = this.projectProvider.get()\n\t\tawait this.tenantClientProvider.get().createProject(project.name, true)\n\n\t\tconst stateMode = await this.schemaStateManager.isStateMode()\n\t\tlet schemaState = stateMode ? await this.schemaStateManager.readState() : undefined\n\n\t\t// The state files always reflect the latest schema. When migrating to an older version, that\n\t\t// state may reference parts of the model that don't exist yet, so skip it rather than push an\n\t\t// inconsistent overlay. Run `migrations:execute` without `--until` to sync the schema state.\n\t\tif (until && schemaState) {\n\t\t\tconsole.log(\n\t\t\t\t'Warning: schema state was not applied because --until targets a specific migration; the state files reflect the latest schema. Run migrations:execute without --until to sync it.',\n\t\t\t)\n\t\t\tschemaState = undefined\n\t\t}\n\n\t\tif (useSnapshot) {\n\t\t\tawait this.tryApplySnapshot({ until, schemaState })\n\t\t}\n\n\t\tconst status = await this.migrationStatusFacade.resolveMigrationsStatus({ force })\n\t\tconst migrations = until\n\t\t\t? status.migrationsToExecute.filter(it => it.version <= MigrationVersionHelper.extractVersion(until))\n\t\t\t: status.migrationsToExecute\n\t\tif (migrations.length === 0 && !schemaState) {\n\t\t\tconsole.log('No migrations to execute')\n\t\t\treturn true\n\t\t}\n\t\tif (migrations.length > 0) {\n\t\t\tconsole.log('Will execute following migrations:')\n\t\t\tmigrations.forEach(it => console.log(it.name))\n\t\t}\n\t\tif (schemaState && migrations.length === 0) {\n\t\t\tconsole.log('Updating schema state')\n\t\t}\n\t\tadditionalMessage && console.log(additionalMessage)\n\n\t\tif (migrations.length > 0 && (typeof requireConfirmation === 'function' ? requireConfirmation(migrations) : requireConfirmation)) {\n\t\t\tif (!process.stdin.isTTY) {\n\t\t\t\tthrow 'TTY not available. Pass --yes option to confirm execution.'\n\t\t\t}\n\t\t\tdo {\n\t\t\t\tconst { action } = await prompts({\n\t\t\t\t\ttype: 'select',\n\t\t\t\t\tname: 'action',\n\t\t\t\t\tmessage: 'Do you want to continue?',\n\t\t\t\t\tchoices: [\n\t\t\t\t\t\t{ value: 'yes', title: 'Execute migrations' },\n\t\t\t\t\t\t{ value: 'describe', title: 'Describe migrations' },\n\t\t\t\t\t\t{ value: 'no', title: 'Abort' },\n\t\t\t\t\t],\n\t\t\t\t})\n\t\t\t\tif (action === 'describe') {\n\t\t\t\t\tconst schema = await this.schemaVersionBuilder.buildSchemaUntil(migrations[0].version)\n\t\t\t\t\tfor (const migration of migrations) {\n\t\t\t\t\t\tconst migrationContent = await migration.localMigration.getContent()\n\t\t\t\t\t\tif (!isSchemaMigration(migrationContent)) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait this.migrationPrinter.printMigrationDescription(schema, migrationContent, {\n\t\t\t\t\t\t\tnoSql: true,\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t} else if (action === 'yes') {\n\t\t\t\t\tbreak\n\t\t\t\t} else {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t} while (true)\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.migrationExecutor.executeMigrations({\n\t\t\t\tclient: this.systemClientProvider.get(),\n\t\t\t\tmigrations,\n\t\t\t\tschemaState,\n\t\t\t\tcontentMigrationFactoryArgs: {\n\t\t\t\t\tapiToken: project.token,\n\t\t\t\t\tapiBaseUrl: project.endpoint,\n\t\t\t\t\tprojectName: project.name,\n\t\t\t\t\tschemaVersionBuilder: this.schemaVersionBuilder,\n\t\t\t\t},\n\t\t\t\tlog: message => console.log(message),\n\t\t\t\tforce,\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tif (isViewReplaceFailure(e)) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t\"\\nAn in-place view update (CREATE OR REPLACE VIEW) failed — Postgres rejects it (SQLSTATE 42P16) when a view's\"\n\t\t\t\t\t\t+ ' output columns changed (e.g. reordered or retyped) even though its fields did not.\\n'\n\t\t\t\t\t\t+ 'Re-generate the migration with `migrations:diff <name> --recreate-views` to drop & recreate the affected'\n\t\t\t\t\t\t+ ' views (and their dependants) instead.\\n',\n\t\t\t\t)\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t\treturn true\n\t}\n\n\tprivate async tryApplySnapshot({ until, schemaState }: { until?: string; schemaState?: SchemaState }): Promise<void> {\n\t\tconst executed = await this.systemClientProvider.get().listExecutedMigrations()\n\t\tconst snapshot = await this.migrationSnapshotFacade.getUsableSnapshot(executed)\n\t\tif (!snapshot) {\n\t\t\treturn\n\t\t}\n\t\tif (until && snapshot.version > MigrationVersionHelper.extractVersion(until)) {\n\t\t\t// snapshot reaches past the requested target — fall back to a normal replay\n\t\t\treturn\n\t\t}\n\t\tconsole.log(`Bootstrapping from snapshot (collapses ${snapshot.covers.length} migrations up to ${snapshot.version})`)\n\t\tif (snapshot.contentMigrations.length > 0) {\n\t\t\tconsole.warn(\n\t\t\t\t`Note: ${snapshot.contentMigrations.length} content migration(s) are covered by the snapshot; their data is NOT reproduced.`,\n\t\t\t)\n\t\t}\n\t\tconst input = await this.migrationSnapshotFacade.buildSnapshotInput(snapshot)\n\t\ttry {\n\t\t\tawait this.systemClientProvider.get().migrateFromSnapshot(input, schemaState)\n\t\t} catch (e) {\n\t\t\tif (isProjectNotEmptyError(e)) {\n\t\t\t\t// The project was migrated between our emptiness check and the server call (e.g. a\n\t\t\t\t// concurrent execute on a fresh database). Fall back to a normal replay rather than\n\t\t\t\t// crashing — the subsequent status resolution will pick up whatever is left to run.\n\t\t\t\tconsole.warn('Snapshot skipped: the project is no longer empty. Falling back to a full replay.')\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t\tconsole.log('Snapshot applied')\n\t}\n}\n\nconst isProjectNotEmptyError = (e: unknown): boolean =>\n\tArray.isArray(e) && e.some(it => it !== null && typeof it === 'object' && (it as { code?: unknown }).code === MigrateErrorCode.ProjectNotEmpty)\n\n// A failed `updateView` modification surfaces as MIGRATION_FAILED whose developerMessage embeds the failing\n// statement (`CREATE OR REPLACE VIEW …`). Since each modification's SQL is executed in isolation, that string\n// is a precise signal that an in-place view update — and not some other statement — is what Postgres rejected.\nconst isViewReplaceFailure = (e: unknown): boolean =>\n\tArray.isArray(e) && e.some(it =>\n\t\tit !== null\n\t\t&& typeof it === 'object'\n\t\t&& (it as { code?: unknown }).code === MigrateErrorCode.MigrationFailed\n\t\t&& typeof (it as { message?: unknown }).message === 'string'\n\t\t&& (it as { message: string }).message.includes('CREATE OR REPLACE VIEW')\n\t)\n"],"names":["MigrationVersionHelper","isSchemaMigration","MigrateErrorCode"],"mappings":";;;;;;;;AAkBO,MAAM,yBAAyB;AAAA,EACrC,YACkB,sBACA,sBACA,iBACA,sBACA,kBACA,mBACA,uBACA,oBACA,yBAChB;AATgB,SAAA,uBAAA;AACA,SAAA,uBAAA;AACA,SAAA,kBAAA;AACA,SAAA,uBAAA;AACA,SAAA,mBAAA;AACA,SAAA,oBAAA;AACA,SAAA,wBAAA;AACA,SAAA,qBAAA;AACA,SAAA,0BAAA;AAIlB,kBAAA,MAAA,WAAU,OAAO;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,IAAA,MAOS;AACvB,YAAM,UAAU,KAAK,gBAAgB,IAAA;AACrC,YAAM,KAAK,qBAAqB,IAAA,EAAM,cAAc,QAAQ,MAAM,IAAI;AAEtE,YAAM,YAAY,MAAM,KAAK,mBAAmB,YAAA;AAChD,UAAI,cAAc,YAAY,MAAM,KAAK,mBAAmB,cAAc;AAK1E,UAAI,SAAS,aAAa;AACzB,gBAAQ;AAAA,UACP;AAAA,QAAA;AAED,sBAAc;AAAA,MACf;AAEA,UAAI,aAAa;AAChB,cAAM,KAAK,iBAAiB,EAAE,OAAO,aAAa;AAAA,MACnD;AAEA,YAAM,SAAS,MAAM,KAAK,sBAAsB,wBAAwB,EAAE,OAAO;AACjF,YAAM,aAAa,QAChB,OAAO,oB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MACD;AACA,YAAM;AAAA,IACP;AACA,YAAQ,IAAI,kBAAkB;AAAA,EAC/B;AACD;AAEA,MAAM,yBAAyB,CAAC,MAC/B,MAAM,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA,OAAM,OAAO,QAAQ,OAAO,OAAO,YAAa,GAA0B,SAASE,iBAAAA,iBAAiB,eAAe;AAK/I,MAAM,uBAAuB,CAAC,MAC7B,MAAM,QAAQ,CAAC,KAAK,EAAE;AAAA,EAAK,QAC1B,OAAO,QACJ,OAAO,OAAO,YACb,GAA0B,SAASA,iBAAAA,iBAAiB,mBACrD,OAAQ,GAA6B,YAAY,YAChD,GAA2B,QAAQ,SAAS,wBAAwB;AACzE;;"}
@@ -1,11 +1,11 @@
1
1
  import prompts from "prompts";
2
- import { isSchemaMigration } from "@contember/migrations-client";
2
+ import { MigrateErrorCode, isSchemaMigration } from "@contember/migrations-client";
3
3
  import { MigrationVersionHelper } from "@contember/engine-common";
4
4
  var __defProp = Object.defineProperty;
5
5
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
6
  var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
7
7
  class MigrationExecutionFacade {
8
- constructor(systemClientProvider, tenantClientProvider, projectProvider, schemaVersionBuilder, migrationPrinter, migrationExecutor, migrationStatusFacade) {
8
+ constructor(systemClientProvider, tenantClientProvider, projectProvider, schemaVersionBuilder, migrationPrinter, migrationExecutor, migrationStatusFacade, schemaStateManager, migrationSnapshotFacade) {
9
9
  this.systemClientProvider = systemClientProvider;
10
10
  this.tenantClientProvider = tenantClientProvider;
11
11
  this.projectProvider = projectProvider;
@@ -13,24 +13,43 @@ class MigrationExecutionFacade {
13
13
  this.migrationPrinter = migrationPrinter;
14
14
  this.migrationExecutor = migrationExecutor;
15
15
  this.migrationStatusFacade = migrationStatusFacade;
16
+ this.schemaStateManager = schemaStateManager;
17
+ this.migrationSnapshotFacade = migrationSnapshotFacade;
16
18
  __publicField(this, "execute", async ({
17
19
  requireConfirmation,
18
20
  force,
19
21
  until,
20
- additionalMessage
22
+ additionalMessage,
23
+ useSnapshot = true
21
24
  }) => {
22
25
  const project = this.projectProvider.get();
23
26
  await this.tenantClientProvider.get().createProject(project.name, true);
27
+ const stateMode = await this.schemaStateManager.isStateMode();
28
+ let schemaState = stateMode ? await this.schemaStateManager.readState() : void 0;
29
+ if (until && schemaState) {
30
+ console.log(
31
+ "Warning: schema state was not applied because --until targets a specific migration; the state files reflect the latest schema. Run migrations:execute without --until to sync it."
32
+ );
33
+ schemaState = void 0;
34
+ }
35
+ if (useSnapshot) {
36
+ await this.tryApplySnapshot({ until, schemaState });
37
+ }
24
38
  const status = await this.migrationStatusFacade.resolveMigrationsStatus({ force });
25
39
  const migrations = until ? status.migrationsToExecute.filter((it) => it.version <= MigrationVersionHelper.extractVersion(until)) : status.migrationsToExecute;
26
- if (migrations.length === 0) {
40
+ if (migrations.length === 0 && !schemaState) {
27
41
  console.log("No migrations to execute");
28
42
  return true;
29
43
  }
30
- console.log("Will execute following migrations:");
31
- migrations.forEach((it) => console.log(it.name));
44
+ if (migrations.length > 0) {
45
+ console.log("Will execute following migrations:");
46
+ migrations.forEach((it) => console.log(it.name));
47
+ }
48
+ if (schemaState && migrations.length === 0) {
49
+ console.log("Updating schema state");
50
+ }
32
51
  additionalMessage && console.log(additionalMessage);
33
- if (typeof requireConfirmation === "function" ? requireConfirmation(migrations) : requireConfirmation) {
52
+ if (migrations.length > 0 && (typeof requireConfirmation === "function" ? requireConfirmation(migrations) : requireConfirmation)) {
34
53
  if (!process.stdin.isTTY) {
35
54
  throw "TTY not available. Pass --yes option to confirm execution.";
36
55
  }
@@ -63,22 +82,63 @@ class MigrationExecutionFacade {
63
82
  }
64
83
  } while (true);
65
84
  }
66
- await this.migrationExecutor.executeMigrations({
67
- client: this.systemClientProvider.get(),
68
- migrations,
69
- contentMigrationFactoryArgs: {
70
- apiToken: project.token,
71
- apiBaseUrl: project.endpoint,
72
- projectName: project.name,
73
- schemaVersionBuilder: this.schemaVersionBuilder
74
- },
75
- log: (message) => console.log(message),
76
- force
77
- });
85
+ try {
86
+ await this.migrationExecutor.executeMigrations({
87
+ client: this.systemClientProvider.get(),
88
+ migrations,
89
+ schemaState,
90
+ contentMigrationFactoryArgs: {
91
+ apiToken: project.token,
92
+ apiBaseUrl: project.endpoint,
93
+ projectName: project.name,
94
+ schemaVersionBuilder: this.schemaVersionBuilder
95
+ },
96
+ log: (message) => console.log(message),
97
+ force
98
+ });
99
+ } catch (e) {
100
+ if (isViewReplaceFailure(e)) {
101
+ console.error(
102
+ "\nAn in-place view update (CREATE OR REPLACE VIEW) failed — Postgres rejects it (SQLSTATE 42P16) when a view's output columns changed (e.g. reordered or retyped) even though its fields did not.\nRe-generate the migration with `migrations:diff <name> --recreate-views` to drop & recreate the affected views (and their dependants) instead.\n"
103
+ );
104
+ }
105
+ throw e;
106
+ }
78
107
  return true;
79
108
  });
80
109
  }
110
+ async tryApplySnapshot({ until, schemaState }) {
111
+ const executed = await this.systemClientProvider.get().listExecutedMigrations();
112
+ const snapshot = await this.migrationSnapshotFacade.getUsableSnapshot(executed);
113
+ if (!snapshot) {
114
+ return;
115
+ }
116
+ if (until && snapshot.version > MigrationVersionHelper.extractVersion(until)) {
117
+ return;
118
+ }
119
+ console.log(`Bootstrapping from snapshot (collapses ${snapshot.covers.length} migrations up to ${snapshot.version})`);
120
+ if (snapshot.contentMigrations.length > 0) {
121
+ console.warn(
122
+ `Note: ${snapshot.contentMigrations.length} content migration(s) are covered by the snapshot; their data is NOT reproduced.`
123
+ );
124
+ }
125
+ const input = await this.migrationSnapshotFacade.buildSnapshotInput(snapshot);
126
+ try {
127
+ await this.systemClientProvider.get().migrateFromSnapshot(input, schemaState);
128
+ } catch (e) {
129
+ if (isProjectNotEmptyError(e)) {
130
+ console.warn("Snapshot skipped: the project is no longer empty. Falling back to a full replay.");
131
+ return;
132
+ }
133
+ throw e;
134
+ }
135
+ console.log("Snapshot applied");
136
+ }
81
137
  }
138
+ const isProjectNotEmptyError = (e) => Array.isArray(e) && e.some((it) => it !== null && typeof it === "object" && it.code === MigrateErrorCode.ProjectNotEmpty);
139
+ const isViewReplaceFailure = (e) => Array.isArray(e) && e.some(
140
+ (it) => it !== null && typeof it === "object" && it.code === MigrateErrorCode.MigrationFailed && typeof it.message === "string" && it.message.includes("CREATE OR REPLACE VIEW")
141
+ );
82
142
  export {
83
143
  MigrationExecutionFacade
84
144
  };
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationExecutionFacade.js","sources":["../../../../../../packages/cli/src/lib/migrations/MigrationExecutionFacade.ts"],"sourcesContent":["import prompts from 'prompts'\nimport { MigrationPrinter } from './MigrationPrinter'\nimport { isSchemaMigration, MigrationExecutor, MigrationToExecuteOkStatus, SchemaVersionBuilder } from '@contember/migrations-client'\nimport { MigrationsStatusFacade } from './MigrationsStatusFacade'\nimport { MigrationVersionHelper } from '@contember/engine-common'\nimport { RemoteProject } from '../project/RemoteProject'\nimport { SystemClientProvider } from '../SystemClientProvider'\nimport { TenantClientProvider } from '../TenantClientProvider'\nimport { RemoteProjectProvider } from '../project/RemoteProjectProvider'\n\nexport class MigrationExecutionFacade {\n\tconstructor(\n\t\tprivate readonly systemClientProvider: SystemClientProvider,\n\t\tprivate readonly tenantClientProvider: TenantClientProvider,\n\t\tprivate readonly projectProvider: RemoteProjectProvider,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly migrationExecutor: MigrationExecutor,\n\t\tprivate readonly migrationStatusFacade: MigrationsStatusFacade,\n\t) {\n\t}\n\n\texecute = async ({\n\t\trequireConfirmation,\n\t\tforce,\n\t\tuntil,\n\t\tadditionalMessage,\n\t}: {\n\t\trequireConfirmation: boolean | ((migrations: MigrationToExecuteOkStatus[]) => boolean)\n\t\tforce?: boolean\n\t\tuntil?: string\n\t\tadditionalMessage?: string\n\t}): Promise<boolean> => {\n\t\tconst project = this.projectProvider.get()\n\t\tawait this.tenantClientProvider.get().createProject(project.name, true)\n\n\t\tconst status = await this.migrationStatusFacade.resolveMigrationsStatus({ force })\n\t\tconst migrations = until\n\t\t\t? status.migrationsToExecute.filter(it => it.version <= MigrationVersionHelper.extractVersion(until))\n\t\t\t: status.migrationsToExecute\n\t\tif (migrations.length === 0) {\n\t\t\tconsole.log('No migrations to execute')\n\t\t\treturn true\n\t\t}\n\t\tconsole.log('Will execute following migrations:')\n\t\tmigrations.forEach(it => console.log(it.name))\n\t\tadditionalMessage && console.log(additionalMessage)\n\n\t\tif (typeof requireConfirmation === 'function' ? requireConfirmation(migrations) : requireConfirmation) {\n\t\t\tif (!process.stdin.isTTY) {\n\t\t\t\tthrow 'TTY not available. Pass --yes option to confirm execution.'\n\t\t\t}\n\t\t\tdo {\n\t\t\t\tconst { action } = await prompts({\n\t\t\t\t\ttype: 'select',\n\t\t\t\t\tname: 'action',\n\t\t\t\t\tmessage: 'Do you want to continue?',\n\t\t\t\t\tchoices: [\n\t\t\t\t\t\t{ value: 'yes', title: 'Execute migrations' },\n\t\t\t\t\t\t{ value: 'describe', title: 'Describe migrations' },\n\t\t\t\t\t\t{ value: 'no', title: 'Abort' },\n\t\t\t\t\t],\n\t\t\t\t})\n\t\t\t\tif (action === 'describe') {\n\t\t\t\t\tconst schema = await this.schemaVersionBuilder.buildSchemaUntil(migrations[0].version)\n\t\t\t\t\tfor (const migration of migrations) {\n\t\t\t\t\t\tconst migrationContent = await migration.localMigration.getContent()\n\t\t\t\t\t\tif (!isSchemaMigration(migrationContent)) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait this.migrationPrinter.printMigrationDescription(schema, migrationContent, {\n\t\t\t\t\t\t\tnoSql: true,\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t} else if (action === 'yes') {\n\t\t\t\t\tbreak\n\t\t\t\t} else {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t} while (true)\n\t\t}\n\n\t\tawait this.migrationExecutor.executeMigrations({\n\t\t\tclient: this.systemClientProvider.get(),\n\t\t\tmigrations,\n\t\t\tcontentMigrationFactoryArgs: {\n\t\t\t\tapiToken: project.token,\n\t\t\t\tapiBaseUrl: project.endpoint,\n\t\t\t\tprojectName: project.name,\n\t\t\t\tschemaVersionBuilder: this.schemaVersionBuilder,\n\t\t\t},\n\t\t\tlog: message => console.log(message),\n\t\t\tforce,\n\t\t})\n\t\treturn true\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAUO,MAAM,yBAAyB;AAAA,EACrC,YACkB,sBACA,sBACA,iBACA,sBACA,kBACA,mBACA,uBAChB;AAPgB,SAAA,uBAAA;AACA,SAAA,uBAAA;AACA,SAAA,kBAAA;AACA,SAAA,uBAAA;AACA,SAAA,mBAAA;AACA,SAAA,oBAAA;AACA,SAAA,wBAAA;AAIlB,kBAAA,MAAA,WAAU,OAAO;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,MAMuB;AACvB,YAAM,UAAU,KAAK,gBAAgB,IAAA;AACrC,YAAM,KAAK,qBAAqB,IAAA,EAAM,cAAc,QAAQ,MAAM,IAAI;AAEtE,YAAM,SAAS,MAAM,KAAK,sBAAsB,wBAAwB,EAAE,OAAO;AACjF,YAAM,aAAa,QAChB,OAAO,oBAAoB,OAAO,CAAA,OAAM,GAAG,WAAW,uBAAuB,eAAe,KAAK,CAAC,IAClG,OAAO;AACV,UAAI,WAAW,WAAW,GAAG;AAC5B,gBAAQ,IAAI,0BAA0B;AACtC,eAAO;AAAA,MACR;AACA,cAAQ,IAAI,oCAAoC;AAChD,iBAAW,QAAQ,CAAA,OAAM,QAAQ,IAAI,GAAG,IAAI,CAAC;AAC7C,2BAAqB,QAAQ,IAAI,iBAAiB;AAElD,UAAI,OAAO,wBAAwB,aAAa,oBAAoB,UAAU,IAAI,qBAAqB;AACtG,YAAI,CAAC,QAAQ,MAAM,OAAO;AACzB,gBAAM;AAAA,QACP;AACA,WAAG;AACF,gBAAM,EAAE,WAAW,MAAM,QAAQ;AAAA,YAChC,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS;AAAA,YACT,SAAS;AAAA,cACR,EAAE,OAAO,OAAO,OAAO,qBAAA;AAAA,cACvB,EAAE,OAAO,YAAY,OAAO,sBAAA;AAAA,cAC5B,EAAE,OAAO,MAAM,OAAO,QAAA;AAAA,YAAQ;AAAA,UAC/B,CACA;AACD,cAAI,WAAW,YAAY;AAC1B,kBAAM,SAAS,MAAM,KAAK,qBAAqB,iBAAiB,WAAW,CAAC,EAAE,OAAO;AACrF,uBAAW,aAAa,YAAY;AACnC,oBAAM,mBAAmB,MAAM,UAAU,eAAe,WAAA;AACxD,kBAAI,CAAC,kBAAkB,gBAAgB,GAAG;AACzC;AAAA,cACD;AAEA,oBAAM,KAAK,iBAAiB,0BAA0B,QAAQ,kBAAkB;AAAA,gBAC/E,OAAO;AAAA,cAAA,CACP;AAAA,YACF;AAAA,UACD,WAAW,WAAW,OAAO;AAC5B;AAAA,UACD,OAAO;AACN,mBAAO;AAAA,UACR;AAAA,QACD,SAAS;AAAA,MACV;AAEA,YAAM,KAAK,kBAAkB,kBAAkB;AAAA,QAC9C,QAAQ,KAAK,qBAAqB,IAAA;AAAA,QAClC;AAAA,QACA,6BAA6B;AAAA,UAC5B,UAAU,QAAQ;AAAA,UAClB,YAAY,QAAQ;AAAA,UACpB,aAAa,QAAQ;AAAA,UACrB,sBAAsB,KAAK;AAAA,QAAA;AAAA,QAE5B,KAAK,CAAA,YAAW,QAAQ,IAAI,OAAO;AAAA,QACnC;AAAA,MAAA,CACA;AACD,aAAO;AAAA,IACR,CAAA;AAAA,EA5EA;AA6ED;"}
1
+ {"version":3,"file":"MigrationExecutionFacade.js","sources":["../../../../../../packages/cli/src/lib/migrations/MigrationExecutionFacade.ts"],"sourcesContent":["import prompts from 'prompts'\nimport { MigrationPrinter } from './MigrationPrinter.js'\nimport {\n\tisSchemaMigration,\n\tMigrateErrorCode,\n\tMigrationExecutor,\n\tMigrationToExecuteOkStatus,\n\tSchemaState,\n\tSchemaStateManager,\n\tSchemaVersionBuilder,\n} from '@contember/migrations-client'\nimport { MigrationsStatusFacade } from './MigrationsStatusFacade.js'\nimport { MigrationSnapshotFacade } from './MigrationSnapshotFacade.js'\nimport { MigrationVersionHelper } from '@contember/engine-common'\nimport { SystemClientProvider } from '../SystemClientProvider.js'\nimport { TenantClientProvider } from '../TenantClientProvider.js'\nimport { RemoteProjectProvider } from '../project/RemoteProjectProvider.js'\n\nexport class MigrationExecutionFacade {\n\tconstructor(\n\t\tprivate readonly systemClientProvider: SystemClientProvider,\n\t\tprivate readonly tenantClientProvider: TenantClientProvider,\n\t\tprivate readonly projectProvider: RemoteProjectProvider,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly migrationExecutor: MigrationExecutor,\n\t\tprivate readonly migrationStatusFacade: MigrationsStatusFacade,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t\tprivate readonly migrationSnapshotFacade: MigrationSnapshotFacade,\n\t) {\n\t}\n\n\texecute = async ({\n\t\trequireConfirmation,\n\t\tforce,\n\t\tuntil,\n\t\tadditionalMessage,\n\t\tuseSnapshot = true,\n\t}: {\n\t\trequireConfirmation: boolean | ((migrations: MigrationToExecuteOkStatus[]) => boolean)\n\t\tforce?: boolean\n\t\tuntil?: string\n\t\tadditionalMessage?: string\n\t\tuseSnapshot?: boolean\n\t}): Promise<boolean> => {\n\t\tconst project = this.projectProvider.get()\n\t\tawait this.tenantClientProvider.get().createProject(project.name, true)\n\n\t\tconst stateMode = await this.schemaStateManager.isStateMode()\n\t\tlet schemaState = stateMode ? await this.schemaStateManager.readState() : undefined\n\n\t\t// The state files always reflect the latest schema. When migrating to an older version, that\n\t\t// state may reference parts of the model that don't exist yet, so skip it rather than push an\n\t\t// inconsistent overlay. Run `migrations:execute` without `--until` to sync the schema state.\n\t\tif (until && schemaState) {\n\t\t\tconsole.log(\n\t\t\t\t'Warning: schema state was not applied because --until targets a specific migration; the state files reflect the latest schema. Run migrations:execute without --until to sync it.',\n\t\t\t)\n\t\t\tschemaState = undefined\n\t\t}\n\n\t\tif (useSnapshot) {\n\t\t\tawait this.tryApplySnapshot({ until, schemaState })\n\t\t}\n\n\t\tconst status = await this.migrationStatusFacade.resolveMigrationsStatus({ force })\n\t\tconst migrations = until\n\t\t\t? status.migrationsToExecute.filter(it => it.version <= MigrationVersionHelper.extractVersion(until))\n\t\t\t: status.migrationsToExecute\n\t\tif (migrations.length === 0 && !schemaState) {\n\t\t\tconsole.log('No migrations to execute')\n\t\t\treturn true\n\t\t}\n\t\tif (migrations.length > 0) {\n\t\t\tconsole.log('Will execute following migrations:')\n\t\t\tmigrations.forEach(it => console.log(it.name))\n\t\t}\n\t\tif (schemaState && migrations.length === 0) {\n\t\t\tconsole.log('Updating schema state')\n\t\t}\n\t\tadditionalMessage && console.log(additionalMessage)\n\n\t\tif (migrations.length > 0 && (typeof requireConfirmation === 'function' ? requireConfirmation(migrations) : requireConfirmation)) {\n\t\t\tif (!process.stdin.isTTY) {\n\t\t\t\tthrow 'TTY not available. Pass --yes option to confirm execution.'\n\t\t\t}\n\t\t\tdo {\n\t\t\t\tconst { action } = await prompts({\n\t\t\t\t\ttype: 'select',\n\t\t\t\t\tname: 'action',\n\t\t\t\t\tmessage: 'Do you want to continue?',\n\t\t\t\t\tchoices: [\n\t\t\t\t\t\t{ value: 'yes', title: 'Execute migrations' },\n\t\t\t\t\t\t{ value: 'describe', title: 'Describe migrations' },\n\t\t\t\t\t\t{ value: 'no', title: 'Abort' },\n\t\t\t\t\t],\n\t\t\t\t})\n\t\t\t\tif (action === 'describe') {\n\t\t\t\t\tconst schema = await this.schemaVersionBuilder.buildSchemaUntil(migrations[0].version)\n\t\t\t\t\tfor (const migration of migrations) {\n\t\t\t\t\t\tconst migrationContent = await migration.localMigration.getContent()\n\t\t\t\t\t\tif (!isSchemaMigration(migrationContent)) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait this.migrationPrinter.printMigrationDescription(schema, migrationContent, {\n\t\t\t\t\t\t\tnoSql: true,\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t} else if (action === 'yes') {\n\t\t\t\t\tbreak\n\t\t\t\t} else {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t} while (true)\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.migrationExecutor.executeMigrations({\n\t\t\t\tclient: this.systemClientProvider.get(),\n\t\t\t\tmigrations,\n\t\t\t\tschemaState,\n\t\t\t\tcontentMigrationFactoryArgs: {\n\t\t\t\t\tapiToken: project.token,\n\t\t\t\t\tapiBaseUrl: project.endpoint,\n\t\t\t\t\tprojectName: project.name,\n\t\t\t\t\tschemaVersionBuilder: this.schemaVersionBuilder,\n\t\t\t\t},\n\t\t\t\tlog: message => console.log(message),\n\t\t\t\tforce,\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tif (isViewReplaceFailure(e)) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t\"\\nAn in-place view update (CREATE OR REPLACE VIEW) failed — Postgres rejects it (SQLSTATE 42P16) when a view's\"\n\t\t\t\t\t\t+ ' output columns changed (e.g. reordered or retyped) even though its fields did not.\\n'\n\t\t\t\t\t\t+ 'Re-generate the migration with `migrations:diff <name> --recreate-views` to drop & recreate the affected'\n\t\t\t\t\t\t+ ' views (and their dependants) instead.\\n',\n\t\t\t\t)\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t\treturn true\n\t}\n\n\tprivate async tryApplySnapshot({ until, schemaState }: { until?: string; schemaState?: SchemaState }): Promise<void> {\n\t\tconst executed = await this.systemClientProvider.get().listExecutedMigrations()\n\t\tconst snapshot = await this.migrationSnapshotFacade.getUsableSnapshot(executed)\n\t\tif (!snapshot) {\n\t\t\treturn\n\t\t}\n\t\tif (until && snapshot.version > MigrationVersionHelper.extractVersion(until)) {\n\t\t\t// snapshot reaches past the requested target — fall back to a normal replay\n\t\t\treturn\n\t\t}\n\t\tconsole.log(`Bootstrapping from snapshot (collapses ${snapshot.covers.length} migrations up to ${snapshot.version})`)\n\t\tif (snapshot.contentMigrations.length > 0) {\n\t\t\tconsole.warn(\n\t\t\t\t`Note: ${snapshot.contentMigrations.length} content migration(s) are covered by the snapshot; their data is NOT reproduced.`,\n\t\t\t)\n\t\t}\n\t\tconst input = await this.migrationSnapshotFacade.buildSnapshotInput(snapshot)\n\t\ttry {\n\t\t\tawait this.systemClientProvider.get().migrateFromSnapshot(input, schemaState)\n\t\t} catch (e) {\n\t\t\tif (isProjectNotEmptyError(e)) {\n\t\t\t\t// The project was migrated between our emptiness check and the server call (e.g. a\n\t\t\t\t// concurrent execute on a fresh database). Fall back to a normal replay rather than\n\t\t\t\t// crashing — the subsequent status resolution will pick up whatever is left to run.\n\t\t\t\tconsole.warn('Snapshot skipped: the project is no longer empty. Falling back to a full replay.')\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t\tconsole.log('Snapshot applied')\n\t}\n}\n\nconst isProjectNotEmptyError = (e: unknown): boolean =>\n\tArray.isArray(e) && e.some(it => it !== null && typeof it === 'object' && (it as { code?: unknown }).code === MigrateErrorCode.ProjectNotEmpty)\n\n// A failed `updateView` modification surfaces as MIGRATION_FAILED whose developerMessage embeds the failing\n// statement (`CREATE OR REPLACE VIEW …`). Since each modification's SQL is executed in isolation, that string\n// is a precise signal that an in-place view update — and not some other statement — is what Postgres rejected.\nconst isViewReplaceFailure = (e: unknown): boolean =>\n\tArray.isArray(e) && e.some(it =>\n\t\tit !== null\n\t\t&& typeof it === 'object'\n\t\t&& (it as { code?: unknown }).code === MigrateErrorCode.MigrationFailed\n\t\t&& typeof (it as { message?: unknown }).message === 'string'\n\t\t&& (it as { message: string }).message.includes('CREATE OR REPLACE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S,wBAAwB;AACzE;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationPrinter.cjs","sources":["../../../../../../packages/cli/src/lib/migrations/MigrationPrinter.ts"],"sourcesContent":["/// <reference path=\"../../../types/chalk-table/index.d.ts\" />\n\nimport { Schema } from '@contember/schema'\nimport chalk from 'chalk'\nimport { AnyMigrationStatus, Migration, MigrationDescriber, MigrationState } from '@contember/migrations-client'\nimport { emptyDatabaseMetadata } from '@contember/database'\nimport chalkTable from 'chalk-table'\nimport { assertNever } from '../assertNever'\n\nexport class MigrationPrinter {\n\tconstructor(\n\t\tprivate readonly migrationsDescriber: MigrationDescriber,\n\t) {\n\t}\n\n\tprintMigrationDescription = (\n\t\tschema: Schema,\n\t\tmigration: Migration,\n\t\toptions: { sqlOnly?: boolean; noSql?: boolean },\n\t) => {\n\t\tconst description = this.migrationsDescriber.describeModifications(schema, migration)\n\t\tdescription.forEach(({ modification, getSql, description }) => {\n\t\t\tconst sql = getSql({\n\t\t\t\tsystemSchema: 'system',\n\t\t\t\tdatabaseMetadata: emptyDatabaseMetadata,\n\t\t\t\tinvalidateDatabaseMetadata: () => null,\n\t\t\t})\n\t\t\tif (options.sqlOnly) {\n\t\t\t\tif (sql.trim()) {\n\t\t\t\t\tconsole.log(sql)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst color = description.isDestructive ? chalk.red : chalk.blue\n\t\t\t\tconsole.group(color(`${description.message} [${modification.modification}]`))\n\t\t\t\tif (description.failureWarning) {\n\t\t\t\t\tconsole.log(chalk.bgWhite(chalk.redBright(description.failureWarning)))\n\t\t\t\t}\n\n\t\t\t\tif (!options.noSql) {\n\t\t\t\t\tif (sql.trim()) {\n\t\t\t\t\t\tconsole.log(sql)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.log('No sql to execute')\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconsole.groupEnd()\n\t\t\t}\n\t\t})\n\t}\n\n\tprintStatusTable = (migrations: AnyMigrationStatus[]) => {\n\t\treturn chalkTable(\n\t\t\t{\n\t\t\t\tcolumns: ['status', 'migration', 'info'],\n\t\t\t},\n\t\t\tmigrations.map(it => {\n\t\t\t\tswitch (it.state) {\n\t\t\t\t\tcase MigrationState.EXECUTED_ERROR:\n\t\t\t\t\t\treturn { status: chalk.bgRedBright.white('ERROR'), migration: it.name, info: it.errorMessage }\n\t\t\t\t\tcase MigrationState.EXECUTED_OK:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgGreen.blackBright('Executed'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: `Executed at ${it.executedMigration.executedAt.toISOString()}`,\n\t\t\t\t\t\t}\n\t\t\t\t\tcase MigrationState.EXECUTED_MISSING:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgRedBright.white('ERROR'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: it.errorMessage,\n\t\t\t\t\t\t}\n\t\t\t\t\tcase MigrationState.TO_EXECUTE_OK:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgBlueBright.white('Not executed'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: 'Will be executed during next deploy',\n\t\t\t\t\t\t}\n\t\t\t\t\tcase MigrationState.TO_EXECUTE_ERROR:\n\t\t\t\t\t\treturn { status: chalk.bgRedBright.white('ERROR'), migration: it.name, info: it.errorMessage }\n\t\t\t\t\tcase MigrationState.SKIP_EMPTY:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgYellow.white('Skip'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: `Skipped because empty`,\n\t\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tassertNever(it)\n\t\t\t\t}\n\t\t\t}),\n\t\t)\n\t}\n}\n"],"names":["description","emptyDatabaseMetadata","Mig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AAG,aAAA;AAAA,YACjF,KAAKA,iBAAAA,eAAe;AACnB,qBAAO;AAAA,gBACN,QAAQ,MAAM,QAAQ,YAAY,UAAU;AAAA,gBAC5C,WAAW,GAAG;AAAA,gBACd,MAAM,eAAe,GAAG,kBAAkB,WAAW,aAAa;AAAA,cAAA;AAAA,YAEpE,KAAKA,iBAAAA,eAAe;AACnB,qBAAO;AAAA,gBACN,QAAQ,MAAM,YAAY,MAAM,OAAO;AAAA,gBACvC,WAAW,GAAG;AAAA,gBACd,MAAM,GAAG;AAAA,cAAA;AAAA,YAEX,KAAKA,iBAAAA,eAAe;AACnB,qBAAO;AAAA,gBACN,QAAQ,MAAM,aAAa,MAAM,cAAc;AAAA,gBAC/C,WAAW,GAAG;AAAA,gBACd,MAAM;AAAA,cAAA;AAAA,YAER,KAAKA,iBAAAA,eAAe;AACnB,qBAAO,EAAE,QAAQ,MAAM,YAAY,MAAM,OAAO,GAAG,WAAW,GAAG,MAAM,MAAM,GAAG,aAAA;AAAA,YACjF,KAAKA,iBAAAA,eAAe;AACnB,qBAAO;AAAA,gBACN,QAAQ,MAAM,SAAS,MAAM,MAAM;AAAA,gBACnC,WAAW,GAAG;AAAA,gBACd,MAAM;AAAA,cAAA;AAAA,YAER;AACCC,0BAAAA,YAAc;AAAA,UAAA;AAAA,QAEjB,CAAC;AAAA,MAAA;AAAA,IAEH,CAAA;AAAA,EA7EA;AA8ED;;"}
1
+ {"version":3,"file":"MigrationPrinter.cjs","sources":["../../../../../../packages/cli/src/lib/migrations/MigrationPrinter.ts"],"sourcesContent":["/// <reference path=\"../../../types/chalk-table/index.d.ts\" />\n\nimport { Schema } from '@contember/schema'\nimport chalk from 'chalk'\nimport { AnyMigrationStatus, Migration, MigrationDescriber, MigrationState } from '@contember/migrations-client'\nimport { emptyDatabaseMetadata } from '@contember/database'\nimport chalkTable from 'chalk-table'\nimport { assertNever } from '../assertNever.js'\n\nexport class MigrationPrinter {\n\tconstructor(\n\t\tprivate readonly migrationsDescriber: MigrationDescriber,\n\t) {\n\t}\n\n\tprintMigrationDescription = (\n\t\tschema: Schema,\n\t\tmigration: Migration,\n\t\toptions: { sqlOnly?: boolean; noSql?: boolean },\n\t) => {\n\t\tconst description = this.migrationsDescriber.describeModifications(schema, migration)\n\t\tdescription.forEach(({ modification, getSql, description }) => {\n\t\t\tconst sql = getSql({\n\t\t\t\tsystemSchema: 'system',\n\t\t\t\tdatabaseMetadata: emptyDatabaseMetadata,\n\t\t\t\tinvalidateDatabaseMetadata: () => null,\n\t\t\t})\n\t\t\tif (options.sqlOnly) {\n\t\t\t\tif (sql.trim()) {\n\t\t\t\t\tconsole.log(sql)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst color = description.isDestructive ? chalk.red : chalk.blue\n\t\t\t\tconsole.group(color(`${description.message} [${modification.modification}]`))\n\t\t\t\tif (description.failureWarning) {\n\t\t\t\t\tconsole.log(chalk.bgWhite(chalk.redBright(description.failureWarning)))\n\t\t\t\t}\n\n\t\t\t\tif (!options.noSql) {\n\t\t\t\t\tif (sql.trim()) {\n\t\t\t\t\t\tconsole.log(sql)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.log('No sql to execute')\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconsole.groupEnd()\n\t\t\t}\n\t\t})\n\t}\n\n\tprintStatusTable = (migrations: AnyMigrationStatus[]) => {\n\t\treturn chalkTable(\n\t\t\t{\n\t\t\t\tcolumns: ['status', 'migration', 'info'],\n\t\t\t},\n\t\t\tmigrations.map(it => {\n\t\t\t\tswitch (it.state) {\n\t\t\t\t\tcase MigrationState.EXECUTED_ERROR:\n\t\t\t\t\t\treturn { status: chalk.bgRedBright.white('ERROR'), migration: it.name, info: it.errorMessage }\n\t\t\t\t\tcase MigrationState.EXECUTED_OK:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgGreen.blackBright('Executed'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: `Executed at ${it.executedMigration.executedAt.toISOString()}`,\n\t\t\t\t\t\t}\n\t\t\t\t\tcase MigrationState.EXECUTED_MISSING:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgRedBright.white('ERROR'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: it.errorMessage,\n\t\t\t\t\t\t}\n\t\t\t\t\tcase MigrationState.TO_EXECUTE_OK:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgBlueBright.white('Not executed'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: 'Will be executed during next deploy',\n\t\t\t\t\t\t}\n\t\t\t\t\tcase MigrationState.TO_EXECUTE_ERROR:\n\t\t\t\t\t\treturn { status: chalk.bgRedBright.white('ERROR'), migration: it.name, info: it.errorMessage }\n\t\t\t\t\tcase MigrationState.SKIP_EMPTY:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgYellow.white('Skip'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: `Skipped because empty`,\n\t\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tassertNever(it)\n\t\t\t\t}\n\t\t\t}),\n\t\t)\n\t}\n}\n"],"names":["description","emptyDatabaseMetadata","MigrationState","assertNever"],"mappings":";;;;;;;;;;AASO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,qBAChB;AADgB,SAAA,sBAAA;AAIlB,kBAAA,MAAA,6BAA4B,CAC3B,QACA,WACA,YACI;AACJ,YAAM,cAAc,KAAK,oBAAoB,sBAAsB,QAAQ,SAAS;AACpF,kBAAY,QAAQ,CAAC,EAAE,cAAc,QAAQ,aAAAA,mBAAkB;AAC9D,cAAM,MAAM,OAAO;AAAA,UAClB,cAAc;AAAA,UACd,kBAAkBC,SAAAA;AAAAA,UAClB,4BAA4B,MAAM;AAAA,QAAA,CAClC;AACD,Y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qBAAO;AAAA,gBACN,QAAQ,MAAM,aAAa,MAAM,cAAc;AAAA,gBAC/C,WAAW,GAAG;AAAA,gBACd,MAAM;AAAA,cAAA;AAAA,YAER,KAAKA,iBAAAA,eAAe;AACnB,qBAAO,EAAE,QAAQ,MAAM,YAAY,MAAM,OAAO,GAAG,WAAW,GAAG,MAAM,MAAM,GAAG,aAAA;AAAA,YACjF,KAAKA,iBAAAA,eAAe;AACnB,qBAAO;AAAA,gBACN,QAAQ,MAAM,SAAS,MAAM,MAAM;AAAA,gBACnC,WAAW,GAAG;AAAA,gBACd,MAAM;AAAA,cAAA;AAAA,YAER;AACCC,0BAAAA,YAAc;AAAA,UAAA;AAAA,QAEjB,CAAC;AAAA,MAAA;AAAA,IAEH,CAAA;AAAA,EA7EA;AA8ED;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationPrinter.js","sources":["../../../../../../packages/cli/src/lib/migrations/MigrationPrinter.ts"],"sourcesContent":["/// <reference path=\"../../../types/chalk-table/index.d.ts\" />\n\nimport { Schema } from '@contember/schema'\nimport chalk from 'chalk'\nimport { AnyMigrationStatus, Migration, MigrationDescriber, MigrationState } from '@contember/migrations-client'\nimport { emptyDatabaseMetadata } from '@contember/database'\nimport chalkTable from 'chalk-table'\nimport { assertNever } from '../assertNever'\n\nexport class MigrationPrinter {\n\tconstructor(\n\t\tprivate readonly migrationsDescriber: MigrationDescriber,\n\t) {\n\t}\n\n\tprintMigrationDescription = (\n\t\tschema: Schema,\n\t\tmigration: Migration,\n\t\toptions: { sqlOnly?: boolean; noSql?: boolean },\n\t) => {\n\t\tconst description = this.migrationsDescriber.describeModifications(schema, migration)\n\t\tdescription.forEach(({ modification, getSql, description }) => {\n\t\t\tconst sql = getSql({\n\t\t\t\tsystemSchema: 'system',\n\t\t\t\tdatabaseMetadata: emptyDatabaseMetadata,\n\t\t\t\tinvalidateDatabaseMetadata: () => null,\n\t\t\t})\n\t\t\tif (options.sqlOnly) {\n\t\t\t\tif (sql.trim()) {\n\t\t\t\t\tconsole.log(sql)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst color = description.isDestructive ? chalk.red : chalk.blue\n\t\t\t\tconsole.group(color(`${description.message} [${modification.modification}]`))\n\t\t\t\tif (description.failureWarning) {\n\t\t\t\t\tconsole.log(chalk.bgWhite(chalk.redBright(description.failureWarning)))\n\t\t\t\t}\n\n\t\t\t\tif (!options.noSql) {\n\t\t\t\t\tif (sql.trim()) {\n\t\t\t\t\t\tconsole.log(sql)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.log('No sql to execute')\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconsole.groupEnd()\n\t\t\t}\n\t\t})\n\t}\n\n\tprintStatusTable = (migrations: AnyMigrationStatus[]) => {\n\t\treturn chalkTable(\n\t\t\t{\n\t\t\t\tcolumns: ['status', 'migration', 'info'],\n\t\t\t},\n\t\t\tmigrations.map(it => {\n\t\t\t\tswitch (it.state) {\n\t\t\t\t\tcase MigrationState.EXECUTED_ERROR:\n\t\t\t\t\t\treturn { status: chalk.bgRedBright.white('ERROR'), migration: it.name, info: it.errorMessage }\n\t\t\t\t\tcase MigrationState.EXECUTED_OK:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgGreen.blackBright('Executed'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: `Executed at ${it.executedMigration.executedAt.toISOString()}`,\n\t\t\t\t\t\t}\n\t\t\t\t\tcase MigrationState.EXECUTED_MISSING:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgRedBright.white('ERROR'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: it.errorMessage,\n\t\t\t\t\t\t}\n\t\t\t\t\tcase MigrationState.TO_EXECUTE_OK:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgBlueBright.white('Not executed'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: 'Will be executed during next deploy',\n\t\t\t\t\t\t}\n\t\t\t\t\tcase MigrationState.TO_EXECUTE_ERROR:\n\t\t\t\t\t\treturn { status: chalk.bgRedBright.white('ERROR'), migration: it.name, info: it.errorMessage }\n\t\t\t\t\tcase MigrationState.SKIP_EMPTY:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgYellow.white('Skip'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: `Skipped because empty`,\n\t\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tassertNever(it)\n\t\t\t\t}\n\t\t\t}),\n\t\t)\n\t}\n}\n"],"names":["description"],"mappings":";;;;;;;;AASO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,qBAChB;AADgB,SAAA,sBAAA;AAIlB,kBAAA,MAAA,6BAA4B,CAC3B,QACA,WACA,YACI;AACJ,YAAM,cAAc,KAAK,oBAAoB,sBAAsB,QAAQ,SAAS;AACpF,kBAAY,QAAQ,CAAC,EAAE,cAAc,QAAQ,aAAAA,mBAAkB;AAC9D,cAAM,MAAM,OAAO;AAAA,UAClB,cAAc;AAAA,UACd,kBAAkB;AAAA,UAClB,4BAA4B,MAAM;AAAA,QAAA,CAClC;AACD,YAAI,QAAQ,SAAS;AACpB,cAAI,IAAI,QAAQ;AACf,oBAAQ,IAAI,GAAG;AAAA,UAChB;AAAA,QACD,OAAO;AACN,gBAAM,QAAQA,aAAY,gBAAgB,MAAM,MAAM,MAAM;AAC5D,kBAAQ,MAAM,MAAM,GAAGA,aAAY,OAAO,KAAK,aAAa,YAAY,GAAG,CAAC;AAC5E,cAAIA,aAAY,gBAAgB;AAC/B,oBAAQ,IAAI,MAAM,QAAQ,MAAM,UAAUA,aAAY,cAAc,CAAC,CAAC;AAAA,UACvE;AAEA,cAAI,CAAC,QAAQ,OAAO;AACnB,gBAAI,IAAI,QAAQ;AACf,sBAAQ,IAAI,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;AA8ED;"}
1
+ {"version":3,"file":"MigrationPrinter.js","sources":["../../../../../../packages/cli/src/lib/migrations/MigrationPrinter.ts"],"sourcesContent":["/// <reference path=\"../../../types/chalk-table/index.d.ts\" />\n\nimport { Schema } from '@contember/schema'\nimport chalk from 'chalk'\nimport { AnyMigrationStatus, Migration, MigrationDescriber, MigrationState } from '@contember/migrations-client'\nimport { emptyDatabaseMetadata } from '@contember/database'\nimport chalkTable from 'chalk-table'\nimport { assertNever } from '../assertNever.js'\n\nexport class MigrationPrinter {\n\tconstructor(\n\t\tprivate readonly migrationsDescriber: MigrationDescriber,\n\t) {\n\t}\n\n\tprintMigrationDescription = (\n\t\tschema: Schema,\n\t\tmigration: Migration,\n\t\toptions: { sqlOnly?: boolean; noSql?: boolean },\n\t) => {\n\t\tconst description = this.migrationsDescriber.describeModifications(schema, migration)\n\t\tdescription.forEach(({ modification, getSql, description }) => {\n\t\t\tconst sql = getSql({\n\t\t\t\tsystemSchema: 'system',\n\t\t\t\tdatabaseMetadata: emptyDatabaseMetadata,\n\t\t\t\tinvalidateDatabaseMetadata: () => null,\n\t\t\t})\n\t\t\tif (options.sqlOnly) {\n\t\t\t\tif (sql.trim()) {\n\t\t\t\t\tconsole.log(sql)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst color = description.isDestructive ? chalk.red : chalk.blue\n\t\t\t\tconsole.group(color(`${description.message} [${modification.modification}]`))\n\t\t\t\tif (description.failureWarning) {\n\t\t\t\t\tconsole.log(chalk.bgWhite(chalk.redBright(description.failureWarning)))\n\t\t\t\t}\n\n\t\t\t\tif (!options.noSql) {\n\t\t\t\t\tif (sql.trim()) {\n\t\t\t\t\t\tconsole.log(sql)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.log('No sql to execute')\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconsole.groupEnd()\n\t\t\t}\n\t\t})\n\t}\n\n\tprintStatusTable = (migrations: AnyMigrationStatus[]) => {\n\t\treturn chalkTable(\n\t\t\t{\n\t\t\t\tcolumns: ['status', 'migration', 'info'],\n\t\t\t},\n\t\t\tmigrations.map(it => {\n\t\t\t\tswitch (it.state) {\n\t\t\t\t\tcase MigrationState.EXECUTED_ERROR:\n\t\t\t\t\t\treturn { status: chalk.bgRedBright.white('ERROR'), migration: it.name, info: it.errorMessage }\n\t\t\t\t\tcase MigrationState.EXECUTED_OK:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgGreen.blackBright('Executed'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: `Executed at ${it.executedMigration.executedAt.toISOString()}`,\n\t\t\t\t\t\t}\n\t\t\t\t\tcase MigrationState.EXECUTED_MISSING:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgRedBright.white('ERROR'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: it.errorMessage,\n\t\t\t\t\t\t}\n\t\t\t\t\tcase MigrationState.TO_EXECUTE_OK:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgBlueBright.white('Not executed'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: 'Will be executed during next deploy',\n\t\t\t\t\t\t}\n\t\t\t\t\tcase MigrationState.TO_EXECUTE_ERROR:\n\t\t\t\t\t\treturn { status: chalk.bgRedBright.white('ERROR'), migration: it.name, info: it.errorMessage }\n\t\t\t\t\tcase MigrationState.SKIP_EMPTY:\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tstatus: chalk.bgYellow.white('Skip'),\n\t\t\t\t\t\t\tmigration: it.name,\n\t\t\t\t\t\t\tinfo: `Skipped because empty`,\n\t\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tassertNever(it)\n\t\t\t\t}\n\t\t\t}),\n\t\t)\n\t}\n}\n"],"names":["description"],"mappings":";;;;;;;;AASO,MAAM,iBAAiB;AAA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,QAAQ,YAAY,UAAU;AAAA,gBAC5C,WAAW,GAAG;AAAA,gBACd,MAAM,eAAe,GAAG,kBAAkB,WAAW,aAAa;AAAA,cAAA;AAAA,YAEpE,KAAK,eAAe;AACnB,qBAAO;AAAA,gBACN,QAAQ,MAAM,YAAY,MAAM,OAAO;AAAA,gBACvC,WAAW,GAAG;AAAA,gBACd,MAAM,GAAG;AAAA,cAAA;AAAA,YAEX,KAAK,eAAe;AACnB,qBAAO;AAAA,gBACN,QAAQ,MAAM,aAAa,MAAM,cAAc;AAAA,gBAC/C,WAAW,GAAG;AAAA,gBACd,MAAM;AAAA,cAAA;AAAA,YAER,KAAK,eAAe;AACnB,qBAAO,EAAE,QAAQ,MAAM,YAAY,MAAM,OAAO,GAAG,WAAW,GAAG,MAAM,MAAM,GAAG,aAAA;AAAA,YACjF,KAAK,eAAe;AACnB,qBAAO;AAAA,gBACN,QAAQ,MAAM,SAAS,MAAM,MAAM;AAAA,gBACnC,WAAW,GAAG;AAAA,gBACd,MAAM;AAAA,cAAA;AAAA,YAER;AACC,0BAAc;AAAA,UAAA;AAAA,QAEjB,CAAC;AAAA,MAAA;AAAA,IAEH,CAAA;AAAA,EA7EA;AA8ED;"}
@@ -6,11 +6,12 @@ var __defProp = Object.defineProperty;
6
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
7
  var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
8
8
  class MigrationRebaseFacade {
9
- constructor(schemaVersionBuilder, migrationsValidator, systemClientProvider, migrationFilesManager) {
9
+ constructor(schemaVersionBuilder, migrationsValidator, systemClientProvider, migrationFilesManager, schemaStateManager) {
10
10
  this.schemaVersionBuilder = schemaVersionBuilder;
11
11
  this.migrationsValidator = migrationsValidator;
12
12
  this.systemClientProvider = systemClientProvider;
13
13
  this.migrationFilesManager = migrationFilesManager;
14
+ this.schemaStateManager = schemaStateManager;
14
15
  __publicField(this, "rebase", async (migrations) => {
15
16
  const versions = migrations.map((it) => it.version);
16
17
  const schemaWithoutMigrations = await this.schemaVersionBuilder.buildSchemaAdvanced(
@@ -34,6 +35,9 @@ class MigrationRebaseFacade {
34
35
  await this.systemClientProvider.get().migrationModify(migration.version, newMigration);
35
36
  await this.migrationFilesManager.moveFile(migration.name, newMigration.name);
36
37
  }
38
+ if (await this.schemaStateManager.isStateMode()) {
39
+ await this.systemClientProvider.get().migrate([], false, await this.schemaStateManager.readState());
40
+ }
37
41
  });
38
42
  }
39
43
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationRebaseFacade.cjs","sources":["../../../../../../packages/cli/src/lib/migrations/MigrationRebaseFacade.ts"],"sourcesContent":["import { Migration, MigrationFilesManager, SchemaVersionBuilder, SystemClient } from '@contember/migrations-client'\nimport { MigrationsValidator } from './MigrationsValidator'\nimport { emptySchema } from '@contember/schema-utils'\nimport { MigrationVersionHelper } from '@contember/engine-common'\nimport { SystemClientProvider } from '../SystemClientProvider'\n\nexport class MigrationRebaseFacade {\n\tconstructor(\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationsValidator: MigrationsValidator,\n\t\tprivate readonly systemClientProvider: SystemClientProvider,\n\t\tprivate readonly migrationFilesManager: MigrationFilesManager,\n\t) {\n\t}\n\n\trebase = async (migrations: Migration[]) => {\n\t\tconst versions = migrations.map(it => it.version)\n\t\tconst schemaWithoutMigrations = await this.schemaVersionBuilder.buildSchemaAdvanced(\n\t\t\temptySchema,\n\t\t\tversion => !versions.includes(version),\n\t\t)\n\t\tconst valid = await this.migrationsValidator.validate(schemaWithoutMigrations, migrations)\n\t\tif (!valid) {\n\t\t\tthrow `Cannot rebase migrations`\n\t\t}\n\n\t\tlet i = 0\n\t\tfor (const migration of migrations) {\n\t\t\tconst name = migration.name.substring(MigrationVersionHelper.prefixLength + 1)\n\t\t\tconst [version, fullName] = MigrationVersionHelper.createVersion(name, i++)\n\t\t\tconst newMigration = {\n\t\t\t\tname: fullName,\n\t\t\t\tversion: version,\n\t\t\t\tformatVersion: migration.formatVersion,\n\t\t\t\tmodifications: migration.modifications,\n\t\t\t}\n\t\t\tawait this.systemClientProvider.get().migrationModify(migration.version, newMigration)\n\t\t\tawait this.migrationFilesManager.moveFile(migration.name, newMigration.name)\n\t\t}\n\t}\n}\n"],"names":["emptySchema","MigrationVersionHelper"],"mappings":";;;;;;;AAMO,MAAM,sBAAsB;AAAA,EAClC,YACkB,sBACA,qBACA,sBACA,uBAChB;AAJgB,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,uBAAA;AACA,SAAA,wBAAA;AAIlB,kBAAA,MAAA,UAAS,OAAO,eAA4B;AAC3C,YAAM,WAAW,WAAW,IAAI,CAAA,OAAM,GAAG,OAAO;AAChD,YAAM,0BAA0B,MAAM,KAAK,qBAAqB;AAAA,QAC/DA,YAAAA;AAAAA,QACA,CAAA,YAAW,CAAC,SAAS,SAAS,OAAO;AAAA,MAAA;AAEtC,YAAM,QAAQ,MAAM,KAAK,oBAAoB,SAAS,yBAAyB,UAAU;AACzF,UAAI,CAAC,OAAO;AACX,cAAM;AAAA,MACP;AAEA,UAAI,IAAI;AACR,iBAAW,aAAa,YAAY;AACnC,cAAM,OAAO,UAAU,KAAK,UAAUC,aAAAA,uBAAuB,eAAe,CAAC;AAC7E,cAAM,CAAC,SAAS,QAAQ,IAAIA,aAAAA,uBAAuB,cAAc,MAAM,GAAG;AAC1E,cAAM,eAAe;AAAA,UACpB,MAAM;AAAA,UACN;AAAA,UACA,eAAe,UAAU;AAAA,UACzB,eAAe,UAAU;AAAA,QAAA;AAE1B,cAAM,KAAK,qBAAqB,IAAA,EAAM,gBAAgB,UAAU,SAAS,YAAY;AACrF,cAAM,KAAK,sBAAsB,SAAS,UAAU,MAAM,aAAa,IAAI;AAAA,MAC5E;AAAA,IACD,CAAA;AAAA,EA1BA;AA2BD;;"}
1
+ {"version":3,"file":"MigrationRebaseFacade.cjs","sources":["../../../../../../packages/cli/src/lib/migrations/MigrationRebaseFacade.ts"],"sourcesContent":["import { Migration, MigrationFilesManager, SchemaStateManager, SchemaVersionBuilder, SystemClient } from '@contember/migrations-client'\nimport { MigrationsValidator } from './MigrationsValidator.js'\nimport { emptySchema } from '@contember/schema-utils'\nimport { MigrationVersionHelper } from '@contember/engine-common'\nimport { SystemClientProvider } from '../SystemClientProvider.js'\n\nexport class MigrationRebaseFacade {\n\tconstructor(\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationsValidator: MigrationsValidator,\n\t\tprivate readonly systemClientProvider: SystemClientProvider,\n\t\tprivate readonly migrationFilesManager: MigrationFilesManager,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t) {\n\t}\n\n\trebase = async (migrations: Migration[]) => {\n\t\tconst versions = migrations.map(it => it.version)\n\t\tconst schemaWithoutMigrations = await this.schemaVersionBuilder.buildSchemaAdvanced(\n\t\t\temptySchema,\n\t\t\tversion => !versions.includes(version),\n\t\t)\n\t\tconst valid = await this.migrationsValidator.validate(schemaWithoutMigrations, migrations)\n\t\tif (!valid) {\n\t\t\tthrow `Cannot rebase migrations`\n\t\t}\n\n\t\tlet i = 0\n\t\tfor (const migration of migrations) {\n\t\t\tconst name = migration.name.substring(MigrationVersionHelper.prefixLength + 1)\n\t\t\tconst [version, fullName] = MigrationVersionHelper.createVersion(name, i++)\n\t\t\tconst newMigration = {\n\t\t\t\tname: fullName,\n\t\t\t\tversion: version,\n\t\t\t\tformatVersion: migration.formatVersion,\n\t\t\t\tmodifications: migration.modifications,\n\t\t\t}\n\t\t\tawait this.systemClientProvider.get().migrationModify(migration.version, newMigration)\n\t\t\tawait this.migrationFilesManager.moveFile(migration.name, newMigration.name)\n\t\t}\n\n\t\t// migrationModify rebuilds the server schema from migrations, dropping the non-model\n\t\t// state; re-apply it from the state files so the server stays consistent.\n\t\tif (await this.schemaStateManager.isStateMode()) {\n\t\t\tawait this.systemClientProvider.get().migrate([], false, await this.schemaStateManager.readState())\n\t\t}\n\t}\n}\n"],"names":["emptySchema","MigrationVersionHelper"],"mappings":";;;;;;;AAMO,MAAM,sBAAsB;AAAA,EAClC,YACkB,sBACA,qBACA,sBACA,uBACA,oBAChB;AALgB,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,uBAAA;AACA,SAAA,wBAAA;AACA,SAAA,qBAAA;AAIlB,kBAAA,MAAA,UAAS,OAAO,eAA4B;AAC3C,YAAM,WAAW,WAAW,IAAI,CAAA,OAAM,GAAG,OAAO;AAChD,YAAM,0BAA0B,MAAM,KAAK,qBAAqB;AAAA,QAC/DA,YAAAA;AAAAA,QACA,CAAA,YAAW,CAAC,SAAS,SAAS,OAAO;AAAA,MAAA;AAEtC,YAAM,QAAQ,MAAM,KAAK,oBAAoB,SAAS,yBAAyB,UAAU;AACzF,UAAI,CAAC,OAAO;AACX,cAAM;AAAA,MACP;AAEA,UAAI,IAAI;AACR,iBAAW,aAAa,YAAY;AACnC,cAAM,OAAO,UAAU,KAAK,UAAUC,aAAAA,uBAAuB,eAAe,CAAC;AAC7E,cAAM,CAAC,SAAS,QAAQ,IAAIA,aAAAA,uBAAuB,cAAc,MAAM,GAAG;AAC1E,cAAM,eAAe;AAAA,UACpB,MAAM;AAAA,UACN;AAAA,UACA,eAAe,UAAU;AAAA,UACzB,eAAe,UAAU;AAAA,QAAA;AAE1B,cAAM,KAAK,qBAAqB,IAAA,EAAM,gBAAgB,UAAU,SAAS,YAAY;AACrF,cAAM,KAAK,sBAAsB,SAAS,UAAU,MAAM,aAAa,IAAI;AAAA,MAC5E;AAIA,UAAI,MAAM,KAAK,mBAAmB,eAAe;AAChD,cAAM,KAAK,qBAAqB,IAAA,EAAM,QAAQ,IAAI,OAAO,MAAM,KAAK,mBAAmB,UAAA,CAAW;AAAA,MACnG;AAAA,IACD,CAAA;AAAA,EAhCA;AAiCD;;"}
@@ -4,11 +4,12 @@ var __defProp = Object.defineProperty;
4
4
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
5
  var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
6
6
  class MigrationRebaseFacade {
7
- constructor(schemaVersionBuilder, migrationsValidator, systemClientProvider, migrationFilesManager) {
7
+ constructor(schemaVersionBuilder, migrationsValidator, systemClientProvider, migrationFilesManager, schemaStateManager) {
8
8
  this.schemaVersionBuilder = schemaVersionBuilder;
9
9
  this.migrationsValidator = migrationsValidator;
10
10
  this.systemClientProvider = systemClientProvider;
11
11
  this.migrationFilesManager = migrationFilesManager;
12
+ this.schemaStateManager = schemaStateManager;
12
13
  __publicField(this, "rebase", async (migrations) => {
13
14
  const versions = migrations.map((it) => it.version);
14
15
  const schemaWithoutMigrations = await this.schemaVersionBuilder.buildSchemaAdvanced(
@@ -32,6 +33,9 @@ class MigrationRebaseFacade {
32
33
  await this.systemClientProvider.get().migrationModify(migration.version, newMigration);
33
34
  await this.migrationFilesManager.moveFile(migration.name, newMigration.name);
34
35
  }
36
+ if (await this.schemaStateManager.isStateMode()) {
37
+ await this.systemClientProvider.get().migrate([], false, await this.schemaStateManager.readState());
38
+ }
35
39
  });
36
40
  }
37
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationRebaseFacade.js","sources":["../../../../../../packages/cli/src/lib/migrations/MigrationRebaseFacade.ts"],"sourcesContent":["import { Migration, MigrationFilesManager, SchemaVersionBuilder, SystemClient } from '@contember/migrations-client'\nimport { MigrationsValidator } from './MigrationsValidator'\nimport { emptySchema } from '@contember/schema-utils'\nimport { MigrationVersionHelper } from '@contember/engine-common'\nimport { SystemClientProvider } from '../SystemClientProvider'\n\nexport class MigrationRebaseFacade {\n\tconstructor(\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationsValidator: MigrationsValidator,\n\t\tprivate readonly systemClientProvider: SystemClientProvider,\n\t\tprivate readonly migrationFilesManager: MigrationFilesManager,\n\t) {\n\t}\n\n\trebase = async (migrations: Migration[]) => {\n\t\tconst versions = migrations.map(it => it.version)\n\t\tconst schemaWithoutMigrations = await this.schemaVersionBuilder.buildSchemaAdvanced(\n\t\t\temptySchema,\n\t\t\tversion => !versions.includes(version),\n\t\t)\n\t\tconst valid = await this.migrationsValidator.validate(schemaWithoutMigrations, migrations)\n\t\tif (!valid) {\n\t\t\tthrow `Cannot rebase migrations`\n\t\t}\n\n\t\tlet i = 0\n\t\tfor (const migration of migrations) {\n\t\t\tconst name = migration.name.substring(MigrationVersionHelper.prefixLength + 1)\n\t\t\tconst [version, fullName] = MigrationVersionHelper.createVersion(name, i++)\n\t\t\tconst newMigration = {\n\t\t\t\tname: fullName,\n\t\t\t\tversion: version,\n\t\t\t\tformatVersion: migration.formatVersion,\n\t\t\t\tmodifications: migration.modifications,\n\t\t\t}\n\t\t\tawait this.systemClientProvider.get().migrationModify(migration.version, newMigration)\n\t\t\tawait this.migrationFilesManager.moveFile(migration.name, newMigration.name)\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;AAMO,MAAM,sBAAsB;AAAA,EAClC,YACkB,sBACA,qBACA,sBACA,uBAChB;AAJgB,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,uBAAA;AACA,SAAA,wBAAA;AAIlB,kBAAA,MAAA,UAAS,OAAO,eAA4B;AAC3C,YAAM,WAAW,WAAW,IAAI,CAAA,OAAM,GAAG,OAAO;AAChD,YAAM,0BAA0B,MAAM,KAAK,qBAAqB;AAAA,QAC/D;AAAA,QACA,CAAA,YAAW,CAAC,SAAS,SAAS,OAAO;AAAA,MAAA;AAEtC,YAAM,QAAQ,MAAM,KAAK,oBAAoB,SAAS,yBAAyB,UAAU;AACzF,UAAI,CAAC,OAAO;AACX,cAAM;AAAA,MACP;AAEA,UAAI,IAAI;AACR,iBAAW,aAAa,YAAY;AACnC,cAAM,OAAO,UAAU,KAAK,UAAU,uBAAuB,eAAe,CAAC;AAC7E,cAAM,CAAC,SAAS,QAAQ,IAAI,uBAAuB,cAAc,MAAM,GAAG;AAC1E,cAAM,eAAe;AAAA,UACpB,MAAM;AAAA,UACN;AAAA,UACA,eAAe,UAAU;AAAA,UACzB,eAAe,UAAU;AAAA,QAAA;AAE1B,cAAM,KAAK,qBAAqB,IAAA,EAAM,gBAAgB,UAAU,SAAS,YAAY;AACrF,cAAM,KAAK,sBAAsB,SAAS,UAAU,MAAM,aAAa,IAAI;AAAA,MAC5E;AAAA,IACD,CAAA;AAAA,EA1BA;AA2BD;"}
1
+ {"version":3,"file":"MigrationRebaseFacade.js","sources":["../../../../../../packages/cli/src/lib/migrations/MigrationRebaseFacade.ts"],"sourcesContent":["import { Migration, MigrationFilesManager, SchemaStateManager, SchemaVersionBuilder, SystemClient } from '@contember/migrations-client'\nimport { MigrationsValidator } from './MigrationsValidator.js'\nimport { emptySchema } from '@contember/schema-utils'\nimport { MigrationVersionHelper } from '@contember/engine-common'\nimport { SystemClientProvider } from '../SystemClientProvider.js'\n\nexport class MigrationRebaseFacade {\n\tconstructor(\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationsValidator: MigrationsValidator,\n\t\tprivate readonly systemClientProvider: SystemClientProvider,\n\t\tprivate readonly migrationFilesManager: MigrationFilesManager,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t) {\n\t}\n\n\trebase = async (migrations: Migration[]) => {\n\t\tconst versions = migrations.map(it => it.version)\n\t\tconst schemaWithoutMigrations = await this.schemaVersionBuilder.buildSchemaAdvanced(\n\t\t\temptySchema,\n\t\t\tversion => !versions.includes(version),\n\t\t)\n\t\tconst valid = await this.migrationsValidator.validate(schemaWithoutMigrations, migrations)\n\t\tif (!valid) {\n\t\t\tthrow `Cannot rebase migrations`\n\t\t}\n\n\t\tlet i = 0\n\t\tfor (const migration of migrations) {\n\t\t\tconst name = migration.name.substring(MigrationVersionHelper.prefixLength + 1)\n\t\t\tconst [version, fullName] = MigrationVersionHelper.createVersion(name, i++)\n\t\t\tconst newMigration = {\n\t\t\t\tname: fullName,\n\t\t\t\tversion: version,\n\t\t\t\tformatVersion: migration.formatVersion,\n\t\t\t\tmodifications: migration.modifications,\n\t\t\t}\n\t\t\tawait this.systemClientProvider.get().migrationModify(migration.version, newMigration)\n\t\t\tawait this.migrationFilesManager.moveFile(migration.name, newMigration.name)\n\t\t}\n\n\t\t// migrationModify rebuilds the server schema from migrations, dropping the non-model\n\t\t// state; re-apply it from the state files so the server stays consistent.\n\t\tif (await this.schemaStateManager.isStateMode()) {\n\t\t\tawait this.systemClientProvider.get().migrate([], false, await this.schemaStateManager.readState())\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;AAMO,MAAM,sBAAsB;AAAA,EAClC,YACkB,sBACA,qBACA,sBACA,uBACA,oBAChB;AALgB,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,uBAAA;AACA,SAAA,wBAAA;AACA,SAAA,qBAAA;AAIlB,kBAAA,MAAA,UAAS,OAAO,eAA4B;AAC3C,YAAM,WAAW,WAAW,IAAI,CAAA,OAAM,GAAG,OAAO;AAChD,YAAM,0BAA0B,MAAM,KAAK,qBAAqB;AAAA,QAC/D;AAAA,QACA,CAAA,YAAW,CAAC,SAAS,SAAS,OAAO;AAAA,MAAA;AAEtC,YAAM,QAAQ,MAAM,KAAK,oBAAoB,SAAS,yBAAyB,UAAU;AACzF,UAAI,CAAC,OAAO;AACX,cAAM;AAAA,MACP;AAEA,UAAI,IAAI;AACR,iBAAW,aAAa,YAAY;AACnC,cAAM,OAAO,UAAU,KAAK,UAAU,uBAAuB,eAAe,CAAC;AAC7E,cAAM,CAAC,SAAS,QAAQ,IAAI,uBAAuB,cAAc,MAAM,GAAG;AAC1E,cAAM,eAAe;AAAA,UACpB,MAAM;AAAA,UACN;AAAA,UACA,eAAe,UAAU;AAAA,UACzB,eAAe,UAAU;AAAA,QAAA;AAE1B,cAAM,KAAK,qBAAqB,IAAA,EAAM,gBAAgB,UAAU,SAAS,YAAY;AACrF,cAAM,KAAK,sBAAsB,SAAS,UAAU,MAAM,aAAa,IAAI;AAAA,MAC5E;AAIA,UAAI,MAAM,KAAK,mBAAmB,eAAe;AAChD,cAAM,KAAK,qBAAqB,IAAA,EAAM,QAAQ,IAAI,OAAO,MAAM,KAAK,mBAAmB,UAAA,CAAW;AAAA,MACnG;AAAA,IACD,CAAA;AAAA,EAhCA;AAiCD;"}
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const schemaUtils = require("@contember/schema-utils");
4
+ const migrationsClient = require("@contember/migrations-client");
5
+ class MigrationSnapshotFacade {
6
+ constructor(migrationsResolver, schemaVersionBuilder, schemaDiffer, schemaMigrator, schemaStateManager, snapshotManager) {
7
+ this.migrationsResolver = migrationsResolver;
8
+ this.schemaVersionBuilder = schemaVersionBuilder;
9
+ this.schemaDiffer = schemaDiffer;
10
+ this.schemaMigrator = schemaMigrator;
11
+ this.schemaStateManager = schemaStateManager;
12
+ this.snapshotManager = snapshotManager;
13
+ }
14
+ /** Collapses all migrations into a single schema snapshot and writes snapshot.json. */
15
+ async create() {
16
+ const files = await this.migrationsResolver.getMigrationFiles();
17
+ if (files.length === 0) {
18
+ throw "No migrations to snapshot";
19
+ }
20
+ const stateMode = await this.schemaStateManager.isStateMode();
21
+ const version = files[files.length - 1].version;
22
+ const collapsedSchema = await this.schemaVersionBuilder.buildSchemaAdvanced(schemaUtils.emptySchema, () => true);
23
+ const modifications = this.schemaDiffer.diffSchemas(schemaUtils.emptySchema, collapsedSchema, {
24
+ skipNonModelDiffers: stateMode
25
+ });
26
+ const covers = [];
27
+ const contentMigrations = [];
28
+ for (const file of files) {
29
+ const content = await file.getContent();
30
+ const schema = migrationsClient.isSchemaMigration(content);
31
+ covers.push({
32
+ version: file.version,
33
+ name: file.name,
34
+ type: schema ? "schema" : "content",
35
+ checksum: schema ? migrationsClient.calculateMigrationChecksum(content) : null
36
+ });
37
+ if (!schema) {
38
+ contentMigrations.push(file.version);
39
+ }
40
+ }
41
+ const snapshot = {
42
+ version,
43
+ stateMode,
44
+ snapshot: { formatVersion: migrationsClient.VERSION_LATEST, modifications },
45
+ covers,
46
+ contentMigrations
47
+ };
48
+ await this.snapshotManager.write(snapshot);
49
+ return snapshot;
50
+ }
51
+ /**
52
+ * Returns the snapshot when it can safely bootstrap the current project, else null.
53
+ * The snapshot is only usable on an empty project (no executed migrations) and only when
54
+ * none of the covered migration files have changed. A present-but-stale snapshot is skipped
55
+ * with a warning, falling back to a full replay.
56
+ */
57
+ async getUsableSnapshot(executedMigrations) {
58
+ if (!await this.snapshotManager.exists()) {
59
+ return null;
60
+ }
61
+ if (executedMigrations.length > 0) {
62
+ return null;
63
+ }
64
+ const snapshot = await this.snapshotManager.read();
65
+ const stale = await this.findStaleness(snapshot);
66
+ if (stale) {
67
+ console.warn(`Ignoring snapshot: ${stale}. Run "migrations:snapshot" to regenerate it.`);
68
+ return null;
69
+ }
70
+ return snapshot;
71
+ }
72
+ /** Maps a snapshot to the GraphQL SnapshotInput; covered migrations are sent as Migration inputs. */
73
+ async buildSnapshotInput(snapshot) {
74
+ const files = await this.migrationsResolver.getMigrationFiles();
75
+ const byVersion = new Map(files.map((it) => [it.version, it]));
76
+ const covers = [];
77
+ for (const covered of snapshot.covers) {
78
+ const file = byVersion.get(covered.version);
79
+ if (!file) {
80
+ throw `Snapshot covers missing migration ${covered.name}`;
81
+ }
82
+ covers.push(migrationContentToInput(covered.version, covered.name, await file.getContent()));
83
+ }
84
+ return {
85
+ formatVersion: snapshot.snapshot.formatVersion,
86
+ modifications: snapshot.snapshot.modifications,
87
+ covers
88
+ };
89
+ }
90
+ /** Offline check that the snapshot still equals a full replay of all migrations. */
91
+ async verify() {
92
+ if (!await this.snapshotManager.exists()) {
93
+ throw 'No snapshot found. Run "migrations:snapshot" first.';
94
+ }
95
+ const snapshot = await this.snapshotManager.read();
96
+ const stale = await this.findStaleness(snapshot);
97
+ if (stale) {
98
+ return { ok: false, message: `Snapshot is stale: ${stale}. Run "migrations:snapshot" to regenerate it.` };
99
+ }
100
+ const stateMode = await this.schemaStateManager.isStateMode();
101
+ const replaySchema = await this.schemaVersionBuilder.buildSchema();
102
+ let snapshotSchema = this.schemaMigrator.applyModifications(schemaUtils.emptySchema, snapshot.snapshot.modifications, snapshot.snapshot.formatVersion);
103
+ if (stateMode) {
104
+ snapshotSchema = { ...snapshotSchema, ...await this.schemaStateManager.readState() };
105
+ }
106
+ const differences = schemaUtils.deepCompare(replaySchema, snapshotSchema, [], (path) => {
107
+ if (path[0] === "model" && path[1] === "entities" && (path[3] === "unique" || path[3] === "index")) {
108
+ return (a, b) => schemaUtils.compareArraysIgnoreOrder(a, b, path);
109
+ }
110
+ return null;
111
+ });
112
+ if (differences.length === 0) {
113
+ return {
114
+ ok: true,
115
+ message: `Snapshot is up to date (covers ${snapshot.covers.length} migrations up to ${snapshot.version}).`
116
+ };
117
+ }
118
+ return {
119
+ ok: false,
120
+ message: 'Snapshot does not match a full replay of all migrations. Run "migrations:snapshot" to regenerate it.'
121
+ };
122
+ }
123
+ async findStaleness(snapshot) {
124
+ if (snapshot.stateMode !== await this.schemaStateManager.isStateMode()) {
125
+ return `schema state mode changed since the snapshot was created`;
126
+ }
127
+ const files = await this.migrationsResolver.getMigrationFiles();
128
+ const byVersion = new Map(files.map((it) => [it.version, it]));
129
+ for (const covered of snapshot.covers) {
130
+ const file = byVersion.get(covered.version);
131
+ if (!file) {
132
+ return `covered migration ${covered.name} is missing`;
133
+ }
134
+ const content = await file.getContent();
135
+ const currentType = migrationsClient.isSchemaMigration(content) ? "schema" : "content";
136
+ if (currentType !== covered.type) {
137
+ return `covered migration ${covered.name} changed type`;
138
+ }
139
+ if (covered.type === "schema") {
140
+ const checksum = migrationsClient.isSchemaMigration(content) ? migrationsClient.calculateMigrationChecksum(content) : null;
141
+ if (checksum !== covered.checksum) {
142
+ return `covered migration ${covered.name} has changed`;
143
+ }
144
+ }
145
+ }
146
+ const coveredVersions = new Set(snapshot.covers.map((it) => it.version));
147
+ for (const file of files) {
148
+ if (file.version <= snapshot.version && !coveredVersions.has(file.version)) {
149
+ return `migration ${file.name} is within the covered range but not part of the snapshot`;
150
+ }
151
+ }
152
+ return null;
153
+ }
154
+ }
155
+ const migrationContentToInput = (version, name, content) => {
156
+ if (migrationsClient.isSchemaMigration(content)) {
157
+ return {
158
+ version,
159
+ name,
160
+ type: "SCHEMA",
161
+ schemaMigration: {
162
+ formatVersion: content.formatVersion,
163
+ modifications: content.modifications,
164
+ skippedErrors: content.skippedErrors
165
+ }
166
+ };
167
+ }
168
+ return { version, name, type: "CONTENT", contentMigration: [] };
169
+ };
170
+ exports.MigrationSnapshotFacade = MigrationSnapshotFacade;
171
+ //# sourceMappingURL=MigrationSnapshotFacade.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MigrationSnapshotFacade.cjs","sources":["../../../../../../packages/cli/src/lib/migrations/MigrationSnapshotFacade.ts"],"sourcesContent":["import { compareArraysIgnoreOrder, deepCompare, emptySchema } from '@contember/schema-utils'\nimport {\n\tcalculateMigrationChecksum,\n\tCoveredMigration,\n\tExecutedMigrationInfo,\n\tisSchemaMigration,\n\tMigrationContent,\n\tMigrationsResolver,\n\tSchemaDiffer,\n\tSchemaMigrator,\n\tSchemaStateManager,\n\tSchemaVersionBuilder,\n\tSnapshotFile,\n\tSnapshotInput,\n\tSnapshotManager,\n\tVERSION_LATEST,\n} from '@contember/migrations-client'\n\nexport class MigrationSnapshotFacade {\n\tconstructor(\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly schemaDiffer: SchemaDiffer,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t\tprivate readonly snapshotManager: SnapshotManager,\n\t) {\n\t}\n\n\t/** Collapses all migrations into a single schema snapshot and writes snapshot.json. */\n\tasync create(): Promise<SnapshotFile> {\n\t\tconst files = await this.migrationsResolver.getMigrationFiles()\n\t\tif (files.length === 0) {\n\t\t\tthrow 'No migrations to snapshot'\n\t\t}\n\t\tconst stateMode = await this.schemaStateManager.isStateMode()\n\t\tconst version = files[files.length - 1].version\n\n\t\t// Replay all schema migrations into a single schema. In state mode the non-model parts\n\t\t// (acl/validation/actions/settings) live in state/ and are skipped here; otherwise they\n\t\t// are part of the migration history and must be included in the collapsed modifications.\n\t\tconst collapsedSchema = await this.schemaVersionBuilder.buildSchemaAdvanced(emptySchema, () => true)\n\t\tconst modifications = this.schemaDiffer.diffSchemas(emptySchema, collapsedSchema, {\n\t\t\tskipNonModelDiffers: stateMode,\n\t\t})\n\n\t\tconst covers: CoveredMigration[] = []\n\t\tconst contentMigrations: string[] = []\n\t\tfor (const file of files) {\n\t\t\tconst content = await file.getContent()\n\t\t\tconst schema = isSchemaMigration(content)\n\t\t\tcovers.push({\n\t\t\t\tversion: file.version,\n\t\t\t\tname: file.name,\n\t\t\t\ttype: schema ? 'schema' : 'content',\n\t\t\t\tchecksum: schema ? calculateMigrationChecksum(content) : null,\n\t\t\t})\n\t\t\tif (!schema) {\n\t\t\t\tcontentMigrations.push(file.version)\n\t\t\t}\n\t\t}\n\n\t\tconst snapshot: SnapshotFile = {\n\t\t\tversion,\n\t\t\tstateMode,\n\t\t\tsnapshot: { formatVersion: VERSION_LATEST, modifications },\n\t\t\tcovers,\n\t\t\tcontentMigrations,\n\t\t}\n\t\tawait this.snapshotManager.write(snapshot)\n\t\treturn snapshot\n\t}\n\n\t/**\n\t * Returns the snapshot when it can safely bootstrap the current project, else null.\n\t * The snapshot is only usable on an empty project (no executed migrations) and only when\n\t * none of the covered migration files have changed. A present-but-stale snapshot is skipped\n\t * with a warning, falling back to a full replay.\n\t */\n\tasync getUsableSnapshot(executedMigrations: ExecutedMigrationInfo[]): Promise<SnapshotFile | null> {\n\t\tif (!(await this.snapshotManager.exists())) {\n\t\t\treturn null\n\t\t}\n\t\tif (executedMigrations.length > 0) {\n\t\t\treturn null\n\t\t}\n\t\tconst snapshot = await this.snapshotManager.read()\n\t\tconst stale = await this.findStaleness(snapshot)\n\t\tif (stale) {\n\t\t\tconsole.warn(`Ignoring snapshot: ${stale}. Run \"migrations:snapshot\" to regenerate it.`)\n\t\t\treturn null\n\t\t}\n\t\treturn snapshot\n\t}\n\n\t/** Maps a snapshot to the GraphQL SnapshotInput; covered migrations are sent as Migration inputs. */\n\tasync buildSnapshotInput(snapshot: SnapshotFile): Promise<SnapshotInput> {\n\t\tconst files = await this.migrationsResolver.getMigrationFiles()\n\t\tconst byVersion = new Map(files.map(it => [it.version, it]))\n\t\tconst covers: unknown[] = []\n\t\tfor (const covered of snapshot.covers) {\n\t\t\tconst file = byVersion.get(covered.version)\n\t\t\tif (!file) {\n\t\t\t\tthrow `Snapshot covers missing migration ${covered.name}`\n\t\t\t}\n\t\t\tcovers.push(migrationContentToInput(covered.version, covered.name, await file.getContent()))\n\t\t}\n\t\treturn {\n\t\t\tformatVersion: snapshot.snapshot.formatVersion,\n\t\t\tmodifications: snapshot.snapshot.modifications,\n\t\t\tcovers,\n\t\t}\n\t}\n\n\t/** Offline check that the snapshot still equals a full replay of all migrations. */\n\tasync verify(): Promise<{ ok: boolean; message: string }> {\n\t\tif (!(await this.snapshotManager.exists())) {\n\t\t\tthrow 'No snapshot found. Run \"migrations:snapshot\" first.'\n\t\t}\n\t\tconst snapshot = await this.snapshotManager.read()\n\n\t\tconst stale = await this.findStaleness(snapshot)\n\t\tif (stale) {\n\t\t\treturn { ok: false, message: `Snapshot is stale: ${stale}. Run \"migrations:snapshot\" to regenerate it.` }\n\t\t}\n\n\t\tconst stateMode = await this.schemaStateManager.isStateMode()\n\t\tconst replaySchema = await this.schemaVersionBuilder.buildSchema()\n\t\tlet snapshotSchema = this.schemaMigrator.applyModifications(emptySchema, snapshot.snapshot.modifications, snapshot.snapshot.formatVersion)\n\t\tif (stateMode) {\n\t\t\tsnapshotSchema = { ...snapshotSchema, ...await this.schemaStateManager.readState() }\n\t\t}\n\n\t\t// Compare with the same order-insensitive equality that SchemaDiffer uses for its own\n\t\t// round-trip check. The collapsed differ emits fields/constraints in a fixed order that may\n\t\t// differ from a replay of an interleaved history (e.g. a column added to an entity that\n\t\t// already has a relation), so a raw checksum (JSON.stringify) would report false mismatches\n\t\t// on schemas that are in fact deeply equal.\n\t\tconst differences = deepCompare(replaySchema, snapshotSchema, [], path => {\n\t\t\tif (path[0] === 'model' && path[1] === 'entities' && (path[3] === 'unique' || path[3] === 'index')) {\n\t\t\t\treturn (a, b) => compareArraysIgnoreOrder(a, b, path)\n\t\t\t}\n\t\t\treturn null\n\t\t})\n\t\tif (differences.length === 0) {\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\tmessage: `Snapshot is up to date (covers ${snapshot.covers.length} migrations up to ${snapshot.version}).`,\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tok: false,\n\t\t\tmessage: 'Snapshot does not match a full replay of all migrations. Run \"migrations:snapshot\" to regenerate it.',\n\t\t}\n\t}\n\n\tprivate async findStaleness(snapshot: SnapshotFile): Promise<string | null> {\n\t\t// The collapsed snapshot is built differently per mode (state mode omits the non-model parts,\n\t\t// see create()), and on bootstrap the non-model overlay is driven by the *current* mode. A mode\n\t\t// switch since the snapshot was created (e.g. migrations:init-state) leaves the covers untouched\n\t\t// and would otherwise pass unnoticed, so treat it as stale and fall back to a full replay.\n\t\tif (snapshot.stateMode !== await this.schemaStateManager.isStateMode()) {\n\t\t\treturn `schema state mode changed since the snapshot was created`\n\t\t}\n\t\tconst files = await this.migrationsResolver.getMigrationFiles()\n\t\tconst byVersion = new Map(files.map(it => [it.version, it]))\n\t\tfor (const covered of snapshot.covers) {\n\t\t\tconst file = byVersion.get(covered.version)\n\t\t\tif (!file) {\n\t\t\t\treturn `covered migration ${covered.name} is missing`\n\t\t\t}\n\t\t\tconst content = await file.getContent()\n\t\t\tconst currentType = isSchemaMigration(content) ? 'schema' : 'content'\n\t\t\t// A covered migration that flipped type (e.g. a content migration manually rewritten into a\n\t\t\t// schema one) is not reflected in the collapsed modifications, so the snapshot no longer\n\t\t\t// equals a replay. Schema covers also verify the checksum; content covers carry none (their\n\t\t\t// data is never reproduced), so the type check is the only identity they get.\n\t\t\tif (currentType !== covered.type) {\n\t\t\t\treturn `covered migration ${covered.name} changed type`\n\t\t\t}\n\t\t\tif (covered.type === 'schema') {\n\t\t\t\tconst checksum = isSchemaMigration(content) ? calculateMigrationChecksum(content) : null\n\t\t\t\tif (checksum !== covered.checksum) {\n\t\t\t\t\treturn `covered migration ${covered.name} has changed`\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// Detect a migration added within the covered range (version <= snapshot.version) that the\n\t\t// snapshot does not know about — e.g. a teammate's migration with an earlier timestamp merged\n\t\t// after the snapshot was generated. Without this, bootstrapping would record the covers up to\n\t\t// snapshot.version and the subsequent normal replay would fail with MUST_FOLLOW_LATEST on the\n\t\t// in-range migration, leaving the database half-bootstrapped. Treat it as stale and fall back.\n\t\tconst coveredVersions = new Set(snapshot.covers.map(it => it.version))\n\t\tfor (const file of files) {\n\t\t\tif (file.version <= snapshot.version && !coveredVersions.has(file.version)) {\n\t\t\t\treturn `migration ${file.name} is within the covered range but not part of the snapshot`\n\t\t\t}\n\t\t}\n\t\treturn null\n\t}\n}\n\nconst migrationContentToInput = (version: string, name: string, content: MigrationContent) => {\n\tif (isSchemaMigration(content)) {\n\t\treturn {\n\t\t\tversion,\n\t\t\tname,\n\t\t\ttype: 'SCHEMA',\n\t\t\tschemaMigration: {\n\t\t\t\tformatVersion: content.formatVersion,\n\t\t\t\tmodifications: content.modifications,\n\t\t\t\tskippedErrors: content.skippedErrors,\n\t\t\t},\n\t\t}\n\t}\n\t// Content migrations are only recorded as executed (no data is replayed), so the queries are irrelevant.\n\treturn { version, name, type: 'CONTENT', contentMigration: [] }\n}\n"],"names":["emptySchema","isSchemaMigration","calculateMigrationChecksum","VERSION_LATEST","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