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

<!-- Differential patch for M/Monit database schema version 17 to 18 -->

<patch>

<!-- sqlite -->

<statements type="sqlite">

<comment>Update statistics long long type</comment>
<statement>
UPDATE statistics SET datatype=3 WHERE datatype=4;
</statement>

<comment>Update statistics float type</comment>
<statement>
UPDATE statistics SET datatype=4 WHERE datatype=8;
</statement>

<comment>Update statistics double type</comment>
<statement>
UPDATE statistics SET datatype=5 WHERE datatype=32;
</statement>

<comment>Update statistics float aggregate and double aggregate types</comment>
<statement>
UPDATE statistics SET datatype=6 WHERE datatype IN (16, 64);
</statement>

<comment>Add values count to aggregation tables</comment>
<statement>
ALTER TABLE statistics_aggregate_1m ADD COLUMN count INTEGER;
</statement>
<statement>
ALTER TABLE statistics_aggregate_15m ADD COLUMN count INTEGER;
</statement>
<statement>
ALTER TABLE statistics_aggregate_2h ADD COLUMN count INTEGER;
</statement>
<statement>
ALTER TABLE statistics_aggregate_12h ADD COLUMN count INTEGER;
</statement>
<statement>
ALTER TABLE statistics_aggregate_1d ADD COLUMN count INTEGER;
</statement>
<statement>
ALTER TABLE statistics_aggregate_7d ADD COLUMN count INTEGER;
</statement>
<statement>
ALTER TABLE statistics_aggregate_14d ADD COLUMN count INTEGER;
</statement>

<comment>Add index for statistics collectedsec</comment>
<statement>
CREATE INDEX statistics_string_collectedsec_index ON statistics_string(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_int_collectedsec_index ON statistics_int(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_llong_collectedsec_index ON statistics_llong(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_float_collectedsec_index ON statistics_float(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_double_collectedsec_index ON statistics_double(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_1m_collectedsec_index ON statistics_aggregate_1m(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_15m_collectedsec_index ON statistics_aggregate_15m(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_2h_collectedsec_index ON statistics_aggregate_2h(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_12h_collectedsec_index ON statistics_aggregate_12h(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_1d_collectedsec_index ON statistics_aggregate_1d(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_7d_collectedsec_index ON statistics_aggregate_7d(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_14d_collectedsec_index ON statistics_aggregate_14d(collectedsec);
</statement>

</statements>


<!-- mysql -->

<statements type="mysql">

<comment>Update statistics long long type</comment>
<statement>
UPDATE statistics SET datatype=3 WHERE datatype=4;
</statement>

<comment>Update statistics float type</comment>
<statement>
UPDATE statistics SET datatype=4 WHERE datatype=8;
</statement>

<comment>Update statistics double type</comment>
<statement>
UPDATE statistics SET datatype=5 WHERE datatype=32;
</statement>

<comment>Update statistics float aggregate and double aggregate types</comment>
<statement>
UPDATE statistics SET datatype=6 WHERE datatype IN (16, 64);
</statement>

<comment>Add values count to aggregation tables</comment>
<statement>
ALTER TABLE statistics_aggregate_1m ADD COLUMN count BIGINT;
</statement>
<statement>
ALTER TABLE statistics_aggregate_15m ADD COLUMN count BIGINT;
</statement>
<statement>
ALTER TABLE statistics_aggregate_2h ADD COLUMN count BIGINT;
</statement>
<statement>
ALTER TABLE statistics_aggregate_12h ADD COLUMN count BIGINT;
</statement>
<statement>
ALTER TABLE statistics_aggregate_1d ADD COLUMN count BIGINT;
</statement>
<statement>
ALTER TABLE statistics_aggregate_7d ADD COLUMN count BIGINT;
</statement>
<statement>
ALTER TABLE statistics_aggregate_14d ADD COLUMN count BIGINT;
</statement>

<comment>Add index for statistics collectedsec</comment>
<statement>
CREATE INDEX statistics_string_collectedsec_index ON statistics_string(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_int_collectedsec_index ON statistics_int(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_llong_collectedsec_index ON statistics_llong(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_float_collectedsec_index ON statistics_float(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_double_collectedsec_index ON statistics_double(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_1m_collectedsec_index ON statistics_aggregate_1m(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_15m_collectedsec_index ON statistics_aggregate_15m(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_2h_collectedsec_index ON statistics_aggregate_2h(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_12h_collectedsec_index ON statistics_aggregate_12h(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_1d_collectedsec_index ON statistics_aggregate_1d(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_7d_collectedsec_index ON statistics_aggregate_7d(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_14d_collectedsec_index ON statistics_aggregate_14d(collectedsec);
</statement>

</statements>


<!-- postgresql -->

<statements type="postgresql">

<comment>Update statistics long long type</comment>
<statement>
UPDATE statistics SET datatype=3 WHERE datatype=4;
</statement>

<comment>Update statistics float type</comment>
<statement>
UPDATE statistics SET datatype=4 WHERE datatype=8;
</statement>

<comment>Update statistics double type</comment>
<statement>
UPDATE statistics SET datatype=5 WHERE datatype=32;
</statement>

<comment>Update statistics float aggregate and double aggregate types</comment>
<statement>
UPDATE statistics SET datatype=6 WHERE datatype IN (16, 64);
</statement>

<comment>Add values count to aggregation tables</comment>
<statement>
ALTER TABLE statistics_aggregate_1m ADD COLUMN count BIGINT;
</statement>
<statement>
ALTER TABLE statistics_aggregate_15m ADD COLUMN count BIGINT;
</statement>
<statement>
ALTER TABLE statistics_aggregate_2h ADD COLUMN count BIGINT;
</statement>
<statement>
ALTER TABLE statistics_aggregate_12h ADD COLUMN count BIGINT;
</statement>
<statement>
ALTER TABLE statistics_aggregate_1d ADD COLUMN count BIGINT;
</statement>
<statement>
ALTER TABLE statistics_aggregate_7d ADD COLUMN count BIGINT;
</statement>
<statement>
ALTER TABLE statistics_aggregate_14d ADD COLUMN count BIGINT;
</statement>

<comment>Add index for statistics collectedsec</comment>
<statement>
CREATE INDEX statistics_string_collectedsec_index ON statistics_string(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_int_collectedsec_index ON statistics_int(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_llong_collectedsec_index ON statistics_llong(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_float_collectedsec_index ON statistics_float(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_double_collectedsec_index ON statistics_double(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_1m_collectedsec_index ON statistics_aggregate_1m(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_15m_collectedsec_index ON statistics_aggregate_15m(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_2h_collectedsec_index ON statistics_aggregate_2h(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_12h_collectedsec_index ON statistics_aggregate_12h(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_1d_collectedsec_index ON statistics_aggregate_1d(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_7d_collectedsec_index ON statistics_aggregate_7d(collectedsec);
</statement>
<statement>
CREATE INDEX statistics_aggregate_14d_collectedsec_index ON statistics_aggregate_14d(collectedsec);
</statement>

</statements>

</patch>

