Module: PhobosDBCheckpoint
- Defined in:
- lib/phobos_db_checkpoint.rb,
lib/phobos_db_checkpoint/cli.rb,
lib/phobos_db_checkpoint/event.rb,
lib/phobos_db_checkpoint/tasks.rb,
lib/phobos_db_checkpoint/errors.rb,
lib/phobos_db_checkpoint/failure.rb,
lib/phobos_db_checkpoint/handler.rb,
lib/phobos_db_checkpoint/version.rb,
lib/phobos_db_checkpoint/events_api.rb,
lib/phobos_db_checkpoint/event_helper.rb,
lib/phobos_db_checkpoint/event_actions.rb,
lib/phobos_db_checkpoint/middleware/logger.rb,
lib/phobos_db_checkpoint/middleware/database.rb,
lib/phobos_db_checkpoint/actions/retry_failure.rb
Defined Under Namespace
Modules: CLI, EventHelper, Handler, Middleware, Tasks Classes: Ack, Event, EventsAPI, Failure, ListenerNotFoundError, PhobosDBCheckpointError, RetryFailure
Constant Summary collapse
- DEFAULT_DB_DIR =
'db'.freeze
- DEFAULT_MIGRATION_PATH =
File.join(DEFAULT_DB_DIR, 'migrate').freeze
- DEFAULT_DB_CONFIG_PATH =
'config/database.yml'.freeze
- DEFAULT_POOL_SIZE =
5.freeze
- VERSION =
'1.0.0'
Class Attribute Summary collapse
-
.db_config ⇒ Object
readonly
Returns the value of attribute db_config.
-
.db_config_path ⇒ Object
Returns the value of attribute db_config_path.
-
.db_dir ⇒ Object
Returns the value of attribute db_dir.
-
.migration_path ⇒ Object
Returns the value of attribute migration_path.
Class Method Summary collapse
- .close_db_connection ⇒ Object
- .configure(pool_size: nil) ⇒ Object
- .env ⇒ Object
- .load_db_config(pool_size: nil) ⇒ Object
- .load_tasks ⇒ Object
Class Attribute Details
.db_config ⇒ Object (readonly)
Returns the value of attribute db_config.
22 23 24 |
# File 'lib/phobos_db_checkpoint.rb', line 22 def db_config @db_config end |
.db_config_path ⇒ Object
Returns the value of attribute db_config_path.
23 24 25 |
# File 'lib/phobos_db_checkpoint.rb', line 23 def db_config_path @db_config_path end |
.db_dir ⇒ Object
Returns the value of attribute db_dir.
23 24 25 |
# File 'lib/phobos_db_checkpoint.rb', line 23 def db_dir @db_dir end |
.migration_path ⇒ Object
Returns the value of attribute migration_path.
23 24 25 |
# File 'lib/phobos_db_checkpoint.rb', line 23 def migration_path @migration_path end |
Class Method Details
.close_db_connection ⇒ Object
47 48 49 50 |
# File 'lib/phobos_db_checkpoint.rb', line 47 def close_db_connection ActiveRecord::Base.connection_pool.disconnect! rescue ActiveRecord::ConnectionNotEstablished end |
.configure(pool_size: nil) ⇒ Object
25 26 27 28 29 |
# File 'lib/phobos_db_checkpoint.rb', line 25 def configure(pool_size: nil) load_db_config(pool_size: pool_size) at_exit { PhobosDBCheckpoint.close_db_connection } ActiveRecord::Base.establish_connection(db_config) end |
.env ⇒ Object
31 32 33 |
# File 'lib/phobos_db_checkpoint.rb', line 31 def env ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] ||= 'development' end |
.load_db_config(pool_size: nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/phobos_db_checkpoint.rb', line 35 def load_db_config(pool_size: nil) @db_config_path ||= ENV['DB_CONFIG'] || DEFAULT_DB_CONFIG_PATH configs = YAML.load_file(File.(@db_config_path)) @db_config = configs[env] if pool_size.nil? && Phobos.config pool_size = Phobos.config.listeners.map { |listener| listener.max_concurrency || 1 }.inject(&:+) end @db_config.merge!('pool' => pool_size || DEFAULT_POOL_SIZE) end |
.load_tasks ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/phobos_db_checkpoint.rb', line 52 def load_tasks @db_dir ||= DEFAULT_DB_DIR @migration_path ||= DEFAULT_MIGRATION_PATH ActiveRecord::Tasks::DatabaseTasks.send(:define_method, :db_dir) { PhobosDBCheckpoint.db_dir } ActiveRecord::Tasks::DatabaseTasks.send(:define_method, :migrations_paths) { [PhobosDBCheckpoint.migration_path] } ActiveRecord::Tasks::DatabaseTasks.send(:define_method, :env) { PhobosDBCheckpoint.env } require 'phobos_db_checkpoint/tasks' end |