| 1 |
ALTER TABLE Feeds RENAME TO backup_Feeds; |
| 2 |
-- ! |
| 3 |
CREATE TABLE Feeds ( |
| 4 |
id $$, |
| 5 |
ordr INTEGER NOT NULL CHECK (ordr >= 0), |
| 6 |
title TEXT NOT NULL CHECK (title != ''), |
| 7 |
description TEXT, |
| 8 |
date_created BIGINT, |
| 9 |
icon ^^, |
| 10 |
category INTEGER NOT NULL CHECK (category >= -1), /* Physical category ID, also root feeds contain -1 here. */ |
| 11 |
source TEXT, |
| 12 |
update_type INTEGER NOT NULL CHECK (update_type >= 0), |
| 13 |
update_interval INTEGER NOT NULL DEFAULT 15 CHECK (update_interval >= 1), |
| 14 |
is_off INTEGER NOT NULL DEFAULT 0 CHECK (is_off >= 0 AND is_off <= 1), |
| 15 |
open_articles INTEGER NOT NULL DEFAULT 0 CHECK (open_articles >= 0 AND open_articles <= 1), |
| 16 |
account_id INTEGER NOT NULL, |
| 17 |
custom_id TEXT NOT NULL CHECK (custom_id != ''), /* Custom ID cannot be empty, it must contain either service-specific ID, or Feeds/id. */ |
| 18 |
/* Custom column for (serialized) custom account-specific data. */ |
| 19 |
custom_data TEXT, |
| 20 |
|
| 21 |
FOREIGN KEY (account_id) REFERENCES Accounts (id) ON DELETE CASCADE |
| 22 |
); |
| 23 |
-- ! |
| 24 |
INSERT INTO Feeds (id, ordr, title, description, date_created, icon, category, source, update_type, update_interval, account_id, custom_id, custom_data) |
| 25 |
SELECT id, id, title, description, date_created, icon, category, source, update_type, update_interval, account_id, custom_id, custom_data |
| 26 |
FROM backup_Feeds; |
| 27 |
-- ! |
| 28 |
DROP TABLE backup_Feeds; |
| 29 |
-- ! |
| 30 |
UPDATE Feeds |
| 31 |
SET ordr = ( |
| 32 |
SELECT COUNT(*) |
| 33 |
FROM Feeds ct |
| 34 |
WHERE Feeds.account_id = ct.account_id AND Feeds.category = ct.category AND ct.id < Feeds.id |
| 35 |
); |
| 36 |
-- ! |
| 37 |
ALTER TABLE Categories RENAME TO backup_Categories; |
| 38 |
-- ! |
| 39 |
CREATE TABLE Categories ( |
| 40 |
id $$, |
| 41 |
ordr INTEGER NOT NULL CHECK (ordr >= 0), |
| 42 |
parent_id INTEGER NOT NULL CHECK (parent_id >= -1), /* Root categories contain -1 here. */ |
| 43 |
title TEXT NOT NULL CHECK (title != ''), |
| 44 |
description TEXT, |
| 45 |
date_created BIGINT, |
| 46 |
icon ^^, |
| 47 |
account_id INTEGER NOT NULL, |
| 48 |
custom_id TEXT, |
| 49 |
|
| 50 |
FOREIGN KEY (account_id) REFERENCES Accounts (id) ON DELETE CASCADE |
| 51 |
); |
| 52 |
-- ! |
| 53 |
INSERT INTO Categories (id, ordr, parent_id, title, description, date_created, icon, account_id, custom_id) |
| 54 |
SELECT id, id, parent_id, title, description, date_created, icon, account_id, custom_id |
| 55 |
FROM backup_Categories; |
| 56 |
-- ! |
| 57 |
DROP TABLE backup_Categories; |
| 58 |
-- ! |
| 59 |
UPDATE Categories |
| 60 |
SET ordr = ( |
| 61 |
SELECT COUNT(*) |
| 62 |
FROM Categories ct |
| 63 |
WHERE Categories.account_id = ct.account_id AND Categories.parent_id = ct.parent_id AND ct.id < Categories.id |
| 64 |
); |
| 65 |
-- ! |
| 66 |
ALTER TABLE Accounts RENAME TO backup_Accounts; |
| 67 |
-- ! |
| 68 |
CREATE TABLE Accounts ( |
| 69 |
id $$, |
| 70 |
ordr INTEGER NOT NULL CHECK (ordr >= 0), |
| 71 |
type TEXT NOT NULL CHECK (type != ''), /* ID of the account type. Each account defines its own, for example 'ttrss'. */ |
| 72 |
proxy_type INTEGER NOT NULL DEFAULT 0 CHECK (proxy_type >= 0), |
| 73 |
proxy_host TEXT, |
| 74 |
proxy_port INTEGER, |
| 75 |
proxy_username TEXT, |
| 76 |
proxy_password TEXT, |
| 77 |
/* Custom column for (serialized) custom account-specific data. */ |
| 78 |
custom_data TEXT |
| 79 |
); |
| 80 |
-- ! |
| 81 |
INSERT INTO Accounts (id, ordr, type, proxy_type, proxy_host, proxy_port, proxy_username, proxy_password, custom_data) |
| 82 |
SELECT id, id - 1, type, proxy_type, proxy_host, proxy_port, proxy_username, proxy_password, custom_data |
| 83 |
FROM backup_Accounts; |
| 84 |
-- ! |
| 85 |
DROP TABLE backup_Accounts; |