Skip to content

Skip migration steps that add an already existing column - #2587

Merged
m3nu merged 2 commits into
borgbase:masterfrom
rajanpanth:fix-tolerate-existing-columns
Nov 3, 2026
Merged

m3nu merged 2 commits into
borgbase:masterfrom
rajanpanth:fix-tolerate-existing-columns

Conversation

@rajanpanth

Copy link
Copy Markdown
Contributor

Description

_apply_schema_update() now runs the migration operations one by one and skips add_column operations whose column already exists in the table (checked with get_columns()), logging a warning. The schema version is still bumped, so the remaining migrations run as usual. Because the check lives in _apply_schema_update(), it covers all existing and future migrations without changing them.

The check works with peewee 3 (Operation.method holds the method name; uv.lock has 3.18.3, distros ship 3.x) and peewee 4 (Operation.fn holds the function; what an unpinned pip install gets today).

Only add_column is handled, since every reported failure is a "duplicate column name". The other non-additive steps were left alone: rename_column/drop_column only exist in the v7 migration, re-running drop_not_null is already harmless, and the data migrations at v11/v13 are already safe to repeat. Existing columns are not backfilled, as apply_default would overwrite existing values.

Related Issue

Fixes #2275
Related to #1797

The same crash was reported before for other columns in #936 (dir_size), #1117 (schedule_interval_unit), #1761 and #2253 (group), which were closed without a general fix.

Motivation and Context

When settings.db already contains a column of a newer schema while its schema version is older (e.g. after a partly applied migration), Vorta crashes on startup with sqlite3.OperationalError: duplicate column name: ... and users have to repair the database by hand. With this change, Vorta skips the redundant step and finishes the migration.

How Has This Been Tested?

  • New tests/unit/test_migrations.py: builds a database at schema version 19 that already has settingsmodel.tooltip (from version 20) and lacks the v21–v23 columns, runs run_migrations(), and checks that it reaches SCHEMA_VERSION with all columns present. Without the fix, it fails with duplicate column name: tooltip.
  • Ran it with peewee 3.18.3 and 4.5.3, together with test_settings_store.py and test_profile.py (Python 3.12, PyQt6 6.10.1, QT_QPA_PLATFORM=offscreen). I could only run part of the suite locally because I'm on Windows without Borg, so I'm relying on CI for the full run.
  • ruff check, ruff format --check and mypy src/vorta/store/ src/vorta/network_status/ pass.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have read the CONTRIBUTING guide.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

I used Claude Code to help write this change and its test. I reviewed and tested it myself and can answer questions about it.

I provide my contribution under the terms of the license of this repository and I affirm the Developer Certificate of Origin.

🤖 Generated with Claude Code

rajanpanth and others added 2 commits October 30, 2026 12:40
Vorta failed to start with "duplicate column name" when a schema
migration tried to add a column that the database already had while
its schema version was older, e.g. after an earlier migration was only
partly applied. The user then had to repair settings.db by hand.

_apply_schema_update() now runs the operations one by one and skips
add_column operations whose column already exists, logging a warning.
The schema version is still bumped, so the remaining migrations run
as usual. This applies to all existing and future migrations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@m3nu
m3nu merged commit b03a533 into borgbase:master Nov 3, 2026
5 checks passed
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.

Uncaught exception: sqlite3.OperationalError: duplicate column name: tooltip

2 participants