Class: OkComputer::SequelCheck

Inherits:
Check
  • Object
show all
Defined in:
lib/ok_computer/built_in_checks/sequel_check.rb

Constant Summary collapse

ConnectionFailed =
Class.new(StandardError)

Constants inherited from Check

Check::CheckNotDefined

Instance Attribute Summary collapse

Attributes inherited from Check

#failure_occurred, #message, #registrant_name, #time

Instance Method Summary collapse

Methods inherited from Check

#<=>, #clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text, #with_benchmarking

Constructor Details

#initialize(options = {}) ⇒ SequelCheck

Public: Initialize the SequelCheck with the database and/or the migration_directory.

Defaults to Sequel:Model.db and ‘db/migration’ respectively. “database” option can be a Proc so that Sequel can be instantiated later in the boot process.



9
10
11
12
# File 'lib/ok_computer/built_in_checks/sequel_check.rb', line 9

def initialize(options={})
  @database = options[:database] || -> { ::Sequel::Model.db }
  @migration_directory = options[:migration_directory] || 'db/migrate'
end

Instance Attribute Details

#migration_directoryObject (readonly)

Returns the value of attribute migration_directory.



3
4
5
# File 'lib/ok_computer/built_in_checks/sequel_check.rb', line 3

def migration_directory
  @migration_directory
end

Instance Method Details

#checkObject

Public: Return the schema version of the database



15
16
17
18
19
20
# File 'lib/ok_computer/built_in_checks/sequel_check.rb', line 15

def check
  mark_message "Schema is #{'not ' unless is_current?}up to date"
rescue ConnectionFailed => e
  mark_failure
  mark_message "Error: '#{e}'"
end

#databaseObject



22
23
24
# File 'lib/ok_computer/built_in_checks/sequel_check.rb', line 22

def database
  @database.is_a?(Proc) ? @database.call : @database
end

#is_current?Boolean

Public: The scema version of the app’s database

Returns a String with the version number

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/ok_computer/built_in_checks/sequel_check.rb', line 29

def is_current?
  ::Sequel.extension(:migration)
  ::Sequel::Migrator.is_current?(database, migration_directory)
rescue => e
  raise ConnectionFailed, e
end