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

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

<patch>

<!-- sqlite -->

<statements type="sqlite">

<comment>Check database integrity before upgrade</comment>
<statement>
PRAGMA integrity_check;
</statement>
<statement>
PRAGMA foreign_key_check;
</statement>

<comment>Disable foreign keys</comment>
<statement>
PRAGMA foreign_keys=OFF;
</statement>

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

<comment>Increase the maximum password size to 128 characters</comment>
<statement>
CREATE TEMPORARY TABLE users_backup (
  id INTEGER PRIMARY KEY,
  uname VARCHAR(20) UNIQUE NOT NULL,
  password VARCHAR(128) NOT NULL,
  fullname VARCHAR(255),
  title VARCHAR(255),
  email VARCHAR(255),
  phone VARCHAR(40),
  mobile VARCHAR(40),
  imname VARCHAR(255),
  imtype VARCHAR(20),
  image VARCHAR(255),
  refresh INTEGER DEFAULT 5000
);
</statement>
<statement>
INSERT INTO users_backup (id, uname, password, fullname, title, email, phone, mobile, imname, imtype, image, refresh) SELECT id, uname, password, fullname, title, email, phone, mobile, imname, imtype, image, refresh FROM users;
</statement>
<statement>
DROP TABLE users;
</statement>
<statement>
CREATE TABLE users (
  id INTEGER PRIMARY KEY,
  uname VARCHAR(20) UNIQUE NOT NULL,
  password VARCHAR(128) NOT NULL,
  fullname VARCHAR(255),
  title VARCHAR(255),
  email VARCHAR(255),
  phone VARCHAR(40),
  mobile VARCHAR(40),
  imname VARCHAR(255),
  imtype VARCHAR(20),
  image VARCHAR(255),
  refresh INTEGER DEFAULT 5000
);
</statement>
<statement>
INSERT INTO users SELECT * FROM users_backup;
</statement>
<statement>
DROP TABLE users_backup;
</statement>
<statement>
CREATE INDEX users_uname_index ON users(uname);
</statement>

<comment>Check database integrity after upgrade</comment>
<statement>
PRAGMA integrity_check;
</statement>
<statement>
PRAGMA foreign_key_check;
</statement>

<comment>Enable foreign keys</comment>
<statement>
PRAGMA foreign_keys=ON;
</statement>

</statements>


<!-- mysql -->

<statements type="mysql">

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

<comment>Increase the maximum password size to 128 characters</comment>
<statement>
ALTER TABLE users MODIFY COLUMN password VARCHAR(128) NOT NULL;
</statement>

</statements>


<!-- postgresql -->

<statements type="postgresql">

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

<comment>Increase the maximum password size to 128 characters</comment>
<statement>
ALTER TABLE users ALTER COLUMN password TYPE CHARACTER VARYING(128);
</statement>

</statements>

</patch>

