Skip to content

Conversation

@mnovelo
Copy link
Collaborator

@mnovelo mnovelo commented Dec 22, 2025

Release v3.4.1

Bug Fixes

  • Fix multi-database rake task enhancement for Rails 7+: When a Rails app has multiple databases configured, Rails 7+ creates namespaced rake tasks (db:migrate:primary, db:rollback:primary, etc.). Apartment now automatically detects databases with database_tasks: true and enhances their namespaced tasks to invoke the corresponding apartment task.

  • Fix connection pool isolation in migrator: Wrap migration operations with with_connection to pin a single database connection for the entire operation. This ensures Tenant.switch sets search_path on the same connection used by migration_context, preventing migrations from running against the wrong schema.

Changes

  • lib/apartment/tasks/enhancements.rb - Added multi-database support
  • lib/apartment/migrator.rb - Added connection pinning
  • spec/unit/rake_task_enhancer_spec.rb - New tests (19 examples)
  • spec/unit/migrator_spec.rb - Added connection pinning tests (3 examples)

🤖 Generated with Claude Code

mnovelo and others added 2 commits December 16, 2025 11:07
* Add RELEASING.md documenting the gem release process

Documents the full release workflow including:
- Version bumping
- PR flow (development → main)
- Automated publish via gem-publish.yml
- GitHub Release creation
- Branch sync after release
- Troubleshooting common issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add context7.json to claim library on Context7

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Use explicit --delete syntax for git push in docs

More readable than the colon syntax.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
…337)

* Add multi-database rake task enhancement for Rails 7+

When a Rails app has multiple databases configured in database.yml,
Rails 7+ creates namespaced rake tasks like `db:migrate:primary` and
`db:rollback:primary`. Previously, Apartment only enhanced base tasks
(`db:migrate`, `db:rollback`), so tenant schemas weren't migrated
when using namespaced tasks.

This change automatically detects databases with `database_tasks: true`
and enhances their namespaced tasks to invoke the corresponding
apartment task:

- `db:migrate:primary` -> `apartment:migrate`
- `db:rollback:primary` -> `apartment:rollback`
- `db:migrate:up:primary` -> `apartment:migrate:up`
- `db:migrate:down:primary` -> `apartment:migrate:down`
- `db:migrate:redo:primary` -> `apartment:migrate:redo`

Replica databases and databases with `database_tasks: false` are
excluded from enhancement.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix connection pool isolation in migrator

Wrap migration operations with `with_connection` to pin a single
database connection for the entire operation. This ensures that
`Tenant.switch` sets `search_path` on the same connection used by
`migration_context`.

Without this fix, the connection pool may return different connections
for the tenant switch vs the actual migration, causing migrations to
run against the wrong schema.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add specs for connection pool isolation in migrator

Verifies that `with_connection` is called to pin a single connection
for the entire migration operation, ensuring search_path consistency.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Refactor specs to fix RSpec/MultipleMemoizedHelpers

Inline config doubles instead of using shared let blocks to reduce
memoized helper count below the limit of 5.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Bump version to 3.4.1

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
@mnovelo mnovelo merged commit d80c8d8 into main Dec 22, 2025
235 checks passed
@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

❌ Patch coverage is 98.07692% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.01%. Comparing base (e88e7f3) to head (d1e6c75).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
lib/apartment/version.rb 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #338      +/-   ##
==========================================
- Coverage   84.40%   82.01%   -2.40%     
==========================================
  Files          36       36              
  Lines         994     1034      +40     
==========================================
+ Hits          839      848       +9     
- Misses        155      186      +31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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