@contember/cli 2.1.0-beta.2 → 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":"EsBuildBuilder.cjs","sources":["../../../../../../packages/cli/src/lib/js/EsBuildBuilder.ts"],"sourcesContent":["import { JsBuilder } from './JsBuilder'\n\nexport class EsBuildBuilder implements JsBuilder {\n\tasync build(path: string): Promise<string> {\n\t\tconst esbuild = await import('esbuild')\n\t\tconst response = await esbuild.build({\n\t\t\tentryPoints: [path],\n\t\t\tplatform: 'node',\n\t\t\tbundle: true,\n\t\t\ttreeShaking: true,\n\t\t\twrite: false,\n\t\t\tloader: { '.sql': 'text' },\n\t\t\texternal: ['@contember/admin', 'react', 'react/jsx-runtime'],\n\t\t})\n\t\treturn response.outputFiles[0].text\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAEO,MAAM,eAAoC;AAAA,EAChD,MAAM,MAAM,MAA+B;AAC1C,UAAM,UAAU,MAAM,OAAO,SAAS;AACtC,UAAM,WAAW,MAAM,QAAQ,MAAM;AAAA,MACpC,aAAa,CAAC,IAAI;AAAA,MAClB,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,OAAO;AAAA,MACP,QAAQ,EAAE,QAAQ,OAAA;AAAA,MAClB,UAAU,CAAC,oBAAoB,SAAS,mBAAmB;AAAA,IAAA,CAC3D;AACD,WAAO,SAAS,YAAY,CAAC,EAAE;AAAA,EAChC;AACD;;"}
1
+ {"version":3,"file":"EsBuildBuilder.cjs","sources":["../../../../../../packages/cli/src/lib/js/EsBuildBuilder.ts"],"sourcesContent":["import { JsBuilder } from './JsBuilder.js'\n\nexport class EsBuildBuilder implements JsBuilder {\n\tasync build(path: string): Promise<string> {\n\t\tconst esbuild = await import('esbuild')\n\t\tconst response = await esbuild.build({\n\t\t\tentryPoints: [path],\n\t\t\tplatform: 'node',\n\t\t\tbundle: true,\n\t\t\ttreeShaking: true,\n\t\t\twrite: false,\n\t\t\tloader: { '.sql': 'text' },\n\t\t\texternal: ['@contember/admin', 'react', 'react/jsx-runtime'],\n\t\t})\n\t\treturn response.outputFiles[0].text\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAEO,MAAM,eAAoC;AAAA,EAChD,MAAM,MAAM,MAA+B;AAC1C,UAAM,UAAU,MAAM,OAAO,SAAS;AACtC,UAAM,WAAW,MAAM,QAAQ,MAAM;AAAA,MACpC,aAAa,CAAC,IAAI;AAAA,MAClB,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,OAAO;AAAA,MACP,QAAQ,EAAE,QAAQ,OAAA;AAAA,MAClB,UAAU,CAAC,oBAAoB,SAAS,mBAAmB;AAAA,IAAA,CAC3D;AACD,WAAO,SAAS,YAAY,CAAC,EAAE;AAAA,EAChC;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"EsBuildBuilder.js","sources":["../../../../../../packages/cli/src/lib/js/EsBuildBuilder.ts"],"sourcesContent":["import { JsBuilder } from './JsBuilder'\n\nexport class EsBuildBuilder implements JsBuilder {\n\tasync build(path: string): Promise<string> {\n\t\tconst esbuild = await import('esbuild')\n\t\tconst response = await esbuild.build({\n\t\t\tentryPoints: [path],\n\t\t\tplatform: 'node',\n\t\t\tbundle: true,\n\t\t\ttreeShaking: true,\n\t\t\twrite: false,\n\t\t\tloader: { '.sql': 'text' },\n\t\t\texternal: ['@contember/admin', 'react', 'react/jsx-runtime'],\n\t\t})\n\t\treturn response.outputFiles[0].text\n\t}\n}\n"],"names":[],"mappings":"AAEO,MAAM,eAAoC;AAAA,EAChD,MAAM,MAAM,MAA+B;AAC1C,UAAM,UAAU,MAAM,OAAO,SAAS;AACtC,UAAM,WAAW,MAAM,QAAQ,MAAM;AAAA,MACpC,aAAa,CAAC,IAAI;AAAA,MAClB,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,OAAO;AAAA,MACP,QAAQ,EAAE,QAAQ,OAAA;AAAA,MAClB,UAAU,CAAC,oBAAoB,SAAS,mBAAmB;AAAA,IAAA,CAC3D;AACD,WAAO,SAAS,YAAY,CAAC,EAAE;AAAA,EAChC;AACD;"}
1
+ {"version":3,"file":"EsBuildBuilder.js","sources":["../../../../../../packages/cli/src/lib/js/EsBuildBuilder.ts"],"sourcesContent":["import { JsBuilder } from './JsBuilder.js'\n\nexport class EsBuildBuilder implements JsBuilder {\n\tasync build(path: string): Promise<string> {\n\t\tconst esbuild = await import('esbuild')\n\t\tconst response = await esbuild.build({\n\t\t\tentryPoints: [path],\n\t\t\tplatform: 'node',\n\t\t\tbundle: true,\n\t\t\ttreeShaking: true,\n\t\t\twrite: false,\n\t\t\tloader: { '.sql': 'text' },\n\t\t\texternal: ['@contember/admin', 'react', 'react/jsx-runtime'],\n\t\t})\n\t\treturn response.outputFiles[0].text\n\t}\n}\n"],"names":[],"mappings":"AAEO,MAAM,eAAoC;AAAA,EAChD,MAAM,MAAM,MAA+B;AAC1C,UAAM,UAAU,MAAM,OAAO,SAAS;AACtC,UAAM,WAAW,MAAM,QAAQ,MAAM;AAAA,MACpC,aAAa,CAAC,IAAI;AAAA,MAClB,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,OAAO;AAAA,MACP,QAAQ,EAAE,QAAQ,OAAA;AAAA,MAClB,UAAU,CAAC,oBAAoB,SAAS,mBAAmB;AAAA,IAAA,CAC3D;AACD,WAAO,SAAS,YAAY,CAAC,EAAE;AAAA,EAChC;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"EvalExecutor.cjs","sources":["../../../../../../packages/cli/src/lib/js/EvalExecutor.ts"],"sourcesContent":["import { JsExecutor } from './JsExecutor'\n\nexport class EvalExecutor implements JsExecutor {\n\tpublic async execute(code: string): Promise<unknown> {\n\t\tconst fn = new Function('require', `var module = {}; ((module) => { ${code} })(module); return module`)\n\t\treturn fn(require).exports\n\t}\n}\n"],"names":[],"mappings":";;AAEO,MAAM,aAAmC;AAAA,EAC/C,MAAa,QAAQ,MAAgC;AACpD,UAAM,KAAK,IAAI,SAAS,WAAW,mCAAmC,IAAI,4BAA4B;AACtG,WAAO,GAAG,OAAO,EAAE;AAAA,EACpB;AACD;;"}
1
+ {"version":3,"file":"EvalExecutor.cjs","sources":["../../../../../../packages/cli/src/lib/js/EvalExecutor.ts"],"sourcesContent":["import { JsExecutor } from './JsExecutor.js'\n\nexport class EvalExecutor implements JsExecutor {\n\tpublic async execute(code: string): Promise<unknown> {\n\t\tconst fn = new Function('require', `var module = {}; ((module) => { ${code} })(module); return module`)\n\t\treturn fn(require).exports\n\t}\n}\n"],"names":[],"mappings":";;AAEO,MAAM,aAAmC;AAAA,EAC/C,MAAa,QAAQ,MAAgC;AACpD,UAAM,KAAK,IAAI,SAAS,WAAW,mCAAmC,IAAI,4BAA4B;AACtG,WAAO,GAAG,OAAO,EAAE;AAAA,EACpB;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"EvalExecutor.js","sources":["../../../../../../packages/cli/src/lib/js/EvalExecutor.ts"],"sourcesContent":["import { JsExecutor } from './JsExecutor'\n\nexport class EvalExecutor implements JsExecutor {\n\tpublic async execute(code: string): Promise<unknown> {\n\t\tconst fn = new Function('require', `var module = {}; ((module) => { ${code} })(module); return module`)\n\t\treturn fn(require).exports\n\t}\n}\n"],"names":[],"mappings":"AAEO,MAAM,aAAmC;AAAA,EAC/C,MAAa,QAAQ,MAAgC;AACpD,UAAM,KAAK,IAAI,SAAS,WAAW,mCAAmC,IAAI,4BAA4B;AACtG,WAAO,GAAG,OAAO,EAAE;AAAA,EACpB;AACD;"}
1
+ {"version":3,"file":"EvalExecutor.js","sources":["../../../../../../packages/cli/src/lib/js/EvalExecutor.ts"],"sourcesContent":["import { JsExecutor } from './JsExecutor.js'\n\nexport class EvalExecutor implements JsExecutor {\n\tpublic async execute(code: string): Promise<unknown> {\n\t\tconst fn = new Function('require', `var module = {}; ((module) => { ${code} })(module); return module`)\n\t\treturn fn(require).exports\n\t}\n}\n"],"names":[],"mappings":"AAEO,MAAM,aAAmC;AAAA,EAC/C,MAAa,QAAQ,MAAgC;AACpD,UAAM,KAAK,IAAI,SAAS,WAAW,mCAAmC,IAAI,4BAA4B;AACtG,WAAO,GAAG,OAAO,EAAE;AAAA,EACpB;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"JsCodeRunner.cjs","sources":["../../../../../../packages/cli/src/lib/js/JsCodeRunner.ts"],"sourcesContent":["import { JsBuilder } from './JsBuilder'\nimport { JsExecutor } from './JsExecutor'\n\nexport class JsCodeRunner {\n\tconstructor(\n\t\tprivate readonly jsBuilder: JsBuilder,\n\t\tprivate readonly jsExecutor: JsExecutor,\n\t) {\n\t}\n\n\trun = async (path: string): Promise<unknown> => {\n\t\tconst builtCode = await this.jsBuilder.build(path)\n\t\treturn this.jsExecutor.execute(builtCode)\n\t}\n}\n"],"names":[],"mappings":";;;;;AAGO,MAAM,aAAa;AAAA,EACzB,YACkB,WACA,YAChB;AAFgB,SAAA,YAAA;AACA,SAAA,aAAA;AAIlB,kBAAA,MAAA,OAAM,OAAO,SAAmC;AAC/C,YAAM,YAAY,MAAM,KAAK,UAAU,MAAM,IAAI;AACjD,aAAO,KAAK,WAAW,QAAQ,SAAS;AAAA,IACzC,CAAA;AAAA,EALA;AAMD;;"}
1
+ {"version":3,"file":"JsCodeRunner.cjs","sources":["../../../../../../packages/cli/src/lib/js/JsCodeRunner.ts"],"sourcesContent":["import { JsBuilder } from './JsBuilder.js'\nimport { JsExecutor } from './JsExecutor.js'\n\nexport class JsCodeRunner {\n\tconstructor(\n\t\tprivate readonly jsBuilder: JsBuilder,\n\t\tprivate readonly jsExecutor: JsExecutor,\n\t) {\n\t}\n\n\trun = async (path: string): Promise<unknown> => {\n\t\tconst builtCode = await this.jsBuilder.build(path)\n\t\treturn this.jsExecutor.execute(builtCode)\n\t}\n}\n"],"names":[],"mappings":";;;;;AAGO,MAAM,aAAa;AAAA,EACzB,YACkB,WACA,YAChB;AAFgB,SAAA,YAAA;AACA,SAAA,aAAA;AAIlB,kBAAA,MAAA,OAAM,OAAO,SAAmC;AAC/C,YAAM,YAAY,MAAM,KAAK,UAAU,MAAM,IAAI;AACjD,aAAO,KAAK,WAAW,QAAQ,SAAS;AAAA,IACzC,CAAA;AAAA,EALA;AAMD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"JsCodeRunner.js","sources":["../../../../../../packages/cli/src/lib/js/JsCodeRunner.ts"],"sourcesContent":["import { JsBuilder } from './JsBuilder'\nimport { JsExecutor } from './JsExecutor'\n\nexport class JsCodeRunner {\n\tconstructor(\n\t\tprivate readonly jsBuilder: JsBuilder,\n\t\tprivate readonly jsExecutor: JsExecutor,\n\t) {\n\t}\n\n\trun = async (path: string): Promise<unknown> => {\n\t\tconst builtCode = await this.jsBuilder.build(path)\n\t\treturn this.jsExecutor.execute(builtCode)\n\t}\n}\n"],"names":[],"mappings":";;;AAGO,MAAM,aAAa;AAAA,EACzB,YACkB,WACA,YAChB;AAFgB,SAAA,YAAA;AACA,SAAA,aAAA;AAIlB,kBAAA,MAAA,OAAM,OAAO,SAAmC;AAC/C,YAAM,YAAY,MAAM,KAAK,UAAU,MAAM,IAAI;AACjD,aAAO,KAAK,WAAW,QAAQ,SAAS;AAAA,IACzC,CAAA;AAAA,EALA;AAMD;"}
1
+ {"version":3,"file":"JsCodeRunner.js","sources":["../../../../../../packages/cli/src/lib/js/JsCodeRunner.ts"],"sourcesContent":["import { JsBuilder } from './JsBuilder.js'\nimport { JsExecutor } from './JsExecutor.js'\n\nexport class JsCodeRunner {\n\tconstructor(\n\t\tprivate readonly jsBuilder: JsBuilder,\n\t\tprivate readonly jsExecutor: JsExecutor,\n\t) {\n\t}\n\n\trun = async (path: string): Promise<unknown> => {\n\t\tconst builtCode = await this.jsBuilder.build(path)\n\t\treturn this.jsExecutor.execute(builtCode)\n\t}\n}\n"],"names":[],"mappings":";;;AAGO,MAAM,aAAa;AAAA,EACzB,YACkB,WACA,YAChB;AAFgB,SAAA,YAAA;AACA,SAAA,aAAA;AAIlB,kBAAA,MAAA,OAAM,OAAO,SAAmC;AAC/C,YAAM,YAAY,MAAM,KAAK,UAAU,MAAM,IAAI;AACjD,aAAO,KAAK,WAAW,QAAQ,SAAS;AAAA,IACzC,CAAA;AAAA,EALA;AAMD;"}
@@ -7,7 +7,7 @@ var __defProp = Object.defineProperty;
7
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
8
  var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
9
9
  class MigrationExecutionFacade {
10
- constructor(systemClientProvider, tenantClientProvider, projectProvider, schemaVersionBuilder, migrationPrinter, migrationExecutor, migrationStatusFacade) {
10
+ constructor(systemClientProvider, tenantClientProvider, projectProvider, schemaVersionBuilder, migrationPrinter, migrationExecutor, migrationStatusFacade, schemaStateManager, migrationSnapshotFacade) {
11
11
  this.systemClientProvider = systemClientProvider;
12
12
  this.tenantClientProvider = tenantClientProvider;
13
13
  this.projectProvider = projectProvider;
@@ -15,24 +15,43 @@ class MigrationExecutionFacade {
15
15
  this.migrationPrinter = migrationPrinter;
16
16
  this.migrationExecutor = migrationExecutor;
17
17
  this.migrationStatusFacade = migrationStatusFacade;
18
+ this.schemaStateManager = schemaStateManager;
19
+ this.migrationSnapshotFacade = migrationSnapshotFacade;
18
20
  __publicField(this, "execute", async ({
19
21
  requireConfirmation,
20
22
  force,
21
23
  until,
22
- additionalMessage
24
+ additionalMessage,
25
+ useSnapshot = true
23
26
  }) => {
24
27
  const project = this.projectProvider.get();
25
28
  await this.tenantClientProvider.get().createProject(project.name, true);
29
+ const stateMode = await this.schemaStateManager.isStateMode();
30
+ let schemaState = stateMode ? await this.schemaStateManager.readState() : void 0;
31
+ if (until && schemaState) {
32
+ console.log(
33
+ "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."
34
+ );
35
+ schemaState = void 0;
36
+ }
37
+ if (useSnapshot) {
38
+ await this.tryApplySnapshot({ until, schemaState });
39
+ }
26
40
  const status = await this.migrationStatusFacade.resolveMigrationsStatus({ force });
27
41
  const migrations = until ? status.migrationsToExecute.filter((it) => it.version <= engineCommon.MigrationVersionHelper.extractVersion(until)) : status.migrationsToExecute;
28
- if (migrations.length === 0) {
42
+ if (migrations.length === 0 && !schemaState) {
29
43
  console.log("No migrations to execute");
30
44
  return true;
31
45
  }
32
- console.log("Will execute following migrations:");
33
- migrations.forEach((it) => console.log(it.name));
46
+ if (migrations.length > 0) {
47
+ console.log("Will execute following migrations:");
48
+ migrations.forEach((it) => console.log(it.name));
49
+ }
50
+ if (schemaState && migrations.length === 0) {
51
+ console.log("Updating schema state");
52
+ }
34
53
  additionalMessage && console.log(additionalMessage);
35
- if (typeof requireConfirmation === "function" ? requireConfirmation(migrations) : requireConfirmation) {
54
+ if (migrations.length > 0 && (typeof requireConfirmation === "function" ? requireConfirmation(migrations) : requireConfirmation)) {
36
55
  if (!process.stdin.isTTY) {
37
56
  throw "TTY not available. Pass --yes option to confirm execution.";
38
57
  }
@@ -65,21 +84,62 @@ class MigrationExecutionFacade {
65
84
  }
66
85
  } while (true);
67
86
  }
68
- await this.migrationExecutor.executeMigrations({
69
- client: this.systemClientProvider.get(),
70
- migrations,
71
- contentMigrationFactoryArgs: {
72
- apiToken: project.token,
73
- apiBaseUrl: project.endpoint,
74
- projectName: project.name,
75
- schemaVersionBuilder: this.schemaVersionBuilder
76
- },
77
- log: (message) => console.log(message),
78
- force
79
- });
87
+ try {
88
+ await this.migrationExecutor.executeMigrations({
89
+ client: this.systemClientProvider.get(),
90
+ migrations,
91
+ schemaState,
92
+ contentMigrationFactoryArgs: {
93
+ apiToken: project.token,
94
+ apiBaseUrl: project.endpoint,
95
+ projectName: project.name,
96
+ schemaVersionBuilder: this.schemaVersionBuilder
97
+ },
98
+ log: (message) => console.log(message),
99
+ force
100
+ });
101
+ } catch (e) {
102
+ if (isViewReplaceFailure(e)) {
103
+ console.error(
104
+ "\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"
105
+ );
106
+ }
107
+ throw e;
108
+ }
80
109
  return true;
81
110
  });
82
111
  }
112
+ async tryApplySnapshot({ until, schemaState }) {
113
+ const executed = await this.systemClientProvider.get().listExecutedMigrations();
114
+ const snapshot = await this.migrationSnapshotFacade.getUsableSnapshot(executed);
115
+ if (!snapshot) {
116
+ return;
117
+ }
118
+ if (until && snapshot.version > engineCommon.MigrationVersionHelper.extractVersion(until)) {
119
+ return;
120
+ }
121
+ console.log(`Bootstrapping from snapshot (collapses ${snapshot.covers.length} migrations up to ${snapshot.version})`);
122
+ if (snapshot.contentMigrations.length > 0) {
123
+ console.warn(
124
+ `Note: ${snapshot.contentMigrations.length} content migration(s) are covered by the snapshot; their data is NOT reproduced.`
125
+ );
126
+ }
127
+ const input = await this.migrationSnapshotFacade.buildSnapshotInput(snapshot);
128
+ try {
129
+ await this.systemClientProvider.get().migrateFromSnapshot(input, schemaState);
130
+ } catch (e) {
131
+ if (isProjectNotEmptyError(e)) {
132
+ console.warn("Snapshot skipped: the project is no longer empty. Falling back to a full replay.");
133
+ return;
134
+ }
135
+ throw e;
136
+ }
137
+ console.log("Snapshot applied");
138
+ }
83
139
  }
140
+ const isProjectNotEmptyError = (e) => Array.isArray(e) && e.some((it) => it !== null && typeof it === "object" && it.code === migrationsClient.MigrateErrorCode.ProjectNotEmpty);
141
+ const isViewReplaceFailure = (e) => Array.isArray(e) && e.some(
142
+ (it) => it !== null && typeof it === "object" && it.code === migrationsClient.MigrateErrorCode.MigrationFailed && typeof it.message === "string" && it.message.includes("CREATE OR REPLACE VIEW")
143
+ );
84
144
  exports.MigrationExecutionFacade = MigrationExecutionFacade;
85
145
  //# sourceMappingURL=MigrationExecutionFacade.cjs.map
@@ -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,uBAAuB,eAAe,KAAK,CAAC,IAClG,OAAO;AACV,UA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rB,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,oBAAoB,OAAO,CAAA,OAAM,GAAG,WAAWA,aAAAA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,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 VIEW')\n\t)\n"],"names":[],"mappings":";;;;;;AAkBO,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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","MigrationState","assertNever"],"mappings":";;;;;;;;;;AASO,MAAM,iB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;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,YAAI,QAAQ,SAAS;AACpB,cAAI,IAAI,QAAQ;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,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,GAAG;AAAA,YAChB,OAAO;AACN,sBAAQ,IAAI,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ources":["../../../../../../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;AAAA,EAC7B,YACkB,qBAChB;AADgB,SAAA,sBAAA;A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AG;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;"}