Module: Hippo::DB

Extended by:
DB
Included in:
DB
Defined in:
lib/hippo/db.rb,
lib/hippo/db/migrations.rb

Defined Under Namespace

Modules: Migrations

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#config_fileObject

Returns the value of attribute config_file


6
7
8
# File 'lib/hippo/db.rb', line 6

def config_file
  @config_file
end

Instance Method Details

#configure_rake_environmentObject


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hippo/db.rb', line 24

def configure_rake_environment
    require_relative "./db/fake_rails"
    require_relative './db/migrations'
    ActiveRecord::Tasks::DatabaseTasks.seed_loader = Hippo::DB
    default_schema = Extensions.controlling.root_path.join("db","schema.rb")
    ENV['SCHEMA']          ||= default_schema.to_s
    ENV['DB_STRUCTURE']    ||= default_schema.to_s
    ActiveRecord::Base.dump_schema_after_migration = !Hippo.env.production?
    Hippo::DB.establish_connection
    ActiveRecord::Tasks::DatabaseTasks.database_configuration = ActiveRecord::Base.configurations
    env=Hippo.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 = Hippo.config.environment) ⇒ Object


8
9
10
11
12
13
14
15
16
17
# File 'lib/hippo/db.rb', line 8

def establish_connection(env=Hippo.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_seedObject


19
20
21
22
# File 'lib/hippo/db.rb', line 19

def load_seed
    path = Pathname.new("./db/seed.rb")
    load path if path.exist?
end