Skip to content

fix(db): consolidate migrations v28-v32 into v33#788

Merged
lklimek merged 3 commits into
v1.0-devfrom
fix/consolidate-migrations-v33
Mar 23, 2026
Merged

fix(db): consolidate migrations v28-v32 into v33#788
lklimek merged 3 commits into
v1.0-devfrom
fix/consolidate-migrations-v33

Conversation

@lklimek
Copy link
Copy Markdown
Contributor

@lklimek lklimek commented Mar 23, 2026

Summary

  • Consolidates DB migrations v28–v32 into a single idempotent v33 step
  • Prevents version-collision issues when users switch between v1.0-dev and zk-fixes branches (both used v28 for different migrations)
  • All sub-migrations use IF NOT EXISTS / column-existence checks, safe to re-run on databases that already applied some or all steps
  • Adds forward-compatible shielded table definitions (shielded_notes, shielded_wallet_meta) so v1.0-dev databases are ready for the ZK feature branch

Migrations included in v33

  1. add_core_wallet_name_column — adds core_wallet_name to wallets
  2. init_contacts_tables — creates contact request tables
  3. create_shielded_tables — creates shielded_notes table
  4. create_shielded_wallet_meta_table — creates shielded_wallet_meta table
  5. rename_network_dash_to_mainnet — renames "dash" network to "mainnet"
  6. add_wallet_transaction_status_column — adds status to wallet_transactions
  7. add_nullifier_sync_timestamp_column — adds last_nullifier_sync_timestamp to shielded_wallet_meta

Test plan

  • Fresh install: create_tables() sets version to 33, all tables exist
  • Upgrade from v27 (pre-fork): v28–v32 are no-ops, v33 applies all migrations
  • Upgrade from v29 (v1.0-dev user): v30–v32 no-ops, v33 re-applies idempotently
  • Upgrade from v32 (zk-fixes user): v33 re-applies idempotently, no errors
  • cargo test --all-features --workspace passes (72 tests verified)

🤖 Co-authored by Claudius the Magnificent AI Agent

Summary by CodeRabbit

  • New Features

    • Adds initial support for shielded wallet data and contact tables to enable private transaction handling and contact management.
  • Chores

    • Database schema version upgraded to 33 with consolidated migrations, network value normalization, added transaction status tracking, and a last-nullifier sync timestamp to improve migration safety and wallet synchronization.

Resolves version numbering collision between zk and v1.0-dev branches:
the zk branch used v28 for shielded tables while v1.0-dev used v28 for
contacts. After merging, users migrating from either branch could end up
with missing tables depending on which version their DB was at.

v33 runs all sub-migrations idempotently in one step, ensuring all
tables exist regardless of prior migration history. Shielded pool
tables are created but unused on v1.0-dev — they prepare the schema
for the upcoming zk merge.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 23, 2026

Warning

Rate limit exceeded

@lklimek has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 48 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5dd86c6e-d640-4746-87f0-80d1555f9d2b

📥 Commits

Reviewing files that changed from the base of the PR and between e21197f and 54c9994.

📒 Files selected for processing (1)
  • src/database/initialization.rs
📝 Walkthrough

Walkthrough

Database schema version bumped from 29 to 33; migrations for 28–32 are effectively consolidated as no-ops, while version 33 applies grouped idempotent sub-migrations (wallet name, contacts, shielded pool/tables, wallet metadata, nullifier sync timestamp, network rename, transaction status). New init path creates shielded tables.

Changes

Cohort / File(s) Summary
Database Schema Migration & Initialization
src/database/initialization.rs
DEFAULT_DB_VERSION updated 29 → 33. Consolidated migration dispatch (28..=32 no-ops); version 33 runs grouped idempotent sub-migrations. Added creation of shielded_notes and shielded_wallet_meta in initial table setup. Added helper methods for shielded tables and conditional last_nullifier_sync_timestamp column; extended network-rename list to include new shielded tables.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 In burrows of code I dig and hum,

I stitch new tables, one by one,
From twenty-nine to thirty-three,
Shielded notes hop safe with me,
A quiet schema thump—hurray, we're done! 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: consolidating multiple database migrations (v28-v32) into a single version (v33).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/consolidate-migrations-v33

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@lklimek lklimek requested a review from Copilot March 23, 2026 15:01
@lklimek lklimek marked this pull request as ready for review March 23, 2026 15:01
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

Consolidates the previously separate DB migrations v28–v32 into a single v33 migration to avoid schema-version collisions across branches, while also introducing shielded-pool tables needed for upcoming ZK features.

Changes:

  • Bumps DEFAULT_DB_VERSION to 33 and makes versions 28–32 no-op placeholders.
  • Adds a consolidated v33 migration that applies the combined v28–v32 schema updates in an idempotent way.
  • Adds shielded table creation during fresh database initialization.
Comments suppressed due to low confidence (1)

src/database/initialization.rs:1017

  • rename_network_dash_to_mainnet claims to update every table that stores network, but the new shielded tables (shielded_notes, shielded_wallet_meta) also have a network column and are not included in the update list. If a user migrates from a branch where these tables already exist with network='dash', those rows will remain inconsistent. Add the shielded tables to the tables list (or otherwise ensure they’re updated too).
        let tables = [
            "settings",
            "wallet",
            "identity_token_balances",
            "platform_address_balances",
            "utxos",
            "asset_lock_transaction",
            "identity",
            "contested_name",
            "contestant",
            "contract",
            "scheduled_votes",
            "dashpay_profiles",
            "dashpay_contact_requests",
            "dashpay_contacts",
            "wallet_transactions",
            "single_key_wallet",
            "token",
        ];

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/database/initialization.rs Outdated
Comment thread src/database/initialization.rs
Comment thread src/database/initialization.rs
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/database/initialization.rs`:
- Around line 54-57: The migration loop currently advances and persists
database_version for the placeholder range 28..=32 (the match arm "28..=32 =>
{}"), which can leave the DB at version 32 if the consolidated v33 migration
fails; modify try_perform_migration() so that these placeholder versions are not
committed individually—either wrap the entire 28..=33 work in a single
transaction or change the 28..=32 path to be a no-op that does not call the code
that persists/commits database_version, and only write/update database_version =
33 after the v33 migration completes successfully (i.e., ensure the
commit/update to database_version happens once, post-success, not for each
placeholder version).
- Around line 966-977: The initial table creation in
create_shielded_wallet_meta_table is missing the last_nullifier_sync_timestamp
column so fresh installs start at v33 without it; update the SQL in
create_shielded_wallet_meta_table to include "last_nullifier_sync_timestamp
INTEGER NOT NULL DEFAULT 0" (alongside last_nullifier_sync_height) so the fresh
schema matches the later migrations and retains the existing PRIMARY KEY
(wallet_seed_hash, network).
- Around line 58-69: The migration branch that calls
rename_network_dash_to_mainnet() currently updates only some tables and neglects
shielded tables; update rename_network_dash_to_mainnet to also rewrite
network='dash' → 'mainnet' for the shielded tables by adding UPDATE statements
for the shielded_notes and shielded_wallet_meta tables (use the same
transaction/tx path and error handling as other updates in
rename_network_dash_to_mainnet), ensuring the SQL targets rows with network =
'dash' and sets network = 'mainnet' so records created earlier (e.g., from
zk-fixes) are migrated as well.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8770ff30-f1b3-4927-b40e-f17ad4c62a52

📥 Commits

Reviewing files that changed from the base of the PR and between 7ee5b90 and c6d49f7.

📒 Files selected for processing (1)
  • src/database/initialization.rs

Comment thread src/database/initialization.rs
Comment thread src/database/initialization.rs
Comment thread src/database/initialization.rs
lklimek and others added 2 commits March 23, 2026 16:13
…coverage

- Add `last_nullifier_sync_timestamp` to CREATE TABLE in
  `create_shielded_wallet_meta_table` so fresh installs at v33 get the
  full schema without relying on the migration column-add path
- Propagate SQL errors from the column-existence check in
  `add_nullifier_sync_timestamp_column` instead of silently swallowing
  them with `unwrap_or(false)`
- Add `shielded_notes` and `shielded_wallet_meta` to the tables array in
  `rename_network_dash_to_mainnet` so the 'dash'→'mainnet' rename covers
  all network-scoped tables

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add FOREIGN KEY (wallet_seed_hash) REFERENCES wallet(seed_hash) ON DELETE CASCADE
to both shielded_notes and shielded_wallet_meta CREATE TABLE statements,
matching the pattern used throughout initialization.rs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/database/initialization.rs
Comment thread src/database/initialization.rs
@lklimek lklimek merged commit 8937c1c into v1.0-dev Mar 23, 2026
9 checks passed
@lklimek lklimek deleted the fix/consolidate-migrations-v33 branch March 23, 2026 15:31
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.

2 participants