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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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":"DeployCommand.js","sources":["../../../../../../packages/cli/src/commands/deploy/DeployCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport prompts from 'prompts'\nimport { maskToken } from '../../lib/maskToken'\nimport { MigrationExecutionFacade } from '../../lib/migrations/MigrationExecutionFacade'\nimport { AdminDeployer } from '../../lib/admin/AdminDeployer'\nimport { FileSystem } from '../../lib/fs/FileSystem'\nimport { RemoteProject } from '../../lib/project/RemoteProject'\nimport { Workspace } from '../../lib/workspace/Workspace'\nimport { RemoteProjectProvider } from '../../lib/project/RemoteProjectProvider'\nimport { RemoteProjectResolver } from '../../lib/project/RemoteProjectResolver'\n\ntype Args = {\n\tdsn?: string\n}\n\ntype Options = {\n\tadmin?: string\n\t['no-admin']?: boolean\n\t['no-migrations']?: boolean\n\troot?: boolean\n\tyes?: boolean\n}\n\nexport class DeployCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly adminDeployer: AdminDeployer,\n\t\tprivate readonly migrationExecutionFacade: MigrationExecutionFacade,\n\t\tprivate readonly fs: FileSystem,\n\t\tprivate readonly remoteProjectProvider: RemoteProjectProvider,\n\t\tprivate readonly remoteProjectResolver: RemoteProjectResolver,\n\t\tprivate readonly workspace: Workspace,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Deploy Contember project')\n\t\tconfiguration.argument('dsn').optional()\n\n\t\tconfiguration.option('admin').valueRequired()\n\t\tconfiguration.option('root').valueNone()\n\t\tconfiguration.option('no-admin').valueNone()\n\t\tconfiguration.option('no-migrations').valueNone()\n\t\tconfiguration //\n\t\t\t.option('yes')\n\t\t\t.valueNone()\n\t\t\t.description('Do not ask for confirmation.')\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<void | number> {\n\t\tconst dsn = input.getArgument('dsn')\n\t\tconst adminEndpoint = input.getOption('admin')\n\t\tconst remoteProject = this.remoteProjectResolver.resolve(dsn, adminEndpoint)\n\t\tif (!remoteProject) {\n\t\t\tthrow `Project not defined. Please provide DSN or environment variables CONTEMBER_*`\n\t\t}\n\t\tthis.remoteProjectProvider.setRemoteProject(remoteProject)\n\n\t\tconst deployMigration = input.getOption('no-migrations') !== true\n\t\tconst yes = input.getOption('yes') === true\n\t\tconst projectAdminDistDir = this.workspace.adminDistDir\n\n\t\tconst deployAdmin = input.getOption('no-admin') !== true && !!remoteProject.adminEndpoint && !!projectAdminDistDir\n\n\t\tconsole.log('')\n\t\tconsole.log('Contember project deployment configuration:')\n\t\tconsole.log(`Target project name: ${remoteProject.name}`)\n\t\tconsole.log(`API URL: ${remoteProject.endpoint}`)\n\t\tconsole.log(`Admin URL: ${remoteProject.adminEndpoint ?? 'none'}`)\n\t\tconsole.log(`Deploy token: ${maskToken(remoteProject.token)}`)\n\t\tconsole.log('')\n\n\t\tif (deployAdmin && !(await this.fs.pathExists(`${projectAdminDistDir}/index.html`))) {\n\t\t\tthrow `Missing ${projectAdminDistDir}/index.html. Please build admin before deploying.`\n\t\t}\n\n\t\tif (deployMigration) {\n\t\t\tconst result = await this.migrationExecutionFacade.execute({\n\t\t\t\tforce: false,\n\t\t\t\trequireConfirmation: !yes,\n\t\t\t\tadditionalMessage: deployAdmin ? 'Admin will be deployed.' : 'Admin will NOT be deployed.',\n\t\t\t})\n\t\t\tif (!result) {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tif (deployAdmin) {\n\t\t\tif (!deployMigration && !yes) {\n\t\t\t\tif (!process.stdin.isTTY) {\n\t\t\t\t\tthrow 'TTY not available. Pass --yes option to confirm execution.'\n\t\t\t\t}\n\t\t\t\tconsole.log('Admin will be deployed.')\n\t\t\t\tconsole.log('(to skip this dialog, you can pass --yes option)')\n\t\t\t\tconsole.log('')\n\t\t\t\tconst { ok } = await prompts({\n\t\t\t\t\ttype: 'confirm',\n\t\t\t\t\tname: 'ok',\n\t\t\t\t\tmessage: `Do you want to continue?`,\n\t\t\t\t})\n\t\t\t\tif (!ok) {\n\t\t\t\t\treturn 1\n\t\t\t\t}\n\t\t\t}\n\t\t\tawait this.adminDeployer.deploy({\n\t\t\t\tdir: projectAdminDistDir,\n\t\t\t\troot: input.getOption('root') === true,\n\t\t\t})\n\t\t}\n\n\t\tconsole.log('')\n\t\tconsole.log('Deployment successful')\n\t\tconsole.log(`API URL: ${remoteProject.endpoint}`)\n\t\tconsole.log(`Admin URL: ${remoteProject.adminEndpoint ?? 'none'}`)\n\n\t\treturn 0\n\t}\n}\n"],"names":[],"mappings":";;;AAuBO,MAAM,sBAAsB,QAAuB;AAAA,EACzD,YACkB,eACA,0BACA,IACA,uBACA,uBACA,WAChB;AACD,UAAA;AAPiB,SAAA,gBAAA;AACA,SAAA,2BAAA;AACA,SAAA,KAAA;AACA,SAAA,wBAAA;AACA,SAAA,wBAAA;AACA,SAAA,YAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,0BAA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B,mBAAmB,cAAc,4BAA4B;AAAA,MAAA,CAC7D;AACD,UAAI,CAAC,QAAQ;AACZ;AAAA,MACD;AAAA,IACD;AAEA,QAAI,aAAa;AAChB,UAAI,CAAC,mBAAmB,CAAC,KAAK;AAC7B,YAAI,CAAC,QAAQ,MAAM,OAAO;AACzB,gBAAM;AAAA,QACP;AACA,gBAAQ,IAAI,yBAAyB;AACrC,gBAAQ,IAAI,kDAAkD;AAC9D,gBAAQ,IAAI,EAAE;AACd,cAAM,EAAE,OAAO,MAAM,QAAQ;AAAA,UAC5B,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,QAAA,CACT;AACD,YAAI,CAAC,IAAI;AACR,iBAAO;AAAA,QACR;AAAA,MACD;AACA,YAAM,KAAK,cAAc,OAAO;AAAA,QAC/B,KAAK;AAAA,QACL,MAAM,MAAM,UAAU,MAAM,MAAM;AAAA,MAAA,CAClC;AAAA,IACF;AAEA,YAAQ,IAAI,EAAE;AACd,YAAQ,IAAI,uBAAuB;AACnC,YAAQ,IAAI,YAAY,cAAc,QAAQ,EAAE;AAChD,YAAQ,IAAI,cAAc,cAAc,iBAAiB,MAAM,EAAE;AAEjE,WAAO;AAAA,EACR;AACD;"}
1
+ {"version":3,"file":"DeployCommand.js","sources":["../../../../../../packages/cli/src/commands/deploy/DeployCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport prompts from 'prompts'\nimport { maskToken } from '../../lib/maskToken.js'\nimport { MigrationExecutionFacade } from '../../lib/migrations/MigrationExecutionFacade.js'\nimport { AdminDeployer } from '../../lib/admin/AdminDeployer.js'\nimport { FileSystem } from '../../lib/fs/FileSystem.js'\nimport { RemoteProject } from '../../lib/project/RemoteProject.js'\nimport { Workspace } from '../../lib/workspace/Workspace.js'\nimport { RemoteProjectProvider } from '../../lib/project/RemoteProjectProvider.js'\nimport { RemoteProjectResolver } from '../../lib/project/RemoteProjectResolver.js'\n\ntype Args = {\n\tdsn?: string\n}\n\ntype Options = {\n\tadmin?: string\n\t['no-admin']?: boolean\n\t['no-migrations']?: boolean\n\troot?: boolean\n\tyes?: boolean\n\tsnapshot?: boolean\n}\n\nexport class DeployCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly adminDeployer: AdminDeployer,\n\t\tprivate readonly migrationExecutionFacade: MigrationExecutionFacade,\n\t\tprivate readonly fs: FileSystem,\n\t\tprivate readonly remoteProjectProvider: RemoteProjectProvider,\n\t\tprivate readonly remoteProjectResolver: RemoteProjectResolver,\n\t\tprivate readonly workspace: Workspace,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Deploy Contember project')\n\t\tconfiguration.argument('dsn').optional()\n\n\t\tconfiguration.option('admin').valueRequired()\n\t\tconfiguration.option('root').valueNone()\n\t\tconfiguration.option('no-admin').valueNone()\n\t\tconfiguration.option('no-migrations').valueNone()\n\t\tconfiguration.option('snapshot')\n\t\t\t.valueNone()\n\t\t\t.description('Bootstrap an empty target database from snapshot.json instead of replaying every migration')\n\t\tconfiguration //\n\t\t\t.option('yes')\n\t\t\t.valueNone()\n\t\t\t.description('Do not ask for confirmation.')\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<void | number> {\n\t\tconst dsn = input.getArgument('dsn')\n\t\tconst adminEndpoint = input.getOption('admin')\n\t\tconst remoteProject = this.remoteProjectResolver.resolve(dsn, adminEndpoint)\n\t\tif (!remoteProject) {\n\t\t\tthrow `Project not defined. Please provide DSN or environment variables CONTEMBER_*`\n\t\t}\n\t\tthis.remoteProjectProvider.setRemoteProject(remoteProject)\n\n\t\tconst deployMigration = input.getOption('no-migrations') !== true\n\t\tconst yes = input.getOption('yes') === true\n\t\tconst projectAdminDistDir = this.workspace.adminDistDir\n\n\t\tconst deployAdmin = input.getOption('no-admin') !== true && !!remoteProject.adminEndpoint && !!projectAdminDistDir\n\n\t\tconsole.log('')\n\t\tconsole.log('Contember project deployment configuration:')\n\t\tconsole.log(`Target project name: ${remoteProject.name}`)\n\t\tconsole.log(`API URL: ${remoteProject.endpoint}`)\n\t\tconsole.log(`Admin URL: ${remoteProject.adminEndpoint ?? 'none'}`)\n\t\tconsole.log(`Deploy token: ${maskToken(remoteProject.token)}`)\n\t\tconsole.log('')\n\n\t\tif (deployAdmin && !(await this.fs.pathExists(`${projectAdminDistDir}/index.html`))) {\n\t\t\tthrow `Missing ${projectAdminDistDir}/index.html. Please build admin before deploying.`\n\t\t}\n\n\t\tif (deployMigration) {\n\t\t\tconst result = await this.migrationExecutionFacade.execute({\n\t\t\t\tforce: false,\n\t\t\t\trequireConfirmation: !yes,\n\t\t\t\tadditionalMessage: deployAdmin ? 'Admin will be deployed.' : 'Admin will NOT be deployed.',\n\t\t\t\tuseSnapshot: input.getOption('snapshot') === true,\n\t\t\t})\n\t\t\tif (!result) {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tif (deployAdmin) {\n\t\t\tif (!deployMigration && !yes) {\n\t\t\t\tif (!process.stdin.isTTY) {\n\t\t\t\t\tthrow 'TTY not available. Pass --yes option to confirm execution.'\n\t\t\t\t}\n\t\t\t\tconsole.log('Admin will be deployed.')\n\t\t\t\tconsole.log('(to skip this dialog, you can pass --yes option)')\n\t\t\t\tconsole.log('')\n\t\t\t\tconst { ok } = await prompts({\n\t\t\t\t\ttype: 'confirm',\n\t\t\t\t\tname: 'ok',\n\t\t\t\t\tmessage: `Do you want to continue?`,\n\t\t\t\t})\n\t\t\t\tif (!ok) {\n\t\t\t\t\treturn 1\n\t\t\t\t}\n\t\t\t}\n\t\t\tawait this.adminDeployer.deploy({\n\t\t\t\tdir: projectAdminDistDir,\n\t\t\t\troot: input.getOption('root') === true,\n\t\t\t})\n\t\t}\n\n\t\tconsole.log('')\n\t\tconsole.log('Deployment successful')\n\t\tconsole.log(`API URL: ${remoteProject.endpoint}`)\n\t\tconsole.log(`Admin URL: ${remoteProject.adminEndpoint ?? 'none'}`)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@contember/schema-migrations");
5
5
  const prompts = require("prompts");
6
6
  const schemaUtils = require("@contember/schema-utils");
7
+ const migrationsClient = require("@contember/migrations-client");
7
8
  const SchemaValidationPrinter = require("../../lib/schema/SchemaValidationPrinter.cjs");
8
9
  class MigrationAmendCommand extends cliCommon.Command {
9
- constructor(migrationsResolver, systemApiClientProvider, migrationsStatusFacade, schemaLoader, schemaVersionBuilder, migrationCreator, migrationsValidator, migrationPrinter, schemaMigrator) {
10
+ constructor(migrationsResolver, systemApiClientProvider, migrationsStatusFacade, schemaLoader, schemaVersionBuilder, migrationCreator, migrationsValidator, migrationPrinter, schemaMigrator, schemaStateManager) {
10
11
  super();
11
12
  this.migrationsResolver = migrationsResolver;
12
13
  this.systemApiClientProvider = systemApiClientProvider;
@@ -17,6 +18,7 @@ class MigrationAmendCommand extends cliCommon.Command {
17
18
  this.migrationsValidator = migrationsValidator;
18
19
  this.migrationPrinter = migrationPrinter;
19
20
  this.schemaMigrator = schemaMigrator;
21
+ this.schemaStateManager = schemaStateManager;
20
22
  }
21
23
  configure(configuration) {
22
24
  configuration.description("Amends latest migration");
@@ -36,11 +38,21 @@ class MigrationAmendCommand extends cliCommon.Command {
36
38
  throw `Some migrations are not executed. Unable to amend.`;
37
39
  }
38
40
  const schema = await this.schemaLoader.loadSchema();
41
+ const stateMode = await this.schemaStateManager.isStateMode();
39
42
  try {
40
43
  const initialSchema = await this.schemaVersionBuilder.buildSchema();
41
- const intermediateResult = await this.migrationCreator.prepareMigration(initialSchema, schema, "");
44
+ const intermediateResult = await this.migrationCreator.prepareMigration(initialSchema, schema, "", {
45
+ skipNonModelDiffers: stateMode
46
+ });
47
+ const schemaState = stateMode ? migrationsClient.SchemaStateManager.schemaStateFromSchema(schema) : void 0;
48
+ const stateChanged = schemaState ? await this.schemaStateManager.writeState(schemaState, { dryRun: true }) : false;
42
49
  if (intermediateResult === null) {
43
- console.log("Nothing to do");
50
+ if (stateChanged) {
51
+ await this.schemaStateManager.writeState(schemaState);
52
+ console.log("Schema state updated (no model changes)");
53
+ } else {
54
+ console.log("Nothing to do");
55
+ }
44
56
  return 0;
45
57
  }
46
58
  if (amendMigration.formatVersion !== intermediateResult.migration.formatVersion) {
@@ -55,7 +67,9 @@ class MigrationAmendCommand extends cliCommon.Command {
55
67
  [...amendMigration.modifications, ...intermediateResult.migration.modifications],
56
68
  amendMigration.formatVersion
57
69
  );
58
- const newMigrationResult = await this.migrationCreator.prepareMigration(prevSchema, newSchema, "");
70
+ const newMigrationResult = await this.migrationCreator.prepareMigration(prevSchema, newSchema, "", {
71
+ skipNonModelDiffers: stateMode
72
+ });
59
73
  const followingMigrations = (await this.migrationsResolver.getSchemaMigrations()).filter(
60
74
  (it) => it.version > amendMigration.version
61
75
  );
@@ -82,6 +96,10 @@ class MigrationAmendCommand extends cliCommon.Command {
82
96
  if (!newMigrationResult && await this.shouldRemove()) {
83
97
  await this.migrationCreator.removeMigration(amendMigration.name);
84
98
  await systemClient.migrationDelete(amendMigration.version);
99
+ if (schemaState) {
100
+ await this.schemaStateManager.writeState(schemaState);
101
+ await systemClient.migrate([], force, schemaState);
102
+ }
85
103
  console.log("Latest migration was removed");
86
104
  return 0;
87
105
  }
@@ -93,6 +111,10 @@ class MigrationAmendCommand extends cliCommon.Command {
93
111
  };
94
112
  await this.migrationCreator.saveMigration(newMigration);
95
113
  await systemClient.migrationModify(amendMigration.version, newMigration);
114
+ if (schemaState) {
115
+ await this.schemaStateManager.writeState(schemaState);
116
+ await systemClient.migrate([], force, schemaState);
117
+ }
96
118
  return 0;
97
119
  } catch (e) {
98
120
  if (e instanceof schemaMigrations.InvalidSchemaException) {
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationAmendCommand.cjs","sources":["../../../../../../packages/cli/src/commands/migrations/MigrationAmendCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { InvalidSchemaException, SchemaMigrator } from '@contember/schema-migrations'\nimport prompts from 'prompts'\nimport { emptySchema } from '@contember/schema-utils'\nimport { MigrationCreator, MigrationsResolver, SchemaVersionBuilder, SystemClient } from '@contember/migrations-client'\nimport { MigrationsStatusFacade } from '../../lib/migrations/MigrationsStatusFacade'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader'\nimport { MigrationsValidator } from '../../lib/migrations/MigrationsValidator'\nimport { MigrationPrinter } from '../../lib/migrations/MigrationPrinter'\nimport { printValidationErrors } from '../../lib/schema/SchemaValidationPrinter'\nimport { SystemClientProvider } from '../../lib/SystemClientProvider'\n\ntype Args = {\n\tmigration?: string\n}\n\ntype Options = {\n\tyes?: true\n\tforce: boolean\n}\n\nexport class MigrationAmendCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t\tprivate readonly systemApiClientProvider: SystemClientProvider,\n\t\tprivate readonly migrationsStatusFacade: MigrationsStatusFacade,\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationCreator: MigrationCreator,\n\t\tprivate readonly migrationsValidator: MigrationsValidator,\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Amends latest migration')\n\t\tconfiguration.argument('migration').optional()\n\t\tconfiguration.option('force').description('Ignore migrations order and missing migrations (dev only)')\n\t\tconfiguration //\n\t\t\t.option('yes')\n\t\t\t.valueNone()\n\t\t\t.description('Do not ask for confirmation.')\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<number> {\n\t\tconst migrationName = input.getArgument('migration')\n\t\tconst amendMigration = migrationName\n\t\t\t? await this.migrationsResolver.findSchemaMigrationByVersion(migrationName)\n\t\t\t: await this.migrationsResolver.findLatestSchemaMigration()\n\t\tif (!amendMigration) {\n\t\t\tthrow 'No migration to amend'\n\t\t}\n\t\tconst force = input.getOption('force')\n\t\tconst status = await this.migrationsStatusFacade.resolveMigrationsStatus({ force })\n\t\tif (status.migrationsToExecute.length > 0) {\n\t\t\tthrow `Some migrations are not executed. Unable to amend.`\n\t\t}\n\n\t\tconst schema = await this.schemaLoader.loadSchema()\n\t\ttry {\n\t\t\tconst initialSchema = await this.schemaVersionBuilder.buildSchema()\n\t\t\tconst intermediateResult = await this.migrationCreator.prepareMigration(initialSchema, schema, '')\n\t\t\tif (intermediateResult === null) {\n\t\t\t\tconsole.log('Nothing to do')\n\t\t\t\treturn 0\n\t\t\t}\n\t\t\tif (amendMigration.formatVersion !== intermediateResult.migration.formatVersion) {\n\t\t\t\tthrow 'Incompatible migration format version'\n\t\t\t}\n\t\t\tconst prevSchema = await this.schemaVersionBuilder.buildSchemaAdvanced(\n\t\t\t\temptySchema,\n\t\t\t\tversion => version < amendMigration.version,\n\t\t\t)\n\t\t\tconst newSchema = await this.schemaMigrator.applyModifications(\n\t\t\t\tprevSchema,\n\t\t\t\t[...amendMigration.modifications, ...intermediateResult.migration.modifications],\n\t\t\t\tamendMigration.formatVersion,\n\t\t\t)\n\t\t\tconst newMigrationResult = await this.migrationCreator.prepareMigration(prevSchema, newSchema, '')\n\t\t\tconst followingMigrations = (await this.migrationsResolver.getSchemaMigrations()).filter(\n\t\t\t\tit => it.version > amendMigration.version,\n\t\t\t)\n\n\t\t\tconst valid = await this.migrationsValidator.validate(\n\t\t\t\tprevSchema,\n\t\t\t\t[...(newMigrationResult ? [newMigrationResult.migration] : []), ...followingMigrations],\n\t\t\t)\n\t\t\tif (!valid) {\n\t\t\t\tthrow `Cannot amend migration`\n\t\t\t}\n\n\t\t\tthis.migrationPrinter.printMigrationDescription(\n\t\t\t\tintermediateResult.initialSchema,\n\t\t\t\tintermediateResult.migration,\n\t\t\t\t{ noSql: true },\n\t\t\t)\n\t\t\tconsole.log(`Amending ${amendMigration.name}`)\n\t\t\tif (!(await this.shouldContinue(input))) {\n\t\t\t\tconsole.log('Aborting')\n\t\t\t\treturn 1\n\t\t\t}\n\t\t\tconst systemClient = this.systemApiClientProvider.get()\n\t\t\tawait systemClient.migrate([intermediateResult.migration], force)\n\t\t\tawait systemClient.migrationDelete(intermediateResult.migration.version)\n\n\t\t\tif (!newMigrationResult && await this.shouldRemove()) {\n\t\t\t\tawait this.migrationCreator.removeMigration(amendMigration.name)\n\t\t\t\tawait systemClient.migrationDelete(amendMigration.version)\n\t\t\t\tconsole.log('Latest migration was removed')\n\t\t\t\treturn 0\n\t\t\t}\n\t\t\tconst newMigration = {\n\t\t\t\tname: amendMigration.name,\n\t\t\t\tversion: amendMigration.version,\n\t\t\t\tformatVersion: newMigrationResult?.migration.formatVersion ?? amendMigration.formatVersion,\n\t\t\t\tmodifications: newMigrationResult?.migration.modifications ?? [],\n\t\t\t}\n\t\t\tawait this.migrationCreator.saveMigration(newMigration)\n\t\t\tawait systemClient.migrationModify(amendMigration.version, newMigration)\n\n\t\t\treturn 0\n\t\t} catch (e) {\n\t\t\tif (e instanceof InvalidSchemaException) {\n\t\t\t\tprintValidationErrors(e.validationErrors, e.message)\n\t\t\t\treturn 1\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n\n\tprivate async shouldContinue(input: Input<{}, { yes?: true }>): Promise<boolean> {\n\t\tconst yes = input.getOption('yes')\n\t\tif (yes) {\n\t\t\treturn true\n\t\t}\n\t\tconst { action } = await prompts({\n\t\t\ttype: 'select',\n\t\t\tname: 'action',\n\t\t\tmessage: 'Do you want to continue?',\n\t\t\tchoices: [\n\t\t\t\t{ value: 'yes', title: 'Yes' },\n\t\t\t\t{ value: 'no', title: 'Abort' },\n\t\t\t],\n\t\t})\n\t\treturn action === 'yes'\n\t}\n\n\tprivate async shouldRemove(): Promise<boolean> {\n\t\tconst { action } = await prompts({\n\t\t\ttype: 'select',\n\t\t\tname: 'action',\n\t\t\tmessage:\n\t\t\t\t'The amendment results in a no-op migration because the changes introduced by the latest migration were reverted.\\nYou can choose to remove the latest migration or to modify it so it is empty.',\n\t\t\tchoices: [\n\t\t\t\t{ value: 'remove', title: 'Remove latest migration' },\n\t\t\t\t{ value: 'keep', title: 'Keep latest migration and make it empty' },\n\t\t\t],\n\t\t})\n\t\treturn action === 'remove'\n\t}\n}\n"],"names":["Command","emptySchema","InvalidSchemaException","printValidationErrors"],"mappings":";;;;;;;AAqBO,MAAM,8BAA8BA,UAAAA,QAAuB;AAAA,EACjE,YACkB,oBACA,yBACA,wBACA,cACA,sBACA,kBACA,qBACA,kBACA,gBAChB;AACD,UAAA;AAViB,SAAA,qBAAA;AACA,SAAA,0BAAA;AACA,SAAA,yBAAA;AACA,SAAA,eAAA;AACA,SAAA,uBAAA;AACA,SAAA,mBAAA;AACA,SAAA,sBAAA;AACA,SAAA,mBAAA;AACA,SAAA,iBAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,yBAAyB;AACnD,kBAAc,SAAS,WAAW,EAAE,SAAA;AACpC,kBAAc,OAAO,OAAO,EAAE,YAAY,2DAA2D;AACrG,kBACE,OAAO,KAAK,EACZ,UAAA,EACA,YAAY,8BAA8B;AAAA,EAC7C;AAAA,EAEA,MAAgB,QAAQ,OAA8C;AACrE,UAAM,gBAAgB,MAAM,YAAY,WAAW;AACnD,UAAM,iBAAiB,gBACpB,MAAM,KAAK,mBAAmB,6BAA6B,aAAa,IACxE,MAAM,KAAK,mBAAmB,0BAAA;AACjC,QAAI,CAAC,gBAAgB;AACpB,YAAM;AAAA,IACP;AACA,UAAM,QAAQ,MAAM,UAAU,OAAO;AACrC,UAAM,SAAS,MAAM,KAAK,uBAAuB,wBAAwB,EAAE,OAAO;AAClF,QAAI,OAAO,oBAAoB,SAAS,GAAG;AAC1C,YAAM;AAAA,IACP;AAEA,UAAM,SAAS,MAAM,KAAK,aAAa,WAAA;AACvC,QAAI;AACH,YAAM,gBAAgB,MAAM,KAAK,qBAAqB,YAAA;AACtD,YAAM,qBAAqB,MAAM,KAAK,iBAAiB,iBAA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and.cjs","sources":["../../../../../../packages/cli/src/commands/migrations/MigrationAmendCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { InvalidSchemaException, SchemaMigrator } from '@contember/schema-migrations'\nimport prompts from 'prompts'\nimport { emptySchema } from '@contember/schema-utils'\nimport { MigrationCreator, MigrationsResolver, SchemaStateManager, SchemaVersionBuilder } from '@contember/migrations-client'\nimport { MigrationsStatusFacade } from '../../lib/migrations/MigrationsStatusFacade.js'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader.js'\nimport { MigrationsValidator } from '../../lib/migrations/MigrationsValidator.js'\nimport { MigrationPrinter } from '../../lib/migrations/MigrationPrinter.js'\nimport { printValidationErrors } from '../../lib/schema/SchemaValidationPrinter.js'\nimport { SystemClientProvider } from '../../lib/SystemClientProvider.js'\n\ntype Args = {\n\tmigration?: string\n}\n\ntype Options = {\n\tyes?: true\n\tforce: boolean\n}\n\nexport class MigrationAmendCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t\tprivate readonly systemApiClientProvider: SystemClientProvider,\n\t\tprivate readonly migrationsStatusFacade: MigrationsStatusFacade,\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationCreator: MigrationCreator,\n\t\tprivate readonly migrationsValidator: MigrationsValidator,\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Amends latest migration')\n\t\tconfiguration.argument('migration').optional()\n\t\tconfiguration.option('force').description('Ignore migrations order and missing migrations (dev only)')\n\t\tconfiguration //\n\t\t\t.option('yes')\n\t\t\t.valueNone()\n\t\t\t.description('Do not ask for confirmation.')\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<number> {\n\t\tconst migrationName = input.getArgument('migration')\n\t\tconst amendMigration = migrationName\n\t\t\t? await this.migrationsResolver.findSchemaMigrationByVersion(migrationName)\n\t\t\t: await this.migrationsResolver.findLatestSchemaMigration()\n\t\tif (!amendMigration) {\n\t\t\tthrow 'No migration to amend'\n\t\t}\n\t\tconst force = input.getOption('force')\n\t\tconst status = await this.migrationsStatusFacade.resolveMigrationsStatus({ force })\n\t\tif (status.migrationsToExecute.length > 0) {\n\t\t\tthrow `Some migrations are not executed. Unable to amend.`\n\t\t}\n\n\t\tconst schema = await this.schemaLoader.loadSchema()\n\t\tconst stateMode = await this.schemaStateManager.isStateMode()\n\t\ttry {\n\t\t\tconst initialSchema = await this.schemaVersionBuilder.buildSchema()\n\t\t\tconst intermediateResult = await this.migrationCreator.prepareMigration(initialSchema, schema, '', {\n\t\t\t\tskipNonModelDiffers: stateMode,\n\t\t\t})\n\n\t\t\tconst schemaState = stateMode ? SchemaStateManager.schemaStateFromSchema(schema) : undefined\n\t\t\tconst stateChanged = schemaState ? await this.schemaStateManager.writeState(schemaState, { dryRun: true }) : false\n\n\t\t\tif (intermediateResult === null) {\n\t\t\t\tif (stateChanged) {\n\t\t\t\t\tawait this.schemaStateManager.writeState(schemaState!)\n\t\t\t\t\tconsole.log('Schema state updated (no model changes)')\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log('Nothing to do')\n\t\t\t\t}\n\t\t\t\treturn 0\n\t\t\t}\n\t\t\tif (amendMigration.formatVersion !== intermediateResult.migration.formatVersion) {\n\t\t\t\tthrow 'Incompatible migration format version'\n\t\t\t}\n\t\t\tconst prevSchema = await this.schemaVersionBuilder.buildSchemaAdvanced(\n\t\t\t\temptySchema,\n\t\t\t\tversion => version < amendMigration.version,\n\t\t\t)\n\t\t\tconst newSchema = await this.schemaMigrator.applyModifications(\n\t\t\t\tprevSchema,\n\t\t\t\t[...amendMigration.modifications, ...intermediateResult.migration.modifications],\n\t\t\t\tamendMigration.formatVersion,\n\t\t\t)\n\t\t\tconst newMigrationResult = await this.migrationCreator.prepareMigration(prevSchema, newSchema, '', {\n\t\t\t\tskipNonModelDiffers: stateMode,\n\t\t\t})\n\t\t\tconst followingMigrations = (await this.migrationsResolver.getSchemaMigrations()).filter(\n\t\t\t\tit => it.version > amendMigration.version,\n\t\t\t)\n\n\t\t\tconst valid = await this.migrationsValidator.validate(\n\t\t\t\tprevSchema,\n\t\t\t\t[...(newMigrationResult ? [newMigrationResult.migration] : []), ...followingMigrations],\n\t\t\t)\n\t\t\tif (!valid) {\n\t\t\t\tthrow `Cannot amend migration`\n\t\t\t}\n\n\t\t\tthis.migrationPrinter.printMigrationDescription(\n\t\t\t\tintermediateResult.initialSchema,\n\t\t\t\tintermediateResult.migration,\n\t\t\t\t{ noSql: true },\n\t\t\t)\n\t\t\tconsole.log(`Amending ${amendMigration.name}`)\n\t\t\tif (!(await this.shouldContinue(input))) {\n\t\t\t\tconsole.log('Aborting')\n\t\t\t\treturn 1\n\t\t\t}\n\t\t\tconst systemClient = this.systemApiClientProvider.get()\n\t\t\tawait systemClient.migrate([intermediateResult.migration], force)\n\t\t\tawait systemClient.migrationDelete(intermediateResult.migration.version)\n\n\t\t\tif (!newMigrationResult && await this.shouldRemove()) {\n\t\t\t\tawait this.migrationCreator.removeMigration(amendMigration.name)\n\t\t\t\tawait systemClient.migrationDelete(amendMigration.version)\n\t\t\t\tif (schemaState) {\n\t\t\t\t\tawait this.schemaStateManager.writeState(schemaState)\n\t\t\t\t\t// migrationDelete rebuilds the server schema from migrations, dropping the\n\t\t\t\t\t// non-model state; re-apply it so the server stays in sync with the state files.\n\t\t\t\t\tawait systemClient.migrate([], force, schemaState)\n\t\t\t\t}\n\t\t\t\tconsole.log('Latest migration was removed')\n\t\t\t\treturn 0\n\t\t\t}\n\t\t\tconst newMigration = {\n\t\t\t\tname: amendMigration.name,\n\t\t\t\tversion: amendMigration.version,\n\t\t\t\tformatVersion: newMigrationResult?.migration.formatVersion ?? amendMigration.formatVersion,\n\t\t\t\tmodifications: newMigrationResult?.migration.modifications ?? [],\n\t\t\t}\n\t\t\tawait this.migrationCreator.saveMigration(newMigration)\n\t\t\tawait systemClient.migrationModify(amendMigration.version, newMigration)\n\n\t\t\tif (schemaState) {\n\t\t\t\tawait this.schemaStateManager.writeState(schemaState)\n\t\t\t\t// migrationModify rebuilds the server schema from migrations, dropping the\n\t\t\t\t// non-model state; re-apply it so the server stays in sync with the state files.\n\t\t\t\tawait systemClient.migrate([], force, schemaState)\n\t\t\t}\n\n\t\t\treturn 0\n\t\t} catch (e) {\n\t\t\tif (e instanceof InvalidSchemaException) {\n\t\t\t\tprintValidationErrors(e.validationErrors, e.message)\n\t\t\t\treturn 1\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n\n\tprivate async shouldContinue(input: Input<{}, { yes?: true }>): Promise<boolean> {\n\t\tconst yes = input.getOption('yes')\n\t\tif (yes) {\n\t\t\treturn true\n\t\t}\n\t\tconst { action } = await prompts({\n\t\t\ttype: 'select',\n\t\t\tname: 'action',\n\t\t\tmessage: 'Do you want to continue?',\n\t\t\tchoices: [\n\t\t\t\t{ value: 'yes', title: 'Yes' },\n\t\t\t\t{ value: 'no', title: 'Abort' },\n\t\t\t],\n\t\t})\n\t\treturn action === 'yes'\n\t}\n\n\tprivate async shouldRemove(): Promise<boolean> {\n\t\tconst { action } = await prompts({\n\t\t\ttype: 'select',\n\t\t\tname: 'action',\n\t\t\tmessage:\n\t\t\t\t'The amendment results in a no-op migration because the changes introduced by the latest migration were reverted.\\nYou can choose to remove the latest migration or to modify it so it is empty.',\n\t\t\tchoices: [\n\t\t\t\t{ value: 'remove', title: 'Remove latest migration' },\n\t\t\t\t{ value: 'keep', title: 'Keep latest migration and make it empty' },\n\t\t\t],\n\t\t})\n\t\treturn action === 'remove'\n\t}\n}\n"],"names":["Command","SchemaStateManager","emptySchema","InvalidSchemaException","printValidationErrors"],"mappings":";;;;;;;;AAqBO,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AA;AAAA,QACvB,EAAE,OAAO,MAAM,OAAO,QAAA;AAAA,MAAQ;AAAA,IAC/B,CACA;AACD,WAAO,WAAW;AAAA,EACnB;AAAA,EAEA,MAAc,eAAiC;AAC9C,UAAM,EAAE,WAAW,MAAM,QAAQ;AAAA,MAChC,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SACC;AAAA,MACD,SAAS;AAAA,QACR,EAAE,OAAO,UAAU,OAAO,0BAAA;AAAA,QAC1B,EAAE,OAAO,QAAQ,OAAO,0CAAA;AAAA,MAA0C;AAAA,IACnE,CACA;AACD,WAAO,WAAW;AAAA,EACnB;AACD;;"}
@@ -2,9 +2,10 @@ import { Command } from "@contember/cli-common";
2
2
  import { InvalidSchemaException } from "@contember/schema-migrations";
3
3
  import prompts from "prompts";
4
4
  import { emptySchema } from "@contember/schema-utils";
5
+ import { SchemaStateManager } from "@contember/migrations-client";
5
6
  import { printValidationErrors } from "../../lib/schema/SchemaValidationPrinter.js";
6
7
  class MigrationAmendCommand extends Command {
7
- constructor(migrationsResolver, systemApiClientProvider, migrationsStatusFacade, schemaLoader, schemaVersionBuilder, migrationCreator, migrationsValidator, migrationPrinter, schemaMigrator) {
8
+ constructor(migrationsResolver, systemApiClientProvider, migrationsStatusFacade, schemaLoader, schemaVersionBuilder, migrationCreator, migrationsValidator, migrationPrinter, schemaMigrator, schemaStateManager) {
8
9
  super();
9
10
  this.migrationsResolver = migrationsResolver;
10
11
  this.systemApiClientProvider = systemApiClientProvider;
@@ -15,6 +16,7 @@ class MigrationAmendCommand extends Command {
15
16
  this.migrationsValidator = migrationsValidator;
16
17
  this.migrationPrinter = migrationPrinter;
17
18
  this.schemaMigrator = schemaMigrator;
19
+ this.schemaStateManager = schemaStateManager;
18
20
  }
19
21
  configure(configuration) {
20
22
  configuration.description("Amends latest migration");
@@ -34,11 +36,21 @@ class MigrationAmendCommand extends Command {
34
36
  throw `Some migrations are not executed. Unable to amend.`;
35
37
  }
36
38
  const schema = await this.schemaLoader.loadSchema();
39
+ const stateMode = await this.schemaStateManager.isStateMode();
37
40
  try {
38
41
  const initialSchema = await this.schemaVersionBuilder.buildSchema();
39
- const intermediateResult = await this.migrationCreator.prepareMigration(initialSchema, schema, "");
42
+ const intermediateResult = await this.migrationCreator.prepareMigration(initialSchema, schema, "", {
43
+ skipNonModelDiffers: stateMode
44
+ });
45
+ const schemaState = stateMode ? SchemaStateManager.schemaStateFromSchema(schema) : void 0;
46
+ const stateChanged = schemaState ? await this.schemaStateManager.writeState(schemaState, { dryRun: true }) : false;
40
47
  if (intermediateResult === null) {
41
- console.log("Nothing to do");
48
+ if (stateChanged) {
49
+ await this.schemaStateManager.writeState(schemaState);
50
+ console.log("Schema state updated (no model changes)");
51
+ } else {
52
+ console.log("Nothing to do");
53
+ }
42
54
  return 0;
43
55
  }
44
56
  if (amendMigration.formatVersion !== intermediateResult.migration.formatVersion) {
@@ -53,7 +65,9 @@ class MigrationAmendCommand extends Command {
53
65
  [...amendMigration.modifications, ...intermediateResult.migration.modifications],
54
66
  amendMigration.formatVersion
55
67
  );
56
- const newMigrationResult = await this.migrationCreator.prepareMigration(prevSchema, newSchema, "");
68
+ const newMigrationResult = await this.migrationCreator.prepareMigration(prevSchema, newSchema, "", {
69
+ skipNonModelDiffers: stateMode
70
+ });
57
71
  const followingMigrations = (await this.migrationsResolver.getSchemaMigrations()).filter(
58
72
  (it) => it.version > amendMigration.version
59
73
  );
@@ -80,6 +94,10 @@ class MigrationAmendCommand extends Command {
80
94
  if (!newMigrationResult && await this.shouldRemove()) {
81
95
  await this.migrationCreator.removeMigration(amendMigration.name);
82
96
  await systemClient.migrationDelete(amendMigration.version);
97
+ if (schemaState) {
98
+ await this.schemaStateManager.writeState(schemaState);
99
+ await systemClient.migrate([], force, schemaState);
100
+ }
83
101
  console.log("Latest migration was removed");
84
102
  return 0;
85
103
  }
@@ -91,6 +109,10 @@ class MigrationAmendCommand extends Command {
91
109
  };
92
110
  await this.migrationCreator.saveMigration(newMigration);
93
111
  await systemClient.migrationModify(amendMigration.version, newMigration);
112
+ if (schemaState) {
113
+ await this.schemaStateManager.writeState(schemaState);
114
+ await systemClient.migrate([], force, schemaState);
115
+ }
94
116
  return 0;
95
117
  } catch (e) {
96
118
  if (e instanceof InvalidSchemaException) {
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationAmendCommand.js","sources":["../../../../../../packages/cli/src/commands/migrations/MigrationAmendCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { InvalidSchemaException, SchemaMigrator } from '@contember/schema-migrations'\nimport prompts from 'prompts'\nimport { emptySchema } from '@contember/schema-utils'\nimport { MigrationCreator, MigrationsResolver, SchemaVersionBuilder, SystemClient } from '@contember/migrations-client'\nimport { MigrationsStatusFacade } from '../../lib/migrations/MigrationsStatusFacade'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader'\nimport { MigrationsValidator } from '../../lib/migrations/MigrationsValidator'\nimport { MigrationPrinter } from '../../lib/migrations/MigrationPrinter'\nimport { printValidationErrors } from '../../lib/schema/SchemaValidationPrinter'\nimport { SystemClientProvider } from '../../lib/SystemClientProvider'\n\ntype Args = {\n\tmigration?: string\n}\n\ntype Options = {\n\tyes?: true\n\tforce: boolean\n}\n\nexport class MigrationAmendCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t\tprivate readonly systemApiClientProvider: SystemClientProvider,\n\t\tprivate readonly migrationsStatusFacade: MigrationsStatusFacade,\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationCreator: MigrationCreator,\n\t\tprivate readonly migrationsValidator: MigrationsValidator,\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Amends latest migration')\n\t\tconfiguration.argument('migration').optional()\n\t\tconfiguration.option('force').description('Ignore migrations order and missing migrations (dev only)')\n\t\tconfiguration //\n\t\t\t.option('yes')\n\t\t\t.valueNone()\n\t\t\t.description('Do not ask for confirmation.')\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<number> {\n\t\tconst migrationName = input.getArgument('migration')\n\t\tconst amendMigration = migrationName\n\t\t\t? await this.migrationsResolver.findSchemaMigrationByVersion(migrationName)\n\t\t\t: await this.migrationsResolver.findLatestSchemaMigration()\n\t\tif (!amendMigration) {\n\t\t\tthrow 'No migration to amend'\n\t\t}\n\t\tconst force = input.getOption('force')\n\t\tconst status = await this.migrationsStatusFacade.resolveMigrationsStatus({ force })\n\t\tif (status.migrationsToExecute.length > 0) {\n\t\t\tthrow `Some migrations are not executed. Unable to amend.`\n\t\t}\n\n\t\tconst schema = await this.schemaLoader.loadSchema()\n\t\ttry {\n\t\t\tconst initialSchema = await this.schemaVersionBuilder.buildSchema()\n\t\t\tconst intermediateResult = await this.migrationCreator.prepareMigration(initialSchema, schema, '')\n\t\t\tif (intermediateResult === null) {\n\t\t\t\tconsole.log('Nothing to do')\n\t\t\t\treturn 0\n\t\t\t}\n\t\t\tif (amendMigration.formatVersion !== intermediateResult.migration.formatVersion) {\n\t\t\t\tthrow 'Incompatible migration format version'\n\t\t\t}\n\t\t\tconst prevSchema = await this.schemaVersionBuilder.buildSchemaAdvanced(\n\t\t\t\temptySchema,\n\t\t\t\tversion => version < amendMigration.version,\n\t\t\t)\n\t\t\tconst newSchema = await this.schemaMigrator.applyModifications(\n\t\t\t\tprevSchema,\n\t\t\t\t[...amendMigration.modifications, ...intermediateResult.migration.modifications],\n\t\t\t\tamendMigration.formatVersion,\n\t\t\t)\n\t\t\tconst newMigrationResult = await this.migrationCreator.prepareMigration(prevSchema, newSchema, '')\n\t\t\tconst followingMigrations = (await this.migrationsResolver.getSchemaMigrations()).filter(\n\t\t\t\tit => it.version > amendMigration.version,\n\t\t\t)\n\n\t\t\tconst valid = await this.migrationsValidator.validate(\n\t\t\t\tprevSchema,\n\t\t\t\t[...(newMigrationResult ? [newMigrationResult.migration] : []), ...followingMigrations],\n\t\t\t)\n\t\t\tif (!valid) {\n\t\t\t\tthrow `Cannot amend migration`\n\t\t\t}\n\n\t\t\tthis.migrationPrinter.printMigrationDescription(\n\t\t\t\tintermediateResult.initialSchema,\n\t\t\t\tintermediateResult.migration,\n\t\t\t\t{ noSql: true },\n\t\t\t)\n\t\t\tconsole.log(`Amending ${amendMigration.name}`)\n\t\t\tif (!(await this.shouldContinue(input))) {\n\t\t\t\tconsole.log('Aborting')\n\t\t\t\treturn 1\n\t\t\t}\n\t\t\tconst systemClient = this.systemApiClientProvider.get()\n\t\t\tawait systemClient.migrate([intermediateResult.migration], force)\n\t\t\tawait systemClient.migrationDelete(intermediateResult.migration.version)\n\n\t\t\tif (!newMigrationResult && await this.shouldRemove()) {\n\t\t\t\tawait this.migrationCreator.removeMigration(amendMigration.name)\n\t\t\t\tawait systemClient.migrationDelete(amendMigration.version)\n\t\t\t\tconsole.log('Latest migration was removed')\n\t\t\t\treturn 0\n\t\t\t}\n\t\t\tconst newMigration = {\n\t\t\t\tname: amendMigration.name,\n\t\t\t\tversion: amendMigration.version,\n\t\t\t\tformatVersion: newMigrationResult?.migration.formatVersion ?? amendMigration.formatVersion,\n\t\t\t\tmodifications: newMigrationResult?.migration.modifications ?? [],\n\t\t\t}\n\t\t\tawait this.migrationCreator.saveMigration(newMigration)\n\t\t\tawait systemClient.migrationModify(amendMigration.version, newMigration)\n\n\t\t\treturn 0\n\t\t} catch (e) {\n\t\t\tif (e instanceof InvalidSchemaException) {\n\t\t\t\tprintValidationErrors(e.validationErrors, e.message)\n\t\t\t\treturn 1\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n\n\tprivate async shouldContinue(input: Input<{}, { yes?: true }>): Promise<boolean> {\n\t\tconst yes = input.getOption('yes')\n\t\tif (yes) {\n\t\t\treturn true\n\t\t}\n\t\tconst { action } = await prompts({\n\t\t\ttype: 'select',\n\t\t\tname: 'action',\n\t\t\tmessage: 'Do you want to continue?',\n\t\t\tchoices: [\n\t\t\t\t{ value: 'yes', title: 'Yes' },\n\t\t\t\t{ value: 'no', title: 'Abort' },\n\t\t\t],\n\t\t})\n\t\treturn action === 'yes'\n\t}\n\n\tprivate async shouldRemove(): Promise<boolean> {\n\t\tconst { action } = await prompts({\n\t\t\ttype: 'select',\n\t\t\tname: 'action',\n\t\t\tmessage:\n\t\t\t\t'The amendment results in a no-op migration because the changes introduced by the latest migration were reverted.\\nYou can choose to remove the latest migration or to modify it so it is empty.',\n\t\t\tchoices: [\n\t\t\t\t{ value: 'remove', title: 'Remove latest migration' },\n\t\t\t\t{ value: 'keep', title: 'Keep latest migration and make it empty' },\n\t\t\t],\n\t\t})\n\t\treturn action === 'remove'\n\t}\n}\n"],"names":[],"mappings":";;;;;AAqBO,MAAM,8BAA8B,QAAuB;AAAA,EACjE,YACkB,oBACA,yBACA,wBACA,cACA,sBACA,kBACA,qBACA,kBACA,gBAChB;AACD,UAAA;AAViB,SAAA,qBAAA;AACA,SAAA,0BAAA;AACA,SAAA,yBAAA;AACA,SAAA,eAAA;AACA,SAAA,uBAAA;AACA,SAAA,mBAAA;AACA,SAAA,sBAAA;AACA,SAAA,mBAAA;AACA,SAAA,iBAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,yBAAyB;AACnD,kBAAc,SAAS,WAAW,EAAE,SAAA;AACpC,kBAAc,OAAO,OAAO,EAAE,YAAY,2DAA2D;AACrG,kBACE,OAAO,KAAK,EACZ,UAAA,EACA,YAAY,8BAA8B;AAAA,EAC7C;AAAA,EAEA,MAAgB,QAAQ,OAA8C;AACrE,UAAM,gBAAgB,MAAM,YAAY,WAAW;AACnD,UAAM,iBAAiB,gBACpB,MAAM,KAAK,mBAAmB,6BAA6B,aAAa,IACxE,MAAM,KAAK,mBAAmB,0BAAA;AACjC,Q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;AAAA,EAEA,MAAc,eAAiC;AAC9C,UAAM,EAAE,WAAW,MAAM,QAAQ;AAAA,MAChC,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SACC;AAAA,MACD,SAAS;AAAA,QACR,EAAE,OAAO,UAAU,OAAO,0BAAA;AAAA,QAC1B,EAAE,OAAO,QAAQ,OAAO,0CAAA;AAAA,MAA0C;AAAA,IACnE,CACA;AACD,WAAO,WAAW;AAAA,EACnB;AACD;"}
1
+ {"version":3,"file":"MigrationAmendCommand.js","sources":["../../../../../../packages/cli/src/commands/migrations/MigrationAmendCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { InvalidSchemaException, SchemaMigrator } from '@contember/schema-migrations'\nimport prompts from 'prompts'\nimport { emptySchema } from '@contember/schema-utils'\nimport { MigrationCreator, MigrationsResolver, SchemaStateManager, SchemaVersionBuilder } from '@contember/migrations-client'\nimport { MigrationsStatusFacade } from '../../lib/migrations/MigrationsStatusFacade.js'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader.js'\nimport { MigrationsValidator } from '../../lib/migrations/MigrationsValidator.js'\nimport { MigrationPrinter } from '../../lib/migrations/MigrationPrinter.js'\nimport { printValidationErrors } from '../../lib/schema/SchemaValidationPrinter.js'\nimport { SystemClientProvider } from '../../lib/SystemClientProvider.js'\n\ntype Args = {\n\tmigration?: string\n}\n\ntype Options = {\n\tyes?: true\n\tforce: boolean\n}\n\nexport class MigrationAmendCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t\tprivate readonly systemApiClientProvider: SystemClientProvider,\n\t\tprivate readonly migrationsStatusFacade: MigrationsStatusFacade,\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationCreator: MigrationCreator,\n\t\tprivate readonly migrationsValidator: MigrationsValidator,\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Amends latest migration')\n\t\tconfiguration.argument('migration').optional()\n\t\tconfiguration.option('force').description('Ignore migrations order and missing migrations (dev only)')\n\t\tconfiguration //\n\t\t\t.option('yes')\n\t\t\t.valueNone()\n\t\t\t.description('Do not ask for confirmation.')\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<number> {\n\t\tconst migrationName = input.getArgument('migration')\n\t\tconst amendMigration = migrationName\n\t\t\t? await this.migrationsResolver.findSchemaMigrationByVersion(migrationName)\n\t\t\t: await this.migrationsResolver.findLatestSchemaMigration()\n\t\tif (!amendMigration) {\n\t\t\tthrow 'No migration to amend'\n\t\t}\n\t\tconst force = input.getOption('force')\n\t\tconst status = await this.migrationsStatusFacade.resolveMigrationsStatus({ force })\n\t\tif (status.migrationsToExecute.length > 0) {\n\t\t\tthrow `Some migrations are not executed. Unable to amend.`\n\t\t}\n\n\t\tconst schema = await this.schemaLoader.loadSchema()\n\t\tconst stateMode = await this.schemaStateManager.isStateMode()\n\t\ttry {\n\t\t\tconst initialSchema = await this.schemaVersionBuilder.buildSchema()\n\t\t\tconst intermediateResult = await this.migrationCreator.prepareMigration(initialSchema, schema, '', {\n\t\t\t\tskipNonModelDiffers: stateMode,\n\t\t\t})\n\n\t\t\tconst schemaState = stateMode ? SchemaStateManager.schemaStateFromSchema(schema) : undefined\n\t\t\tconst stateChanged = schemaState ? await this.schemaStateManager.writeState(schemaState, { dryRun: true }) : false\n\n\t\t\tif (intermediateResult === null) {\n\t\t\t\tif (stateChanged) {\n\t\t\t\t\tawait this.schemaStateManager.writeState(schemaState!)\n\t\t\t\t\tconsole.log('Schema state updated (no model changes)')\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log('Nothing to do')\n\t\t\t\t}\n\t\t\t\treturn 0\n\t\t\t}\n\t\t\tif (amendMigration.formatVersion !== intermediateResult.migration.formatVersion) {\n\t\t\t\tthrow 'Incompatible migration format version'\n\t\t\t}\n\t\t\tconst prevSchema = await this.schemaVersionBuilder.buildSchemaAdvanced(\n\t\t\t\temptySchema,\n\t\t\t\tversion => version < amendMigration.version,\n\t\t\t)\n\t\t\tconst newSchema = await this.schemaMigrator.applyModifications(\n\t\t\t\tprevSchema,\n\t\t\t\t[...amendMigration.modifications, ...intermediateResult.migration.modifications],\n\t\t\t\tamendMigration.formatVersion,\n\t\t\t)\n\t\t\tconst newMigrationResult = await this.migrationCreator.prepareMigration(prevSchema, newSchema, '', {\n\t\t\t\tskipNonModelDiffers: stateMode,\n\t\t\t})\n\t\t\tconst followingMigrations = (await this.migrationsResolver.getSchemaMigrations()).filter(\n\t\t\t\tit => it.version > amendMigration.version,\n\t\t\t)\n\n\t\t\tconst valid = await this.migrationsValidator.validate(\n\t\t\t\tprevSchema,\n\t\t\t\t[...(newMigrationResult ? [newMigrationResult.migration] : []), ...followingMigrations],\n\t\t\t)\n\t\t\tif (!valid) {\n\t\t\t\tthrow `Cannot amend migration`\n\t\t\t}\n\n\t\t\tthis.migrationPrinter.printMigrationDescription(\n\t\t\t\tintermediateResult.initialSchema,\n\t\t\t\tintermediateResult.migration,\n\t\t\t\t{ noSql: true },\n\t\t\t)\n\t\t\tconsole.log(`Amending ${amendMigration.name}`)\n\t\t\tif (!(await this.shouldContinue(input))) {\n\t\t\t\tconsole.log('Aborting')\n\t\t\t\treturn 1\n\t\t\t}\n\t\t\tconst systemClient = this.systemApiClientProvider.get()\n\t\t\tawait systemClient.migrate([intermediateResult.migration], force)\n\t\t\tawait systemClient.migrationDelete(intermediateResult.migration.version)\n\n\t\t\tif (!newMigrationResult && await this.shouldRemove()) {\n\t\t\t\tawait this.migrationCreator.removeMigration(amendMigration.name)\n\t\t\t\tawait systemClient.migrationDelete(amendMigration.version)\n\t\t\t\tif (schemaState) {\n\t\t\t\t\tawait this.schemaStateManager.writeState(schemaState)\n\t\t\t\t\t// migrationDelete rebuilds the server schema from migrations, dropping the\n\t\t\t\t\t// non-model state; re-apply it so the server stays in sync with the state files.\n\t\t\t\t\tawait systemClient.migrate([], force, schemaState)\n\t\t\t\t}\n\t\t\t\tconsole.log('Latest migration was removed')\n\t\t\t\treturn 0\n\t\t\t}\n\t\t\tconst newMigration = {\n\t\t\t\tname: amendMigration.name,\n\t\t\t\tversion: amendMigration.version,\n\t\t\t\tformatVersion: newMigrationResult?.migration.formatVersion ?? amendMigration.formatVersion,\n\t\t\t\tmodifications: newMigrationResult?.migration.modifications ?? [],\n\t\t\t}\n\t\t\tawait this.migrationCreator.saveMigration(newMigration)\n\t\t\tawait systemClient.migrationModify(amendMigration.version, newMigration)\n\n\t\t\tif (schemaState) {\n\t\t\t\tawait this.schemaStateManager.writeState(schemaState)\n\t\t\t\t// migrationModify rebuilds the server schema from migrations, dropping the\n\t\t\t\t// non-model state; re-apply it so the server stays in sync with the state files.\n\t\t\t\tawait systemClient.migrate([], force, schemaState)\n\t\t\t}\n\n\t\t\treturn 0\n\t\t} catch (e) {\n\t\t\tif (e instanceof InvalidSchemaException) {\n\t\t\t\tprintValidationErrors(e.validationErrors, e.message)\n\t\t\t\treturn 1\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}\n\n\tprivate async shouldContinue(input: Input<{}, { yes?: true }>): Promise<boolean> {\n\t\tconst yes = input.getOption('yes')\n\t\tif (yes) {\n\t\t\treturn true\n\t\t}\n\t\tconst { action } = await prompts({\n\t\t\ttype: 'select',\n\t\t\tname: 'action',\n\t\t\tmessage: 'Do you want to continue?',\n\t\t\tchoices: [\n\t\t\t\t{ value: 'yes', title: 'Yes' },\n\t\t\t\t{ value: 'no', title: 'Abort' },\n\t\t\t],\n\t\t})\n\t\treturn action === 'yes'\n\t}\n\n\tprivate async shouldRemove(): Promise<boolean> {\n\t\tconst { action } = await prompts({\n\t\t\ttype: 'select',\n\t\t\tname: 'action',\n\t\t\tmessage:\n\t\t\t\t'The amendment results in a no-op migration because the changes introduced by the latest migration were reverted.\\nYou can choose to remove the latest migration or to modify it so it is empty.',\n\t\t\tchoices: [\n\t\t\t\t{ value: 'remove', title: 'Remove latest migration' },\n\t\t\t\t{ value: 'keep', title: 'Keep latest migration and make it empty' },\n\t\t\t],\n\t\t})\n\t\treturn action === 'remove'\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAqBO,MAAM,8BAA8B,QAAuB;AAAA,EACjE,YACkB,oBACA,yBACA,wBACA,cACA,sBACA,kBACA,qBACA,kBACA,gBACA,oBAChB;AACD,UAAA;AAXiB,SAAA,qBAAA;AACA,SAAA,0BAAA;AACA,SAAA,yBAAA;AACA,SAAA,eAAA;AACA,SAAA,uBAAA;AACA,SAAA,mBAAA;AACA,SAAA,sBAAA;AACA,SAAA,mBAAA;AACA,SAAA,iBAAA;AACA,SAAA,qBAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,yBAAyB;AACnD,kBAAc,SAAS,WAAW,EAAE,SAAA;AACpC,kBAAc,OAAO,OAAO,EAAE,YAAY,2DAA2D;AACrG,kBACE,OAAO,KAAK,EACZ,UAAA,EACA,YAAY,8BAA8B;AAAA,EAC7C;AAAA,EAEA,MAAgB,QAAQ,OAA8C;AACrE,UAAM,gBAAgB,MAAM,YAAY,WAAW;AACnD,UAAM,iBAAiB,gBACpB,MAAM,KAAK,mBAAmB,6BAA6B,aAAa,IACxE,MAAM,KAAK,mBAAmB,0BAAA;AACjC,QAAI,CAAC,gBAAgB;AACpB,YAAM;AAAA,IACP;AACA,UAAM,QAAQ,MAAM,UAAU,OAAO;AACrC,UAAM,SAAS,MAAM,KAAK,uBAAuB,wBAAwB,EAAE,OAAO;AAClF,QAAI,OAAO,oBAAoB,SAAS,GAAG;AAC1C,YAAM;AAAA,IACP;AAEA,UAAM,SAAS,MAAM,KAAK,aAAa,WAAA;AACvC,UAAM,YAAY,MAAM,KAAK,mBAAm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D;AAChF,UAAM,MAAM,MAAM,UAAU,KAAK;AACjC,QAAI,KAAK;AACR,aAAO;AAAA,IACR;AACA,UAAM,EAAE,WAAW,MAAM,QAAQ;AAAA,MAChC,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS;AAAA,QACR,EAAE,OAAO,OAAO,OAAO,MAAA;AAAA,QACvB,EAAE,OAAO,MAAM,OAAO,QAAA;AAAA,MAAQ;AAAA,IAC/B,CACA;AACD,WAAO,WAAW;AAAA,EACnB;AAAA,EAEA,MAAc,eAAiC;AAC9C,UAAM,EAAE,WAAW,MAAM,QAAQ;AAAA,MAChC,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SACC;AAAA,MACD,SAAS;AAAA,QACR,EAAE,OAAO,UAAU,OAAO,0BAAA;AAAA,QAC1B,EAAE,OAAO,QAAQ,OAAO,0CAAA;AAAA,MAA0C;AAAA,IACnE,CACA;AACD,WAAO,WAAW;AAAA,EACnB;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationDescribeCommand.cjs","sources":["../../../../../../packages/cli/src/commands/migrations/MigrationDescribeCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { MigrationPrinter } from '../../lib/migrations/MigrationPrinter'\nimport { MigrationsResolver, SchemaVersionBuilder } from '@contember/migrations-client'\n\ntype Args = {\n\tmigration?: string\n}\n\ntype Options = {\n\t['sql-only']: boolean\n\t['no-sql']: boolean\n}\n\nexport class MigrationDescribeCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Describes a migration')\n\t\tconfiguration.argument('migration').optional()\n\t\tconfiguration.option('sql-only').valueNone()\n\t\tconfiguration.option('no-sql').valueNone()\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<void> {\n\t\tconst migrationArg = input.getArgument('migration')\n\t\tconst sqlOnly = input.getOption('sql-only')\n\t\tconst noSql = input.getOption('no-sql')\n\n\t\tconst migration = migrationArg\n\t\t\t? await this.migrationsResolver.findSchemaMigrationByVersion(migrationArg)\n\t\t\t: await this.migrationsResolver.findLatestSchemaMigration()\n\n\t\tif (!migration) {\n\t\t\tthrow 'Undefined migration'\n\t\t}\n\t\tconst schema = await this.schemaVersionBuilder.buildSchemaUntil(migration.version)\n\t\tthis.migrationPrinter.printMigrationDescription(schema, migration, { sqlOnly, noSql })\n\t}\n}\n"],"names":["Command"],"mappings":";;;AAaO,MAAM,iCAAiCA,UAAAA,QAAuB;AAAA,EACpE,YACkB,kBACA,sBACA,oBAChB;AACD,UAAA;AAJiB,SAAA,mBAAA;AACA,SAAA,uBAAA;AACA,SAAA,qBAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,uBAAuB;AACjD,kBAAc,SAAS,WAAW,EAAE,SAAA;AACpC,kBAAc,OAAO,UAAU,EAAE,UAAA;AACjC,kBAAc,OAAO,QAAQ,EAAE,UAAA;AAAA,EAChC;AAAA,EAEA,MAAgB,QAAQ,OAA4C;AACnE,UAAM,eAAe,MAAM,YAAY,WAAW;AAClD,UAAM,UAAU,MAAM,UAAU,UAAU;AAC1C,UAAM,QAAQ,MAAM,UAAU,QAAQ;AAEtC,UAAM,YAAY,eACf,MAAM,KAAK,mBAAmB,6BAA6B,YAAY,IACvE,MAAM,KAAK,mBAAmB,0BAAA;AAEjC,QAAI,CAAC,WAAW;AACf,YAAM;AAAA,IACP;AACA,UAAM,SAAS,MAAM,KAAK,qBAAqB,iBAAiB,UAAU,OAAO;AACjF,SAAK,iBAAiB,0BAA0B,QAAQ,WAAW,EAAE,SAAS,OAAO;AAAA,EACtF;AACD;;"}
1
+ {"version":3,"file":"MigrationDescribeCommand.cjs","sources":["../../../../../../packages/cli/src/commands/migrations/MigrationDescribeCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { MigrationPrinter } from '../../lib/migrations/MigrationPrinter.js'\nimport { MigrationsResolver, SchemaVersionBuilder } from '@contember/migrations-client'\n\ntype Args = {\n\tmigration?: string\n}\n\ntype Options = {\n\t['sql-only']: boolean\n\t['no-sql']: boolean\n}\n\nexport class MigrationDescribeCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Describes a migration')\n\t\tconfiguration.argument('migration').optional()\n\t\tconfiguration.option('sql-only').valueNone()\n\t\tconfiguration.option('no-sql').valueNone()\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<void> {\n\t\tconst migrationArg = input.getArgument('migration')\n\t\tconst sqlOnly = input.getOption('sql-only')\n\t\tconst noSql = input.getOption('no-sql')\n\n\t\tconst migration = migrationArg\n\t\t\t? await this.migrationsResolver.findSchemaMigrationByVersion(migrationArg)\n\t\t\t: await this.migrationsResolver.findLatestSchemaMigration()\n\n\t\tif (!migration) {\n\t\t\tthrow 'Undefined migration'\n\t\t}\n\t\tconst schema = await this.schemaVersionBuilder.buildSchemaUntil(migration.version)\n\t\tthis.migrationPrinter.printMigrationDescription(schema, migration, { sqlOnly, noSql })\n\t}\n}\n"],"names":["Command"],"mappings":";;;AAaO,MAAM,iCAAiCA,UAAAA,QAAuB;AAAA,EACpE,YACkB,kBACA,sBACA,oBAChB;AACD,UAAA;AAJiB,SAAA,mBAAA;AACA,SAAA,uBAAA;AACA,SAAA,qBAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,uBAAuB;AACjD,kBAAc,SAAS,WAAW,EAAE,SAAA;AACpC,kBAAc,OAAO,UAAU,EAAE,UAAA;AACjC,kBAAc,OAAO,QAAQ,EAAE,UAAA;AAAA,EAChC;AAAA,EAEA,MAAgB,QAAQ,OAA4C;AACnE,UAAM,eAAe,MAAM,YAAY,WAAW;AAClD,UAAM,UAAU,MAAM,UAAU,UAAU;AAC1C,UAAM,QAAQ,MAAM,UAAU,QAAQ;AAEtC,UAAM,YAAY,eACf,MAAM,KAAK,mBAAmB,6BAA6B,YAAY,IACvE,MAAM,KAAK,mBAAmB,0BAAA;AAEjC,QAAI,CAAC,WAAW;AACf,YAAM;AAAA,IACP;AACA,UAAM,SAAS,MAAM,KAAK,qBAAqB,iBAAiB,UAAU,OAAO;AACjF,SAAK,iBAAiB,0BAA0B,QAAQ,WAAW,EAAE,SAAS,OAAO;AAAA,EACtF;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationDescribeCommand.js","sources":["../../../../../../packages/cli/src/commands/migrations/MigrationDescribeCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { MigrationPrinter } from '../../lib/migrations/MigrationPrinter'\nimport { MigrationsResolver, SchemaVersionBuilder } from '@contember/migrations-client'\n\ntype Args = {\n\tmigration?: string\n}\n\ntype Options = {\n\t['sql-only']: boolean\n\t['no-sql']: boolean\n}\n\nexport class MigrationDescribeCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Describes a migration')\n\t\tconfiguration.argument('migration').optional()\n\t\tconfiguration.option('sql-only').valueNone()\n\t\tconfiguration.option('no-sql').valueNone()\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<void> {\n\t\tconst migrationArg = input.getArgument('migration')\n\t\tconst sqlOnly = input.getOption('sql-only')\n\t\tconst noSql = input.getOption('no-sql')\n\n\t\tconst migration = migrationArg\n\t\t\t? await this.migrationsResolver.findSchemaMigrationByVersion(migrationArg)\n\t\t\t: await this.migrationsResolver.findLatestSchemaMigration()\n\n\t\tif (!migration) {\n\t\t\tthrow 'Undefined migration'\n\t\t}\n\t\tconst schema = await this.schemaVersionBuilder.buildSchemaUntil(migration.version)\n\t\tthis.migrationPrinter.printMigrationDescription(schema, migration, { sqlOnly, noSql })\n\t}\n}\n"],"names":[],"mappings":";AAaO,MAAM,iCAAiC,QAAuB;AAAA,EACpE,YACkB,kBACA,sBACA,oBAChB;AACD,UAAA;AAJiB,SAAA,mBAAA;AACA,SAAA,uBAAA;AACA,SAAA,qBAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,uBAAuB;AACjD,kBAAc,SAAS,WAAW,EAAE,SAAA;AACpC,kBAAc,OAAO,UAAU,EAAE,UAAA;AACjC,kBAAc,OAAO,QAAQ,EAAE,UAAA;AAAA,EAChC;AAAA,EAEA,MAAgB,QAAQ,OAA4C;AACnE,UAAM,eAAe,MAAM,YAAY,WAAW;AAClD,UAAM,UAAU,MAAM,UAAU,UAAU;AAC1C,UAAM,QAAQ,MAAM,UAAU,QAAQ;AAEtC,UAAM,YAAY,eACf,MAAM,KAAK,mBAAmB,6BAA6B,YAAY,IACvE,MAAM,KAAK,mBAAmB,0BAAA;AAEjC,QAAI,CAAC,WAAW;AACf,YAAM;AAAA,IACP;AACA,UAAM,SAAS,MAAM,KAAK,qBAAqB,iBAAiB,UAAU,OAAO;AACjF,SAAK,iBAAiB,0BAA0B,QAAQ,WAAW,EAAE,SAAS,OAAO;AAAA,EACtF;AACD;"}
1
+ {"version":3,"file":"MigrationDescribeCommand.js","sources":["../../../../../../packages/cli/src/commands/migrations/MigrationDescribeCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { MigrationPrinter } from '../../lib/migrations/MigrationPrinter.js'\nimport { MigrationsResolver, SchemaVersionBuilder } from '@contember/migrations-client'\n\ntype Args = {\n\tmigration?: string\n}\n\ntype Options = {\n\t['sql-only']: boolean\n\t['no-sql']: boolean\n}\n\nexport class MigrationDescribeCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Describes a migration')\n\t\tconfiguration.argument('migration').optional()\n\t\tconfiguration.option('sql-only').valueNone()\n\t\tconfiguration.option('no-sql').valueNone()\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<void> {\n\t\tconst migrationArg = input.getArgument('migration')\n\t\tconst sqlOnly = input.getOption('sql-only')\n\t\tconst noSql = input.getOption('no-sql')\n\n\t\tconst migration = migrationArg\n\t\t\t? await this.migrationsResolver.findSchemaMigrationByVersion(migrationArg)\n\t\t\t: await this.migrationsResolver.findLatestSchemaMigration()\n\n\t\tif (!migration) {\n\t\t\tthrow 'Undefined migration'\n\t\t}\n\t\tconst schema = await this.schemaVersionBuilder.buildSchemaUntil(migration.version)\n\t\tthis.migrationPrinter.printMigrationDescription(schema, migration, { sqlOnly, noSql })\n\t}\n}\n"],"names":[],"mappings":";AAaO,MAAM,iCAAiC,QAAuB;AAAA,EACpE,YACkB,kBACA,sBACA,oBAChB;AACD,UAAA;AAJiB,SAAA,mBAAA;AACA,SAAA,uBAAA;AACA,SAAA,qBAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,uBAAuB;AACjD,kBAAc,SAAS,WAAW,EAAE,SAAA;AACpC,kBAAc,OAAO,UAAU,EAAE,UAAA;AACjC,kBAAc,OAAO,QAAQ,EAAE,UAAA;AAAA,EAChC;AAAA,EAEA,MAAgB,QAAQ,OAA4C;AACnE,UAAM,eAAe,MAAM,YAAY,WAAW;AAClD,UAAM,UAAU,MAAM,UAAU,UAAU;AAC1C,UAAM,QAAQ,MAAM,UAAU,QAAQ;AAEtC,UAAM,YAAY,eACf,MAAM,KAAK,mBAAmB,6BAA6B,YAAY,IACvE,MAAM,KAAK,mBAAmB,0BAAA;AAEjC,QAAI,CAAC,WAAW;AACf,YAAM;AAAA,IACP;AACA,UAAM,SAAS,MAAM,KAAK,qBAAqB,iBAAiB,UAAU,OAAO;AACjF,SAAK,iBAAiB,0BAA0B,QAAQ,WAAW,EAAE,SAAS,OAAO;AAAA,EACtF;AACD;"}
@@ -3,15 +3,18 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const cliCommon = require("@contember/cli-common");
4
4
  const schemaMigrations = require("@contember/schema-migrations");
5
5
  const prompts = require("prompts");
6
+ const migrationsClient = require("@contember/migrations-client");
6
7
  const SchemaValidationPrinter = require("../../lib/schema/SchemaValidationPrinter.cjs");
7
8
  class MigrationDiffCommand extends cliCommon.Command {
8
- constructor(schemaLoader, schemaVersionBuilder, migrationCreator, migrationPrinter, migrationExecutorFacade) {
9
+ constructor(schemaLoader, schemaVersionBuilder, migrationCreator, migrationPrinter, migrationExecutorFacade, schemaStateManager, migrationsResolver) {
9
10
  super();
10
11
  this.schemaLoader = schemaLoader;
11
12
  this.schemaVersionBuilder = schemaVersionBuilder;
12
13
  this.migrationCreator = migrationCreator;
13
14
  this.migrationPrinter = migrationPrinter;
14
15
  this.migrationExecutorFacade = migrationExecutorFacade;
16
+ this.schemaStateManager = schemaStateManager;
17
+ this.migrationsResolver = migrationsResolver;
15
18
  }
16
19
  configure(configuration) {
17
20
  configuration.description("Creates schema migration diff");
@@ -19,20 +22,47 @@ class MigrationDiffCommand extends cliCommon.Command {
19
22
  configuration.option("execute").valueNone();
20
23
  configuration.option("yes").valueNone().description("Do not ask for confirmation.");
21
24
  configuration.option("skip-initial-schema-validation");
25
+ configuration.option("recreate-views").valueNone().description(
26
+ "Drop & recreate changed views instead of updating them in-place (CREATE OR REPLACE VIEW). Use when an in-place view update fails with SQLSTATE 42P16."
27
+ );
22
28
  }
23
29
  async execute(input) {
24
30
  const migrationName = input.getArgument("migrationName");
25
31
  let shouldExecute = input.getOption("execute");
26
32
  const yes = input.getOption("yes");
27
33
  const skipInitialSchemaValidation = input.getOption("skip-initial-schema-validation") === true;
34
+ const recreateViews = input.getOption("recreate-views") === true;
28
35
  const schema = await this.schemaLoader.loadSchema();
36
+ let stateMode = await this.schemaStateManager.isStateMode();
37
+ if (!stateMode && (await this.migrationsResolver.getSchemaMigrations()).length === 0) {
38
+ console.log("No migrations found — enabling schema state mode for this project.");
39
+ console.log("ACL, validation, actions and settings will be managed in the state/ directory instead of migrations.");
40
+ await this.schemaStateManager.extractState(schema);
41
+ stateMode = true;
42
+ }
29
43
  try {
30
44
  const initialSchema = await this.schemaVersionBuilder.buildSchema();
31
45
  const result = await this.migrationCreator.prepareMigration(initialSchema, schema, migrationName, {
32
- skipInitialSchemaValidation
46
+ skipInitialSchemaValidation,
47
+ skipNonModelDiffers: stateMode,
48
+ recreateViews
33
49
  });
50
+ const schemaState = stateMode ? migrationsClient.SchemaStateManager.schemaStateFromSchema(schema) : void 0;
51
+ const stateChanged = schemaState ? await this.schemaStateManager.writeState(schemaState, { dryRun: true }) : false;
34
52
  if (result === null) {
35
- console.log("Nothing to do");
53
+ if (stateChanged) {
54
+ console.log("Schema state updated (no model changes)");
55
+ await this.schemaStateManager.writeState(schemaState);
56
+ } else {
57
+ console.log("Nothing to do");
58
+ }
59
+ if (stateChanged && shouldExecute) {
60
+ console.log("Syncing schema state to server...");
61
+ await this.migrationExecutorFacade.execute({
62
+ force: false,
63
+ requireConfirmation: false
64
+ });
65
+ }
36
66
  return;
37
67
  }
38
68
  this.migrationPrinter.printMigrationDescription(result.initialSchema, result.migration, { noSql: true });
@@ -56,7 +86,13 @@ class MigrationDiffCommand extends cliCommon.Command {
56
86
  }
57
87
  }
58
88
  const filename = await this.migrationCreator.saveMigration(result.migration);
89
+ if (stateChanged) {
90
+ await this.schemaStateManager.writeState(schemaState);
91
+ }
59
92
  console.log(`${filename} created`);
93
+ if (stateChanged) {
94
+ console.log("Schema state files updated");
95
+ }
60
96
  } catch (e) {
61
97
  if (e instanceof schemaMigrations.InvalidSchemaException) {
62
98
  SchemaValidationPrinter.printValidationErrors(e.validationErrors, e.message);
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationDiffCommand.cjs","sources":["../../../../../../packages/cli/src/commands/migrations/MigrationDiffCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { InvalidSchemaException } from '@contember/schema-migrations'\nimport prompts from 'prompts'\nimport { MigrationCreator, SchemaVersionBuilder } from '@contember/migrations-client'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader'\nimport { MigrationPrinter } from '../../lib/migrations/MigrationPrinter'\nimport { MigrationExecutionFacade } from '../../lib/migrations/MigrationExecutionFacade'\nimport { printValidationErrors } from '../../lib/schema/SchemaValidationPrinter'\n\ntype Args = {\n\tmigrationName: string\n}\n\ntype Options = {\n\texecute?: true\n\tyes?: true\n\t'skip-initial-schema-validation'?: true\n}\n\nexport class MigrationDiffCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationCreator: MigrationCreator,\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly migrationExecutorFacade: MigrationExecutionFacade,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Creates schema migration diff')\n\t\tconfiguration.argument('migrationName')\n\t\tconfiguration.option('execute').valueNone()\n\t\tconfiguration //\n\t\t\t.option('yes')\n\t\t\t.valueNone()\n\t\t\t.description('Do not ask for confirmation.')\n\n\t\tconfiguration.option('skip-initial-schema-validation')\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<void> {\n\t\tconst migrationName = input.getArgument('migrationName')\n\t\tlet shouldExecute = input.getOption('execute')\n\t\tconst yes = input.getOption('yes')\n\t\tconst skipInitialSchemaValidation = input.getOption('skip-initial-schema-validation') === true\n\n\t\tconst schema = await this.schemaLoader.loadSchema()\n\t\ttry {\n\t\t\tconst initialSchema = await this.schemaVersionBuilder.buildSchema()\n\t\t\tconst result = await this.migrationCreator.prepareMigration(initialSchema, schema, migrationName, {\n\t\t\t\tskipInitialSchemaValidation: skipInitialSchemaValidation,\n\t\t\t})\n\t\t\tif (result === null) {\n\t\t\t\tconsole.log('Nothing to do')\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.migrationPrinter.printMigrationDescription(result.initialSchema, result.migration, { noSql: true })\n\n\t\t\tif (!yes) {\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: 'Yes' },\n\t\t\t\t\t\t...(!shouldExecute ? [{ value: 'execute', title: 'Yes and execute immediately' }] : []),\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 || action === 'no') {\n\t\t\t\t\tconsole.log('Aborting')\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (action === 'execute') {\n\t\t\t\t\tshouldExecute = true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst filename = await this.migrationCreator.saveMigration(result.migration)\n\n\t\t\tconsole.log(`${filename} created`)\n\t\t} catch (e) {\n\t\t\tif (e instanceof InvalidSchemaException) {\n\t\t\t\tprintValidationErrors(e.validationErrors, e.message)\n\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\n\t\tif (shouldExecute) {\n\t\t\tawait this.migrationExecutorFacade.execute({\n\t\t\t\tforce: false,\n\t\t\t\trequireConfirmation: migrations => migrations.length !== 1 && !yes,\n\t\t\t})\n\t\t}\n\t}\n}\n"],"names":["Command","InvalidSchemaException","printValidationErrors"],"mappings":";;;;;;AAmBO,MAAM,6BAA6BA,UAAAA,QAAuB;AAAA,EAChE,YACkB,cACA,sBACA,kBACA,kBACA,yBAChB;AACD,UAAA;AANiB,SAAA,eAAA;AACA,SAAA,uBAAA;AACA,SAAA,mBAAA;AACA,SAAA,mBAAA;AACA,SAAA,0BAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,+BAA+B;AACzD,kBAAc,SAAS,eAAe;AACtC,kBAAc,OAAO,SAAS,EAAE,UAAA;AAChC,kBACE,OAAO,KAAK,EACZ,UAAA,EACA,YAAY,8BAA8B;AAE5C,kBAAc,OAAO,gCAAgC;AAAA,EACtD;AAAA,EAEA,MAAgB,QAAQ,OAA4C;AACnE,UAAM,gBAAgB,MAAM,YAAY,eAAe;AACvD,QAAI,gBAAgB,MAAM,UAAU,SAAS;AAC7C,UAAM,MAAM,MAAM,UAAU,KAAK;AACjC,UAAM,8BAA8B,MAAM,UAAU,gCAAgC,MAAM;AAE1F,UAAM,SAAS,MAAM,KAAK,aAAa,WAAA;AACvC,QAAI;AACH,YAAM,gBAAgB,MAAM,KAAK,qBAAqB,YAAA;AACtD,YAAM,SAAS,MAAM,KAAK,iBAAiB,iBAAiB,eAAe,QAAQ,eAAe;AAAA,QACjG;AAAA,MAAA,CACA;AACD,UAAI,WAAW,MAAM;AACpB,gBAAQ,IAAI,eAAe;AAC3B;AAAA,MACD;AACA,WAAK,iBAAiB,0BAA0B,OAAO,eAAe,OAAO,WAAW,EAAE,OAAO,MAAM;AAEvG,UAAI,CAAC,KAAK;AACT,cAAM,EAAE,WAAW,MAAM,QAAQ;AAAA,UAChC,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,UACT,SAAS;AAAA,YACR,EAAE,OAAO,OAAO,OAAO,MAAA;AAAA,YACvB,GAAI,CAAC,gBAAgB,CAAC,EAAE,OAAO,WAAW,OAAO,8BAAA,CAA+B,IAAI,CAAA;AAAA,YACpF,EAAE,OAAO,MAAM,OAAO,QAAA;AAAA,UAAQ;AAAA,QAC/B,CACA;AACD,YAAI,CAAC,UAAU,WAAW,MAAM;AAC/B,kBAAQ,IAAI,UAAU;AACtB;AAAA,QACD;AACA,YAAI,WAAW,WAAW;AACzB,0BAAgB;AAAA,QACjB;AAAA,MACD;AAEA,YAAM,WAAW,MAAM,KAAK,iBAAiB,cAAc,OAAO,SAAS;AAE3E,cAAQ,IAAI,GAAG,QAAQ,UAAU;AAAA,IAClC,SAAS,GAAG;AACX,UAAI,aAAaC,iBAAAA,wBAAwB;AACxCC,gCAAAA,sBAAsB,EAAE,kBAAkB,EAAE,OAAO;AAEnD;AAAA,MACD;AACA,YAAM;AAAA,IACP;AAEA,QAAI,eAAe;AAClB,YAAM,KAAK,wBAAwB,QAAQ;AAAA,QAC1C,OAAO;AAAA,QACP,qBAAqB,CAAA,eAAc,WAAW,WAAW,KAAK,CAAC;AAAA,MAAA,CAC/D;AAAA,IACF;AAAA,EACD;AACD;;"}
1
+ {"version":3,"file":"MigrationDiffCommand.cjs","sources":["../../../../../../packages/cli/src/commands/migrations/MigrationDiffCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { InvalidSchemaException } from '@contember/schema-migrations'\nimport prompts from 'prompts'\nimport { MigrationCreator, MigrationsResolver, SchemaStateManager, SchemaVersionBuilder } from '@contember/migrations-client'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader.js'\nimport { MigrationPrinter } from '../../lib/migrations/MigrationPrinter.js'\nimport { MigrationExecutionFacade } from '../../lib/migrations/MigrationExecutionFacade.js'\nimport { printValidationErrors } from '../../lib/schema/SchemaValidationPrinter.js'\n\ntype Args = {\n\tmigrationName: string\n}\n\ntype Options = {\n\texecute?: true\n\tyes?: true\n\t'skip-initial-schema-validation'?: true\n\t'recreate-views'?: true\n}\n\nexport class MigrationDiffCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationCreator: MigrationCreator,\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly migrationExecutorFacade: MigrationExecutionFacade,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Creates schema migration diff')\n\t\tconfiguration.argument('migrationName')\n\t\tconfiguration.option('execute').valueNone()\n\t\tconfiguration //\n\t\t\t.option('yes')\n\t\t\t.valueNone()\n\t\t\t.description('Do not ask for confirmation.')\n\n\t\tconfiguration.option('skip-initial-schema-validation')\n\t\tconfiguration //\n\t\t\t.option('recreate-views')\n\t\t\t.valueNone()\n\t\t\t.description(\n\t\t\t\t'Drop & recreate changed views instead of updating them in-place (CREATE OR REPLACE VIEW). Use when an in-place view update fails with SQLSTATE 42P16.',\n\t\t\t)\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<void> {\n\t\tconst migrationName = input.getArgument('migrationName')\n\t\tlet shouldExecute = input.getOption('execute')\n\t\tconst yes = input.getOption('yes')\n\t\tconst skipInitialSchemaValidation = input.getOption('skip-initial-schema-validation') === true\n\t\tconst recreateViews = input.getOption('recreate-views') === true\n\n\t\tconst schema = await this.schemaLoader.loadSchema()\n\t\tlet stateMode = await this.schemaStateManager.isStateMode()\n\n\t\t// New project (no migrations yet) defaults to schema state mode. To opt out, create a migration first (e.g. `migrations:blank`).\n\t\tif (!stateMode && (await this.migrationsResolver.getSchemaMigrations()).length === 0) {\n\t\t\tconsole.log('No migrations found — enabling schema state mode for this project.')\n\t\t\tconsole.log('ACL, validation, actions and settings will be managed in the state/ directory instead of migrations.')\n\t\t\tawait this.schemaStateManager.extractState(schema)\n\t\t\tstateMode = true\n\t\t}\n\n\t\ttry {\n\t\t\tconst initialSchema = await this.schemaVersionBuilder.buildSchema()\n\t\t\tconst result = await this.migrationCreator.prepareMigration(initialSchema, schema, migrationName, {\n\t\t\t\tskipInitialSchemaValidation: skipInitialSchemaValidation,\n\t\t\t\tskipNonModelDiffers: stateMode,\n\t\t\t\trecreateViews,\n\t\t\t})\n\n\t\t\tconst schemaState = stateMode ? SchemaStateManager.schemaStateFromSchema(schema) : undefined\n\t\t\tconst stateChanged = schemaState ? await this.schemaStateManager.writeState(schemaState, { dryRun: true }) : false\n\n\t\t\tif (result === null) {\n\t\t\t\tif (stateChanged) {\n\t\t\t\t\tconsole.log('Schema state updated (no model changes)')\n\t\t\t\t\tawait this.schemaStateManager.writeState(schemaState!)\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log('Nothing to do')\n\t\t\t\t}\n\t\t\t\tif (stateChanged && shouldExecute) {\n\t\t\t\t\tconsole.log('Syncing schema state to server...')\n\t\t\t\t\tawait this.migrationExecutorFacade.execute({\n\t\t\t\t\t\tforce: false,\n\t\t\t\t\t\trequireConfirmation: false,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.migrationPrinter.printMigrationDescription(result.initialSchema, result.migration, { noSql: true })\n\n\t\t\tif (!yes) {\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: 'Yes' },\n\t\t\t\t\t\t...(!shouldExecute ? [{ value: 'execute', title: 'Yes and execute immediately' }] : []),\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 || action === 'no') {\n\t\t\t\t\tconsole.log('Aborting')\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (action === 'execute') {\n\t\t\t\t\tshouldExecute = true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst filename = await this.migrationCreator.saveMigration(result.migration)\n\t\t\tif (stateChanged) {\n\t\t\t\tawait this.schemaStateManager.writeState(schemaState!)\n\t\t\t}\n\n\t\t\tconsole.log(`${filename} created`)\n\t\t\tif (stateChanged) {\n\t\t\t\tconsole.log('Schema state files updated')\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (e instanceof InvalidSchemaException) {\n\t\t\t\tprintValidationErrors(e.validationErrors, e.message)\n\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\n\t\tif (shouldExecute) {\n\t\t\tawait this.migrationExecutorFacade.execute({\n\t\t\t\tforce: false,\n\t\t\t\trequireConfirmation: migrations => migrations.length !== 1 && !yes,\n\t\t\t})\n\t\t}\n\t}\n}\n"],"names":["Command","SchemaStateManager","InvalidSchemaException","printValidationErrors"],"mappings":";;;;;;;AAoBO,MAAM,6BAA6BA,UAAAA,QAAuB;AAAA,EAChE,YACkB,cACA,sBACA,kBACA,kBACA,yBACA,oBACA,oBAChB;AACD,UAAA;AARiB,SAAA,eAAA;AACA,SAAA,uBAAA;AACA,SAAA,mBAAA;AACA,SAAA,mBAAA;AACA,SAAA,0BAAA;AACA,SAAA,qBAAA;AACA,SAAA,qBAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,+BAA+B;AACzD,kBAAc,SAAS,eAAe;AACtC,kBAAc,OAAO,SAAS,EAAE,UAAA;AAChC,kBACE,OAAO,KAAK,EACZ,UAAA,EACA,YAAY,8BAA8B;AAE5C,kBAAc,OAAO,gCAAgC;AACrD,kBACE,OAAO,gBAAgB,EACvB,UAAA,EACA;AAAA,MACA;AAAA,IAAA;AAAA,EA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,eAAe,OAAO,WAAW,EAAE,OAAO,MAAM;AAEvG,UAAI,CAAC,KAAK;AACT,cAAM,EAAE,WAAW,MAAM,QAAQ;AAAA,UAChC,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,UACT,SAAS;AAAA,YACR,EAAE,OAAO,OAAO,OAAO,MAAA;AAAA,YACvB,GAAI,CAAC,gBAAgB,CAAC,EAAE,OAAO,WAAW,OAAO,8BAAA,CAA+B,IAAI,CAAA;AAAA,YACpF,EAAE,OAAO,MAAM,OAAO,QAAA;AAAA,UAAQ;AAAA,QAC/B,CACA;AACD,YAAI,CAAC,UAAU,WAAW,MAAM;AAC/B,kBAAQ,IAAI,UAAU;AACtB;AAAA,QACD;AACA,YAAI,WAAW,WAAW;AACzB,0BAAgB;AAAA,QACjB;AAAA,MACD;AAEA,YAAM,WAAW,MAAM,KAAK,iBAAiB,cAAc,OAAO,SAAS;AAC3E,UAAI,cAAc;AACjB,cAAM,KAAK,mBAAmB,WAAW,WAAY;AAAA,MACtD;AAEA,cAAQ,IAAI,GAAG,QAAQ,UAAU;AACjC,UAAI,cAAc;AACjB,gBAAQ,IAAI,4BAA4B;AAAA,MACzC;AAAA,IACD,SAAS,GAAG;AACX,UAAI,aAAaC,iBAAAA,wBAAwB;AACxCC,gCAAAA,sBAAsB,EAAE,kBAAkB,EAAE,OAAO;AAEnD;AAAA,MACD;AACA,YAAM;AAAA,IACP;AAEA,QAAI,eAAe;AAClB,YAAM,KAAK,wBAAwB,QAAQ;AAAA,QAC1C,OAAO;AAAA,QACP,qBAAqB,CAAA,eAAc,WAAW,WAAW,KAAK,CAAC;AAAA,MAAA,CAC/D;AAAA,IACF;AAAA,EACD;AACD;;"}
@@ -1,15 +1,18 @@
1
1
  import { Command } from "@contember/cli-common";
2
2
  import { InvalidSchemaException } from "@contember/schema-migrations";
3
3
  import prompts from "prompts";
4
+ import { SchemaStateManager } from "@contember/migrations-client";
4
5
  import { printValidationErrors } from "../../lib/schema/SchemaValidationPrinter.js";
5
6
  class MigrationDiffCommand extends Command {
6
- constructor(schemaLoader, schemaVersionBuilder, migrationCreator, migrationPrinter, migrationExecutorFacade) {
7
+ constructor(schemaLoader, schemaVersionBuilder, migrationCreator, migrationPrinter, migrationExecutorFacade, schemaStateManager, migrationsResolver) {
7
8
  super();
8
9
  this.schemaLoader = schemaLoader;
9
10
  this.schemaVersionBuilder = schemaVersionBuilder;
10
11
  this.migrationCreator = migrationCreator;
11
12
  this.migrationPrinter = migrationPrinter;
12
13
  this.migrationExecutorFacade = migrationExecutorFacade;
14
+ this.schemaStateManager = schemaStateManager;
15
+ this.migrationsResolver = migrationsResolver;
13
16
  }
14
17
  configure(configuration) {
15
18
  configuration.description("Creates schema migration diff");
@@ -17,20 +20,47 @@ class MigrationDiffCommand extends Command {
17
20
  configuration.option("execute").valueNone();
18
21
  configuration.option("yes").valueNone().description("Do not ask for confirmation.");
19
22
  configuration.option("skip-initial-schema-validation");
23
+ configuration.option("recreate-views").valueNone().description(
24
+ "Drop & recreate changed views instead of updating them in-place (CREATE OR REPLACE VIEW). Use when an in-place view update fails with SQLSTATE 42P16."
25
+ );
20
26
  }
21
27
  async execute(input) {
22
28
  const migrationName = input.getArgument("migrationName");
23
29
  let shouldExecute = input.getOption("execute");
24
30
  const yes = input.getOption("yes");
25
31
  const skipInitialSchemaValidation = input.getOption("skip-initial-schema-validation") === true;
32
+ const recreateViews = input.getOption("recreate-views") === true;
26
33
  const schema = await this.schemaLoader.loadSchema();
34
+ let stateMode = await this.schemaStateManager.isStateMode();
35
+ if (!stateMode && (await this.migrationsResolver.getSchemaMigrations()).length === 0) {
36
+ console.log("No migrations found — enabling schema state mode for this project.");
37
+ console.log("ACL, validation, actions and settings will be managed in the state/ directory instead of migrations.");
38
+ await this.schemaStateManager.extractState(schema);
39
+ stateMode = true;
40
+ }
27
41
  try {
28
42
  const initialSchema = await this.schemaVersionBuilder.buildSchema();
29
43
  const result = await this.migrationCreator.prepareMigration(initialSchema, schema, migrationName, {
30
- skipInitialSchemaValidation
44
+ skipInitialSchemaValidation,
45
+ skipNonModelDiffers: stateMode,
46
+ recreateViews
31
47
  });
48
+ const schemaState = stateMode ? SchemaStateManager.schemaStateFromSchema(schema) : void 0;
49
+ const stateChanged = schemaState ? await this.schemaStateManager.writeState(schemaState, { dryRun: true }) : false;
32
50
  if (result === null) {
33
- console.log("Nothing to do");
51
+ if (stateChanged) {
52
+ console.log("Schema state updated (no model changes)");
53
+ await this.schemaStateManager.writeState(schemaState);
54
+ } else {
55
+ console.log("Nothing to do");
56
+ }
57
+ if (stateChanged && shouldExecute) {
58
+ console.log("Syncing schema state to server...");
59
+ await this.migrationExecutorFacade.execute({
60
+ force: false,
61
+ requireConfirmation: false
62
+ });
63
+ }
34
64
  return;
35
65
  }
36
66
  this.migrationPrinter.printMigrationDescription(result.initialSchema, result.migration, { noSql: true });
@@ -54,7 +84,13 @@ class MigrationDiffCommand extends Command {
54
84
  }
55
85
  }
56
86
  const filename = await this.migrationCreator.saveMigration(result.migration);
87
+ if (stateChanged) {
88
+ await this.schemaStateManager.writeState(schemaState);
89
+ }
57
90
  console.log(`${filename} created`);
91
+ if (stateChanged) {
92
+ console.log("Schema state files updated");
93
+ }
58
94
  } catch (e) {
59
95
  if (e instanceof InvalidSchemaException) {
60
96
  printValidationErrors(e.validationErrors, e.message);
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationDiffCommand.js","sources":["../../../../../../packages/cli/src/commands/migrations/MigrationDiffCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { InvalidSchemaException } from '@contember/schema-migrations'\nimport prompts from 'prompts'\nimport { MigrationCreator, SchemaVersionBuilder } from '@contember/migrations-client'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader'\nimport { MigrationPrinter } from '../../lib/migrations/MigrationPrinter'\nimport { MigrationExecutionFacade } from '../../lib/migrations/MigrationExecutionFacade'\nimport { printValidationErrors } from '../../lib/schema/SchemaValidationPrinter'\n\ntype Args = {\n\tmigrationName: string\n}\n\ntype Options = {\n\texecute?: true\n\tyes?: true\n\t'skip-initial-schema-validation'?: true\n}\n\nexport class MigrationDiffCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationCreator: MigrationCreator,\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly migrationExecutorFacade: MigrationExecutionFacade,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Creates schema migration diff')\n\t\tconfiguration.argument('migrationName')\n\t\tconfiguration.option('execute').valueNone()\n\t\tconfiguration //\n\t\t\t.option('yes')\n\t\t\t.valueNone()\n\t\t\t.description('Do not ask for confirmation.')\n\n\t\tconfiguration.option('skip-initial-schema-validation')\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<void> {\n\t\tconst migrationName = input.getArgument('migrationName')\n\t\tlet shouldExecute = input.getOption('execute')\n\t\tconst yes = input.getOption('yes')\n\t\tconst skipInitialSchemaValidation = input.getOption('skip-initial-schema-validation') === true\n\n\t\tconst schema = await this.schemaLoader.loadSchema()\n\t\ttry {\n\t\t\tconst initialSchema = await this.schemaVersionBuilder.buildSchema()\n\t\t\tconst result = await this.migrationCreator.prepareMigration(initialSchema, schema, migrationName, {\n\t\t\t\tskipInitialSchemaValidation: skipInitialSchemaValidation,\n\t\t\t})\n\t\t\tif (result === null) {\n\t\t\t\tconsole.log('Nothing to do')\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.migrationPrinter.printMigrationDescription(result.initialSchema, result.migration, { noSql: true })\n\n\t\t\tif (!yes) {\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: 'Yes' },\n\t\t\t\t\t\t...(!shouldExecute ? [{ value: 'execute', title: 'Yes and execute immediately' }] : []),\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 || action === 'no') {\n\t\t\t\t\tconsole.log('Aborting')\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (action === 'execute') {\n\t\t\t\t\tshouldExecute = true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst filename = await this.migrationCreator.saveMigration(result.migration)\n\n\t\t\tconsole.log(`${filename} created`)\n\t\t} catch (e) {\n\t\t\tif (e instanceof InvalidSchemaException) {\n\t\t\t\tprintValidationErrors(e.validationErrors, e.message)\n\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\n\t\tif (shouldExecute) {\n\t\t\tawait this.migrationExecutorFacade.execute({\n\t\t\t\tforce: false,\n\t\t\t\trequireConfirmation: migrations => migrations.length !== 1 && !yes,\n\t\t\t})\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;AAmBO,MAAM,6BAA6B,QAAuB;AAAA,EAChE,YACkB,cACA,sBACA,kBACA,kBACA,yBAChB;AACD,UAAA;AANiB,SAAA,eAAA;AACA,SAAA,uBAAA;AACA,SAAA,mBAAA;AACA,SAAA,mBAAA;AACA,SAAA,0BAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,+BAA+B;AACzD,kBAAc,SAAS,eAAe;AACtC,kBAAc,OAAO,SAAS,EAAE,UAAA;AAChC,kBACE,OAAO,KAAK,EACZ,UAAA,EACA,YAAY,8BAA8B;AAE5C,kBAAc,OAAO,gCAAgC;AAAA,EACtD;AAAA,EAEA,MAAgB,QAAQ,OAA4C;AACnE,UAAM,gBAAgB,MAAM,YAAY,eAAe;AACvD,QAAI,gBAAgB,MAAM,UAAU,SAAS;AAC7C,UAAM,MAAM,MAAM,UAAU,K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AA,IACF;AAAA,EACD;AACD;"}
1
+ {"version":3,"file":"MigrationDiffCommand.js","sources":["../../../../../../packages/cli/src/commands/migrations/MigrationDiffCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { InvalidSchemaException } from '@contember/schema-migrations'\nimport prompts from 'prompts'\nimport { MigrationCreator, MigrationsResolver, SchemaStateManager, SchemaVersionBuilder } from '@contember/migrations-client'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader.js'\nimport { MigrationPrinter } from '../../lib/migrations/MigrationPrinter.js'\nimport { MigrationExecutionFacade } from '../../lib/migrations/MigrationExecutionFacade.js'\nimport { printValidationErrors } from '../../lib/schema/SchemaValidationPrinter.js'\n\ntype Args = {\n\tmigrationName: string\n}\n\ntype Options = {\n\texecute?: true\n\tyes?: true\n\t'skip-initial-schema-validation'?: true\n\t'recreate-views'?: true\n}\n\nexport class MigrationDiffCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t\tprivate readonly migrationCreator: MigrationCreator,\n\t\tprivate readonly migrationPrinter: MigrationPrinter,\n\t\tprivate readonly migrationExecutorFacade: MigrationExecutionFacade,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Creates schema migration diff')\n\t\tconfiguration.argument('migrationName')\n\t\tconfiguration.option('execute').valueNone()\n\t\tconfiguration //\n\t\t\t.option('yes')\n\t\t\t.valueNone()\n\t\t\t.description('Do not ask for confirmation.')\n\n\t\tconfiguration.option('skip-initial-schema-validation')\n\t\tconfiguration //\n\t\t\t.option('recreate-views')\n\t\t\t.valueNone()\n\t\t\t.description(\n\t\t\t\t'Drop & recreate changed views instead of updating them in-place (CREATE OR REPLACE VIEW). Use when an in-place view update fails with SQLSTATE 42P16.',\n\t\t\t)\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<void> {\n\t\tconst migrationName = input.getArgument('migrationName')\n\t\tlet shouldExecute = input.getOption('execute')\n\t\tconst yes = input.getOption('yes')\n\t\tconst skipInitialSchemaValidation = input.getOption('skip-initial-schema-validation') === true\n\t\tconst recreateViews = input.getOption('recreate-views') === true\n\n\t\tconst schema = await this.schemaLoader.loadSchema()\n\t\tlet stateMode = await this.schemaStateManager.isStateMode()\n\n\t\t// New project (no migrations yet) defaults to schema state mode. To opt out, create a migration first (e.g. `migrations:blank`).\n\t\tif (!stateMode && (await this.migrationsResolver.getSchemaMigrations()).length === 0) {\n\t\t\tconsole.log('No migrations found — enabling schema state mode for this project.')\n\t\t\tconsole.log('ACL, validation, actions and settings will be managed in the state/ directory instead of migrations.')\n\t\t\tawait this.schemaStateManager.extractState(schema)\n\t\t\tstateMode = true\n\t\t}\n\n\t\ttry {\n\t\t\tconst initialSchema = await this.schemaVersionBuilder.buildSchema()\n\t\t\tconst result = await this.migrationCreator.prepareMigration(initialSchema, schema, migrationName, {\n\t\t\t\tskipInitialSchemaValidation: skipInitialSchemaValidation,\n\t\t\t\tskipNonModelDiffers: stateMode,\n\t\t\t\trecreateViews,\n\t\t\t})\n\n\t\t\tconst schemaState = stateMode ? SchemaStateManager.schemaStateFromSchema(schema) : undefined\n\t\t\tconst stateChanged = schemaState ? await this.schemaStateManager.writeState(schemaState, { dryRun: true }) : false\n\n\t\t\tif (result === null) {\n\t\t\t\tif (stateChanged) {\n\t\t\t\t\tconsole.log('Schema state updated (no model changes)')\n\t\t\t\t\tawait this.schemaStateManager.writeState(schemaState!)\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log('Nothing to do')\n\t\t\t\t}\n\t\t\t\tif (stateChanged && shouldExecute) {\n\t\t\t\t\tconsole.log('Syncing schema state to server...')\n\t\t\t\t\tawait this.migrationExecutorFacade.execute({\n\t\t\t\t\t\tforce: false,\n\t\t\t\t\t\trequireConfirmation: false,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.migrationPrinter.printMigrationDescription(result.initialSchema, result.migration, { noSql: true })\n\n\t\t\tif (!yes) {\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: 'Yes' },\n\t\t\t\t\t\t...(!shouldExecute ? [{ value: 'execute', title: 'Yes and execute immediately' }] : []),\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 || action === 'no') {\n\t\t\t\t\tconsole.log('Aborting')\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (action === 'execute') {\n\t\t\t\t\tshouldExecute = true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst filename = await this.migrationCreator.saveMigration(result.migration)\n\t\t\tif (stateChanged) {\n\t\t\t\tawait this.schemaStateManager.writeState(schemaState!)\n\t\t\t}\n\n\t\t\tconsole.log(`${filename} created`)\n\t\t\tif (stateChanged) {\n\t\t\t\tconsole.log('Schema state files updated')\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (e instanceof InvalidSchemaException) {\n\t\t\t\tprintValidationErrors(e.validationErrors, e.message)\n\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\n\t\tif (shouldExecute) {\n\t\t\tawait this.migrationExecutorFacade.execute({\n\t\t\t\tforce: false,\n\t\t\t\trequireConfirmation: migrations => migrations.length !== 1 && !yes,\n\t\t\t})\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;AAoBO,MAAM,6BAA6B,QAAuB;AAAA,EAChE,YACkB,cACA,sBACA,kBACA,kBACA,yBACA,oBACA,oBAChB;AACD,UAAA;AARiB,SAAA,eAAA;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,YAAM;AAAA,IACP;AAEA,QAAI,eAAe;AAClB,YAAM,KAAK,wBAAwB,QAAQ;AAAA,QAC1C,OAAO;AAAA,QACP,qBAAqB,CAAA,eAAc,WAAW,WAAW,KAAK,CAAC;AAAA,MAAA,CAC/D;AAAA,IACF;AAAA,EACD;AACD;"}
@@ -10,6 +10,7 @@ class MigrationExecuteCommand extends cliCommon.Command {
10
10
  configuration.description("Executes migrations on Contember server.");
11
11
  configuration.option("force").description("Ignore migrations order and missing migrations (dev only)");
12
12
  configuration.option("until").valueRequired().description("Execute all migrations leading up to, and inclusive of, a specified migration");
13
+ configuration.option("no-snapshot").valueNone().description("Do not bootstrap a fresh database from snapshot.json; replay every migration instead");
13
14
  configuration.option("yes").valueNone().description("Do not ask for confirmation.");
14
15
  }
15
16
  async execute(input) {
@@ -18,7 +19,8 @@ class MigrationExecuteCommand extends cliCommon.Command {
18
19
  await this.migrationExecutorFacade.execute({
19
20
  force,
20
21
  until,
21
- requireConfirmation: !input.getOption("yes")
22
+ requireConfirmation: !input.getOption("yes"),
23
+ useSnapshot: input.getOption("no-snapshot") !== true
22
24
  });
23
25
  }
24
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MigrationExecuteCommand.cjs","sources":["../../../../../../packages/cli/src/commands/migrations/MigrationExecuteCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { MigrationExecutionFacade } from '../../lib/migrations/MigrationExecutionFacade'\n\ntype Args = {}\n\ntype Options = {\n\tuntil?: string\n\tforce: boolean\n\tyes?: boolean\n}\n\nexport class MigrationExecuteCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly migrationExecutorFacade: MigrationExecutionFacade,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Executes migrations on Contember server.')\n\t\tconfiguration.option('force')\n\t\t\t.description('Ignore migrations order and missing migrations (dev only)')\n\t\tconfiguration.option('until')\n\t\t\t.valueRequired()\n\t\t\t.description('Execute all migrations leading up to, and inclusive of, a specified migration')\n\t\tconfiguration //\n\t\t\t.option('yes')\n\t\t\t.valueNone()\n\t\t\t.description('Do not ask for confirmation.')\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<void> {\n\t\tconst force = input.getOption('force')\n\t\tconst until = input.getOption('until')\n\n\t\tawait this.migrationExecutorFacade.execute({\n\t\t\tforce,\n\t\t\tuntil,\n\t\t\trequireConfirmation: !input.getOption('yes'),\n\t\t})\n\t}\n}\n"],"names":["Command"],"mappings":";;;AAWO,MAAM,gCAAgCA,UAAAA,QAAuB;AAAA,EACnE,YACkB,yBAChB;AACD,UAAA;AAFiB,SAAA,0BAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,0CAA0C;AACpE,kBAAc,OAAO,OAAO,EAC1B,YAAY,2DAA2D;AACzE,kBAAc,OAAO,OAAO,EAC1B,cAAA,EACA,YAAY,+EAA+E;AAC7F,kBACE,OAAO,KAAK,EACZ,UAAA,EACA,YAAY,8BAA8B;AAAA,EAC7C;AAAA,EAEA,MAAgB,QAAQ,OAA4C;AACnE,UAAM,QAAQ,MAAM,UAAU,OAAO;AACrC,UAAM,QAAQ,MAAM,UAAU,OAAO;AAErC,UAAM,KAAK,wBAAwB,QAAQ;AAAA,MAC1C;AAAA,MACA;AAAA,MACA,qBAAqB,CAAC,MAAM,UAAU,KAAK;AAAA,IAAA,CAC3C;AAAA,EACF;AACD;;"}
1
+ {"version":3,"file":"MigrationExecuteCommand.cjs","sources":["../../../../../../packages/cli/src/commands/migrations/MigrationExecuteCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { MigrationExecutionFacade } from '../../lib/migrations/MigrationExecutionFacade.js'\n\ntype Args = {}\n\ntype Options = {\n\tuntil?: string\n\tforce: boolean\n\tyes?: boolean\n\t['no-snapshot']?: boolean\n}\n\nexport class MigrationExecuteCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly migrationExecutorFacade: MigrationExecutionFacade,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Executes migrations on Contember server.')\n\t\tconfiguration.option('force')\n\t\t\t.description('Ignore migrations order and missing migrations (dev only)')\n\t\tconfiguration.option('until')\n\t\t\t.valueRequired()\n\t\t\t.description('Execute all migrations leading up to, and inclusive of, a specified migration')\n\t\tconfiguration.option('no-snapshot')\n\t\t\t.valueNone()\n\t\t\t.description('Do not bootstrap a fresh database from snapshot.json; replay every migration instead')\n\t\tconfiguration //\n\t\t\t.option('yes')\n\t\t\t.valueNone()\n\t\t\t.description('Do not ask for confirmation.')\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<void> {\n\t\tconst force = input.getOption('force')\n\t\tconst until = input.getOption('until')\n\n\t\tawait this.migrationExecutorFacade.execute({\n\t\t\tforce,\n\t\t\tuntil,\n\t\t\trequireConfirmation: !input.getOption('yes'),\n\t\t\tuseSnapshot: input.getOption('no-snapshot') !== true,\n\t\t})\n\t}\n}\n"],"names":["Command"],"mappings":";;;AAYO,MAAM,gCAAgCA,UAAAA,QAAuB;AAAA,EACnE,YACkB,yBAChB;AACD,UAAA;AAFiB,SAAA,0BAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,0CAA0C;AACpE,kBAAc,OAAO,OAAO,EAC1B,YAAY,2DAA2D;AACzE,kBAAc,OAAO,OAAO,EAC1B,cAAA,EACA,YAAY,+EAA+E;AAC7F,kBAAc,OAAO,aAAa,EAChC,UAAA,EACA,YAAY,sFAAsF;AACpG,kBACE,OAAO,KAAK,EACZ,UAAA,EACA,YAAY,8BAA8B;AAAA,EAC7C;AAAA,EAEA,MAAgB,QAAQ,OAA4C;AACnE,UAAM,QAAQ,MAAM,UAAU,OAAO;AACrC,UAAM,QAAQ,MAAM,UAAU,OAAO;AAErC,UAAM,KAAK,wBAAwB,QAAQ;AAAA,MAC1C;AAAA,MACA;AAAA,MACA,qBAAqB,CAAC,MAAM,UAAU,KAAK;AAAA,MAC3C,aAAa,MAAM,UAAU,aAAa,MAAM;AAAA,IAAA,CAChD;AAAA,EACF;AACD;;"}