Ravn::BDE::

MissionRecord module

Constants and functions used for SQLite3 history and event logging.

Constants

Model

Set up an abstract base model class and a factory method for creating subclasses.

Public Instance Methods

db()

The current handle for the mission record database

# File lib/ravn/bde/mission_record.rb, line 31
singleton_attr_reader :db
reset()

Close the database handle and remove the file from disk.

# File lib/ravn/bde/mission_record.rb, line 39
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.

# File lib/ravn/bde/mission_record.rb, line 52
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