Ravn::BDE::
MissionRecord
module
Constants and functions used for SQLite3 history and event logging.
- Model
Set up an abstract base model class and a factory method for creating subclasses.
The current handle for the mission record database
singleton_attr_reader :db
Close the database handle and remove the file from disk.
def reset
self.log.warn "resetting database connection"
@db&.disconnect
@db = nil
if Ravn::BDE.history_db_path.exist?
self.log.warn "Purging history database at: %s" % [ Ravn::BDE.history_db_path ]
Ravn::BDE.history_db_path.unlink
end
end
setup_database( memory: false )
Initialize and return an open handle to the history database.
def setup_database( memory: false )
@db ||= begin
if memory
self.log.info "Setting up in-memory history DB"
newdb = Sequel.sqlite
else
dbpath = Ravn::BDE.history_db_path
self.log.info "Connecting to history DB at: %p" % [ dbpath ]
dbpath.dirname.mkpath
newdb = Sequel.connect( "sqlite://%s" % [ dbpath.to_s ] )
end
Ravn::BDE::MissionRecord::Model.db = newdb
Ravn::BDE::MissionRecord::Model.require_models
Ravn::BDE::MissionRecord::Model.migrate
newdb
end
end