Welcome to docs.opsview.com
Database models
Upgrades
Update the upgradedb_{db}.pl script with the required changes for an existing database.
Use the next schema version number, based on the branch (or instance, if changing BRAN-3.3, use a schema version of “3.3”). For the sub version number, start from 1.
You could do different actions from the install scripts versus the upgrade scripts, such as setting different initial values.
If you are creating a new table, run the following first:
drop table if exists {name}
Runtime
When upgrading runtime database, there's two different db variables:
- $nagios_db - for the nagios_* tables
- $db - for the Opsview specific tables (opsivew_*)
We do not use NDOutil's upgrade scripts any more - any new upgrades will put the schema change information into our own $nagios_db.
Need to carefully check the changes made to the install scripts when updating NDOutils.
Create db
Make equivalent changes to the opsview-core/bin/db_{dbname} install script. Make sure you update the schema version number.
Test database
Need to update test database
cd /usr/local/nagios bin/db_opsview -t db_restore < t/var/opsview.test.db installer/upgradedb_opsview.pl bin/db_opsview -t db_backup > t/var/opsview.test.db svn diff t/var/opsview.test.db # To check changes to db are as expected
Model
Currently, Opsview uses Class::DBI for the model layer. We are migrating over to DBIx::Class.
Model files for Opsview in /usr/local/nagios/lib (Class::DBI) and /usr/local/nagios/lib/Opsview/Schema (DBIx::Class).
Similarly for Runtime.
For ODW and Reports, update the Class::DBI files.
To create models defined from the database, you can use DBIx::Class::Schema::Loader. Do the following:
opsview-core/utils/dump_dbix_schema Runtime
This dumps the schema to /tmp and you can copy the relevant file into opsview-core/lib/…
Update filelist with new model.
Troubleshooting
If you still get problems, you may need to change Runtime/Schema.pm by making sure DBIx::Class::Schema::Loader is set, so that it loads the db and then generate the output:
package Runtime::Schema; use strict; use warnings; use base 'DBIx::Class::Schema::Loader';
Class::DBI and DBIx::Class differences
Cascade deletes
Cascade deletes in DBIx::Class expect the database to do the work, whereas Class::DBI does it for you.
In Opsview, will need to convert all the relevant constraints to be ON CASCADE DELETE (see contacts and hostgroupnotify).
Trace: » platforms » agents » rpm_agent » nagvis » controllers » opsview3.1 » extendingtheapi » ndoutils » faq » databasemodel