diff --git a/lib/Database.php b/lib/Database.php index 7c47ad39..cecfb33f 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -37,7 +37,7 @@ use JKingWeb\Arsse\Misc\ValueInfo; */ class Database { /** The version number of the latest schema the interface is aware of */ - const SCHEMA_VERSION = 4; + const SCHEMA_VERSION = 5; /** The size of a set of values beyond which the set will be embedded into the query text */ const LIMIT_SET_SIZE = 25; /** The length of a string in an embedded set beyond which a parameter placeholder will be used for the string */ diff --git a/sql/MySQL/0.sql b/sql/MySQL/0.sql index f6b00e26..3901ad74 100644 --- a/sql/MySQL/0.sql +++ b/sql/MySQL/0.sql @@ -5,7 +5,7 @@ -- Please consult the SQLite 3 schemata for commented version create table arsse_meta( - `key` varchar(255) primary key, + "key" varchar(255) primary key, value longtext ) character set utf8mb4; @@ -21,9 +21,9 @@ create table arsse_users( create table arsse_users_meta( owner varchar(255) not null references arsse_users(id) on delete cascade on update cascade, - `key` varchar(255) not null, + "key" varchar(255) not null, value varchar(255), - primary key(owner,`key`) + primary key(owner,"key") ) character set utf8mb4; create table arsse_folders( @@ -93,7 +93,7 @@ create table arsse_enclosures( create table arsse_marks( article bigint not null references arsse_articles(id) on delete cascade, subscription bigint not null references arsse_subscriptions(id) on delete cascade on update cascade, - `read` boolean not null default 0, + "read" boolean not null default 0, starred boolean not null default 0, modified datetime(0) not null default CURRENT_TIMESTAMP, primary key(article,subscription) @@ -110,4 +110,4 @@ create table arsse_categories( name varchar(255) ) character set utf8mb4; -insert into arsse_meta(`key`,value) values('schema_version','1'); +insert into arsse_meta("key",value) values('schema_version','1'); diff --git a/sql/MySQL/1.sql b/sql/MySQL/1.sql index eb4ce5f1..f7a85425 100644 --- a/sql/MySQL/1.sql +++ b/sql/MySQL/1.sql @@ -8,7 +8,7 @@ create table arsse_sessions ( id varchar(255) primary key, created datetime(0) not null default CURRENT_TIMESTAMP, expires datetime(0) not null, - `user` varchar(255) not null references arsse_users(id) on delete cascade on update cascade + "user" varchar(255) not null references arsse_users(id) on delete cascade on update cascade ) character set utf8mb4; create table arsse_labels ( @@ -30,4 +30,4 @@ create table arsse_label_members ( alter table arsse_marks add column note longtext; -update arsse_meta set value = '2' where `key` = 'schema_version'; +update arsse_meta set value = '2' where "key" = 'schema_version'; diff --git a/sql/MySQL/2.sql b/sql/MySQL/2.sql index d63cbb6a..feaf4c9a 100644 --- a/sql/MySQL/2.sql +++ b/sql/MySQL/2.sql @@ -20,4 +20,4 @@ alter table arsse_articles convert to character set utf8mb4 collate utf8mb4_unic alter table arsse_categories convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table arsse_labels convert to character set utf8mb4 collate utf8mb4_unicode_ci; -update arsse_meta set value = '3' where `key` = 'schema_version'; +update arsse_meta set value = '3' where "key" = 'schema_version'; diff --git a/sql/MySQL/3.sql b/sql/MySQL/3.sql index c02df032..32f87a64 100644 --- a/sql/MySQL/3.sql +++ b/sql/MySQL/3.sql @@ -7,4 +7,4 @@ alter table arsse_marks change column modified modified datetime(0); alter table arsse_marks add column touched boolean not null default 0; -update arsse_meta set value = '4' where `key` = 'schema_version'; +update arsse_meta set value = '4' where "key" = 'schema_version'; diff --git a/sql/MySQL/4.sql b/sql/MySQL/4.sql new file mode 100644 index 00000000..aa073a6e --- /dev/null +++ b/sql/MySQL/4.sql @@ -0,0 +1,23 @@ +-- SPDX-License-Identifier: MIT +-- Copyright 2017 J. King, Dustin Wilson et al. +-- See LICENSE and AUTHORS files for details + +-- Please consult the SQLite 3 schemata for commented version + +create table arsse_tags( + id serial primary key, + owner varchar(255) not null references arsse_users(id) on delete cascade on update cascade, + name varchar(255) not null, + modified datetime(0) not null default CURRENT_TIMESTAMP, + unique(owner,name) +) character set utf8mb4 collate utf8mb4_unicode_ci; + +create table arsse_tag_members( + tag bigint not null references arsse_tags(id) on delete cascade, + subscription bigint not null references arsse_subscriptions(id) on delete cascade, + assigned boolean not null default 1, + modified datetime(0) not null default CURRENT_TIMESTAMP, + primary key(tag,subscription) +) character set utf8mb4 collate utf8mb4_unicode_ci; + +update arsse_meta set value = '5' where "key" = 'schema_version'; diff --git a/sql/PostgreSQL/0.sql b/sql/PostgreSQL/0.sql index 3d940f5a..d11c2c43 100644 --- a/sql/PostgreSQL/0.sql +++ b/sql/PostgreSQL/0.sql @@ -110,4 +110,4 @@ create table arsse_categories( name text ); -insert into arsse_meta(key,value) values('schema_version','1'); +insert into arsse_meta("key",value) values('schema_version','1'); diff --git a/sql/PostgreSQL/1.sql b/sql/PostgreSQL/1.sql index 1549fd5f..d2a5480f 100644 --- a/sql/PostgreSQL/1.sql +++ b/sql/PostgreSQL/1.sql @@ -30,4 +30,4 @@ create table arsse_label_members ( alter table arsse_marks add column note text not null default ''; -update arsse_meta set value = '2' where key = 'schema_version'; +update arsse_meta set value = '2' where "key" = 'schema_version'; diff --git a/sql/PostgreSQL/2.sql b/sql/PostgreSQL/2.sql index 847edb70..33863fbd 100644 --- a/sql/PostgreSQL/2.sql +++ b/sql/PostgreSQL/2.sql @@ -13,4 +13,4 @@ alter table arsse_articles alter column author type text collate "und-x-icu"; alter table arsse_categories alter column name type text collate "und-x-icu"; alter table arsse_labels alter column name type text collate "und-x-icu"; -update arsse_meta set value = '3' where key = 'schema_version'; +update arsse_meta set value = '3' where "key" = 'schema_version'; diff --git a/sql/PostgreSQL/3.sql b/sql/PostgreSQL/3.sql index 2290ae5d..091cf46d 100644 --- a/sql/PostgreSQL/3.sql +++ b/sql/PostgreSQL/3.sql @@ -8,4 +8,4 @@ alter table arsse_marks alter column modified drop default; alter table arsse_marks alter column modified drop not null; alter table arsse_marks add column touched smallint not null default 0; -update arsse_meta set value = '4' where key = 'schema_version'; +update arsse_meta set value = '4' where "key" = 'schema_version'; diff --git a/sql/PostgreSQL/4.sql b/sql/PostgreSQL/4.sql new file mode 100644 index 00000000..e0cd8eb7 --- /dev/null +++ b/sql/PostgreSQL/4.sql @@ -0,0 +1,23 @@ +-- SPDX-License-Identifier: MIT +-- Copyright 2017 J. King, Dustin Wilson et al. +-- See LICENSE and AUTHORS files for details + +-- Please consult the SQLite 3 schemata for commented version + +create table arsse_tags( + id bigserial primary key, + owner text not null references arsse_users(id) on delete cascade on update cascade, + name text not null collate "und-x-icu", + modified timestamp(0) without time zone not null default CURRENT_TIMESTAMP, + unique(owner,name) +); + +create table arsse_tag_members( + tag bigint not null references arsse_tags(id) on delete cascade, + subscription bigint not null references arsse_subscriptions(id) on delete cascade, + assigned smallint not null default 1, + modified timestamp(0) without time zone not null default CURRENT_TIMESTAMP, + primary key(tag,subscription) +); + +update arsse_meta set value = '5' where "key" = 'schema_version'; diff --git a/sql/SQLite3/0.sql b/sql/SQLite3/0.sql index 7a9dea6a..97f54514 100644 --- a/sql/SQLite3/0.sql +++ b/sql/SQLite3/0.sql @@ -130,4 +130,4 @@ create table arsse_categories( -- set version marker pragma user_version = 1; -insert into arsse_meta(key,value) values('schema_version','1'); +insert into arsse_meta("key",value) values('schema_version','1'); diff --git a/sql/SQLite3/1.sql b/sql/SQLite3/1.sql index dc7862d9..38176450 100644 --- a/sql/SQLite3/1.sql +++ b/sql/SQLite3/1.sql @@ -20,7 +20,7 @@ create table arsse_labels( ); create table arsse_label_members( --- uabels assignments for articles +-- label assignments for articles label integer not null references arsse_labels(id) on delete cascade, -- label ID associated to an article; label IDs belong to a user article integer not null references arsse_articles(id) on delete cascade, -- article associated to a label subscription integer not null references arsse_subscriptions(id) on delete cascade, -- Subscription is included so that records are deleted when a subscription is removed @@ -48,4 +48,4 @@ alter table arsse_marks_new rename to arsse_marks; -- set version marker pragma user_version = 2; -update arsse_meta set value = '2' where key = 'schema_version'; +update arsse_meta set value = '2' where "key" = 'schema_version'; diff --git a/sql/SQLite3/2.sql b/sql/SQLite3/2.sql index b378467b..14a253d1 100644 --- a/sql/SQLite3/2.sql +++ b/sql/SQLite3/2.sql @@ -121,4 +121,4 @@ alter table arsse_labels_new rename to arsse_labels; -- set version marker pragma user_version = 3; -update arsse_meta set value = '3' where key = 'schema_version'; +update arsse_meta set value = '3' where "key" = 'schema_version'; diff --git a/sql/SQLite3/3.sql b/sql/SQLite3/3.sql index 0d583249..087bf32a 100644 --- a/sql/SQLite3/3.sql +++ b/sql/SQLite3/3.sql @@ -24,4 +24,4 @@ reindex nocase; -- set version marker pragma user_version = 4; -update arsse_meta set value = '4' where key = 'schema_version'; +update arsse_meta set value = '4' where "key" = 'schema_version'; diff --git a/sql/SQLite3/4.sql b/sql/SQLite3/4.sql new file mode 100644 index 00000000..aa7cfbd8 --- /dev/null +++ b/sql/SQLite3/4.sql @@ -0,0 +1,25 @@ +-- SPDX-License-Identifier: MIT +-- Copyright 2017 J. King, Dustin Wilson et al. +-- See LICENSE and AUTHORS files for details + +create table arsse_tags( +-- user-defined subscription tags + id integer primary key, -- numeric ID + owner text not null references arsse_users(id) on delete cascade on update cascade, -- owning user + name text not null collate nocase, -- tag text + modified text not null default CURRENT_TIMESTAMP, -- time at which the tag was last modified + unique(owner,name) +); + +create table arsse_tag_members( +-- tag assignments for subscriptions + tag integer not null references arsse_tags(id) on delete cascade, -- tag ID associated to a subscription + subscription integer not null references arsse_subscriptions(id) on delete cascade, -- Subscription associated to a tag + assigned boolean not null default 1, -- whether the association is current, to support soft deletion + modified text not null default CURRENT_TIMESTAMP, -- time at which the association was last made or unmade + primary key(tag,subscription) -- only one association of a given tag to a given subscription +) without rowid; + +-- set version marker +pragma user_version = 5; +update arsse_meta set value = '5' where "key" = 'schema_version';