<?xml version="1.0" encoding="UTF-8"?>

<!-- Differential patch for M/Monit database schema version 25 to 26 -->

<patch>

<!-- sqlite -->

<statements type="sqlite">

<comment>Drop index for statistics table</comment>
<statement>
DROP INDEX statistics_serviceid_index;
</statement>
<statement>
DROP INDEX statistics_type_index;
</statement>

<comment>Drop index for statistics_string table</comment>
<statement>
DROP INDEX statistics_string_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_string_statisticsid_index;
</statement>

<comment>Drop index for statistics_int table</comment>
<statement>
DROP INDEX statistics_int_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_int_statisticsid_index;
</statement>

<comment>Drop index for statistics_llong table</comment>
<statement>
DROP INDEX statistics_llong_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_llong_statisticsid_index;
</statement>

<comment>Drop index for statistics_float table</comment>
<statement>
DROP INDEX statistics_float_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_float_statisticsid_index;
</statement>

<comment>Drop index for statistics_double table</comment>
<statement>
DROP INDEX statistics_double_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_double_statisticsid_index;
</statement>

<comment>Drop index for statistics_aggregate_1m table</comment>
<statement>
DROP INDEX statistics_aggregate_1m_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_aggregate_1m_statisticsid_index;
</statement>

<comment>Drop index for statistics_aggregate_2m table</comment>
<statement>
DROP INDEX statistics_aggregate_2m_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_aggregate_2m_statisticsid_index;
</statement>

<comment>Drop index for statistics_aggregate_15m table</comment>
<statement>
DROP INDEX statistics_aggregate_15m_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_aggregate_15m_statisticsid_index;
</statement>

<comment>Drop index for statistics_aggregate_30m table</comment>
<statement>
DROP INDEX statistics_aggregate_30m_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_aggregate_30m_statisticsid_index;
</statement>

<comment>Drop index for statistics_aggregate_1h table</comment>
<statement>
DROP INDEX statistics_aggregate_1h_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_aggregate_1h_statisticsid_index;
</statement>

<comment>Drop index for statistics_aggregate_2h table</comment>
<statement>
DROP INDEX statistics_aggregate_2h_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_aggregate_2h_statisticsid_index;
</statement>

<comment>Drop index for statistics_aggregate_4h table</comment>
<statement>
DROP INDEX statistics_aggregate_4h_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_aggregate_4h_statisticsid_index;
</statement>

<comment>Drop index for statistics_12h table</comment>
<statement>
DROP INDEX statistics_aggregate_12h_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_aggregate_12h_statisticsid_index;
</statement>

<comment>Drop index for statistics_1d table</comment>
<statement>
DROP INDEX statistics_aggregate_1d_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_aggregate_1d_statisticsid_index;
</statement>

<comment>Drop index for statistics_3d table</comment>
<statement>
DROP INDEX statistics_aggregate_3d_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_aggregate_3d_statisticsid_index;
</statement>

<comment>Drop index for statistics_7d table</comment>
<statement>
DROP INDEX statistics_aggregate_7d_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_aggregate_7d_statisticsid_index;
</statement>

<comment>Drop index for statistics_14d table</comment>
<statement>
DROP INDEX statistics_aggregate_14d_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_aggregate_14d_statisticsid_index;
</statement>

<comment>Drop index for statistics_4w table</comment>
<statement>
DROP INDEX statistics_aggregate_4w_collectedsec_index;
</statement>
<statement>
DROP INDEX statistics_aggregate_4w_statisticsid_index;
</statement>

<comment>Create composite indexes for statistics table</comment>
<statement>
CREATE INDEX statistics_serviceid_type_index ON statistics(serviceid, type);
</statement>

<comment>Create composite indexes for statistics_string table</comment>
<statement>
CREATE INDEX statistics_string_statisticsid_collectedsec_index ON statistics_string(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_int table</comment>
<statement>
CREATE INDEX statistics_int_statisticsid_collectedsec_index ON statistics_int(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_llong table</comment>
<statement>
CREATE INDEX statistics_llong_statisticsid_collectedsec_index ON statistics_llong(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_float table</comment>
<statement>
CREATE INDEX statistics_float_statisticsid_collectedsec_index ON statistics_float(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_double table</comment>
<statement>
CREATE INDEX statistics_double_statisticsid_collectedsec_index ON statistics_double(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_1m table</comment>
<statement>
CREATE INDEX statistics_aggregate_1m_statisticsid_collectedsec_index ON statistics_aggregate_1m(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_2m table</comment>
<statement>
CREATE INDEX statistics_aggregate_2m_statisticsid_collectedsec_index ON statistics_aggregate_2m(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_15m table</comment>
<statement>
CREATE INDEX statistics_aggregate_15m_statisticsid_collectedsec_index ON statistics_aggregate_15m(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_30m table</comment>
<statement>
CREATE INDEX statistics_aggregate_30m_statisticsid_collectedsec_index ON statistics_aggregate_30m(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_1h table</comment>
<statement>
CREATE INDEX statistics_aggregate_1h_statisticsid_collectedsec_index ON statistics_aggregate_1h(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_2h table</comment>
<statement>
CREATE INDEX statistics_aggregate_2h_statisticsid_collectedsec_index ON statistics_aggregate_2h(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_4h table</comment>
<statement>
CREATE INDEX statistics_aggregate_4h_statisticsid_collectedsec_index ON statistics_aggregate_4h(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_12h table</comment>
<statement>
CREATE INDEX statistics_aggregate_12h_statisticsid_collectedsec_index ON statistics_aggregate_12h(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_1d table</comment>
<statement>
CREATE INDEX statistics_aggregate_1d_statisticsid_collectedsec_index ON statistics_aggregate_1d(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_3d table</comment>
<statement>
CREATE INDEX statistics_aggregate_3d_statisticsid_collectedsec_index ON statistics_aggregate_3d(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_7d table</comment>
<statement>
CREATE INDEX statistics_aggregate_7d_statisticsid_collectedsec_index ON statistics_aggregate_7d(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_14d table</comment>
<statement>
CREATE INDEX statistics_aggregate_14d_statisticsid_collectedsec_index ON statistics_aggregate_14d(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_4w table</comment>
<statement>
CREATE INDEX statistics_aggregate_4w_statisticsid_collectedsec_index ON statistics_aggregate_4w(statisticsid, collectedsec);
</statement>

<comment>Enable welcome screen to show news</comment>
<statement>
UPDATE mmonit SET welcome=1;
</statement>

<comment>Vacuum the database</comment>
<statement>
VACUUM;
</statement>

</statements>

<!-- mysql -->

<statements type="mysql">

<comment>Drop foreign keys on statistics table</comment>
<statement>
ALTER TABLE statistics DROP FOREIGN KEY statistics_serviceid_fk;
</statement>

<comment>Drop foreign keys on statistics_string table</comment>
<statement>
ALTER TABLE statistics_string DROP FOREIGN KEY statistics_string_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_int table</comment>
<statement>
ALTER TABLE statistics_int DROP FOREIGN KEY statistics_int_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_llong table</comment>
<statement>
ALTER TABLE statistics_llong DROP FOREIGN KEY statistics_llong_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_float table</comment>
<statement>
ALTER TABLE statistics_float DROP FOREIGN KEY statistics_float_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_double table</comment>
<statement>
ALTER TABLE statistics_double DROP FOREIGN KEY statistics_double_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_aggregate_1m table</comment>
<statement>
ALTER TABLE statistics_aggregate_1m DROP FOREIGN KEY statistics_aggregate_1m_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_aggregate_2m table</comment>
<statement>
ALTER TABLE statistics_aggregate_2m DROP FOREIGN KEY statistics_aggregate_2m_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_aggregate_15m table</comment>
<statement>
ALTER TABLE statistics_aggregate_15m DROP FOREIGN KEY statistics_aggregate_15m_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_aggregate_30m table</comment>
<statement>
ALTER TABLE statistics_aggregate_30m DROP FOREIGN KEY statistics_aggregate_30m_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_aggregate_1h table</comment>
<statement>
ALTER TABLE statistics_aggregate_1h DROP FOREIGN KEY statistics_aggregate_1h_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_aggregate_2h table</comment>
<statement>
ALTER TABLE statistics_aggregate_2h DROP FOREIGN KEY statistics_aggregate_2h_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_aggregate_4h table</comment>
<statement>
ALTER TABLE statistics_aggregate_4h DROP FOREIGN KEY statistics_aggregate_4h_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_aggregate_12h table</comment>
<statement>
ALTER TABLE statistics_aggregate_12h DROP FOREIGN KEY statistics_aggregate_12h_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_aggregate_1d table</comment>
<statement>
ALTER TABLE statistics_aggregate_1d DROP FOREIGN KEY statistics_aggregate_1d_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_aggregate_3d table</comment>
<statement>
ALTER TABLE statistics_aggregate_3d DROP FOREIGN KEY statistics_aggregate_3d_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_aggregate_7d table</comment>
<statement>
ALTER TABLE statistics_aggregate_7d DROP FOREIGN KEY statistics_aggregate_7d_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_aggregate_14d table</comment>
<statement>
ALTER TABLE statistics_aggregate_14d DROP FOREIGN KEY statistics_aggregate_14d_statisticsid_fk;
</statement>

<comment>Drop foreign keys on statistics_aggregate_4w table</comment>
<statement>
ALTER TABLE statistics_aggregate_4w DROP FOREIGN KEY statistics_aggregate_4w_statisticsid_fk;
</statement>

<dropindexesfortable>statistics</dropindexesfortable>
<dropindexesfortable>statistics_string</dropindexesfortable>
<dropindexesfortable>statistics_int</dropindexesfortable>
<dropindexesfortable>statistics_llong</dropindexesfortable>
<dropindexesfortable>statistics_float</dropindexesfortable>
<dropindexesfortable>statistics_double</dropindexesfortable>
<dropindexesfortable>statistics_aggregate_1m</dropindexesfortable>
<dropindexesfortable>statistics_aggregate_2m</dropindexesfortable>
<dropindexesfortable>statistics_aggregate_15m</dropindexesfortable>
<dropindexesfortable>statistics_aggregate_30m</dropindexesfortable>
<dropindexesfortable>statistics_aggregate_1h</dropindexesfortable>
<dropindexesfortable>statistics_aggregate_2h</dropindexesfortable>
<dropindexesfortable>statistics_aggregate_4h</dropindexesfortable>
<dropindexesfortable>statistics_aggregate_12h</dropindexesfortable>
<dropindexesfortable>statistics_aggregate_1d</dropindexesfortable>
<dropindexesfortable>statistics_aggregate_3d</dropindexesfortable>
<dropindexesfortable>statistics_aggregate_7d</dropindexesfortable>
<dropindexesfortable>statistics_aggregate_14d</dropindexesfortable>
<dropindexesfortable>statistics_aggregate_4w</dropindexesfortable>

<comment>Create composite indexes for statistics table</comment>
<statement>
CREATE INDEX statistics_serviceid_type_index ON statistics(serviceid, type);
</statement>

<comment>Create composite indexes for statistics_string table</comment>
<statement>
CREATE INDEX statistics_string_statisticsid_collectedsec_index ON statistics_string(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_int table</comment>
<statement>
CREATE INDEX statistics_int_statisticsid_collectedsec_index ON statistics_int(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_llong table</comment>
<statement>
CREATE INDEX statistics_llong_statisticsid_collectedsec_index ON statistics_llong(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_float table</comment>
<statement>
CREATE INDEX statistics_float_statisticsid_collectedsec_index ON statistics_float(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_double table</comment>
<statement>
CREATE INDEX statistics_double_statisticsid_collectedsec_index ON statistics_double(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_1m table</comment>
<statement>
CREATE INDEX statistics_aggregate_1m_statisticsid_collectedsec_index ON statistics_aggregate_1m(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_2m table</comment>
<statement>
CREATE INDEX statistics_aggregate_2m_statisticsid_collectedsec_index ON statistics_aggregate_2m(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_15m table</comment>
<statement>
CREATE INDEX statistics_aggregate_15m_statisticsid_collectedsec_index ON statistics_aggregate_15m(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_30m table</comment>
<statement>
CREATE INDEX statistics_aggregate_30m_statisticsid_collectedsec_index ON statistics_aggregate_30m(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_1h table</comment>
<statement>
CREATE INDEX statistics_aggregate_1h_statisticsid_collectedsec_index ON statistics_aggregate_1h(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_2h table</comment>
<statement>
CREATE INDEX statistics_aggregate_2h_statisticsid_collectedsec_index ON statistics_aggregate_2h(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_4h table</comment>
<statement>
CREATE INDEX statistics_aggregate_4h_statisticsid_collectedsec_index ON statistics_aggregate_4h(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_12h table</comment>
<statement>
CREATE INDEX statistics_aggregate_12h_statisticsid_collectedsec_index ON statistics_aggregate_12h(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_1d table</comment>
<statement>
CREATE INDEX statistics_aggregate_1d_statisticsid_collectedsec_index ON statistics_aggregate_1d(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_3d table</comment>
<statement>
CREATE INDEX statistics_aggregate_3d_statisticsid_collectedsec_index ON statistics_aggregate_3d(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_7d table</comment>
<statement>
CREATE INDEX statistics_aggregate_7d_statisticsid_collectedsec_index ON statistics_aggregate_7d(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_14d table</comment>
<statement>
CREATE INDEX statistics_aggregate_14d_statisticsid_collectedsec_index ON statistics_aggregate_14d(statisticsid, collectedsec);
</statement>

<comment>Create composite indexes for statistics_aggregate_4w table</comment>
<statement>
CREATE INDEX statistics_aggregate_4w_statisticsid_collectedsec_index ON statistics_aggregate_4w(statisticsid, collectedsec);
</statement>

<comment>Create foreign keys for statistics table</comment>
<statement>
ALTER TABLE statistics ADD CONSTRAINT statistics_serviceid_fk FOREIGN KEY (serviceid) REFERENCES service(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_string table</comment>
<statement>
ALTER TABLE statistics_string ADD CONSTRAINT statistics_string_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_int table</comment>
<statement>
ALTER TABLE statistics_int ADD CONSTRAINT statistics_int_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_llong table</comment>
<statement>
ALTER TABLE statistics_llong ADD CONSTRAINT statistics_llong_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_float table</comment>
<statement>
ALTER TABLE statistics_float ADD CONSTRAINT statistics_float_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_double table</comment>
<statement>
ALTER TABLE statistics_double ADD CONSTRAINT statistics_double_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_aggregate_1m table</comment>
<statement>
ALTER TABLE statistics_aggregate_1m ADD CONSTRAINT statistics_aggregate_1m_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_aggregate_2m table</comment>
<statement>
ALTER TABLE statistics_aggregate_2m ADD CONSTRAINT statistics_aggregate_2m_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_aggregate_15m table</comment>
<statement>
ALTER TABLE statistics_aggregate_15m ADD CONSTRAINT statistics_aggregate_15m_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_aggregate_30m table</comment>
<statement>
ALTER TABLE statistics_aggregate_30m ADD CONSTRAINT statistics_aggregate_30m_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_aggregate_1h table</comment>
<statement>
ALTER TABLE statistics_aggregate_1h ADD CONSTRAINT statistics_aggregate_1h_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_aggregate_2h table</comment>
<statement>
ALTER TABLE statistics_aggregate_2h ADD CONSTRAINT statistics_aggregate_2h_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_aggregate_4h table</comment>
<statement>
ALTER TABLE statistics_aggregate_4h ADD CONSTRAINT statistics_aggregate_4h_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_aggregate_12h table</comment>
<statement>
ALTER TABLE statistics_aggregate_12h ADD CONSTRAINT statistics_aggregate_12h_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_aggregate_1d table</comment>
<statement>
ALTER TABLE statistics_aggregate_1d ADD CONSTRAINT statistics_aggregate_1d_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_aggregate_3d table</comment>
<statement>
ALTER TABLE statistics_aggregate_3d ADD CONSTRAINT statistics_aggregate_3d_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_aggregate_7d table</comment>
<statement>
ALTER TABLE statistics_aggregate_7d ADD CONSTRAINT statistics_aggregate_7d_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_aggregate_14d table</comment>
<statement>
ALTER TABLE statistics_aggregate_14d ADD CONSTRAINT statistics_aggregate_14d_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Create foreign keys for statistics_aggregate_4w table</comment>
<statement>
ALTER TABLE statistics_aggregate_4w ADD CONSTRAINT statistics_aggregate_4w_statisticsid_fk FOREIGN KEY (statisticsid) REFERENCES statistics(id) ON DELETE CASCADE
</statement>

<comment>Enable welcome screen to show news</comment>
<statement>
UPDATE mmonit SET welcome=1;
</statement>

</statements>


<!-- postgresql -->

<statements type="postgresql">

<comment>No changes needed for PostgreSQL</comment>

</statements>

</patch>

