Module: WatchTower::Server::Database

Extended by:
Database
Included in:
Database
Defined in:
lib/watch_tower/server/database.rb

Instance Method Summary collapse

Instance Method Details

#is_connected?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/watch_tower/server/database.rb', line 46

def is_connected?
  ActiveRecord::Base.connected?
end

#is_migrated?Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/watch_tower/server/database.rb', line 50

def is_migrated?
  ActiveRecord::Migrator.current_version ==
    ActiveRecord::Migrator.migrations(MIGRATIONS_PATH).last.version
end

#start!(options = {}) ⇒ Object

Start the database server

see #connect! see #migrate!

Parameters:

  • options (Hash) (defaults to: {})


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/watch_tower/server/database.rb', line 15

def start!(options = {})
  LOG.debug("#{__FILE__}:#{__LINE__}: Starting the database server.")

  # Connect to the Database
  connect!

  # Migrate the database
  migrate!
rescue DatabaseConfigNotFoundError
  raise ConfigNotFound,
    "Database configurations are missing, please edit #{Config.config_file} and try again."
rescue ::ActiveRecord::ConnectionNotEstablished => e
  raise DatabaseError,
    "There was an error connecting to the database: #{error}"
end

#stop!(options = {}) ⇒ Object

Stop the database server

see #disconnect!

Parameters:

  • options (Hash) (defaults to: {})


35
36
37
38
39
40
41
42
43
44
# File 'lib/watch_tower/server/database.rb', line 35

def stop!(options = {})
  # Disconnect from the database
  disconnect!
rescue DatabaseConfigNotFoundError
  raise ConfigNotFound,
    "Database configurations are missing, please edit #{Config.config_file} and try again."
rescue ::ActiveRecord::ConnectionNotEstablished => e
  raise DatabaseError,
    "There was an error connecting to the database: #{error}"
end