
= DB changes between version =

Document the DB changes between versions

== Future planned changes ===

The future plan is to, implement a TTL snmptrap event.

Add a TTL event to table "event_type".

  INSERT INTO event_type (bitmask, label, description) VALUES
    ( 16, "ttl_change", "Indicate TTL changed");


== From: 0.9.0 to 0.9.1 ===

To apply changes described below run:

  cd database/
  mysql -u root -p tvprobe < database-upgrade-0.9.0-to-0.9.1.sql

Need to support packet and byte counters (named "packets" and
"payload_bytes").  The column "packets" already exist, and the column
"bytes" need to be renamed to "payload_bytes".

  ALTER TABLE log_event
  	CHANGE `bytes` `payload_bytes` BIGINT(20) unsigned default '0';

Also store the delta for payload_bytes and packets.  This can be
easily used for calculation a number of things, e.g. bandwidth
combined with delta time since last record (delta_poll is not usable
for this purpose), if TS mapping 7 is used or not.

  ALTER TABLE log_event
   ADD `delta_payload_bytes` int(10) unsigned NOT NULL default '0',
   ADD `delta_packets`       int(10) unsigned NOT NULL default '0';

To relate the delta counters, to something, we need to know when the
last record were updated, so we can determine the seconds these delta
counters account for.  This way is possible to calculate bandwidth and
packets per sec.

Add a "last_update" timestamp and a "delta_update" time:

  ALTER TABLE log_event
   ADD last_update   timestamp NOT NULL default '0000-00-00 00:00:00',
   ADD delta_update  float unsigned default NULL;

Change "delta_poll" to use type "float" instead of "int(11)"
(eventhough the precision of "delta_poll" is not as important as
"delta_update").

  ALTER TABLE log_event
   MODIFY delta_poll float unsigned default NULL;

=== Event types ===

Introducing new event types in this version.

* New event type(4): "no-signal" detection.
* New event type(32): "transition".
* New event type(64): "heartbeat".
* New event type(128): "invalid".

Old event types:

* Event type(2): "drop".
* Event type(1): "new_stream".

Need a side table describing the event types, as there previously were
only one event type (drops) (and implicit "new_stream" event).

Event datatype, design discussion: We also need to consider that,
potentially/theoretically, is possible for two events type to occur in
the same poll cycle.  Thus, either we need some kind of bit-vector so
several events can be recorded together, or else the software needs to
record two log_event records.  Its possible to use the MySQL
"SET-type", to create a SQL bit-vector.  The problem with this
approach is, that each time a new event type is created, the database
needs to be altered.

Future event types, could be related to burst, jitter, PCR-clock issues.

Change the datatype of "event_type", to support a large bit-vector
number. Choose to simply use an 32-bit INT type (instead of MySQLs BIT
type, as its strange to use, and it does not convert well).  To view
the bits, MySQL select supports the "bin" cast
(e.g. "select bin(event_type) from log_event;").

  ALTER TABLE log_event
    MODIFY event_type INT(10) unsigned NOT NULL default '0';

Create side table:

  DROP TABLE IF EXISTS event_type;
  CREATE TABLE event_type (
    bitmask     int(10) unsigned NOT NULL default '0',
    label       varchar(15) NOT NULL,
    description varchar(255),
    PRIMARY KEY (bitmask)
  ) ENGINE=InnoDB

  INSERT INTO event_type (bitmask, label, description) VALUES
  (  1, "new_stream", "New stream detected"),
  (  2, "drop"      , "Drops detected, both skips and discon"),
  (  4, "no_signal" , "Stream have stopped transmitting data"),
  ( 32, "transition", "The event_state changed since last poll"),
  ( 64, "heartbeat" , "Heartbeat event to monitor status"),
  (128, "invalid"   , "Some invalid event situation arose");

=== Extra change ===

As the database gets update anyhow, also complete the renaming from
mp2t to mpeg2ts.

 ALTER TABLE daemon_session
  CHANGE `mp2t_created` `mpeg2ts_created` timestamp NOT NULL default '0000-00-00 00:00:00',
  CHANGE `mp2t_version` `mpeg2ts_version` varchar(50) default NULL;


