Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running parallel:migrate when using structure.sql instead of schema.rb causes invalid SQL #913

Open
alecvn opened this issue Aug 18, 2023 · 3 comments

Comments

@alecvn
Copy link

alecvn commented Aug 18, 2023

We're experiencing an issue where, when there are migrations to run, running parallel:migrate causes our structure.sql file to contain invalid SQL.

After glancing at the code it seems like parallel_tests is just running db:migrate in parallel for each of the databases, and so the issue isn't caused by parallel_tests itself but rather by Rails.

I would just like to confirm that this understanding is correct, as it would entail that one basically can't use parallel:migrate if you're using structure.sql over schema.rb.

@grosser
Copy link
Owner

grosser commented Aug 20, 2023

There could be an issue where the parallel migrations all write to the same file somehow.
You should be able to see the steps with rake <task> --trace.
The code looks like it's just running migrate X times, so a fix might be either:

  • run migrate, run a single "db:schema:dump" or "db:structure:dump"
  • save the original schema/structure, run migrate, restore it (that might be the easiest and fastest way)
    ... can you try these and see if they work ?

@neo87cs
Copy link

neo87cs commented Sep 13, 2023

Rails 7 + Ruby 3.1.2
@grosser i solved following your suggestion and wrote a little script:

rm -f db/structure.sql
RAILS_ENV=test rails parallel:drop parallel:create
RAILS_ENV=test rails parallel:migrate
RAILS_ENV=test rails db:schema:dump
RAILS_ENV=test rails parallel:spec

Should be possible to automatize it by doing a wrapping rake to run on a rake task too

@grosser
Copy link
Owner

grosser commented Sep 13, 2023

running a full migration before each test will be slow and brittle, so that's not a great approach
I'd prefer something like copying the schema, running parallel:migrate and then restoring the schema
(or finding a way to make the db tasks not dump the schema)

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

No branches or pull requests

3 participants