-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
165 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* Icinga Reporting | (c) 2023 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Icinga\Module\Reporting\Model; | ||
|
||
use ipl\Orm\Behavior\MillisecondTimestamp; | ||
use ipl\Orm\Behaviors; | ||
use ipl\Orm\Model; | ||
|
||
class Schema extends Model | ||
{ | ||
public function getTableName() | ||
{ | ||
return 'reporting_schema'; | ||
} | ||
|
||
public function getKeyName() | ||
{ | ||
return 'id'; | ||
} | ||
|
||
public function getColumns() | ||
{ | ||
return [ | ||
'version', | ||
'timestamp', | ||
]; | ||
} | ||
|
||
public function createBehaviors(Behaviors $behaviors) | ||
{ | ||
$behaviors->add(new MillisecondTimestamp(['timestamp'])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/* Icinga Reporting | (c) 2023 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Icinga\Module\Reporting\ProvidedHook; | ||
|
||
use Icinga\Application\Hook\DBMigrationHook; | ||
use Icinga\Module\Reporting\Database; | ||
use Icinga\Module\Reporting\Model\Schema; | ||
|
||
class DBMigration extends DBMigrationHook | ||
{ | ||
use Database; | ||
|
||
public function getName(): string | ||
{ | ||
return $this->translate('Icinga Reporting'); | ||
} | ||
|
||
public function getDescription(): string | ||
{ | ||
return $this->translate(''); | ||
} | ||
|
||
public function getVersion(): string | ||
{ | ||
$conn = $this->getDb(); | ||
$schema = Schema::on($conn)->columns('version'); | ||
if (static::tableExists($conn, $schema->getModel()->getTableName())) { | ||
$schema = $schema->first(); | ||
if ($schema) { | ||
return $schema->version; | ||
} | ||
|
||
// Schema version table exist, but the user has probably deleted the entry! | ||
return '1.0.0'; | ||
} | ||
|
||
if ($this->getBackendType() !== static::PGSQL_BACKEND) { | ||
if (! static::tableExists($conn, 'template')) { | ||
if (static::getColumnType($conn, 'timeframe', 'name') !== 'varchar(128)') { | ||
// Use the initial version as the last migrated schema version! | ||
return '0.9.0'; | ||
} | ||
|
||
// Upgrade script 0.9.1 alters the timeframe.name column from `varchar(255)` -> `varchar(128)`. | ||
// Therefore, we can safely use this as the last migrated version. | ||
return '0.9.1'; | ||
} | ||
} | ||
|
||
// We have added Postgres support and the template table with 0.10.0. | ||
// So, use this as the last (migrated) version. | ||
return '0.10.0'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ALTER TABLE schedule | ||
DROP COLUMN IF EXISTS start, | ||
DROP COLUMN IF EXISTS frequency; | ||
|
||
CREATE TABLE IF NOT EXISTS reporting_schema ( | ||
id int unsigned NOT NULL AUTO_INCREMENT, | ||
version varchar(64) NOT NULL, | ||
timestamp int unsigned NOT NULL, | ||
|
||
PRIMARY KEY (id) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC; | ||
|
||
INSERT INTO reporting_schema (id, version, timestamp) | ||
VALUES (1, '1.0.0', UNIX_TIMESTAMP()) ON DUPLICATE KEY UPDATE version = VALUES(version), timestamp = VALUES(timestamp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ALTER TABLE schedule | ||
DROP COLUMN IF EXISTS start, | ||
DROP COLUMN IF EXISTS frequency; | ||
|
||
CREATE TABLE reporting_schema ( | ||
id serial, | ||
version varchar(64) NOT NULL, | ||
timestamp int NOT NULL, | ||
|
||
CONSTRAINT pk_reporting_schema PRIMARY KEY (id) | ||
); | ||
|
||
INSERT INTO reporting_schema (version, timestamp) | ||
VALUES ('1.0.0', UNIX_TIMESTAMP()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters