2
votes

I'm calling ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:sql, file) in a Ruby file script (essentially it's a Thor task) in a Ruby off Rails app and I get the following error:

/gems/activerecord-4.2.5/lib/active_record/connection_adapters/connection_specification.rb:248:in `resolve_symbol_connection': 'development' database is not configured. Available: [] (ActiveRecord::AdapterNotSpecified)

Does ActiveRecord::Tasks::DatabaseTasks give me the functions I need to set up a default database configuration outside of rails (I'm assuming I need to provide info similar to what's in database.yml in Rails)? If so, what are the functions I would need to call? I'm looking at http://api.rubyonrails.org/classes/ActiveRecord/Tasks/DatabaseTasks.html but it's a bit unclear to me.

2

2 Answers

0
votes

Before load the schema, you need to load the database configuration (like the database.yml):

DatabaseTasks.database_configuration = YAML.load_file('my_database_config.yml')
0
votes

I was able to get this to work in a non-Rails project with the following...

db_config = YAML.load_file('path/to/database.yml')
ActiveRecord::Tasks::DatabaseTasks.load_schema_for(
  db_config, :ruby, 'path/to/schema.rb')