DROP DATABASE IF EXISTS rssguard;
-- !
CREATE DATABASE IF NOT EXISTS rssguard CHARACTER SET utf8 COLLATE utf8_general_ci;
-- !
USE rssguard;
-- !
DROP TABLE IF EXISTS Information;
-- !
CREATE TABLE IF NOT EXISTS Information (
  id              INTEGER     AUTO_INCREMENT PRIMARY KEY,
  inf_key         TEXT        NOT NULL,
  inf_value       TEXT        NOT NULL
);
-- !
INSERT INTO Information VALUES (1, 'schema_version', '0.0.2');
-- !
DROP TABLE IF EXISTS Categories;
-- !
CREATE TABLE IF NOT EXISTS Categories (
  id              INTEGER       AUTO_INCREMENT PRIMARY KEY,
  parent_id       INTEGER       NOT NULL,
  title           VARCHAR(100)  NOT NULL UNIQUE CHECK (title != ''),
  description     TEXT,
  date_created    BIGINT        NOT NULL CHECK (date_created != 0),
  icon            BLOB
);
-- !
DROP TABLE IF EXISTS Feeds;
-- !
CREATE TABLE IF NOT EXISTS Feeds (
  id              INTEGER       AUTO_INCREMENT PRIMARY KEY,
  title           TEXT          NOT NULL CHECK (title != ''),
  description     TEXT,
  date_created    BIGINT        NOT NULL CHECK (date_created != 0),
  icon            BLOB,
  category        INTEGER       NOT NULL CHECK (category >= -1),
  encoding        TEXT          NOT NULL CHECK (encoding != ''),
  url             VARCHAR(100)  NOT NULL UNIQUE CHECK (url != ''),
  protected       INTEGER(1)    NOT NULL CHECK (protected >= 0 AND protected <= 1),
  username        TEXT,
  password        TEXT,
  update_type     INTEGER(1)    NOT NULL CHECK (update_type >= 0),
  update_interval INTEGER       NOT NULL DEFAULT 15 CHECK (update_interval >= 5),
  type            INTEGER       NOT NULL CHECK (type >= 0)
);
-- !
DROP TABLE IF EXISTS FeedsData;
-- !
CREATE TABLE IF NOT EXISTS FeedsData (
  feed_id         INTEGER       NOT NULL,
  feed_key        VARCHAR(100)  NOT NULL,
  feed_value      TEXT,
  
  PRIMARY KEY (feed_id, feed_key),
  FOREIGN KEY (feed_id) REFERENCES Feeds (id)
);
-- !
DROP TABLE IF EXISTS Messages;
-- !
CREATE TABLE IF NOT EXISTS Messages (
  id              INTEGER     AUTO_INCREMENT PRIMARY KEY,
  is_read         INTEGER(1)  NOT NULL DEFAULT 0 CHECK (is_read >= 0 AND is_read <= 1),
  is_deleted      INTEGER(1)  NOT NULL DEFAULT 0 CHECK (is_deleted >= 0 AND is_deleted <= 1),
  is_important    INTEGER(1)  NOT NULL DEFAULT 0 CHECK (is_important >= 0 AND is_important <= 1),
  feed            INTEGER     NOT NULL,
  title           TEXT        NOT NULL CHECK (title != ''),
  url             TEXT        NOT NULL,
  author          TEXT        NOT NULL,
  date_created    BIGINT      NOT NULL CHECK (date_created != 0),
  contents        TEXT,
  is_pdeleted       INTEGER(1)  NOT NULL DEFAULT 0 CHECK (is_pdeleted >= 0 AND is_pdeleted <= 1),
  
  FOREIGN KEY (feed) REFERENCES Feeds (id)
);
-- !
INSERT INTO Categories (id, parent_id, title, description, date_created, icon) VALUES (1, -1, 'Linux', 'Collections of GNU/Linux-related feeds.', 1388678961000, 'AAAAIgBRAFAAaQB4AG0AYQBwAEkAYwBvAG4ARQBuAGcAaQBuAGUAAAABAAAAAYlQTkcNChoKAAAADUlIRFIAAABAAAAAQAgGAAAAqmlx3gAAAAlwSFlzAAAOxAAADsQBlSsOGwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxMS0wNy0yOVQxNToxOTo1MCswMzowMMnGKbgAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTEtMDctMjlUMTU6MTg6MzcrMDM6MDBUkc0zAAAHP0lEQVR4nO1bzW4byRGu6u6RhqRImiJlErQBWQgPWgJrR9cY2D3swTDyBntIgN08RE55gCB5gzxA7jn5sMcA0cJGYishEIRrQ7sytdFfRIW0VsPpqhw0Qw+H3UOO5RVHm/2AAcmZ/qmqrv66qtkD8CP+v4FzPMc5ysXBkSvTSFJM1ut1t1gs5jc3N6u5XM5J0a5++fLlwbNnz04BwL+ijN8rlOW+qFar+XK5XHv48OGnlUrll4hYRMSZI8rMCACj27dv/1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kajmxUCxuA4Dne73fBdoSnC+B/xChTkpBznVAAAAABJRU5ErkJgggAAAKoAQwA6AC8AVQBzAGUAcgBzAC8AcgBvAHQAdABlAHIALwBEAG8AYwB1AG0AZQBuAHQAcwAvAFAAcgBvAGoAZQBrAHQAeQAvAHIAcwBzAGcAdQBhAHIAZAAtAGIAdQBpAGwAZAAvAGkAYwBvAG4AcwAvAG0AaQBuAGkALQBrAGYAYQBlAG4AegBhAC8AZgBvAGwAZABlAHIALQBiAGwAYQBjAGsALgBwAG4AZwAAAEAAAABAAAAAAAAAAAE=');
-- !
INSERT INTO Categories (id, parent_id, title, description, date_created, icon) VALUES (2, -1, 'RSS Guard', 'News and updates on RSS Guard.', 1388678961000, 'AAAAIgBRAFAAaQB4AG0AYQBwAEkAYwBvAG4ARQBuAGcAaQBuAGUAAAABAAAAAYlQTkcNChoKAAAADUlIRFIAAABAAAAAQAgGAAAAqmlx3gAAAAlwSFlzAAAOxAAADsQBlSsOGwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxMS0wNy0yOVQxNToxOTo1MCswMzowMMnGKbgAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTEtMDctMjlUMTU6MTg6MzcrMDM6MDBUkc0zAAAHP0lEQVR4nO1bzW4byRGu6u6RhqRImiJlErQBWQgPWgJrR9cY2D3swTDyBntIgN08RE55gCB5gzxA7jn5sMcA0cJGYishEIRrQ7sytdFfRIW0VsPpqhw0Qw+H3UOO5RVHm/2AAcmZ/qmqrv66qtkD8CP+v4FzPMc5ysXBkSvTSFJM1ut1t1gs5jc3N6u5XM5J0a5++fLlwbNnz04BwL+ijN8rlOW+qFar+XK5XHv48OGnlUrll4hYRMSZI8rMCACj27dv/1Ep9fvt7e0jANDvVer3CKMB2u22Ojw8LFQqlc1CofArrfU95nTe7DjO561W6+n29vafAOA7yOh0MBpgOBwKIYQLAFUiKvu+D2kNoJRaLRaLnz548ODPz58//zcsxgAMAJRUwDYFYHl5WTCzGI1Gly2lNAARgVLq462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AcwBzAGcAdQBhAHIAZAAtAGIAdQBpAGwAZAAvAGkAYwBvAG4AcwAvAG0AaQBuAGkALQBrAGYAYQBlAG4AegBhAC8AZgBvAGwAZABlAHIALQBiAGwAYQBjAGsALgBwAG4AZwAAAEAAAABAAAAAAAAAAAE=');
-- !
INSERT INTO Feeds (title, description, date_created, category, encoding, url, protected, update_type, type) VALUES ('Linux Today', 'Linux Today - Linux News on Internet Time.', 1388678961000, 1, 'UTF-8', 'http://feeds.feedburner.com/linuxtoday/linux?format=xml', 0, 1, 1);
-- !
INSERT INTO Feeds (title, description, date_created, category, encoding, url, protected, update_type, type) VALUES ('LinuxInsider', 'LinuxInsider: Linux News & Information from Around the World.', 1388678961000, 1, 'UTF-8', 'http://www.linuxinsider.com/perl/syndication/rssfull.pl', 0, 1, 1);
-- !
INSERT INTO Feeds (title, description, date_created, category, encoding, url, protected, update_type, type) VALUES ('LXer: Linux News', 'The world is talking about GNU/Linux and Free/Open Source Software.', 1388678961000, 1, 'UTF-8', 'http://lxer.com/module/newswire/headlines.rss', 0, 1, 2);
-- !
INSERT INTO Feeds (title, description, date_created, category, encoding, url, protected, update_type, update_interval, type) VALUES ('Recent Commits', 'Recent commits for RSS Guard project.', 1388678961000, 2, 'UTF-8', 'http://bitbucket.org/skunkos/rssguard/rss', 0, 2, 30, 1);