Jesterovskiy
Hi. Ca you push v0.1.6 to Rubygems? Thank you)
#3 · closed · 17 comments
Hi. Ca you push v0.1.6 to Rubygems? Thank you)
Any particular reason for that? Nothing changed feature wise as much as I can tell you. If you need some of the recent changes just let me know.
@rosenfeld I get `Database already exists - aborting` when it doesn't. I'm thinking, that maybe this change is helps https://github.com/rosenfeld/sequel_tools/commit/a531def5d3e424f2f8a6ed5d528c2bea6d4087b0#diff-04c6e90faac2675aa89e2176d2eec7d8R60
Actually, I think it may be related to this: https://github.com/rosenfeld/sequel_tools/commit/608c3754c6fbb4f8d2d9c25eceb87acea3ec82dd I'll try to remember to push a new release once I get back to home, a few hours from now. For the mean time you may try to unset PG related ENV and confirm this is the issue.
I get latest master and cleaned this ENV vars - same problem
Then that means that a new release won't help you. If you are able to debug what is wrong in case your settings are correct then I would be able to replicate and fix the issue. If you have a sample application replicating that problem it would also work.
@rosenfeld ``` ruby [2] pry(SequelTools::ActionsManager)> Action[:connect_db].run({}, context) => #<SequelTools::SequelToolsLogger:0x00007fe6812d41b8 @default_formatter=#<Logger::Formatter:0x00007fe6812d4168 @datetime_format=nil>, @formatter=#<Proc:0x00007fe67fc9ff50@/Users/jester/.rvm/gems/ruby-2.4.2/gems/sequel_tools-0.1.5/lib/sequel_tools/sequel_tools_logger.rb:10>, @level=1, @logdev= #<Logger::LogDevice:0x00007fe6812d4118 @dev=#<IO:<STDOUT>>, @filename=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x00007fe6812d40a0>, @mon_owner=nil, @shift_age=nil, @shift_period_suffix=nil, @shift_size=nil>, @progname=nil> ``` as I understand, This method must return exception, but returns this logger. Maybe this will help?
``` ruby {:config=> {:project_root=>"/Users/jester/Projects/test/lib/test/tasks", :pg_dump=>"pg_dump", :psql=>"psql", :maintenancedb=>"postgres", :migrations_location=>"/Users/jester/Projects/test/lib/test/migrations", :schema_location=>"/Users/jester/Projects/test/lib/test/migrations/schema.sql", :seeds_location=>"/Users/jester/Projects/test/lib/test/seeds/seeds.rb", :dbname=>"db_development", :dbhost=>"localhost", :dbadapter=>"postgres", :dbport=>5432, :username=>"rails", :password=>"rails", :dump_schema_on_migrate=>true, :log_level=>:info, :sql_log_level=>:debug}, ```
> This method must return exception, but returns this logger. Actually this method isn't supposed to return anything meaningful for the time being, although it may raise an exception. Could you please provide a full application repository so that I can reproduce the issue?
@rosenfeld sorry, I can't. But provide for you some code: ``` ruby require 'yaml' require 'bundler/setup' require 'sequel_tools' base_config = SequelTools.base_config( project_root: File.expand_path(__dir__), dbadapter: 'postgres', dbname: 'mydb', username: 'myuser', password: 'secret', dbport: 5432, # default log_level is nil, in which mode the executed actions such as # starting/finishing a migration in a given direction or creating and # dropping the database are not logged to standard output. log_level: :info, # Default options: sql_log_level: :debug, dump_schema_on_migrate: false, # it's a good idea to enable it for the reference environment pg_dump: 'pg_dump', # command used to run pg_dump # pg_dump: 'psql', # command used to run psql when calling rake db:shell if adapter is postgres migrations_location: '../migrations', schema_location: '../migrations/schema.sql', seeds_location: '../seeds/seeds.rb', # for tasks such as creating the database: # when nil, defaults to the value of the :dbadapter config. # This is the database we should connect to before executing "create database dbname" maintenancedb: :default, ) db_config = YAML.load_file('lib/test/config/database.yml') st_db_config_dev = { dbname: db_config['development']['database'], username: db_config['development']['user'], password: db_config['development']['password'] } st_db_config_test = { dbname: db_config['test']['database'], username: db_config['test']['user'], password: db_config['test']['password'] } namespace 'db' do SequelTools.inject_rake_tasks base_config.merge(dump_schema_on_migrate: true).merge(st_db_config_dev), self end namespace 'dbtest' do SequelTools.inject_rake_tasks base_config.merge(st_db_config_test), self end ``` database.yml ``` ruby --- default: &default adapter: postgres encoding: utf8 development: <<: *default database: development user: rails password: rails test: <<: *default database: test user: rails password: rails ```
Here's what I did, besides the provided sources above: Gemfile: ```ruby source "https://rubygems.org" gem 'sequel_tools' gem 'pg' ``` Then I created the rails user with superuser privileges to make it simpler: ```shell createuser -U postgres -h localhost -l -s -P rails ``` After running bundle, this was the output I got when running `rake db:create` twice: ``` $ rake db:create [INFO] Created database 'development' $ rake db:create Database already exists - aborting ``` Just as expected. Without a full application demonstrating the issue it's hard for me to understand what could be happening.
@rosenfeld ok, lets sync: which version of Sequel you use? Also, this string must raise exception https://github.com/rosenfeld/sequel_tools/blob/master/lib/sequel_tools/actions/connect_db.rb#L11 if DB doesn't exist?
Here's my Gemfile.lock: ``` GEM remote: https://rubygems.org/ specs: pg (0.21.0) sequel (5.4.0) sequel_tools (0.1.5) sequel PLATFORMS ruby DEPENDENCIES pg sequel_tools BUNDLED WITH 1.16.1 ```
And yes, calling Sequel.connect with invalid settings or valid settings but inexisting database should raise.
@rosenfeld I found issue. For your code, you need to specify sequel ~> 5.x.x, because for 4.49.0: ``` ruby [4] pry(main)> context[:db] = db = SequelTools.suppress_java_output do [4] pry(main)* Sequel.connect context[:uri_builder].call config [4] pry(main)* end => #<Sequel::Postgres::Database: "postgres://localhost:5432/development?user=rails&password=rails"> ``` 5.4.0 ``` ruby [3] pry(main)> context[:db] = db = SequelTools.suppress_java_output do [3] pry(main)* Sequel.connect context[:uri_builder].call config [3] pry(main)* end Sequel::DatabaseConnectionError: PG::ConnectionBad: FATAL: database "development" does not exist from /Users/jester/.rvm/gems/ruby-2.4.2/gems/sequel-5.4.0/lib/sequel/adapters/postgres.rb:190:in `initialize' ``` or you can add http://www.rubydoc.info/gems/sequel/4.38.0/Sequel%2FDatabase%3Atest_connection - this method will raise error in both versions
That makes sense. Could you please test with latest commit in master? If it works I'll release a new version.
@rosenfeld It works, thank you =)
v0.1.6 is released. Thanks for your investigation :)