DROP TABLE IF EXISTS Information;
-- !
CREATE TABLE IF NOT EXISTS Information (
  key           TEXT        PRIMARY KEY,
  value         TEXT        NOT NULL
);
-- !
INSERT INTO Information VALUES ('schema_version', '0.0.1');
-- !
DROP TABLE IF EXISTS Categories;
-- !
CREATE TABLE IF NOT EXISTS Categories (
  id             INTEGER    PRIMARY KEY,
  parent_id      INTEGER    NOT NULL,
  title          TEXT       NOT NULL UNIQUE CHECK (title != ''),
  description    TEXT,
  date_created   INTEGER    NOT NULL CHECK (date_created != 0),
  icon           BLOB,
  type           INTEGER    NOT NULL,
  
  FOREIGN KEY (parent_id) REFERENCES Categories (id)
);
-- !
DROP TABLE IF EXISTS Feeds;
-- !
CREATE TABLE IF NOT EXISTS Feeds (
  id             INTEGER    PRIMARY KEY,
  title          TEXT       NOT NULL CHECK (title != ''),
  description    TEXT,
  date_created   INTEGER    NOT NULL CHECK (date_created != 0),
  icon           BLOB,
  category       INTEGER    NOT NULL CHECK (category >= -1),
  encoding       TEXT       NOT NULL CHECK (encoding != ''),
  url            TEXT       NOT NULL UNIQUE CHECK (url != ''),
  language       TEXT,
  type           INTEGER    NOT NULL CHECK (type >= 0)
);
-- !
DROP TABLE IF EXISTS FeedsData;
-- !
CREATE TABLE IF NOT EXISTS FeedsData (
  id             INTEGER	NOT NULL,
  key		     TEXT		NOT NULL,
  value	         TEXT,
  
  PRIMARY KEY (id, key),
  FOREIGN KEY (id) REFERENCES Feeds (id)
);
-- !
DROP TABLE IF EXISTS Messages;
-- !
CREATE TABLE IF NOT EXISTS Messages (
  id             INTEGER    PRIMARY KEY,
  read           INTEGER(1) NOT NULL CHECK (read >= 0 AND read <= 1) DEFAULT (0),
  deleted        INTEGER(1) NOT NULL CHECK (deleted >= 0 AND deleted <= 1) DEFAULT (0),
  important      INTEGER(1) NOT NULL CHECK (important >= 0 AND important <= 1) DEFAULT (0),
  feed           INTEGER    NOT NULL,
  title          TEXT       NOT NULL CHECK (title != ''),
  url            TEXT,
  author         TEXT,
  date_created   INTEGER       NOT NULL CHECK (date_created != 0),
  contents       TEXT,
  
  FOREIGN KEY (feed) REFERENCES Feeds (id)
);
-- !
INSERT INTO Categories (id, parent_id, title, description, date_created, type, icon) VALUES (1, -1, 'Linux', 'Collections of GNU/Linux-related feeds.', 1388678961000, 0, 'AAAAIgBRAFAAaQB4AG0AYQBwAEkAYwBvAG4ARQBuAGcAaQBuAGUAAAABAAAAAYlQTkcNChoKAAAADUlIRFIAAABAAAAAQAgGAAAAqmlx3gAAAAlwSFlzAAAOxAAADsQBlSsOGwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxMS0wNy0yOVQxNToxOTo1MCswMzowMMnGKbgAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTEtMDctMjlUMTU6MTg6MzcrMDM6MDBUkc0zAAAHP0lEQVR4nO1bzW4byRGu6u6RhqRImiJlErQBWQgPWgJrR9cY2D3swTDyBntIgN08RE55gCB5gzxA7jn5sMcA0cJGYishEIRrQ7sytdFfRIW0VsPpqhw0Qw+H3UOO5RVHm/2AAcmZ/qmqrv66qtkD8CP+v4FzPMc5ysXBkSvTSFJM1ut1t1gs5jc3N6u5XM5J0a5++fLlwbNnz04BwL+ijN8rlOW+qFar+XK5XHv48OGnlUrll4hYRMSZI8rMCACj27dv/1Ep9fvt7e0jANDvVer3CKMB2u22Ojw8LFQqlc1CofArrfU95nTe7DjO561W6+n29vafAOA7yOh0MBpgOBwKIYQLAFUiKvu+D2kNoJRaLRaLnz548ODPz58//zcsxgAMAJRUwDYFYHl5WTCzGI1Gly2lNAARgVLq462trV/cv3//n8HUuBZorQe9Xu+rnZ2dg0aj8V2n0xmBZQCsBog0BkSJRrSCmW/lcrnfMPPonRp4RzCzXygUdorF4u+ePn36l1arddbtdi9MZa0GYGZkZiQi0Fqn9gCAS+N5nuciopu68hWhlPpodXXVbzQavz45OenC5Wo0RcaJHkBE4Hke+H6mV7IpMDMIIUAp9aGU8t5gMOi12+1hp9OZywByd3dXbm1tFUql0iozi3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4qL3s2wE2+6wjbCndoSICG0nQrKw7s+CSfZw0IhoauN35ikxU2M/JBgDoSQl4x6waIPMI08sDpgmwci/w8Zs0EaKWYKN9Ax8gJD077AJNlLMAhICnrnqjw2glMKAJCYaSRMZZglxuUNdiAiVUpPpMMDlGRqIccBNUtgGQ1yA0TNQiVPgh2KApOkwMQXCCia3z/r6H0cSIUanwNgAwTsBqbfFF22YtF7KzBg9+xw9JSYg4IQ0jd7AaSKklGLilFgETESZfb/nqgh0mxgxAQDQ7/dJKeVdXFwM37x5cxLdCc5q4DMLcdkREYbD4fH5+flQKeX1+/23Z4Xz+bzv+/6AmQ96vd5z13XrrusWTMdi5gkyvi9emGeHyibj+fn58PXr1y+01gda60G5XB4dHh5eGmB3d9er1+t9RNw9ODj4UmudbzabH66srNySUo5PlJsUm0fZeeolxfBJmFVPa60Hg8Fpr9fbOT4+/pKZd33f73e73RHA21WAXNc9Y+ZviOivx8fHXr/ff6WUqgohUmeMIaJ/sFwFV3lhg4h83/ePfd//FzP/Qwjxjeu6ZxAcl48OA9br9Xwul6t5ntcUQtQR8RYRpXljNHMQQoyY+ZSZv3UcZ//i4uJwf3//HAIyjPsmtttt5+zsbEVrvSKlXCKi9zOMC4IQgrTWnpRyUCqVBp1OZ+JFCNsERgCQrVZLjkajmxUCxuA4Dne73fBdoSnC+B/xChTkpBznVAAAAABJRU5ErkJgggAAAKoAQwA6AC8AVQBzAGUAcgBzAC8AcgBvAHQAdABlAHIALwBEAG8AYwB1AG0AZQBuAHQAcwAvAFAAcgBvAGoAZQBrAHQAeQAvAHIAcwBzAGcAdQBhAHIAZAAtAGIAdQBpAGwAZAAvAGkAYwBvAG4AcwAvAG0AaQBuAGkALQBrAGYAYQBlAG4AegBhAC8AZgBvAGwAZABlAHIALQBiAGwAYQBjAGsALgBwAG4AZwAAAEAAAABAAAAAAAAAAAE=');
-- !
INSERT INTO Categories (id, parent_id, title, description, date_created, type, icon) VALUES (2, -1, 'RSS Guard', 'News and updates on RSS Guard.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lGRqIccBNUtgGQ1yA0TNQiVPgh2KApOkwMQXCCia3z/r6H0cSIUanwNgAwTsBqbfFF22YtF7KzBg9+xw9JSYg4IQ0jd7AaSKklGLilFgETESZfb/nqgh0mxgxAQDQ7/dJKeVdXFwM37x5cxLdCc5q4DMLcdkREYbD4fH5+flQKeX1+/23Z4Xz+bzv+/6AmQ96vd5z13XrrusWTMdi5gkyvi9emGeHyibj+fn58PXr1y+01gda60G5XB4dHh5eGmB3d9er1+t9RNw9ODj4UmudbzabH66srNySUo5PlJsUm0fZeeolxfBJmFVPa60Hg8Fpr9fbOT4+/pKZd33f73e73RHA21WAXNc9Y+ZviOivx8fHXr/ff6WUqgohUmeMIaJ/sFwFV3lhg4h83/ePfd//FzP/Qwjxjeu6ZxAcl48OA9br9Xwul6t5ntcUQtQR8RYRpXljNHMQQoyY+ZSZv3UcZ//i4uJwf3//HAIyjPsmtttt5+zsbEVrvSKlXCKi9zOMC4IQgrTWnpRyUCqVBp1OZ+JFCNsERgCQrVZLjkajmxUCxuA4Dne73fBdoSnC+B/xChTkpBznVAAAAABJRU5ErkJgggAAAKoAQwA6AC8AVQBzAGUAcgBzAC8AcgBvAHQAdABlAHIALwBEAG8AYwB1AG0AZQBuAHQAcwAvAFAAcgBvAGoAZQBrAHQAeQAvAHIAcwBzAGcAdQBhAHIAZAAtAGIAdQBpAGwAZAAvAGkAYwBvAG4AcwAvAG0AaQBuAGkALQBrAGYAYQBlAG4AegBhAC8AZgBvAGwAZABlAHIALQBiAGwAYQBjAGsALgBwAG4AZwAAAEAAAABAAAAAAAAAAAE=');
-- !
INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Linux Today', 'Linux Today - Linux News on Internet Time.', 1388678961000, 1, 'UTF-8', 'http://feeds.feedburner.com/linuxtoday/linux?format=xml', 1);
-- !
INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('LinuxInsider', 'LinuxInsider: Linux News & Information from Around the World.', 1388678961000, 1, 'UTF-8', 'http://www.linuxinsider.com/perl/syndication/rssfull.pl', 2);
-- !
INSERT INTO Feeds (title, description, date_created, category, encoding, url, 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', 2);
-- !
INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Recent Commits', 'Recent commits for RSS Guard project.', 1388678961000, 2, 'UTF-8', 'https://github.com/martinrotter/rssguard/commits/master.atom', 3);
-- !
INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Releases', 'Releases for RSS Guard.', 1388678961000, 2, 'UTF-8', 'https://github.com/martinrotter/rssguard/releases.atom', 3);
-- !
INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Author''s Activity', 'RSS Guard author public activity overview.', 1388678961000, 2, 'UTF-8', 'https://github.com/martinrotter.atom', 3);