ch-migrate-cli 0.5.0__tar.gz → 0.5.1__tar.gz

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 (65) hide show
  1. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/PKG-INFO +4 -4
  2. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/README.md +3 -3
  3. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/__init__.py +1 -1
  4. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/cli.py +5 -2
  5. ch_migrate_cli-0.5.1/tests/test_status_command.py +36 -0
  6. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/.gitignore +0 -0
  7. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/LICENSE +0 -0
  8. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/authoring.py +0 -0
  9. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/bootstrap.py +0 -0
  10. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/config.py +0 -0
  11. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/connection.py +0 -0
  12. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/deps.py +0 -0
  13. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/diff.py +0 -0
  14. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/display.py +0 -0
  15. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/downgrade.py +0 -0
  16. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/env.py +0 -0
  17. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/helpers.py +0 -0
  18. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/hooks.py +0 -0
  19. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/introspect.py +0 -0
  20. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/lint.py +0 -0
  21. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/mv_validate.py +0 -0
  22. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/py.typed +0 -0
  23. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/rebase.py +0 -0
  24. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/runner.py +0 -0
  25. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/scaffold.py +0 -0
  26. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/secrets.py +0 -0
  27. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/skills/ch-migrate/SKILL.md +0 -0
  28. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/sql.py +0 -0
  29. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/statements.py +0 -0
  30. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/templates/bootstrap/init_users.sql +0 -0
  31. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/templates/project/alembic.ini.template +0 -0
  32. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/templates/project/config.yaml.template +0 -0
  33. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/templates/project/env.local.example.template +0 -0
  34. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/templates/project/script.py.mako.template +0 -0
  35. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/ch_migrate/ui.py +0 -0
  36. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/clickhouse_alembic/__init__.py +0 -0
  37. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/pyproject.toml +0 -0
  38. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/integration/conftest.py +0 -0
  39. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/integration/test_irreversible.py +0 -0
  40. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/integration/test_lint_pending.py +0 -0
  41. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/integration/test_readme_quickstart.py +0 -0
  42. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/integration/test_run_sql.py +0 -0
  43. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/integration/test_smoke.py +0 -0
  44. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/integration/test_sql_first.py +0 -0
  45. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_bootstrap.py +0 -0
  46. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_compat_import.py +0 -0
  47. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_config.py +0 -0
  48. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_deps.py +0 -0
  49. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_diff.py +0 -0
  50. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_display.py +0 -0
  51. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_downgrade.py +0 -0
  52. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_helpers.py +0 -0
  53. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_hooks.py +0 -0
  54. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_introspect.py +0 -0
  55. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_lint.py +0 -0
  56. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_mv_validate.py +0 -0
  57. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_new.py +0 -0
  58. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_package.py +0 -0
  59. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_readme.py +0 -0
  60. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_rebase.py +0 -0
  61. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_scaffold.py +0 -0
  62. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_secrets.py +0 -0
  63. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_snapshot.py +0 -0
  64. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_sql.py +0 -0
  65. {ch_migrate_cli-0.5.0 → ch_migrate_cli-0.5.1}/tests/test_statements.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: ch-migrate-cli
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: SQL-first ClickHouse schema migrations across environments: the ch-migrate command
5
5
  Project-URL: Homepage, https://github.com/DRYCodeWorks/ch-migrate
6
6
  Project-URL: Repository, https://github.com/DRYCodeWorks/ch-migrate
@@ -58,7 +58,7 @@ pip install ch-migrate-cli
58
58
  ch-migrate --version
59
59
  ```
60
60
 
61
- The command is `ch-migrate`, the PyPI package is `ch-migrate-cli` (PyPI treats `ch-migrate` as the same name as the existing, unrelated `chmigrate`), and migrations import from `ch_migrate`. Versions up to 0.4.1 were published as `clickhouse-alembic` with the import package `clickhouse_alembic`; that import still works with a deprecation warning until 1.0, so existing migration files keep running. Replace `clickhouse_alembic` with `ch_migrate` in them when convenient, and run `ch-migrate upgrade-env` to refresh `migrations/env.py`.
61
+ The command is `ch-migrate`, the PyPI package is `ch-migrate-cli` (PyPI treats `ch-migrate` as the same name as the existing, unrelated `chmigrate`), and migrations import from `ch_migrate`. Versions up to 0.4.1 were published as `clickhouse-alembic` with the import package `clickhouse_alembic`; that import still works with a deprecation warning until 1.0, so existing migration files keep running. Replace `clickhouse_alembic` with `ch_migrate` in them when convenient. For `migrations/env.py`, run `ch-migrate upgrade-env` only if you never edited it; if you did (for example to add connection settings), change its `clickhouse_alembic` imports to `ch_migrate` by hand instead, because `upgrade-env` replaces the whole file.
62
62
 
63
63
  To switch an existing install, remove the old package first, because both install the `ch-migrate` command and the `clickhouse_alembic` folder: `uv tool uninstall clickhouse-alembic && uv tool install ch-migrate-cli`, or `pip uninstall clickhouse-alembic && pip install ch-migrate-cli`. In a project that lists `clickhouse-alembic` as a dependency, replace it with `ch-migrate-cli`.
64
64
 
@@ -285,7 +285,7 @@ Example: `ch-migrate down dev --revision base`
285
285
 
286
286
  ### `status`
287
287
 
288
- `ch-migrate status ENV` shows connection information, applied/pending counts, and head status, and names the `up` command when migrations are pending. No command-specific options. Exits 1 if it cannot reach the database.
288
+ `ch-migrate status ENV` shows connection information, applied/pending counts, and head status, and names the `up` command when migrations are pending. No command-specific options. Status is a report: it exits 0 when the database is unreachable (with a warning) or migrations are pending, and exits 1 only when the configuration or `migrations/versions/` is missing, so CI can run it as a non-blocking check.
289
289
 
290
290
  Example: `ch-migrate status dev`
291
291
 
@@ -335,7 +335,7 @@ Example: `ch-migrate rebase dev --onto abc123 --dry-run`
335
335
 
336
336
  ### `upgrade-env`
337
337
 
338
- `ch-migrate upgrade-env` replaces `migrations/env.py` with the installed version and backs up the old file as `env.py.bak`. No command-specific options. Review and reapply local customizations from the backup.
338
+ `ch-migrate upgrade-env` replaces `migrations/env.py` with the installed version and backs up the old file as `env.py.bak`. No command-specific options. It does not merge: any local customizations (connection settings, session pins, hooks) are dropped from the new file. Reapply them from the backup, or skip `upgrade-env` and edit a customized `env.py` by hand.
339
339
 
340
340
  Example: `ch-migrate upgrade-env`
341
341
 
@@ -15,7 +15,7 @@ pip install ch-migrate-cli
15
15
  ch-migrate --version
16
16
  ```
17
17
 
18
- The command is `ch-migrate`, the PyPI package is `ch-migrate-cli` (PyPI treats `ch-migrate` as the same name as the existing, unrelated `chmigrate`), and migrations import from `ch_migrate`. Versions up to 0.4.1 were published as `clickhouse-alembic` with the import package `clickhouse_alembic`; that import still works with a deprecation warning until 1.0, so existing migration files keep running. Replace `clickhouse_alembic` with `ch_migrate` in them when convenient, and run `ch-migrate upgrade-env` to refresh `migrations/env.py`.
18
+ The command is `ch-migrate`, the PyPI package is `ch-migrate-cli` (PyPI treats `ch-migrate` as the same name as the existing, unrelated `chmigrate`), and migrations import from `ch_migrate`. Versions up to 0.4.1 were published as `clickhouse-alembic` with the import package `clickhouse_alembic`; that import still works with a deprecation warning until 1.0, so existing migration files keep running. Replace `clickhouse_alembic` with `ch_migrate` in them when convenient. For `migrations/env.py`, run `ch-migrate upgrade-env` only if you never edited it; if you did (for example to add connection settings), change its `clickhouse_alembic` imports to `ch_migrate` by hand instead, because `upgrade-env` replaces the whole file.
19
19
 
20
20
  To switch an existing install, remove the old package first, because both install the `ch-migrate` command and the `clickhouse_alembic` folder: `uv tool uninstall clickhouse-alembic && uv tool install ch-migrate-cli`, or `pip uninstall clickhouse-alembic && pip install ch-migrate-cli`. In a project that lists `clickhouse-alembic` as a dependency, replace it with `ch-migrate-cli`.
21
21
 
@@ -242,7 +242,7 @@ Example: `ch-migrate down dev --revision base`
242
242
 
243
243
  ### `status`
244
244
 
245
- `ch-migrate status ENV` shows connection information, applied/pending counts, and head status, and names the `up` command when migrations are pending. No command-specific options. Exits 1 if it cannot reach the database.
245
+ `ch-migrate status ENV` shows connection information, applied/pending counts, and head status, and names the `up` command when migrations are pending. No command-specific options. Status is a report: it exits 0 when the database is unreachable (with a warning) or migrations are pending, and exits 1 only when the configuration or `migrations/versions/` is missing, so CI can run it as a non-blocking check.
246
246
 
247
247
  Example: `ch-migrate status dev`
248
248
 
@@ -292,7 +292,7 @@ Example: `ch-migrate rebase dev --onto abc123 --dry-run`
292
292
 
293
293
  ### `upgrade-env`
294
294
 
295
- `ch-migrate upgrade-env` replaces `migrations/env.py` with the installed version and backs up the old file as `env.py.bak`. No command-specific options. Review and reapply local customizations from the backup.
295
+ `ch-migrate upgrade-env` replaces `migrations/env.py` with the installed version and backs up the old file as `env.py.bak`. No command-specific options. It does not merge: any local customizations (connection settings, session pins, hooks) are dropped from the new file. Reapply them from the backup, or skip `upgrade-env` and edit a customized `env.py` by hand.
296
296
 
297
297
  Example: `ch-migrate upgrade-env`
298
298
 
@@ -5,7 +5,7 @@ Usage:
5
5
  from ch_migrate import read_sql, get_db, get_env_config, create_dictionary
6
6
  """
7
7
 
8
- __version__ = "0.5.0"
8
+ __version__ = "0.5.1"
9
9
 
10
10
 
11
11
  from typing import Any
@@ -250,14 +250,17 @@ def status(environment: str) -> None:
250
250
  """Show migration status.
251
251
 
252
252
  Displays environment info, applied/pending counts, and head status.
253
- Exits 1 if the database cannot be reached.
253
+ Status is a report: it exits 0 even when the database cannot be reached or
254
+ migrations are pending, and exits 1 only when the config or migrations/versions/
255
+ is missing. CI jobs use it as a non-blocking reporter.
254
256
  """
255
257
  from ch_migrate.display import render_status
256
258
 
257
259
  state = _load_migration_state(environment)
258
260
  render_status(environment, state.env_config, state.graph, state.applied, db_error=state.db_error)
259
261
  if state.db_error:
260
- ui.fail(f"Could not reach the database: {state.db_error.strip().splitlines()[0]}")
262
+ ui.warn(f"Could not reach the database: {state.db_error.strip().splitlines()[0]}")
263
+ return
261
264
  pending = len(set(state.graph.migrations) - (state.applied or set()))
262
265
  if pending:
263
266
  noun = "migration" if pending == 1 else "migrations"
@@ -0,0 +1,36 @@
1
+ """`ch-migrate status` is a report: CI runs it as a non-blocking check.
2
+
3
+ Sazabi's required "ClickHouse Migration Status" job relies on status exiting 0 when
4
+ the database is unreachable or migrations are pending; only a broken project fails.
5
+ """
6
+
7
+ import pytest
8
+ from click.testing import CliRunner
9
+
10
+ from ch_migrate import connection
11
+ from ch_migrate.cli import main
12
+
13
+
14
+ @pytest.fixture
15
+ def project(tmp_path, monkeypatch):
16
+ result = CliRunner().invoke(main, ["init", str(tmp_path), "--name", "demo"])
17
+ assert result.exit_code == 0, result.output
18
+ monkeypatch.chdir(tmp_path)
19
+ monkeypatch.setenv("CH_DEV_MIGRATION_PASSWORD", "test-only")
20
+ return tmp_path
21
+
22
+
23
+ def test_unreachable_database_is_reported_and_exits_zero(project, monkeypatch):
24
+ def refuse(env_config):
25
+ raise ConnectionError("Connection refused")
26
+
27
+ monkeypatch.setattr(connection, "get_current_heads", refuse)
28
+ result = CliRunner().invoke(main, ["status", "dev"])
29
+ assert result.exit_code == 0, result.output
30
+ assert "Could not reach the database: Connection refused" in result.output
31
+
32
+
33
+ def test_unknown_environment_fails(project):
34
+ result = CliRunner().invoke(main, ["status", "nope"])
35
+ assert result.exit_code == 1
36
+ assert "Unknown environment: nope" in result.output
File without changes