Load schema when running db:migrate on fresh db#52830
Merged
rafaelfranca merged 1 commit intorails:mainfrom Sep 11, 2024
Merged
Load schema when running db:migrate on fresh db#52830rafaelfranca merged 1 commit intorails:mainfrom
rafaelfranca merged 1 commit intorails:mainfrom
Conversation
bbbe7c0 to
1c28120
Compare
sambostock
reviewed
Sep 8, 2024
| @@ -179,20 +179,9 @@ def prepare_all | |||
|
|
|||
| each_current_configuration(env) do |db_config| | |||
| with_temporary_pool(db_config) do | |||
Contributor
There was a problem hiding this comment.
I notice initialize_database already has with_temporary_pool, so it looks like we're nesting temporary pools. Is it safe to remove it here?
1c28120 to
b696583
Compare
… before running migrations. If we have an existing schema file and we run db:migrate before setting up the database, we will not load the schema before running migrations, so when we dump the schema will overwrite the existing schema file and lose the tables define there. Instead, we should check if the db is setup and if it is not lload the schema, before running migrations.
b696583 to
66aacb6
Compare
mkasztelnik
added a commit
to mkasztelnik/rails
that referenced
this pull request
Oct 15, 2024
Loading database schemas before db:migrate for a single database was fixed in rails#52830. However, this approach fails when multiple databases are defined. This fix addresses the issue by moving schema loading to occur before initiating database migrations.
mkasztelnik
added a commit
to mkasztelnik/rails
that referenced
this pull request
Oct 15, 2024
Loading database schemas before db:migrate for a single database was fixed in rails#52830. However, this approach fails when multiple databases are defined. This fix addresses the issue by moving schema loading to occur before initiating database migrations.
mkasztelnik
added a commit
to mkasztelnik/rails
that referenced
this pull request
Oct 15, 2024
Loading database schemas before db:migrate for a single database was fixed in rails#52830. However, this approach fails when multiple databases are defined. This fix addresses the issue by moving schema loading to occur before initiating database migrations. Fixes rails#52829
mkasztelnik
added a commit
to mkasztelnik/rails
that referenced
this pull request
Oct 15, 2024
Loading database schemas before db:migrate for a single database was fixed in rails#52830. However, this approach fails when multiple databases are defined. This fix addresses the issue by moving schema loading to occur before initiating database migrations. Fixes rails#52829
This was referenced Oct 15, 2024
mkasztelnik
added a commit
to mkasztelnik/rails
that referenced
this pull request
Oct 16, 2024
Loading database schemas before db:migrate for a single database was fixed in rails#52830. However, this approach fails when multiple databases are defined. This fix addresses the issue by moving schema loading to occur before initiating database migrations. Fixes rails#52829
mkasztelnik
added a commit
to mkasztelnik/rails
that referenced
this pull request
Oct 16, 2024
Loading database schemas before db:migrate for a single database was fixed in rails#52830. However, this approach fails when multiple databases are defined. This fix addresses the issue by moving schema loading to occur before initiating database migrations. Fixes rails#52829
mkasztelnik
added a commit
to mkasztelnik/rails
that referenced
this pull request
Oct 16, 2024
Loading database schemas before db:migrate for a single database was fixed in rails#52830. However, this approach fails when multiple databases are defined. This fix addresses the issue by moving schema loading to occur before initiating database migrations. Fixes rails#52829
mkasztelnik
added a commit
to mkasztelnik/rails
that referenced
this pull request
Oct 18, 2024
Loading database schemas before db:migrate for a single database was fixed in rails#52830. However, this approach fails when multiple databases are defined. This fix addresses the issue by moving schema loading to occur before initiating database migrations. Fixes rails#52829
jeremy
added a commit
that referenced
this pull request
Oct 28, 2024
Backport #53320 to 8-0-stable. Loading database schemas before db:migrate for a single database was fixed in #52830. However, this approach fails when multiple databases are defined. This fix addresses the issue by moving schema loading to occur before initiating database migrations. Fixes #52829 Co-authored-by: Marek Kasztelnik <[email protected]>
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.
Motivation / Background
Fixes #52829
When we have a schema file, if we run
db:migratebefore setting up the db, we do not load the schema and then we blow away the contents of the file when we dump the schema after migrations.You can repro by creating a fresh app and running the following commands:
After following these steps, the schema file will be empty and the posts table will not exist.
Detail
We should make sure the db is setup before we run migrations. This is what we do in the
db:preparetask. So, I extracted the code from that task and reused it in the migration task.Additional information
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]