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

Forces a DB connection to be established when running assets:precompile #222

Open
defsprite opened this issue Sep 6, 2022 · 4 comments
Open

Comments

@defsprite
Copy link
Contributor

It looks like merely adding data_migrate to the Gemfile will force a database connection to be established during assets:clobber or assets:precompile tasks.

This is highly undesirable for Docker builds, as we have no database available unless we resort to nulldb or temporary sqlite connections during container builds.

This happens with data_migrate 8.1.1 and rails 7.0.3.1, but there might be other versions affected.

There is a small rails app at https://github.com/foxondo/data-migrate-bug to showcase the problem. Please find further details in the README there.

We've opened #221 as a proposed fix for the issue, but there might be other ways to fix this.

@ilyakatz
Copy link
Owner

ilyakatz commented Sep 6, 2022

Hi there, I haven't done rails in a long time, but wouldn't setting bundle dependency to not autoload solve your issue?

@defsprite
Copy link
Contributor Author

Excellent thought! Briefly looked into this:

  • Using require: false does solve the issue, but all the rake tasks will disappear.
  • Using require: "data_migrate/railtie" makes the rake tasks reappear, but will bail on a rake task (db:migrate:with_data) with NameError: uninitialized constant DataMigrate::DataMigrator

I could try and restructure the gem loading (e.g. use autoload if Rails::Railtie is defined) if that route seems more appropriate to you.

What do you think?

@ilyakatz
Copy link
Owner

ilyakatz commented Sep 6, 2022

Thanks for the research so far! It does seems like restructure could be beneficial. But in the end of the day, I'm happy to follow your recommendation.

@dfritsch
Copy link

I recently ran up on this issue as well and was able to work around this with require: false on the gem and adding the following in my application config:

    require "data_migrate/railtie"
    ActiveSupport.on_load(:active_record) do
      require "data_migrate"
    end

I believe the railtie require needs to happen before initializers to make sure it picks up the tasks properly, but in general, we want to delay loading this gem until active record itself loads since currently loading the gem forces ActiveRecord to load which was causing some surprises configuring ActiveRecord.

For what its worth, I'm a fan of #221 which will let us just rely on this being required automatically.

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