Skip to content

feat(db): add v1.1.0 database migration for cost tracking and git config - #51

Merged
frankbria merged 3 commits into
mainfrom
feature/issue-29-v1.1-migration
Jan 29, 2026
Merged

feat(db): add v1.1.0 database migration for cost tracking and git config#51
frankbria merged 3 commits into
mainfrom
feature/issue-29-v1.1-migration

Conversation

@frankbria

@frankbria frankbria commented Jan 29, 2026

Copy link
Copy Markdown
Owner

Summary

Implements GitHub issue #29: Database migration for v1.1.0 schema changes.

This migration adds the database schema required for:

  • Git configuration tracking: git_user, git_email, ssh_key_provided
  • Cost tracking: budget_limit, cost_estimate, actual_cost
  • Template tracking: template_name
  • Budget tracking table: For period-based spending limits (daily/weekly/monthly)

Changes

  • Create migrations/v1.1.0.sql using copy-recreate pattern (consistent with v1.0.0)
  • Add hasV11Columns() helper method to SessionDB
  • Update migrateToLatest() to target v1.1.0
  • Update CLI migrate command to support 1.1.0 version
  • Update CLI update command description for v1.1.0
  • Add TypeScript types: BudgetPeriod, BudgetTrackingRow, BudgetTracking
  • Extend Session and SessionRow interfaces with v1.1.0 fields
  • Update CLAUDE.md with new schema documentation

Test plan

  • All 873 existing tests pass
  • 12 new TDD tests for v1.1.0 migration:
    • Add v1.1.0 columns to sessions table
    • Create budget_tracking table
    • Create budget_tracking indexes
    • Maintain backward compatibility with v1.0.0 sessions
    • Migration is idempotent (can run multiple times)
    • Schema version updates to 1.1.0
    • hasV11Columns() returns false before migration
    • hasV11Columns() returns true after migration
    • migrateToLatest() reaches v1.1.0 from scratch
    • migrateToLatest() runs only v1.1.0 from v1.0.0
    • migrateToLatest() skips if already at v1.1.0

Closes

Closes #29

Summary by CodeRabbit

  • New Features

    • Added budget tracking (daily/weekly/monthly), session cost estimates and actual cost fields
    • Git config and SSH key presence tracking for sessions
    • Template and sandbox-related session metadata
  • CLI

    • Update/migrate commands now target v1.1.0 with updated messaging and migration flow
  • Documentation

    • Database schema and command docs updated for v1.1.0
  • Tests

    • Expanded migration tests covering v1.1.0 scenarios and idempotency
  • Chores

    • CI workflow: cancel duplicate PR runs via concurrency rule

✏️ Tip: You can customize this high-level summary in your review settings.

Implements GitHub issue #29: Database migration for v1.1.0 schema changes.

Changes:
- Create migrations/v1.1.0.sql with copy-recreate pattern for sessions table
- Add v1.1.0 columns to sessions: git_user, git_email, ssh_key_provided,
  budget_limit, cost_estimate, actual_cost, template_name
- Add budget_tracking table for period-based spending limits
- Add hasV11Columns() helper method to SessionDB
- Update migrateToLatest() to target v1.1.0
- Update CLI migrate command to support 1.1.0 version
- Update types.ts with BudgetPeriod, BudgetTrackingRow, BudgetTracking
- Add comprehensive TDD tests for v1.1.0 migration (12 new tests)
- Update CLAUDE.md with new schema documentation

All 873 tests pass. Migration is backward compatible with existing v1.0.0
sessions (new columns default to NULL/0).
@coderabbitai

coderabbitai Bot commented Jan 29, 2026

Copy link
Copy Markdown

Walkthrough

Adds v1.1.0 DB migration: extends sessions with git/cost/template fields, adds budget_tracking table and indexes, updates CLI migrate/update to default to v1.1.0, expands DB layer and types, and adds tests covering migration sequencing and idempotency.

Changes

Cohort / File(s) Summary
Schema Migration & Docs
migrations/v1.1.0.sql, CLAUDE.md
New v1.1.0 migration adds columns to sessions (git_user, git_email, ssh_key_provided, budget_limit, cost_estimate, actual_cost, template_name), creates budget_tracking table and idx_budget_period, recreates views/indexes, and updates schema metadata; docs updated to reflect changes.
CLI
src/cli.ts
migrate/update command help and flow updated to support default target 1.1.0; migrate option accepts 0.5.0, 1.0.0, 1.1.0 and enforces prerequisite migration sequence (0.5.0 → 1.0.0 → 1.1.0).
DB Layer
src/db.ts
Added hasV11Columns(); extended row-to-session mapping to include new v1.1 fields; migrateToLatest()/runMigration() updated to apply and verify v1.1.0 migration.
Types
src/types.ts
Expanded Session/SessionRow with v1.1 fields (git_user, git_email, ssh_key_provided, budget_limit, cost_estimate, actual_cost, template_name); added BudgetPeriod, BudgetTrackingRow, BudgetTracking types.
Tests
tests/migration.test.ts
Reworked test suite to cover migration sequencing, v1.1.0 column existence, budget_tracking table/index creation, idempotency, and backward compatibility across 0.5.0→1.0.0→1.1.0 flows.
CI Workflow
.github/workflows/opencode-review.yml
Added concurrency block to cancel duplicate in-progress workflow runs for the same PR.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI as CLI (migrate/update)
    participant SessionDB as SessionDB
    participant Migrations as Migration Files
    participant SQLite as SQLite DB

    User->>CLI: migrate --version 1.1.0
    CLI->>SessionDB: read current schema version
    SessionDB->>SQLite: SELECT schema_metadata
    SQLite-->>SessionDB: current version

    alt version < 0.5.0
        CLI->>Migrations: load v0.5.0 SQL
        Migrations-->>SQLite: execute v0.5.0
    end

    alt version < 1.0.0
        CLI->>Migrations: load v1.0.0 SQL
        Migrations-->>SQLite: execute v1.0.0
    end

    alt version < 1.1.0
        CLI->>Migrations: load v1.1.0 SQL (add columns + budget table)
        Migrations-->>SQLite: execute v1.1.0
        SQLite->>SQLite: alter sessions, create budget_tracking, recreate views/indexes
    end

    CLI->>SessionDB: verify hasV11Columns()
    SessionDB->>SQLite: check new columns/index/table
    SQLite-->>SessionDB: verification result
    CLI->>SQLite: update schema_metadata to 1.1.0
    SQLite-->>CLI: done
    CLI-->>User: migration complete
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I nibble at schemas, hopping through rows,
New columns unfurl where the soft wind blows.
Budgets and git names snug in a nest,
Migrations applied — now off for a rest.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely summarizes the main objective: adding a v1.1.0 database migration for cost tracking and git configuration, which aligns with the primary change across all modified files.
Linked Issues check ✅ Passed All coding requirements from issue #29 are met: v1.1.0 migration implemented with new sessions columns (git_user, git_email, ssh_key_provided, budget_limit, cost_estimate, actual_cost, template_name), budget_tracking table with proper index, migration file created, DB logic updated, CLI commands updated, TypeScript types added, backward compatibility ensured, and comprehensive tests added.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing v1.1.0 database migration and required supporting updates. The GitHub workflow change (concurrency block) is a minor infrastructure improvement to prevent duplicate runs, which is reasonably scoped as a cleanup item alongside the main migration work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/issue-29-v1.1-migration

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

@macroscopeapp

macroscopeapp Bot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Add v1.1.0 database migration for cost tracking and git config and update CLI and DB to target schema 1.1.0

  • Introduce v1.1.0 SQL migration that adds cost and git fields to sessions and creates budget_tracking with an index in migrations/v1.1.0.sql
  • Update CLI migrate/update commands to target 1.1.0 in src/cli.ts
  • Extend types.Session/types.SessionRow and add budget tracking types in src/types.ts
  • Map new sessions fields and run auto-migration to 1.1.0 in SessionDB in src/db.ts
  • Add workflow run concurrency control in .github/workflows/opencode-review.yml

📍Where to Start

Start with the SessionDB.migrateToLatest flow and the v1.1.0 SQL in src/db.ts and migrations/v1.1.0.sql.


Macroscope summarized 51e2b0f.

@github-actions

Copy link
Copy Markdown

Review Summary

This PR implements the v1.1.0 database migration for cost tracking and git configuration. Overall, the implementation is well-structured and follows established patterns from previous migrations (v1.0.0). The test coverage is comprehensive with 12 new tests covering all key scenarios.

✅ Strengths

  1. Consistent migration pattern - Uses copy-recreate approach matching v1.0.0
  2. Proper transaction wrapping - Ensures atomic operations with rollback on failure
  3. Comprehensive test coverage - Tests columns, tables, indexes, backward compatibility, idempotency, and schema versioning
  4. Defensive programming - Drops views before table recreation, recreates all views
  5. Proper TypeScript types - Clean type extensions for Session/SessionRow and new BudgetPeriod/BudgetTracking types
  6. Helper method consistency - hasV11Columns() follows same pattern as hasE2BColumns()

🐛 Issues Found

1. Incorrect version message in CLI output (src/cli.ts:1056)

console.log(chalk.dim('Database is now at version 1.0.0'));  // ❌ WRONG

Should be:

console.log(chalk.dim('Database is now at version 1.1.0'));  // ✅ CORRECT

This is the only actual bug. When users run parallel-cc update to migrate to v1.1.0, they'll be told the database is at version 1.0.0, causing confusion.

⚠️ Minor Suggestions

  1. Test coverage for ssh_key_provided conversion (tests/migration.test.ts)

The rowToSession() method in src/db.ts:281 handles boolean conversion:

ssh_key_provided: row.ssh_key_provided === 1 ? true : row.ssh_key_provided === 0 ? false : undefined,

While your tests verify the columns exist, consider adding a specific test to validate this conversion logic handles all three cases (0, 1, NULL) correctly. This is minor since the existing backward compatibility test covers the general case.

  1. Migration verification assertions (migrations/v1.1.0.sql:230-248)

The verification queries at the end of the migration check for existence but don't assert the results. This is acceptable since runMigration() in src/db.ts already verifies the schema version (line 1538), which provides the same guarantee.

✅ Code Quality

  • Security: No concerns - new columns store config and cost data, no sensitive data exposure
  • Performance: Appropriate indexes with WHERE clauses for partial indexes (e.g., WHERE template_name IS NOT NULL)
  • Best practices: Follows all patterns from CLAUDE.md and prior migrations
  • Type safety: Proper TypeScript typing throughout

📝 Test Coverage

Excellent coverage - All critical paths tested:

  • ✅ Column addition to sessions table
  • ✅ budget_tracking table creation
  • ✅ Index creation
  • ✅ Backward compatibility with v1.0.0 sessions
  • ✅ Idempotency (multiple runs)
  • ✅ Schema version updates
  • hasV11Columns() helper function

🎯 Recommendation

Approve with minor changes required:

  1. Fix line 1056 in src/cli.ts (change "1.0.0" to "1.1.0")
  2. (Optional) Add a specific test for ssh_key_provided boolean conversion

The single bug should be fixed before merge, but it's a trivial typo and doesn't affect functionality. Otherwise, this is a solid migration implementation ready for v1.1.0.

@github-actions

Copy link
Copy Markdown

I've completed my review of PR #51 and posted a comprehensive comment. The review identified:

Key Findings:

  • 1 Bug Found: Incorrect version message in CLI output (line 1056 in src/cli.ts shows "1.0.0" instead of "1.1.0")
  • Excellent test coverage: 12 new tests covering all critical paths
  • Solid implementation: Follows established migration patterns with proper transaction wrapping, defensive programming, and appropriate indexing

The PR is well-executed overall and requires only a trivial typo fix before merge. All other aspects (security, performance, code quality, backward compatibility, idempotency) are properly addressed.

New%20session%20-%202026-01-29T20%3A47%3A50.330Z
opencode session  |  github run

Adds concurrency configuration to cancel in-progress workflow runs
when a PR is updated, avoiding duplicate reviews and wasted compute.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/cli.ts (1)

1021-1058: Update command still reports v1.0.0 after migrating to v1.1.0.
This output is now misleading given the new target version.

🛠️ Suggested fix
-          console.log(chalk.dim('Database is now at version 1.0.0'));
-          console.log(chalk.dim('E2B sandbox features are now available'));
+          console.log(chalk.dim(`Database is now at version ${result.to}`));
+          console.log(chalk.dim('E2B sandbox + git/cost/template/budget tracking features are now available'));

The update command was displaying "version 1.0.0" instead of "1.1.0"
after running migrations. Also updated the feature message to be
more generic for v1.1.
@github-actions

Copy link
Copy Markdown

Review Summary

This PR implements the v1.1.0 database migration for cost tracking and git configuration. The implementation is excellent and follows established patterns from previous migrations.

✅ Strengths

  1. Consistent migration pattern - Uses copy-recreate approach matching v1.0.0
  2. Proper transaction wrapping - Ensures atomic operations with rollback on failure
  3. Comprehensive test coverage - 12 new tests covering all critical paths
  4. Defensive programming - Drops views before table recreation, recreates all views
  5. Proper TypeScript types - Clean type extensions for Session/SessionRow and new BudgetPeriod/BudgetTracking types
  6. Helper method consistency - hasV11Columns() follows same pattern as hasE2BColumns()
  7. Excellent documentation - Migration SQL is well-commented with clear explanations

✅ Bug Status

The bug mentioned in prior reviews (incorrect version message on line 1056) has already been fixed in commit 51e2b0f. The current code correctly displays "1.1.0".

💡 Minor Suggestions (Enhancement, Not Blocking)

  1. Make CLI version message dynamic (src/cli.ts:1056)

    Current:

    console.log(chalk.dim('Database is now at version 1.1.0'));

    Suggested:

    console.log(chalk.dim(`Database is now at version ${result.to}`));

    This would make the message future-proof and avoid hard-coding version numbers.

  2. Test coverage for ssh_key_provided conversion (optional)

    The rowToSession() method in src/db.ts:281 handles boolean conversion for three cases (0, 1, NULL). While existing tests verify columns exist, a specific test for this conversion would be more explicit. This is minor since backward compatibility tests cover the general case.

  3. Migration verification assertions (optional)

    The verification queries in migrations/v1.1.0.sql:230-248 check for existence but don't assert results. This is acceptable since runMigration() in src/db.ts:1538 already verifies the schema version, providing the same guarantee.

✅ Code Quality

  • Security: No concerns - new columns store config and cost data, no sensitive data exposure
  • Performance: Appropriate indexes with WHERE clauses for partial indexes
  • Best practices: Follows all patterns from CLAUDE.md and prior migrations
  • Type safety: Proper TypeScript typing throughout

📝 Test Coverage

Excellent coverage - All critical paths tested:

  • ✅ Column addition to sessions table
  • ✅ budget_tracking table creation
  • ✅ Index creation
  • ✅ Backward compatibility with v1.0.0 sessions
  • ✅ Idempotency (multiple runs)
  • ✅ Schema version updates
  • hasV11Columns() helper function

🎯 Recommendation

Approve - The implementation is solid and ready for v1.1.0. The suggested improvements are optional enhancements for future maintainability, not blocking issues.

The bug referenced in prior reviews has been fixed, and all other aspects (security, performance, code quality, backward compatibility, idempotency) are properly addressed.

@github-actions

Copy link
Copy Markdown

I've posted a comprehensive review to PR #51. The review confirms:

✅ Ready to Approve

The v1.1.0 database migration is well-implemented with:

  • Consistent patterns from prior migrations
  • Comprehensive test coverage (12 new tests)
  • Proper transaction wrapping and defensive programming
  • Clean TypeScript type extensions

The bug mentioned in prior reviews (incorrect version message) has already been fixed in commit 51e2b0f.

Minor optional suggestions were provided for future maintainability (making CLI version messages dynamic), but none are blocking issues.

New%20session%20-%202026-01-29T21%3A00%3A26.414Z
opencode session  |  github run

@frankbria
frankbria merged commit 5270a6b into main Jan 29, 2026
4 checks passed
@frankbria
frankbria deleted the feature/issue-29-v1.1-migration branch January 29, 2026 21:10
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.

[v1.1] Database migration for v1.1.0 schema changes

1 participant