-
Notifications
You must be signed in to change notification settings - Fork 81
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
rails db:create doesn't work #158
Comments
I am guessing on line 3 of I just encountered this problem. It's weird because |
Same issue in my project. I use this workaround: begin
DB = Sequel::Model.db
DB.extension :pg_array, :pg_json, :pg_enum
rescue Sequel::Error
end |
This happens for me on a brand new Rails project which has no references to Sequel other than the This is the culprit: it's called in |
I found a solution that works in my case. The error exists because of full environment initialization during the rake task invocation. So when I try to create the database, it loads my initializers, where I have Sequel customization. And even if I place it under the ActiveSupport lazy load hook (on_load(:sequel) do ), trailblazer-loader gem will do force loading of models, which will execute the hook and once again I will catch an error and no database will be created. So possible solutions is to: 1) don't load all the env for rake task (currently I use this one), 2) to rescue Sequel database errors and force execute createdb commands. My rake task looks like this: Rake::Task['db:create'].clear
namespace :db do
desc 'Create the database defined in config/database.yml for the current Rails.env'
task :create do
database_config = {
Rails.env => Rails.application.config_for('database')
}
::SequelRails::Configuration.for(Rails.root, database_config)
unless SequelRails::Storage.create_environment(Rails.env)
abort "Could not create database for #{Rails.env}."
end
end
end |
Digging a little deeper into this, the problem is that the code that decides whether to connect to the database is dependent on
This is true even if I run |
In initializer 'sequel.connect' do |app|
::SequelRails.setup(::Rails.env) if database_connection_required?(app)
end If I change that conditional to Is there a reason it needs to run at all, or run outside of production? |
So it does seem that we need to call This also causes some issues when attempting to solve #159, because I have to figure out a way to disconnect Sequel before the parallel test processes are forked. Currently the parallel testing support doesn't have any hooks that can be called pre-fork, but one may need to be added to make this compatible with Sequel / sequel-rails. |
So I had the same problem and spent couple of days to figure out the problem and the solution. So basically, Sequel read database configuration directly from config/database.yml
If you removed this option and have the correct database config in |
If you create a brand new rails app w/ sequel-rails (and no initializer at all) the issue is still present. So it happens even without |
Have the same problem in |
@gencer, try to use my solution, it should work. |
@unrooty, I just applied your solution. However there is one problem. My application tries to execute an initializer from Let me illustrate with log:
Do you know how can I make sure this initializers should not executed or at least not complain about my database? Doorkeeper is using |
hi @gencer . @unrooty works with database without loading application env. So it looks strange that you command loads initializers. Also it is possible that Doorkeeper (or Doorkeeper-Sequel) directly loads Sequel, so it triggers the error (but as far as I remember doorkeeper-sequel uses lazy loading of Sequel gem). You can try to bypass this problem by adding a "top-level" initializer like GitLab does ( |
@nbulaj, I tried something like in if Rails.env.test?
::Sequel::Model.require_valid_table = false
end or just Do you know any method so that Interestingly, |
@gencer Have you tried to remove |
@engpeter2010 yes, That was the first thing I tried. |
@gencer and which |
@engpeter2010 v1.0.1 (latest available at the moment.) They claim this version has included fixes about Maybe internally true, however, this is my case. |
@gencer: I think it might be something related to Doorkeeper-sequel gem as
I don't use Doorkeeper but sequel-rails. It is a strange issue. I spent
hours to know the trick with sequel-rails as the doc is not clear.
Hopefully, you will find a solution soon.
…On Wed, 18 Jul 2018 19:35 Gencer W. Genç, ***@***.***> wrote:
@engpeter2010 <https://github.com/engpeter2010> v1.0.1 (latest available
at the moment.)
They claim this version has included fixes about db:create. However, one
of my initializers (doorkeeper.rb#3 using as orm: sequel) is complaining
about my database.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#158 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACAbisWSnrHfbRM9eXEF8AFU5HeIm9L0ks5uH3HogaJpZM4SYA-h>
.
|
Try enabling extensions only after the DB connection is successfully established, per https://github.com/TalentBox/sequel-rails#enabling-plugins. For example:
|
Is there any update on this yet? I am unable to run I'm also getting this error |
Hi @MorneL, what version of Rails are you using? If you're using Rails >= 5.0, then can you try: I don't have any issue on a fresh Rails 5.2 app using |
@JonathanTron. On fresh installed Rails, there is no problem. I believe @MorneL is using some kind of extension that rely on Sequel (e.g.: |
Frustratingly, the `bundle exec rake db:create` step is failing, likely due to a bug in the `sequel-rails` package: TalentBox/sequel-rails#158 The workaround seems to be manually creating the database, because sequel-rails screws something up such that db:create fails due to the database not existing. Something in the initializers about attempting to connect to the db prior to actually creating it, but I wasn't able to ferret it out or successfully implement their supposed fixes.
I have such error running rails db:create. Can anybody help?
The text was updated successfully, but these errors were encountered: