Class: Mihari::Database
- Inherits:
-
Object
- Object
- Mihari::Database
- Defined in:
- lib/mihari/database.rb
Class Method Summary collapse
-
.close ⇒ Object
Close DB connection(s).
-
.connect ⇒ Object
Establish DB connection.
-
.migrate(direction) ⇒ Object
DB migraration.
Class Method Details
.close ⇒ Object
Close DB connection(s)
162 163 164 165 166 |
# File 'lib/mihari/database.rb', line 162 def close return unless ActiveRecord::Base.connected? ActiveRecord::Base.clear_active_connections! end |
.connect ⇒ Object
Establish DB connection
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/mihari/database.rb', line 142 def connect return if ActiveRecord::Base.connected? case adapter when "postgresql", "mysql2" ActiveRecord::Base.establish_connection(Mihari.config.database_url.to_s) else ActiveRecord::Base.establish_connection( adapter: adapter, database: Mihari.config.database_url.path[1..] ) end ActiveRecord::Base.logger = Logger.new($stdout) if development_env? rescue StandardError => e Mihari.logger.error e end |
.migrate(direction) ⇒ Object
DB migraration
135 136 137 |
# File 'lib/mihari/database.rb', line 135 def migrate(direction) schemas.each { |schema| schema.migrate direction } end |