Patch ActiveRecord::ConnectionNotEstablished snag#3
Merged
Conversation
Updated data_migrate’s db:prepare:with_data initialization check so it inspects the schema_migrations table through the temporary pool connection for the database currently being prepared. This avoids the nested connection checkout path that can raise ActiveRecord::ConnectionNotEstablished on newer Rails immediately after a database is created. We needed this because db:prepare was working, but db:prepare:with_data was failing during the “is this database already initialized?” check. The fix keeps the existing Rails-compatible behavior intact: missing databases are still created, and databases that already exist but have not been initialized still have schema restored before migrations run.
There was a problem hiding this comment.
Pull request overview
Updates DataMigrate::DatabaseTasks.database_initialized? to check for the schema migrations table using the temporary pool’s checked-out connection (instead of implicitly using the global ActiveRecord connection), avoiding ActiveRecord::ConnectionNotEstablished during db:prepare:with_data right after database creation on newer Rails.
Changes:
- Switch initialization detection to
pool.with_connection { |conn| conn.data_source_exists?(schema_migration.table_name) }. - Add specs asserting initialization checks are performed via the temporary pool connection and correctly handle missing
schema_migrations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/data_migrate/database_tasks.rb | Fixes initialization check to query schema_migrations via the temporary pool’s connection to avoid nested checkout/connection establishment issues. |
| spec/data_migrate/database_tasks_spec.rb | Adds focused tests for the new database_initialized? behavior using a temporary pool + connection double. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fhock-ut
approved these changes
Apr 16, 2026
Author
|
What changed:
Why we needed it:
What did not change:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updated data_migrate’s db:prepare:with_data initialization check so it inspects the schema_migrations table through the temporary pool connection for the database currently being prepared.
This avoids the nested connection checkout path that can raise ActiveRecord::ConnectionNotEstablished on newer Rails immediately after a database is created.
We needed this because db:prepare was working, but db:prepare:with_data was failing during the “is this database already initialized?” check.
The fix keeps the existing Rails-compatible behavior intact: missing databases are still created, and databases that already exist but have not been initialized still have schema restored before migrations run.