Giter Club home page Giter Club logo

otr-activerecord's Introduction

otr-activerecord

An easy way to use ActiveRecord "off the rails." Works with Grape, Sinatra, plain old Rack, or even in a boring little script! The defaults are all very Railsy (config/database.yml, db/seeds.rb, db/migrate, etc.), but you can easily change them. (Formerly known as grape-activerecord.) Supports:

  • ActiveRecord 7.0 (new AR features, like encryption, not tested)
  • ActiveRecord 6.x
  • ActiveRecord 5.x
  • ActiveRecord 4.2

How to use

1. Add it to your Gemfile

gem "otr-activerecord"

2. Configure your database connection

After loading your gems, tell OTR::ActiveRecord about your database config using one of the following examples:

OTR::ActiveRecord.configure_from_file! "config/database.yml"
OTR::ActiveRecord.configure_from_url! ENV['DATABASE_URL'] # e.g. postgres://user:pass@host/db
OTR::ActiveRecord.configure_from_hash!(adapter: "postgresql", host: "localhost", database: "db", username: "user", password: "pass", encoding: "utf8", pool: 10, timeout: 5000)

Important note: configure_from_file! won't work as expected if you have already DATABASE_URL set as part of your environment variables. This is because in ActiveRecord when that env variable is set it will merge its properties into the current connection configuration.

3. Connect to your database(s)

If you have a single database (most apps), use this helper:

OTR::ActiveRecord.establish_connection!

If you're using multiple databases, call your base class(es) instead:

MyBase.establish_connection :primary
MyBase.establish_connection :primary_replica
...

4. Enable middleware for Rack apps

Add these middlewares in config.ru:

# Clean up database connections after every request (required)
use OTR::ActiveRecord::ConnectionManagement

# Enable ActiveRecord's QueryCache for every request (optional)
use OTR::ActiveRecord::QueryCache

5. Import ActiveRecord tasks into your Rakefile

This will give you most of the standard db: tasks you get in Rails. Add it to your Rakefile.

require "bundler/setup"
load "tasks/otr-activerecord.rake"

namespace :db do
  # Some db tasks require your app code to be loaded; they'll expect to find it here
  task :environment do
    require_relative "app"
  end
end

Unlike in Rails, creating a new migration is also a rake task. Run bundle exec rake -T to get a full list of tasks.

bundle exec rake db:create_migration[create_widgets]

Examples

Look under /examples for some example apps.

Advanced options

The defaults for db-related files like migrations, seeds, and fixtures are the same as Rails. If you want to override them, use the following options in your Rakefile:

OTR::ActiveRecord.db_dir = 'db'
OTR::ActiveRecord.migrations_paths = ['db/migrate']
OTR::ActiveRecord.fixtures_path = 'test/fixtures'
OTR::ActiveRecord.seed_file = 'seeds.rb'

License

Licensed under the MIT License

Copyright 2016 Jordan Hollinger

otr-activerecord's People

Contributors

alkalin3 avatar brynbayliss87 avatar jhollinger avatar jsantos avatar scudelletti avatar vidok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

otr-activerecord's Issues

1.4.2 release?

Hello,

We need to use some functionality that is exposed in activercecord 6.1 and above. We use otr as one of our dependencies and is blocking us from upgrading. When do we estimate 1.4.2 will go out?

Patch level update to 1.2.6 broke our stuff

In our environment we have our own variable for controlling the environment (lets call it XX_ENV) and we are validating that either RACK_ENV does not exist or is same to the XX_ENV. Commit a9dbeba broke that assumption since it sets RACK_ENV even when it's not set as env variable before running the process.

I'm not sure hard-setting env variable like this without a way to suppress it is nice but why was it done as patch level only change when it has a chance of breaking stuff (as it did).

Would it be possible to revert the change and release new major version since this is obviously breaking change?

Thanks for considering this.

using diagram generators

I was wondering if it was possible to generate diagrams for otr-activerecord with things like https://github.com/voormedia/rails-erd ?

I just tried and got:

$ bundle exec erd
Loading application in my-app'...
Failed: NameError: uninitialized constant RailsERD::CLI::ActiveRecord

I also tried https://github.com/preston/railroady and that failed with:

$ bundle exec rake diagram:all

rake aborted!
Don't know how to build task 'diagram:all' (See the list of available tasks with `rake --tasks`)

Cache?

Hi, I'm look into how to get activerecord query cache working otr.
After adding this to my config.ru:

use ActiveRecord::QueryCache

On starting my server I now see this error :

/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:86:in `initialize': wrong number of arguments (given 1, expected 0) (ArgumentError)
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:86:in `new'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:86:in `block in use'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:147:in `block in to_app'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:147:in `each'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:147:in `inject'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:147:in `to_app'
    from /Users/jamestindall/Documents/doc_baton/BatonSite/dist/config.ru:32:in `<main>'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/server.rb:272:in `start'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/server.rb:147:in `start'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/bin/rackup:4:in `<top (required)>'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/bin/rackup:22:in `load'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/bin/rackup:22:in `<main>'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
    from /Users/jamestindall/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'

Any ideas? Have you had activerecord query cache working otr?

Task [db:drop] is running in [default_env] environment

I have my Rakefile like this:

load 'tasks/otr-activerecord.rake'
OTR::ActiveRecord.configure_from_file!(File.join(__dir__, 'config/database.yml'))

When I run rake db:setup the database is set up correctly. However, when I do rake db:drop it says

ActiveRecord::EnvironmentMismatchError: You are attempting to modify a database that was last run in `development` environment.
You are running in `default_env` environment.

Issue goes away when I add ENV['RACK_ENV'] ||= 'development' in Rakefile, but is this the expected behavior? I thought db:drop should behave similar to db:create?

Issue with square brackets in zsh

  • Mac: OS X El Capitan (10.11.6)
  • otr-activerecord: 1.2.0
  • Ruby: 2.3.1
  • zsh: zsh 5.2 (x86_64-apple-darwin15.4.0)

Running the create_migration command without escaping square brackets:

$ bundle exec rake db:create_migration[create_widgets]
# zsh: no matches found: db:create_migration[create_widgets]

Running the create_migration command escaping square brackets:

$ bundle exec rake db:create_migration\[create_widgets\]
# db/migrate/20161102143458_create_widgets.rb

Update:
Found this as a possible fix: https://robots.thoughtbot.com/how-to-use-arguments-in-a-rake-task

Unable to run ActiveRecord::Base.connection.execute

Hi,
using otr-activerecord version 1.2.7, (database.yml is correct and connects to remote RDS) but when I call ActiveRecord::Base execute it tries to connect to localhost
Error Stack

[2019-03-18 10:29:06] ERROR PG::ConnectionBad: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/pg-0.18.4/lib/pg.rb:45:in `initialize'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/pg-0.18.4/lib/pg.rb:45:in `new'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/pg-0.18.4/lib/pg.rb:45:in `connect'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in `checkout_new_connection'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in `try_to_checkout_new_connection'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1010:in `retrieve_connection'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/activerecord-5.2.2.1/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/activerecord-5.2.2.1/lib/active_record/connection_handling.rb:90:in `connection'
	/usr/local/loc/exporter/app/apis/trips.rb:21:in `block (2 levels) in <class:Trips>'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/grape-1.2.3/lib/grape/endpoint.rb:57:in `call'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/grape-1.2.3/lib/grape/endpoint.rb:57:in `block (2 levels) in generate_api_method'
	/home/deployer/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/activesupport-5.2.2.1/lib/active_support/notifications.rb:170:in `instrument'
....
  1. Gemfile
source 'http://rubygems.org'
gem 'grape', '1.2.3'
gem 'otr-activerecord', '1.2.7'
...
  1. config.ru
require 'rack'
require 'grape'
require './app/core'

OTR::ActiveRecord.configure_from_file! "config/database.yml"
use OTR::ActiveRecord::ConnectionManagement

run Base
  1. app/api/trips
class Trips < Grape::API
  resource 'trips' do
    desc 'List all trips.'
    get '/' do
      query = "select count(*) from trips group by owner_type;"
      ActiveRecord::Base.connection.execute(query).values
    end

  end
end

Does otr-activerecord supports running direct queries, instead of using models?

migrations_paths being ignored

I have setup OTR::ActiveRecord as expected, but I get this on my rakefile:

puts "OTR: {OTR::ActiveRecord.migrations_paths.inspect}"
puts "AR: #{::ActiveRecord::Tasks::DatabaseTasks.migrations_paths}"

Resulting in:

OTR: ["/Users/papipo/Projects/mathtrades/backend/apps/auth/migrations"]
AR: ["db/migrate"]

Thus my migrations aren't run.

Tests fail with activerecord 6.0.x

The Gemfile allows activerecord 6.0.x. When executing the tests with this version, the tests fail due to

Failures:

  1) OTR::ActiveRecord.configure_from_file! when simple configuration file is given configures active record
     Failure/Error:
       expect(::ActiveRecord::Base.configurations['test']).to eq(
         adapter: 'sqlite3',
         database: 'tmp/simple.sqlite3',
         migrations_paths: ['db/migrate']
       )
     
       expected: {:adapter=>"sqlite3", :database=>"tmp/simple.sqlite3", :migrations_paths=>["db/migrate"]}
            got: {"adapter"=>"sqlite3", "database"=>"tmp/simple.sqlite3", "migrations_paths"=>["db/migrate"]}
     
       (compared using ==)
     
       Diff:
       @@ -1,4 +1,4 @@
       -:adapter => "sqlite3",
       -:database => "tmp/simple.sqlite3",
       -:migrations_paths => ["db/migrate"],
       +"adapter" => "sqlite3",
       +"database" => "tmp/simple.sqlite3",
       +"migrations_paths" => ["db/migrate"],
       
     # ./spec/otr-activerecord/activerecord_spec.rb:9:in `block (4 levels) in <top (required)>'

  2) OTR::ActiveRecord.configure_from_file! when configuration file with multiple roles given configures active record
     Failure/Error:
       expect(::ActiveRecord::Base.configurations['test']).to eq(
         adapter: 'sqlite3',
         database: 'tmp/multi.sqlite3',
         migrations_paths: ['db/migrate']
       )
     
       expected: {:adapter=>"sqlite3", :database=>"tmp/multi.sqlite3", :migrations_paths=>["db/migrate"]}
            got: {"adapter"=>"sqlite3", "database"=>"tmp/multi.sqlite3", "migrations_paths"=>["db/migrate"]}
     
       (compared using ==)
     
       Diff:
       @@ -1,4 +1,4 @@
       -:adapter => "sqlite3",
       -:database => "tmp/multi.sqlite3",
       -:migrations_paths => ["db/migrate"],
       +"adapter" => "sqlite3",
       +"database" => "tmp/multi.sqlite3",
       +"migrations_paths" => ["db/migrate"],
       
     # ./spec/otr-activerecord/activerecord_spec.rb:23:in `block (4 levels) in <top (required)>'

Finished in 0.01645 seconds (files took 0.3151 seconds to load)
2 examples, 2 failures

Failed examples:

rspec ./spec/otr-activerecord/activerecord_spec.rb:6 # OTR::ActiveRecord.configure_from_file! when simple configuration file is given configures active record
rspec ./spec/otr-activerecord/activerecord_spec.rb:20 # OTR::ActiveRecord.configure_from_file! when configuration file with multiple roles given configures active record

The tests succeed with activerecord 6.1.

create_migration not working

When trying to create a migration, getting like this:

bundle exec rake db:create_migration[create_widgets]

zsh: no matches found: db:create_migration[create_widgets]

db:drop/create:all not working

Hi Jordan,

Did you manage to get db:drop:all or db:create:all working?

I get the following...

rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:298:in `block in each_local_configuration'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:297:in `each_value'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:297:in `each_local_configuration'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:147:in `drop_all'
/Users/jamestindall/Documents/doc_baton/BatonSite/src/server/Rakefile:64:in `block (3 levels) in <top (required)>'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/task.rb:248:in `block in execute'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/task.rb:243:in `each'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/task.rb:243:in `execute'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/Users/jamestindall/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/task.rb:173:in `invoke'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:152:in `invoke_task'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:108:in `each'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:108:in `block in top_level'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:117:in `run_with_threads'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:102:in `top_level'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:80:in `block in run'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:178:in `standard_exception_handling'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:77:in `run'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/bin/rake:23:in `load'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/bin/rake:23:in `<main>'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:drop:all

uninitialized constant Hashie::Extensions::Array from the rake task

When using the following rake file

require 'bundler/setup'
require 'rake/testtask'
load 'tasks/otr-activerecord.rake'

namespace :db do
  task :environment do
    require_relative 'config/application'
  end
end

Rake::TestTask.new do |t|
  t.libs << 'test'
  t.test_files = FileList['spec/**/*_spec.rb']
end

I get the following error message, when trying to run the example applications on Ruby 2.3.1

rake aborted!
NameError: uninitialized constant Hashie::Extensions::Array
Did you mean?  Hashie::Array
               Array
/usr/local/bundle/gems/hashie-3.4.5/lib/hashie/array.rb:3:in `<class:Array>'
/usr/local/bundle/gems/hashie-3.4.5/lib/hashie/array.rb:2:in `<module:Hashie>'
/usr/local/bundle/gems/hashie-3.4.5/lib/hashie/array.rb:1:in `<top (required)>'
/usr/local/bundle/gems/hashie-3.4.5/lib/hashie/mash.rb:2:in `require'
/usr/local/bundle/gems/hashie-3.4.5/lib/hashie/mash.rb:2:in `<top (required)>'
/usr/local/bundle/gems/hashie-forbidden_attributes-0.1.1/lib/hashie-forbidden_attributes/hashie/mash.rb:1:in `require'
/usr/local/bundle/gems/hashie-forbidden_attributes-0.1.1/lib/hashie-forbidden_attributes/hashie/mash.rb:1:in `<top (required)>'
/usr/local/bundle/gems/hashie-forbidden_attributes-0.1.1/lib/hashie-forbidden_attributes.rb:1:in `require'
/usr/local/bundle/gems/hashie-forbidden_attributes-0.1.1/lib/hashie-forbidden_attributes.rb:1:in `<top (required)>'
/usr/local/bundle/gems/otr-activerecord-1.2.0/lib/otr-activerecord.rb:2:in `require'
/usr/local/bundle/gems/otr-activerecord-1.2.0/lib/otr-activerecord.rb:2:in `<top (required)>'
/usr/local/bundle/gems/otr-activerecord-1.2.0/lib/tasks/otr-activerecord.rake:5:in `require'
/usr/local/bundle/gems/otr-activerecord-1.2.0/lib/tasks/otr-activerecord.rake:5:in `<top (required)>'
/var/www/bunny/rakefile:3:in `load'
/var/www/bunny/rakefile:3:in `<top (required)>'
/usr/local/bundle/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)

Some default rails tasks iterate over all databases

Tasks such as db:create db:schema:load and db:reset appear to disregard the RAILS_ENV setting and iterate over all the non protected (so not production or admin) databases listed in your config. I find this highly undesirable. Is there any way to prevent this other than doing Rake::Task['db:schema:load'].clear and then writing my own implementation?

db:seed:dump

With the seed_dump gem installed and required into the Rakefile running rake db:seed:dump throws this error :

$ rake db:seed:dump --trace
rake aborted!
Don't know how to build task 'db:seed:dump' (see --tasks)
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/task_manager.rb:71:in `[]'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:151:in `invoke_task'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:108:in `each'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:108:in `block in top_level'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:117:in `run_with_threads'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:102:in `top_level'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:80:in `block in run'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:178:in `standard_exception_handling'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:77:in `run'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/bin/rake:23:in `load'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/bin/rake:23:in `<main>'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
/Users/jamestindall/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'

Any ideas on how to get this working? Or know of another way to dump the db contents to seeds.rb ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.