Skip to content

VB-Toml to DB migration: sync toml to DB as first step#12263

Merged
Byron merged 4 commits intogitbutlerapp:masterfrom
Byron:next2
Feb 26, 2026
Merged

VB-Toml to DB migration: sync toml to DB as first step#12263
Byron merged 4 commits intogitbutlerapp:masterfrom
Byron:next2

Conversation

@Byron
Copy link
Copy Markdown
Collaborator

@Byron Byron commented Feb 6, 2026

Sync the vb.toml file to its equivalent database representation.

Goals

  • backward compatibility - we keep writing the toml file, but don't read from it.
  • DB-backed versions of RefMetadata and VirtualBranchesHandle
  • Update call-sites with new types, they shouldn't notice a difference and it can be done incrementally.

Tasks

  • but-db
    • needs savepoint to align multiple queries to different tables (or do it all in one query
    • docs
  • but-meta
    • RefMetadata uses DB version of toml snapshot
  • VirtualBranchesHandle uses DB - no, it keeps using vb.toml file and but-meta is expected to auto-sync it anyway. Then the next step is to remove VirtualBranchesHandle usage from the codebase.
  • Plan
  • test GUI by hand - all fine and I saw the database sync the data correctly.

Follow-ups

  • remove VirtualBranchesHandle usages
  • make db.meta() possible, and write the database after each change. Sync the toml file on drop only, knowing well that this may write data that is going to be rolled back, and only for backward compatbility
  • make the cut: migrate data to clean data model and use that directly instead, cut backwards compatibility

Prompts

Look at #12263 and figure out how to best approach this transformation. The database schema of the virtual branches toml data should be human-editable, so ideally splits the data up into columns of multiple tables with foreign key connections.
Also make sure it's backwards compatible, so the virtual-branches.toml file needs to still be written and exists. If it changes and is more recent than what's in the database, the database value should be overwritten with it.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 6, 2026

@Byron is attempting to deploy a commit to the GitButler Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the rust Pull requests that update Rust code label Feb 20, 2026
@Byron Byron force-pushed the next2 branch 6 times, most recently from e50df01 to 784c8f5 Compare February 24, 2026 14:50
@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 24, 2026

Deployment failed with the following error:

Creating the Deployment Timed Out.

@Byron Byron force-pushed the next2 branch 5 times, most recently from 78829a6 to 51b4043 Compare February 25, 2026 11:39
@Byron Byron changed the title VB-Toml to DB migration VB-Toml to DB migration: sync toml to DB as first step Feb 25, 2026
@Byron Byron force-pushed the next2 branch 3 times, most recently from 81721a1 to 25ab444 Compare February 25, 2026 12:33
@Byron Byron marked this pull request as ready for review February 25, 2026 12:34
@Byron Byron requested a review from krlvi as a code owner February 25, 2026 12:34
Copilot AI review requested due to automatic review settings February 25, 2026 12:34
@Byron Byron requested a review from Caleb-T-Owens as a code owner February 25, 2026 12:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements the first step of migrating from TOML-based virtual branches metadata to a database-backed approach. The core change synchronizes .git/gitbutler/virtual-branches.toml with an equivalent SQLite database representation while maintaining backward compatibility by continuing to write the TOML file.

Changes:

  • Added normalized database schema for virtual branches metadata (vb_state, vb_stacks, vb_stack_heads, vb_branch_targets tables)
  • Implemented bidirectional TOML↔DB synchronization with mtime+SHA256 conflict detection
  • Updated VirtualBranchesHandle to transparently use DB with TOML mirroring for backward compatibility

Reviewed changes

Copilot reviewed 28 out of 29 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
etc/plans/consistent-data.md Comprehensive plan document outlining data consistency migration strategy
crates/but-db/src/table/virtual_branches.rs New normalized database schema with savepoint-based mutation API
crates/but-db/src/table/mod.rs Registered virtual_branches module
crates/but-db/src/lib.rs Exported VirtualBranches types and added migration, enforced documentation
crates/but-db/src/migration.rs Enabled foreign key enforcement in improve_concurrency
crates/but-db/src/poll.rs Added documentation to poll types
crates/but-db/tests/db/table/virtual_branches.rs Comprehensive tests for VB snapshot operations and FK cascades
crates/but-db/tests/db/table/mod.rs Added virtual_branches test module
crates/but-db/tests/db/migration.rs Updated expected schema to include VB tables
crates/but-db/tests/db/transaction.rs Added savepoint isolation test demonstrating consistent multi-table reads
crates/but-meta/src/legacy/storage.rs Core TOML↔DB synchronization logic with conflict resolution
crates/but-meta/src/legacy/mod.rs Refactored to use storage module for read/write operations
crates/but-meta/src/lib.rs Exported legacy_storage module
crates/but-meta/Cargo.toml Added but-db, but-fs, and sha2 dependencies
crates/but-meta/tests/meta/ref_metadata_legacy.rs Updated tests to reflect TOML mirror behavior (no longer deleted)
crates/gitbutler-stack/src/state.rs Updated VirtualBranchesHandle to use synchronized storage
crates/gitbutler-stack/Cargo.toml Removed but-fs dependency (moved to but-meta)
crates/gitbutler-stack/tests/mod.rs Extensive sync behavior tests (bootstrap, recreation, newer TOML, invalid TOML, restore)
crates/gitbutler-oplog/src/oplog.rs Added import_toml_into_db_for_restore call for oplog snapshot restoration
crates/but-db/src/table/*.rs Added #![allow(missing_docs)] to existing table modules for consistency
Cargo.lock Updated dependencies

Comment thread crates/but-meta/src/legacy/storage.rs
Comment thread etc/plans/consistent-data.md Outdated
Comment thread etc/plans/consistent-data.md Outdated
Comment thread etc/plans/consistent-data.md Outdated
Comment thread etc/plans/consistent-data.md Outdated
Comment thread etc/plans/consistent-data.md Outdated
Comment thread crates/but-meta/src/legacy/storage.rs
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25ab4440e0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/but-meta/src/legacy/storage.rs Outdated
The idea is that we are encouraged to write docs, without being forced
if it's "too obvious" what's happening.
chatgpt-codex-connector Bot and others added 2 commits February 25, 2026 15:32
…l` file.

It also keeps track of enough state to know if the snapshot is uptodate with
the vb.toml file so it can be resynced at will.

Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
It will be used to track tasks relates to the transition towards
data-consistency, probably maintained by an agent.

Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 25, 2026 14:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 28 out of 29 changed files in this pull request and generated 3 comments.

Comment thread crates/but-meta/src/legacy/storage.rs
Comment thread crates/but-meta/src/legacy/storage.rs Outdated
Comment thread crates/but-meta/src/legacy/storage.rs Outdated
The source of truth is the database at least for `but-meta`, but it
makes sure that the toml file stays in sync with the database
and vice-versa.

Adapt `but-oplog` and `VirtualBranchesHandle` to deal with database
mirror correctly.

Removed `toml_file_is_dirty` flag as it didn't seem useful.

Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
@Byron Byron marked this pull request as draft February 26, 2026 06:19
@Byron Byron marked this pull request as ready for review February 26, 2026 10:04
Copilot AI review requested due to automatic review settings February 26, 2026 10:04
@Byron Byron enabled auto-merge February 26, 2026 10:09
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 40147d6a24

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/but-meta/src/legacy/storage.rs
Comment thread crates/but-meta/src/legacy/storage.rs
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 28 out of 29 changed files in this pull request and generated 1 comment.

Comment thread crates/but-meta/src/legacy/storage.rs
@Byron Byron merged commit 1165d88 into gitbutlerapp:master Feb 26, 2026
40 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants