Module: Lanes::DB
Defined Under Namespace
Modules: Migrations
Instance Attribute Summary collapse
-
#config_file ⇒ Object
Returns the value of attribute config_file.
Instance Method Summary collapse
- #configure_rake_environment ⇒ Object
- #establish_connection(env = Lanes.config.environment) ⇒ Object
- #load_seed ⇒ Object
Instance Attribute Details
#config_file ⇒ Object
Returns the value of attribute config_file.
6 7 8 |
# File 'lib/lanes/db.rb', line 6 def config_file @config_file end |
Instance Method Details
#configure_rake_environment ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lanes/db.rb', line 24 def configure_rake_environment ActiveRecord::Tasks::DatabaseTasks.seed_loader = Lanes::DB default_schema = Extensions.controlling.root_path.join("db","schema.sql") ENV['SCHEMA'] ||= default_schema.to_s ENV['DB_STRUCTURE'] ||= default_schema.to_s ActiveRecord::Base.schema_format = :sql ActiveRecord::Base.dump_schema_after_migration = !Lanes.env.production? Lanes::DB.establish_connection ActiveRecord::Tasks::DatabaseTasks.database_configuration = ActiveRecord::Base.configurations env=Lanes.config.environment.to_s ActiveRecord::Tasks::DatabaseTasks.env = env ActiveRecord::Tasks::DatabaseTasks.migrations_paths = 'db/migrate' ActiveRecord::Tasks::DatabaseTasks.current_config( config: ActiveRecord::Base.configurations[env] ) end |
#establish_connection(env = Lanes.config.environment) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/lanes/db.rb', line 8 def establish_connection(env=Lanes.config.environment) if ENV['DATABASE_URL'] ::ActiveRecord::Base.establish_connection(ENV['DATABASE_URL']) else file = config_file || Extensions.controlling.root_path.join("config","database.yml") config = YAML::load( IO.read(file) ) ::ActiveRecord::Base.configurations = config ::ActiveRecord::Base.establish_connection(::ActiveRecord::Base.configurations[env.to_s]) end end |
#load_seed ⇒ Object
19 20 21 22 |
# File 'lib/lanes/db.rb', line 19 def load_seed path = Pathname.new("./db/seed.rb") load path if path.exist? end |