Skip to content

feat(upgrade): migrate only from 1.5; add cli/upgrade_legacy.php; move CLI scripts to cli/ (#839) - #905

Merged
TheWitness merged 3 commits into
developfrom
feature/839-upgrade-baseline-1.5
Dec 4, 2026
Merged

TheWitness merged 3 commits into
developfrom
feature/839-upgrade-baseline-1.5

Conversation

@TheWitness

@TheWitness TheWitness commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Closes #839

Summary

  • Upgrade baseline is 1.5. includes/database.php now migrates only from THOLD_UPGRADE_BASELINE (1.5). All gates below 1.5 are gone (0.4 through 1.2.4), so the file shrinks from 2,208 to about 960 lines. The 1.5.1, 1.5.3, 1.6, 1.8 and 1.8.3 gates and the unconditional column checks are unchanged.
  • Older installs are refused, with nothing changed. If plugin_config records a version below 1.5, thold_upgrade_database() writes a Cacti log error that names the CLI and returns before touching the schema or the recorded version. A fresh install (empty version) is unaffected.
  • force now means "from the baseline". The repair callers (thold.php, poller_thold.php, cli/upgrade.php) re-run every retained gate starting from 1.5, instead of from 0.1.

cli/upgrade_legacy.php

New CLI in a new cli/ folder, with the usual option parsing plus display_version() and display_help():

Option
--dry-run Report the installed version and the legacy steps that would run; change nothing
--debug, -d Print the migration steps as they run
--version, -v, -V / --help, -h, -H Standard

Flow:

  1. Not installed: error.
  2. Below 1.0: error with "uninstall and install the current release". Pre-1.0 migrations are discarded, as decided.
  3. Already 1.5 or later: nothing to do.
  4. Otherwise: thold_setup_database(), then the 1.0.1 - 1.2.4 gates moved verbatim from database.php. It then records 1.5, runs plugin_thold_install(true) (current hooks, realms, and thold_upgrade_database() from the baseline) and thold_prune_files().

Other

  • manifest.json: cli/ added to expected; cli/index.php is the usual directory guard.
  • tests/bin/patch-coverage.php: cli/upgrade_legacy.php and cli/index.php added to the unmeasured allowlist, alongside the other CLI entry points.
  • README.md upgrade note and a CHANGELOG.md entry.

Tests

UpgradeBaselineTest:

  • thold_upgrade_needs_legacy() across fresh install, 1.0, 1.2.4, 1.4.9, 1.5 and 1.8.3.
  • A 1.2.4 install is refused with no db_execute* calls and a log line naming the CLI.
  • database.php contains no gate at or below 1.5.
  • The CLI carries every retired 1.0.1 - 1.2.4 gate and none from before 1.0.

The harness gains a cacti_version_compare() stub and an empty cacti-lib/database.php fixture. Local run: 680 passed; validate-manifest.php OK.

Review updates (5ceb6ab)

A pre-1.5 install is refused before any side effects, and force cannot bypass it:

  • thold_upgrade_database() checks the recorded version before applying $force.
  • plugin_thold_upgrade() checks before plugin_thold_install(true) and thold_prune_files().
  • plugin_thold_install(true) checks before registering hooks and realms.

The shared check and its log line are thold_upgrade_blocked_by_legacy(). The refused install keeps its recorded version, schema, hooks and files until cli/upgrade_legacy.php runs.

CLI scripts moved into cli/ (95b847e)

All non-polling command line scripts now live in cli/, without the cli_ prefix:

Old New
cli_thresholds.php cli/thresholds.php
cli_import.php cli/import.php
extras/upgrade.php cli/upgrade.php
extras/apply_realms.php cli/apply_realms.php
  • The polling scripts (poller_thold.php, thold_daemon.php, thold_process.php, thold_notify.php) stay at the plugin root.
  • extras/ is now empty and removed.
  • cli_thresholds.php, cli_import.php and extras/ are tombstoned in manifest.json, so an upgrade deletes the old copies. cli/upgrade_legacy.php is new, so it has nothing to tombstone.
  • The cli_check.php include and the chdir() paths are adjusted for the extra directory level.
  • Usage text, README, .github/copilot-instructions.md, the coverage allowlist and the CHANGELOG are updated.

includes/database.php now migrates only from THOLD_UPGRADE_BASELINE
(1.5). The 1.0.1 - 1.2.4 migrations move verbatim to the new
cli/upgrade_legacy.php, which brings a 1.0 - 1.4 install to 1.5 and then
runs the normal upgrade; anything before 1.0 is discarded. An older
install is refused with a Cacti log error and nothing changed, and a
forced upgrade re-runs the migrations from the baseline.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical upgrade safeguards remain incomplete: forced repairs can skip required legacy migrations, and baseline refusal does not prevent installer side effects, hook activation, or file pruning.

2 open issues
What changed in this PR

Establishes Thold 1.5 as the automatic-upgrade baseline, separating legacy migrations from the Cacti plugin’s normal upgrade path.

Changes:

  • Adds a legacy upgrade CLI with dry-run and debug options.
  • Removes pre-baseline migrations from the normal upgrader and changes forced repairs to start at 1.5.
  • Updates documentation, packaging, and baseline regression tests.
File Description
tests/​Unit/​UpgradeBaselineTest.php Tests baseline checks and migration placement.
tests/​Fixtures/​cacti-lib/​database.php Adds a database include fixture.
tests/​bootstrap-unit.php Adds a version-comparison stub.
tests/​bin/​patch-coverage.php Excludes new CLI files from coverage measurement.
README.md Documents the legacy upgrade procedure.
manifest.json Includes the new CLI directory.
includes/​database.php Enforces the baseline and retains newer migrations.
cli/​upgrade_legacy.php Runs legacy migrations before the standard upgrade.
cli/​index.php Adds a directory redirect guard.
CHANGELOG.md Records the upgrade-policy changes.

Review effort: Balanced

Comment thread includes/database.php Resolved
Comment thread includes/database.php Resolved
TheWitness and others added 2 commits December 3, 2026 20:49
…839)

- thold_upgrade_database() checks the recorded version before applying
  $force, so a forced repair (poller_thold.php forces one when a column
  is missing) cannot mark a legacy install current.
- plugin_thold_upgrade() refuses before plugin_thold_install(true) and
  thold_prune_files(), and plugin_thold_install(true) refuses before
  registering hooks and realms, so a legacy install is left untouched
  until cli/upgrade_legacy.php runs. The check and its log line live in
  thold_upgrade_blocked_by_legacy().

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- cli_thresholds.php -> cli/thresholds.php
- cli_import.php -> cli/import.php
- extras/upgrade.php -> cli/upgrade.php
- extras/apply_realms.php -> cli/apply_realms.php

The polling scripts (poller_thold.php, thold_daemon.php,
thold_process.php, thold_notify.php) stay at the plugin root. The old
paths and extras/ are tombstoned in manifest.json so an upgrade removes
them; the paths to include/cli_check.php are adjusted for the new depth.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TheWitness TheWitness changed the title feat(upgrade): migrate only from 1.5; add cli/upgrade_legacy.php (#839) feat(upgrade): migrate only from 1.5; add cli/upgrade_legacy.php; move CLI scripts to cli/ (#839) Dec 4, 2026
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
8.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecate old upgrade paths so bespoke version-gated migrations can be retired for db_update_table

3 participants