1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Use SQLite nocase collation; improves #127

This commit is contained in:
J. King 2017-12-07 18:05:34 -05:00
parent c8f012c5fc
commit 0b3b3cb49c
5 changed files with 124 additions and 5 deletions

View file

@ -6,8 +6,12 @@ Bug fixes:
- Accept base64-encoded passwords from TTRSS clients - Accept base64-encoded passwords from TTRSS clients
- Rename feeds correctly via TTRSS protocol - Rename feeds correctly via TTRSS protocol
- Toggle marks correctly via TTRSS protocol - Toggle marks correctly via TTRSS protocol
- Sort everything case-insensitively
- Be even stricter about output data types in NextCloud News - Be even stricter about output data types in NextCloud News
Changes:
- Do not omit read feeds from TTRSS' getCounters, to fix some clients
Version 0.2.0 (2017-11-30) Version 0.2.0 (2017-11-30)
========================== ==========================

View file

@ -14,7 +14,7 @@ use JKingWeb\Arsse\Misc\Date;
use JKingWeb\Arsse\Misc\ValueInfo; use JKingWeb\Arsse\Misc\ValueInfo;
class Database { class Database {
const SCHEMA_VERSION = 2; const SCHEMA_VERSION = 3;
const LIMIT_ARTICLES = 50; const LIMIT_ARTICLES = 50;
// articleList verbosity levels // articleList verbosity levels
const LIST_MINIMAL = 0; // only that metadata which is required for context matching const LIST_MINIMAL = 0; // only that metadata which is required for context matching

View file

@ -90,6 +90,8 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
} }
$sep = \DIRECTORY_SEPARATOR; $sep = \DIRECTORY_SEPARATOR;
$path = ($basePath ?? \JKingWeb\Arsse\BASE."sql").$sep."SQLite3".$sep; $path = ($basePath ?? \JKingWeb\Arsse\BASE."sql").$sep."SQLite3".$sep;
// turn off foreign keys
$this->exec("PRAGMA foreign_keys = no");
// lock the database // lock the database
$this->savepointCreate(true); $this->savepointCreate(true);
for ($a = $this->schemaVersion(); $a < $to; $a++) { for ($a = $this->schemaVersion(); $a < $to; $a++) {
@ -124,6 +126,8 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
$this->savepointRelease(); $this->savepointRelease();
} }
$this->savepointRelease(); $this->savepointRelease();
// turn foreign keys back on
$this->exec("PRAGMA foreign_keys = yes");
return true; return true;
} }

111
sql/SQLite3/2.sql Normal file
View file

@ -0,0 +1,111 @@
-- SPDX-License-Identifier: MIT
-- Copyright 2017 J. King, Dustin Wilson et al.
-- See LICENSE and AUTHORS files for details
-- Correct collation sequences
alter table arsse_users rename to arsse_users_old;
create table arsse_users(
id text primary key not null collate nocase,
password text,
name text collate nocase,
avatar_type text,
avatar_data blob,
admin boolean default 0,
rights integer not null default 0
);
insert into arsse_users(id,password,name,avatar_type,avatar_data,admin,rights) select id,password,name,avatar_type,avatar_data,admin,rights from arsse_users_old;
drop table arsse_users_old;
alter table arsse_folders rename to arsse_folders_old;
create table arsse_folders(
id integer primary key,
owner text not null references arsse_users(id) on delete cascade on update cascade,
parent integer references arsse_folders(id) on delete cascade,
name text not null collate nocase,
modified text not null default CURRENT_TIMESTAMP, --
unique(owner,name,parent)
);
insert into arsse_folders select * from arsse_folders_old;
drop table arsse_folders_old;
alter table arsse_feeds rename to arsse_feeds_old;
create table arsse_feeds(
id integer primary key,
url text not null,
title text collate nocase,
favicon text,
source text,
updated text,
modified text,
next_fetch text,
orphaned text,
etag text not null default '',
err_count integer not null default 0,
err_msg text,
username text not null default '',
password text not null default '',
size integer not null default 0,
scrape boolean not null default 0,
unique(url,username,password)
);
insert into arsse_feeds select * from arsse_feeds_old;
drop table arsse_feeds_old;
alter table arsse_subscriptions rename to arsse_subscriptions_old;
create table arsse_subscriptions(
id integer primary key,
owner text not null references arsse_users(id) on delete cascade on update cascade,
feed integer not null references arsse_feeds(id) on delete cascade,
added text not null default CURRENT_TIMESTAMP,
modified text not null default CURRENT_TIMESTAMP,
title text collate nocase,
order_type int not null default 0,
pinned boolean not null default 0,
folder integer references arsse_folders(id) on delete cascade,
unique(owner,feed)
);
insert into arsse_subscriptions select * from arsse_subscriptions_old;
drop table arsse_subscriptions_old;
alter table arsse_articles rename to arsse_articles_old;
create table arsse_articles(
id integer primary key,
feed integer not null references arsse_feeds(id) on delete cascade,
url text,
title text collate nocase,
author text collate nocase,
published text,
edited text,
modified text not null default CURRENT_TIMESTAMP,
content text,
guid text,
url_title_hash text not null,
url_content_hash text not null,
title_content_hash text not null
);
insert into arsse_articles select * from arsse_articles_old;
drop table arsse_articles_old;
alter table arsse_categories rename to arsse_categories_old;
create table arsse_categories(
article integer not null references arsse_articles(id) on delete cascade,
name text collate nocase
);
insert into arsse_categories select * from arsse_categories_old;
drop table arsse_categories_old;
alter table arsse_labels rename to arsse_labels_old;
create table arsse_labels (
id integer primary key,
owner text not null references arsse_users(id) on delete cascade on update cascade,
name text not null collate nocase,
modified text not null default CURRENT_TIMESTAMP,
unique(owner,name)
);
insert into arsse_labels select * from arsse_labels_old;
drop table arsse_labels_old;
-- set version marker
pragma user_version = 3;
update arsse_meta set value = '3' where key is 'schema_version';

View file

@ -110,7 +110,7 @@ trait SeriesSubscription {
public function setUpSeries() { public function setUpSeries() {
$this->data['arsse_feeds']['rows'] = [ $this->data['arsse_feeds']['rows'] = [
[1,"http://example.com/feed1", "Ook", "", "",strtotime("now"),''], [1,"http://example.com/feed1", "Ook", "", "",strtotime("now"),''],
[2,"http://example.com/feed2", "Eek", "", "",strtotime("now - 1 hour"),'http://example.com/favicon.ico'], [2,"http://example.com/feed2", "eek", "", "",strtotime("now - 1 hour"),'http://example.com/favicon.ico'],
[3,"http://example.com/feed3", "Ack", "", "",strtotime("now + 1 hour"),''], [3,"http://example.com/feed3", "Ack", "", "",strtotime("now + 1 hour"),''],
]; ];
// initialize a partial mock of the Database object to later manipulate the feedUpdate method // initialize a partial mock of the Database object to later manipulate the feedUpdate method
@ -237,7 +237,7 @@ trait SeriesSubscription {
$exp = [ $exp = [
[ [
'url' => "http://example.com/feed2", 'url' => "http://example.com/feed2",
'title' => "Eek", 'title' => "eek",
'folder' => null, 'folder' => null,
'top_folder' => null, 'top_folder' => null,
'unread' => 4, 'unread' => 4,
@ -254,7 +254,7 @@ trait SeriesSubscription {
'order_type' => 1, 'order_type' => 1,
], ],
]; ];
$this->assertResult($exp, Arsse::$db->subscriptionList($this->user)); $this->assertSame($exp, Arsse::$db->subscriptionList($this->user)->getAll());
Phake::verify(Arsse::$user)->authorize($this->user, "subscriptionList"); Phake::verify(Arsse::$user)->authorize($this->user, "subscriptionList");
$this->assertArraySubset($exp[0], Arsse::$db->subscriptionPropertiesGet($this->user, 1)); $this->assertArraySubset($exp[0], Arsse::$db->subscriptionPropertiesGet($this->user, 1));
Phake::verify(Arsse::$user)->authorize($this->user, "subscriptionPropertiesGet"); Phake::verify(Arsse::$user)->authorize($this->user, "subscriptionPropertiesGet");
@ -265,7 +265,7 @@ trait SeriesSubscription {
$exp = [ $exp = [
[ [
'url' => "http://example.com/feed2", 'url' => "http://example.com/feed2",
'title' => "Eek", 'title' => "eek",
'folder' => null, 'folder' => null,
'top_folder' => null, 'top_folder' => null,
'unread' => 4, 'unread' => 4,