Ferreteria/v0.42/log

From Woozle Writes Code
< Ferreteria
Revision as of 16:13, 25 January 2020 by htyp>Woozle (→‎Migration: saving work)
Jump to navigation Jump to search

The event-logging system uses the object-data system, including the table structure (under different names). Schema documentation here will be kept separate in case of tweaks, and to make it easier to construct the tables.

Tentatively, the "log.Type" field will be slightly repurposed from its usage in node.

Tables

log

Documentation: Template:L/version

CREATE TABLE `log` (
  `ID`       INT(4)       NOT NULL AUTO_INCREMENT,
  `Type`     VARCHAR(255) NOT NULL COMMENT "name of event type",
  `WhenMade` DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY(`ID`)
) ENGINE=InnoDB;

log_leaf

Documentation: Template:L/version

CREATE TABLE `log_leaf` (
  `ID`      INT(4)        NOT NULL AUTO_INCREMENT,
  `ID_Node` INT(4)        NOT NULL COMMENT "ID of event to which this value belongs",
  `Name`    VARCHAR(255)  NOT NULL COMMENT "field name of this value",
  `Value`   LONGTEXT  DEFAULT NULL COMMENT "value, in string format",
  PRIMARY KEY(`ID`),
  UNIQUE KEY(`ID_Node`,`Name`)
) ENGINE=InnoDB;

Migration

Migrate core events:

INSERT log(ID,Type,WhenMade) SELECT ID,IFNULL(TypeCode,'2020-was-null'),WhenStart FROM event;

Migrate fields from event table to log_leaf:

INSERT log_leaf(ID_Node,Name,Type,Value) SELECT ID,'ID_Session','id',ID_Session FROM event WHERE ID_Session IS NOT NULL;
INSERT log_leaf(ID_Node,Name,Type,Value) SELECT ID,'ID_Acct','id',ID_Acct FROM event WHERE ID_Acct IS NOT NULL;
INSERT log_leaf(ID_Node,Name,Type,Value) SELECT ID,'Descrip','text',Descrip FROM event WHERE Descrip IS NOT NULL;
INSERT log_leaf(ID_Node,Name,Type,Value) SELECT ID,'Stash','text',Stash FROM event WHERE Stash IS NOT NULL;

Migrate fields from old event-leaf records:

INSERT log_leaf(ID_Node,Name,Type,Value) SELECT ID_Event,'WhenFinish','date',WhenFinish FROM event_done WHERE WhenFinish IS NOT NULL;