Closed rolftimmermans closed 6 years ago
I'm also running into this issue when trying to upgrade to the latest 1.0 version of the gem. I can't issue a rake sequel:drop , rake sequel:create and have it just work. Now it is stuck with an error saying that the database needs to exist.
I was able to get around these issues by adding test: false as a property to the database.yml. This reverts the connection behavior to sequel 4.x which will NOT attempt to connect to the database by default.
@JonathanTron Could you prioritize merging this as an emergency patch? 1.0 of the gem effectively makes it impossible to use a new Rails app (no schema) at this time because of the attempt to connect prior to db rake tasks.
I've helped document this issue along with @mofmn in this issue.
@rolftimmermans You have duplicated commits in this branch. Could you rebase and merge them so this PR can be merge more easily?
@rolftimmermans @olivierlacan thanks!
@rolftimmermans @JonathanTron I've grabbed the gem from master and somehow this didn't fix the issue for me. I'll try to step through with pry to see what's happening in the railtie.
Correct, I ran into the same thing.
I now have the equivalent of this code:
if !defined?(Rails::Server) && (Rails.env.development? || Rails.env.test?)
config.sequel.skip_connect = true
end
That seems to work fine.
So presumably we can use something like this instead of this PR:
if defined?(Rails::Server) || (!Rails.env.development? && !Rails.env.test?)
::SequelRails.setup ::Rails.env unless app.config.sequel[:skip_connect]
end
@rolftimmermans See https://github.com/TalentBox/sequel-rails/pull/148. I think we can simply set skip_connect
when appropriate instead of wrapping a complex condition around the SequelRails.setup
command.
I couldn't think of a reason why we'd have to avoid a connection attempt to the database than when we're trying to create it, and maybe drop it. I could clearly be forgetting something, but for me #148 fixes my db:create
issues.
When running
rake db:create
with a default sequel-rails installation (testing this with Rails 5.1.4), the following exception occurs:This happens because by default a connection is made to the configured database. This patch checks to see if we are running inside a Rake tasks and does not automatically connect if we do.
The Rake tasks themselves then call
db_for_current_env
if they need a connection to the database for the current environment. This only sets up a database connection in Rake tasks as needed.This solves the exception on
db:create
for us and others remain working.