mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-24 22:34:24 +02:00
Introduce database models required by migration hooks
This commit is contained in:
parent
ac369f9156
commit
21bde13274
49
library/Icinga/Model/Schema.php
Normal file
49
library/Icinga/Model/Schema.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/* Icinga Web 2 | (c) 2023 Icinga GmbH | GPLv2+ */
|
||||||
|
|
||||||
|
namespace Icinga\Model;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use ipl\Orm\Behavior\BoolCast;
|
||||||
|
use ipl\Orm\Behavior\MillisecondTimestamp;
|
||||||
|
use ipl\Orm\Behaviors;
|
||||||
|
use ipl\Orm\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A database model for Icinga Web schema version table
|
||||||
|
*
|
||||||
|
* @property int $id Unique identifier of the database schema entries
|
||||||
|
* @property string $version The current schema version of Icinga Web
|
||||||
|
* @property DateTime $timestamp The insert/modify time of the schema entry
|
||||||
|
* @property bool $success Whether the database migration of the current version was successful
|
||||||
|
* @property ?string $reason The reason why the database migration has failed
|
||||||
|
*/
|
||||||
|
class Schema extends Model
|
||||||
|
{
|
||||||
|
public function getTableName(): string
|
||||||
|
{
|
||||||
|
return 'icingaweb_schema';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getKeyName()
|
||||||
|
{
|
||||||
|
return 'id';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getColumns(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'version',
|
||||||
|
'timestamp',
|
||||||
|
'success',
|
||||||
|
'reason'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createBehaviors(Behaviors $behaviors): void
|
||||||
|
{
|
||||||
|
$behaviors->add(new BoolCast(['success']));
|
||||||
|
$behaviors->add(new MillisecondTimestamp(['timestamp']));
|
||||||
|
}
|
||||||
|
}
|
@ -49,6 +49,8 @@ parameters:
|
|||||||
count: 2
|
count: 2
|
||||||
path: library/Icinga/Protocol/Ldap/LdapConnection.php
|
path: library/Icinga/Protocol/Ldap/LdapConnection.php
|
||||||
|
|
||||||
|
- '#Call to an undefined method ipl\\Sql\\Connection::exec\(\)#'
|
||||||
|
|
||||||
scanDirectories:
|
scanDirectories:
|
||||||
- vendor
|
- vendor
|
||||||
|
|
||||||
@ -56,6 +58,7 @@ parameters:
|
|||||||
- library/Icinga/Test
|
- library/Icinga/Test
|
||||||
|
|
||||||
universalObjectCratesClasses:
|
universalObjectCratesClasses:
|
||||||
|
- ipl\Orm\Model
|
||||||
- Icinga\Data\ConfigObject
|
- Icinga\Data\ConfigObject
|
||||||
- Icinga\Web\View
|
- Icinga\Web\View
|
||||||
- Icinga\Module\Monitoring\Object\MonitoredObject
|
- Icinga\Module\Monitoring\Object\MonitoredObject
|
||||||
|
11
schema/mysql-upgrades/2.12.0.sql
Normal file
11
schema/mysql-upgrades/2.12.0.sql
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
ALTER TABLE icingaweb_schema
|
||||||
|
MODIFY COLUMN timestamp bigint unsigned NOT NULL,
|
||||||
|
MODIFY COLUMN version varchar(64) NOT NULL,
|
||||||
|
ADD COLUMN IF NOT EXISTS success enum ('n', 'y') DEFAULT NULL,
|
||||||
|
ADD COLUMN IF NOT EXISTS reason text DEFAULT NULL,
|
||||||
|
DROP CONSTRAINT IF EXISTS idx_icingaweb_schema_version,
|
||||||
|
ADD CONSTRAINT idx_icingaweb_schema_version UNIQUE (version);
|
||||||
|
|
||||||
|
INSERT INTO icingaweb_schema (version, timestamp, success, reason)
|
||||||
|
VALUES('2.12.0', UNIX_TIMESTAMP() * 1000, 'y', NULL)
|
||||||
|
ON DUPLICATE KEY UPDATE timestamp = VALUES(timestamp), success = VALUES(success), reason = VALUES(reason);
|
@ -55,11 +55,14 @@ CREATE TABLE `icingaweb_rememberme`(
|
|||||||
|
|
||||||
CREATE TABLE icingaweb_schema (
|
CREATE TABLE icingaweb_schema (
|
||||||
id int unsigned NOT NULL AUTO_INCREMENT,
|
id int unsigned NOT NULL AUTO_INCREMENT,
|
||||||
version smallint unsigned NOT NULL,
|
version varchar(64) NOT NULL,
|
||||||
timestamp int unsigned NOT NULL,
|
timestamp bigint NOT NULL,
|
||||||
|
success enum ('n', 'y') DEFAULT NULL,
|
||||||
|
reason text DEFAULT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id),
|
||||||
|
CONSTRAINT idx_icingaweb_schema_version UNIQUE (version)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
|
||||||
|
|
||||||
INSERT INTO icingaweb_schema (version, timestamp)
|
INSERT INTO icingaweb_schema (version, timestamp, success)
|
||||||
VALUES (6, UNIX_TIMESTAMP());
|
VALUES ('2.12.0', UNIX_TIMESTAMP() * 1000, 'y');
|
||||||
|
13
schema/pgsql-upgrades/2.12.0.sql
Normal file
13
schema/pgsql-upgrades/2.12.0.sql
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
CREATE TYPE boolenum AS ENUM ('n', 'y');
|
||||||
|
|
||||||
|
ALTER TABLE icingaweb_schema
|
||||||
|
ALTER COLUMN timestamp TYPE bigint,
|
||||||
|
ALTER COLUMN version TYPE varchar(64),
|
||||||
|
ADD COLUMN success boolenum DEFAULT NULL,
|
||||||
|
ADD COLUMN reason text DEFAULT NULL,
|
||||||
|
DROP CONSTRAINT IF EXISTS idx_icingaweb_schema_version,
|
||||||
|
ADD CONSTRAINT idx_icingaweb_schema_version UNIQUE (version);
|
||||||
|
|
||||||
|
INSERT INTO icingaweb_schema (version, timestamp, success, reason)
|
||||||
|
VALUES('2.12.0', EXTRACT(EPOCH FROM now()) * 1000, 'y', NULL)
|
||||||
|
ON CONFLICT ON CONSTRAINT idx_icingaweb_schema_version DO UPDATE SET timestamp = EXCLUDED.timestamp, success = EXCLUDED.success, reason = EXCLUDED.reason;
|
@ -118,13 +118,18 @@ ALTER TABLE ONLY "icingaweb_rememberme"
|
|||||||
"id"
|
"id"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TYPE boolenum AS ENUM ('n', 'y');
|
||||||
|
|
||||||
CREATE TABLE "icingaweb_schema" (
|
CREATE TABLE "icingaweb_schema" (
|
||||||
"id" serial,
|
"id" serial,
|
||||||
"version" smallint NOT NULL,
|
"version" varchar(64) NOT NULL,
|
||||||
"timestamp" int NOT NULL,
|
"timestamp" bigint NOT NULL,
|
||||||
|
"success" boolenum DEFAULT NULL,
|
||||||
|
"reason" text DEFAULT NULL,
|
||||||
|
|
||||||
CONSTRAINT pk_icingaweb_schema PRIMARY KEY ("id")
|
CONSTRAINT pk_icingaweb_schema PRIMARY KEY ("id"),
|
||||||
|
CONSTRAINT idx_icingaweb_schema_version UNIQUE (version)
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO icingaweb_schema (version, timestamp)
|
INSERT INTO icingaweb_schema (version, timestamp, success)
|
||||||
VALUES (6, extract(epoch from now()));
|
VALUES ('2.12.0', extract(epoch from now()) * 1000, 'y');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user