source: trunk/Application/UpdateTrace.php

Last change on this file was 95, checked in by chronos, 3 years ago
  • Modified: Updated Common package.
  • Added: Explicit types for better type checking.
  • Fixed: Support for php 8.0.
File size: 3.6 KB
Line 
1<?php
2
3function FullInstall($Manager): void
4{
5 $Manager->Execute('CREATE TABLE IF NOT EXISTS `SystemVersion` (
6 `Id` int(11) NOT NULL AUTO_INCREMENT,
7 `Revision` int(11) NOT NULL,
8 PRIMARY KEY (`Id`)
9) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
10 $Manager->Execute('INSERT INTO `SystemVersion` (`Id`, `Revision`) VALUES (NULL, 65);');
11 $Manager->Execute('CREATE TABLE IF NOT EXISTS `measure` (
12 `Id` int(11) NOT NULL auto_increment,
13 `Name` varchar(255) collate utf8_general_ci NOT NULL,
14 `Description` varchar(255) collate utf8_general_ci NOT NULL,
15 `Divider` int(11) NOT NULL default 1,
16 `Unit` varchar(16) collate utf8_general_ci NOT NULL,
17 `Continuity` tinyint(1) NOT NULL default 0,
18 `Period` int(11) NOT NULL default 60,
19 `OldName` varchar(32) collate utf8_general_ci NOT NULL,
20 `PermissionView` varchar(255) collate utf8_general_ci NOT NULL default "all",
21 `PermissionAdd` varchar(255) collate utf8_general_ci NOT NULL default "localhost.localdomain",
22 `Info` varchar(255) collate utf8_general_ci NOT NULL,
23 `Enabled` int(11) NOT NULL default 1,
24 `Cumulative` int(11) NOT NULL default 0,
25 `DataTable` varchar(32) collate utf8_general_ci NOT NULL default "data",
26 `DataType` varchar(32) collate utf8_general_ci NOT NULL,
27 PRIMARY KEY (`Id`)
28) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
29}
30
31function UpdateTo67($Manager): void
32{
33 $Manager->Execute('RENAME TABLE `measure` TO `Measure`;');
34/*
35 $Manager->Execute('CREATE TABLE IF NOT EXISTS `Permission` (
36 `Id` int(11) NOT NULL AUTO_INCREMENT,
37 `Measure` int(11) NOT NULL,
38 `Address` varchar(255) NOT NULL,
39 `Operation` varchar(255) NOT NULL,
40 PRIMARY KEY (`Id`),
41 KEY `Measure` (`Measure`)
42) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
43 $Manager->Execute('ALTER TABLE `Permission` ADD FOREIGN KEY (`Measure`) '.
44 'REFERENCES `Measure`(`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT;');
45 $DbResult = $Manager->Execute('SELECT `Id`, `PermissionAdd` FROM `Measure`');
46 while ($DbRow = $DbResult->fetch_assoc())
47 {
48 $Manager->Execute('INSERT INTO `Permission` (`Measure`, `Operation`) VALUES ('.
49 $DbRow['Id'].', "add");');
50 }
51 $DbResult = $Manager->Execute('SELECT `Id`, `PermissionView` FROM `Measure`');
52 while ($DbRow = $DbResult->fetch_assoc())
53 {
54 $Manager->Execute('INSERT INTO `Permission` (`Measure`, `Operation`) VALUES ('.
55 $DbRow['Id'].', "view");');
56 }
57 */
58}
59
60function UpdateTo79($Manager): void
61{
62 $DbResult = $Manager->Execute('SELECT `DataTable`,`DataType` FROM `Measure`;');
63 while ($Measure = $DbResult->fetch_assoc())
64 {
65 $Table = $Measure['DataTable'];
66 $Type = $Measure['DataType'];
67 $Manager->Execute('DELETE FROM `'.$Table.'` WHERE CAST(`time` AS CHAR(20))="0000-00-00 00:00:00"');
68 $Manager->Execute('ALTER TABLE `'.$Table.'` CHANGE `time` `Time` DATETIME NULL DEFAULT NULL');
69 $Manager->Execute('ALTER TABLE `'.$Table.'` CHANGE `measure` `Measure` SMALLINT(11) NOT NULL DEFAULT "0"');
70 $Manager->Execute('ALTER TABLE `'.$Table.'` CHANGE `min` `Min` '.$Type.' NOT NULL DEFAULT "0"');
71 $Manager->Execute('ALTER TABLE `'.$Table.'` CHANGE `avg` `Avg` '.$Type.' NOT NULL DEFAULT "0"');
72 $Manager->Execute('ALTER TABLE `'.$Table.'` CHANGE `max` `Max` '.$Type.' NOT NULL DEFAULT "0"');
73 $Manager->Execute('ALTER TABLE `'.$Table.'` CHANGE `continuity` `Continuity` TINYINT(1) NOT NULL DEFAULT "0"');
74 $Manager->Execute('ALTER TABLE `'.$Table.'` CHANGE `level` `Level` TINYINT(4) NOT NULL DEFAULT "0"');
75 }
76}
77
78class Updates
79{
80 function Get(): array
81 {
82 return array(
83 65 => array('Revision' => 67, 'Function' => 'UpdateTo67'),
84 67 => array('Revision' => 79, 'Function' => 'UpdateTo79'),
85 );
86 }
87}
Note: See TracBrowser for help on using the repository browser.