Skip to content

Commit 6b60e94

Browse files
committed
do not upgrade if beta_testing
1 parent e97f9df commit 6b60e94

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

docs/docs/cli.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
usage: pum [-h] [-c CONFIG_FILE] -p PG_CONNECTION [-d DIR] [-v] [--version] {info,install,upgrade,role,check,dump,restore,baseline} ...
1+
usage: pum [-h] [-c CONFIG_FILE] -p PG_CONNECTION [-d DIR] [-v] [-q] [--version] {info,install,upgrade,role,check,dump,restore,baseline} ...
22
### options:
33
- `-h, --help`: show this help message and exit
44
- `-c CONFIG_FILE, --config_file CONFIG_FILE`: set the config file. Default: .pum.yaml
55
- `-p PG_CONNECTION, --pg-connection PG_CONNECTION`: PostgreSQL service name or connection string (e.g., 'mydb' or 'postgresql://user:pass@host/db')
66
- `-d DIR, --dir DIR`: Directory or URL of the module. Default: .
7-
- `-v, --verbose`: Increase output verbosity (e.g. -v, -vv)
7+
- `-v, --verbose`: Increase verbosity (-v for DEBUG, -vv for SQL statements)
8+
- `-q, --quiet`: Suppress info messages, only show warnings and errors
89
- `--version`: Show program's version number and exit.
910
### commands:
1011
valid pum commands

docs/docs/cli/upgrade.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
usage: pum upgrade [-h] [-p PARAMETER PARAMETER] [-u MAX_VERSION] [--skip-grant] [--beta-testing] [--skip-drop-app] [--skip-create-app]
1+
usage: pum upgrade [-h] [-p PARAMETER PARAMETER] [-u MAX_VERSION] [--skip-grant] [--beta-testing] [--force] [--skip-drop-app] [--skip-create-app]
22
### options:
33
- `-h, --help`: show this help message and exit
44
- `-p PARAMETER PARAMETER, --parameter PARAMETER PARAMETER`: Assign variable for running SQL deltas. Format is name value.
55
- `-u MAX_VERSION, --max-version MAX_VERSION`: maximum version to upgrade
66
- `--skip-grant`: Skip granting permissions to roles
77
- `--beta-testing`: Install in beta testing mode.
8+
- `--force`: Allow upgrading a module installed in beta testing mode.
89
- `--skip-drop-app`: Skip drop app handlers during upgrade.
910
- `--skip-create-app`: Skip create app handlers during upgrade.

pum/cli.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ def formatter_class(prog):
210210
parser_upgrade.add_argument(
211211
"--beta-testing", help="Install in beta testing mode.", action="store_true"
212212
)
213+
parser_upgrade.add_argument(
214+
"--force",
215+
help="Allow upgrading a module installed in beta testing mode.",
216+
action="store_true",
217+
)
213218
parser_upgrade.add_argument(
214219
"--skip-drop-app",
215220
help="Skip drop app handlers during upgrade.",
@@ -466,6 +471,7 @@ def cli() -> int: # noqa: PLR0912
466471
max_version=args.max_version,
467472
grant=not args.skip_grant,
468473
beta_testing=args.beta_testing,
474+
force=args.force,
469475
skip_drop_app=args.skip_drop_app,
470476
skip_create_app=args.skip_create_app,
471477
)

pum/upgrader.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def upgrade(
193193
parameters: dict | None = None,
194194
max_version: str | packaging.version.Version | None = None,
195195
beta_testing: bool = False,
196+
force: bool = False,
196197
skip_drop_app: bool = False,
197198
skip_create_app: bool = False,
198199
grant: bool = True,
@@ -211,6 +212,8 @@ def upgrade(
211212
If True, the module is upgraded in beta testing mode.
212213
This means that the module will not be allowed to receive any future updates.
213214
We strongly discourage using this for production.
215+
force:
216+
If True, allow upgrading a module that is installed in beta testing mode.
214217
skip_drop_app:
215218
If True, drop app handlers will be skipped.
216219
skip_create_app:
@@ -225,6 +228,17 @@ def upgrade(
225228
)
226229
raise PumException(msg)
227230

231+
migration_details = self.schema_migrations.migration_details(connection)
232+
installed_beta_testing = bool(migration_details.get("beta_testing", False))
233+
if installed_beta_testing and not force:
234+
msg = (
235+
"This module is installed in beta testing mode, upgrades are disabled. "
236+
"Re-run with force=True (or --force in the CLI) if you really want to upgrade anyway."
237+
)
238+
raise PumException(msg)
239+
240+
effective_beta_testing = beta_testing or installed_beta_testing
241+
228242
logger.info("Starting upgrade process...")
229243

230244
if not skip_drop_app:
@@ -251,7 +265,7 @@ def upgrade(
251265
commit=False,
252266
parameters=parameters,
253267
schema_migrations=self.schema_migrations,
254-
beta_testing=beta_testing,
268+
beta_testing=effective_beta_testing,
255269
)
256270

257271
if not skip_create_app:

test/test_upgrader.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,28 @@ def test_upgrade(self) -> None:
473473
upgrader.upgrade(connection=conn)
474474
self.assertEqual(sm.baseline(conn), Version("2.0.0"))
475475

476+
def test_upgrade_blocked_when_installed_beta_testing_unless_forced(self) -> None:
477+
"""Upgrading a beta-testing installation should be blocked unless forced."""
478+
test_dir = Path("test") / "data" / "multiple_changelogs"
479+
cfg = PumConfig(test_dir)
480+
sm = SchemaMigrations(cfg)
481+
with psycopg.connect(f"service={self.pg_service}") as conn:
482+
self.assertFalse(sm.exists(conn))
483+
upgrader = Upgrader(config=cfg)
484+
upgrader.install(connection=conn, max_version="1.2.3", beta_testing=True)
485+
self.assertEqual(sm.baseline(conn), Version("1.2.3"))
486+
self.assertTrue(sm.migration_details(conn)["beta_testing"])
487+
488+
with self.assertRaises(PumException):
489+
upgrader.upgrade(connection=conn, max_version="1.2.4")
490+
491+
upgrader.upgrade(connection=conn, max_version="1.2.4", force=True)
492+
self.assertEqual(sm.baseline(conn), Version("1.2.4"))
493+
self.assertTrue(sm.migration_details(conn)["beta_testing"])
494+
495+
with self.assertRaises(PumException):
496+
upgrader.upgrade(connection=conn, force=False)
497+
476498
def test_upgrade_with_grant(self) -> None:
477499
"""Test that permissions are granted correctly after upgrade."""
478500
test_dir = Path("test") / "data" / "roles"

0 commit comments

Comments
 (0)