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

rake db:migrate not running #335

Open
sachinsaxena1996 opened this issue Oct 8, 2021 · 1 comment
Open

rake db:migrate not running #335

sachinsaxena1996 opened this issue Oct 8, 2021 · 1 comment

Comments

@sachinsaxena1996
Copy link

Hi,

I am using gem 'makara', '0.5.0' with rails 5.2.6. I get below error when I run rake db: migrate --trace
Ruby version is 2.6.2. Any help is appreciated!

arkecode@sachins:~/repository/Factory$ rake db:migrate --trace
warning: parser/current is loading parser/ruby26, which recognizes
warning: 2.6.8-compliant syntax, but you are running 2.6.2.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
** Invoke db:migrate (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:structure:dump (first_time)
** Invoke db:load_config 
** Execute db:structure:dump
rake aborted!
TypeError: no implicit conversion of nil into String
/home/arkecode/.rvm/gems/ruby-2.6.2/gems/activerecord-5.2.6/lib/active_record/tasks/postgresql_database_tasks.rb:117:in `system'
/home/arkecode/.rvm/gems/ruby-2.6.2/gems/activerecord-5.2.6/lib/active_record/tasks/postgresql_database_tasks.rb:117:in `run_cmd'
/home/arkecode/.rvm/gems/ruby-2.6.2/gems/activerecord-5.2.6/lib/active_record/tasks/postgresql_database_tasks.rb:79:in `structure_dump'
/home/arkecode/.rvm/gems/ruby-2.6.2/gems/activerecord-5.2.6/lib/active_record/tasks/database_tasks.rb:228:in `structure_dump'
/home/arkecode/.rvm/gems/ruby-2.6.2/gems/activerecord-5.2.6/lib/active_record/railties/databases.rake:287:in `block (3 levels) in <top (required)>'

@sachinsaxena1996
Copy link
Author

Actualy I found a workaround for this where I am overiding rake db:structure:dump as follows in a file lib/tasks/xyz.rake :

Rake::Task['db:structure:dump'].overwrite do
config = PostgresUtility.db_connection_config
filename = ENV['DB_STRUCTURE'] || Rails.root.join('db/structure.sql')
raise "Task not supported by #{config[:adapter]}" unless PostgresUtility.postgresql?

conf = config.stringify_keys
ENV['PGHOST'] = conf['host'] if conf['host']
ENV['PGPORT'] = conf['port'].to_s if conf['port']
ENV['PGPASSWORD'] = conf['password'].to_s if conf['password']
ENV['PGUSER'] = conf['username'].to_s if conf['username']

search_path = config[:schema_search_path]
if search_path.present?
search_path = search_path.split(',').map do |search_path_part|
"--schema=#{Shellwords.escape(search_path_part.strip)}"
end.join(' ')
end
database = PostgresUtility.db_name
pg_dump --no-tablespaces -s -x -O -f #{Shellwords.escape(filename)} #{search_path} #{Shellwords.escape(database)}
raise 'Error dumping database' if $CHILD_STATUS.exitstatus == 1

File.open(filename, 'a') { |f| f << "SET search_path TO #{ActiveRecord::Base.connection.schema_search_path};\n\n" }
File.open(filename, 'a') { |f| f << ActiveRecord::Base.connection.dump_schema_information }
end
I hope it helps anyone else facing the same issue

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

1 participant