Skip to content

Migration backup#6742

Open
semohr wants to merge 5 commits into
masterfrom
migration_backup
Open

Migration backup#6742
semohr wants to merge 5 commits into
masterfrom
migration_backup

Conversation

@semohr

@semohr semohr commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Description

Creates a timestamped .bak copy of the database before any pending schema migration runs, so users can recover if a migration goes wrong. Controlled by the new create_backup_before_migrations config option (default: yes).

Changes:

  • Migration.migrate_model: before running migration data, copies the database file to <library.db>.<timestamp>.bak (once per startup, guarded by a ClassVar flag)
  • Database.create_copy(dest): copies the SQLite file to the given path

TODOs:

  • Documentation.
  • Changelog. (Add an entry to docs/changelog.rst to the bottom of one of the lists near the top of the document.)
  • Tests. (Very much encouraged but not strictly required.)

@semohr semohr requested a review from a team as a code owner June 14, 2026 15:59
Copilot AI review requested due to automatic review settings June 14, 2026 15:59
@semohr semohr force-pushed the migration_backup branch from 9fffe1d to 536b10a Compare June 14, 2026 16:02

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.

Pull request overview

PR add safety net for db schema migrations: make timestamp .bak copy of library db before first pending migration run. This fit beets startup migration path, so user can roll back when migration go bad.

Changes:

  • Add create_backup_before_migrations config (default yes) and document it.
  • Add backup creation hook in Migration.migrate_model before migration work runs.
  • Add test for config on/off behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
beets/dbcore/db.py Add backup-before-migration hook and Database.create_copy helper.
beets/config_default.yaml Set default create_backup_before_migrations: yes.
docs/reference/config.rst Document new global config option.
docs/changelog.rst Add changelog entry for migration backup feature.
test/library/test_migrations.py Add regression test for backup creation controlled by config.

Comment thread beets/dbcore/db.py
Comment thread beets/dbcore/db.py Outdated
Comment thread beets/dbcore/db.py Outdated
Comment thread docs/changelog.rst Outdated
@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.55%. Comparing base (2337cfb) to head (60d14b8).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6742      +/-   ##
==========================================
+ Coverage   74.52%   74.55%   +0.02%     
==========================================
  Files         162      162              
  Lines       20818    20836      +18     
  Branches     3295     3297       +2     
==========================================
+ Hits        15515    15534      +19     
  Misses       4547     4547              
+ Partials      756      755       -1     
Files with missing lines Coverage Δ
beets/dbcore/db.py 94.44% <100.00%> (+0.16%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread beets/dbcore/db.py Outdated
Comment thread beets/dbcore/db.py Outdated
Comment thread beets/dbcore/db.py Outdated
Comment thread beets/dbcore/db.py Outdated
Comment thread beets/dbcore/db.py Outdated
Comment thread beets/dbcore/db.py Outdated
assert str_item.path == abs_bytes_path


class TestMigrationBackup:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be possible to move this test to any of existing test classes? Ideally we'd want to reuse the setup

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would wait on #6709 to takle this.

@semohr semohr force-pushed the migration_backup branch 2 times, most recently from 94e30ac to f9080b2 Compare June 16, 2026 16:33
@semohr semohr force-pushed the migration_backup branch from f9080b2 to 817e283 Compare June 16, 2026 16:34
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.

3 participants