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

Add numeric IDs and other Miniflux data to SQLite schema

This commit is contained in:
J. King 2020-10-30 15:25:22 -04:00
parent 3ac010d5b6
commit 4db1b95cf4
14 changed files with 84 additions and 31 deletions

View file

@ -35,7 +35,7 @@ use JKingWeb\Arsse\Misc\URL;
* deletes a user from the database, and labelArticlesSet() changes a label's * deletes a user from the database, and labelArticlesSet() changes a label's
* associations with articles. There has been an effort to keep public method * associations with articles. There has been an effort to keep public method
* names consistent throughout, but protected methods, having different * names consistent throughout, but protected methods, having different
* concerns, will typicsally follow different conventions. * concerns, will typically follow different conventions.
*/ */
class Database { class Database {
/** The version number of the latest schema the interface is aware of */ /** The version number of the latest schema the interface is aware of */
@ -256,7 +256,7 @@ class Database {
throw new User\Exception("alreadyExists", ["action" => __FUNCTION__, "user" => $user]); throw new User\Exception("alreadyExists", ["action" => __FUNCTION__, "user" => $user]);
} }
$hash = (strlen($password) > 0) ? password_hash($password, \PASSWORD_DEFAULT) : ""; $hash = (strlen($password) > 0) ? password_hash($password, \PASSWORD_DEFAULT) : "";
$this->db->prepare("INSERT INTO arsse_users(id,password) values(?,?)", "str", "str")->runArray([$user,$hash]); $this->db->prepare("INSERT INTO arsse_users(id,password,num) values(?, ?, coalesce((select max(num) from arsse_users), 0) + 1)", "str", "str")->runArray([$user,$hash]);
return true; return true;
} }

View file

@ -2,6 +2,30 @@
-- Copyright 2017 J. King, Dustin Wilson et al. -- Copyright 2017 J. King, Dustin Wilson et al.
-- See LICENSE and AUTHORS files for details -- See LICENSE and AUTHORS files for details
-- Add multiple columns to the users table
-- In particular this adds a numeric identifier for each user, which Miniflux requires
create table arsse_users_new(
-- users
id text primary key not null collate nocase, -- user id
password text, -- password, salted and hashed; if using external authentication this would be blank
num integer unique not null, -- numeric identfier used by Miniflux
admin boolean not null default 0, -- Whether the user is an administrator
lang text, -- The user's chosen language code e.g. 'en', 'fr-ca'; null uses the system default
tz text not null default 'Etc/UTC', -- The user's chosen time zone, in zoneinfo format
sort_asc boolean not null default 0 -- Whether the user prefers to sort articles in ascending order
) without rowid;
create temp table arsse_users_existing(
id text not null,
num integer primary key
);
insert into arsse_users_existing(id) select id from arsse_users;
insert into arsse_users_new(id, password, num)
select id, password, num
from arsse_users
join arsse_users_existing using(id);
drop table arsse_users;
drop table arsse_users_existing;
alter table arsse_users_new rename to arsse_users;
-- set version marker -- set version marker
pragma user_version = 7; pragma user_version = 7;

View file

@ -19,12 +19,13 @@ trait SeriesArticle {
'columns' => [ 'columns' => [
'id' => 'str', 'id' => 'str',
'password' => 'str', 'password' => 'str',
'num' => 'int',
], ],
'rows' => [ 'rows' => [
["jane.doe@example.com", ""], ["jane.doe@example.com", "",1],
["john.doe@example.com", ""], ["john.doe@example.com", "",2],
["john.doe@example.org", ""], ["john.doe@example.org", "",3],
["john.doe@example.net", ""], ["john.doe@example.net", "",4],
], ],
], ],
'arsse_feeds' => [ 'arsse_feeds' => [

View file

@ -30,10 +30,11 @@ trait SeriesCleanup {
'columns' => [ 'columns' => [
'id' => 'str', 'id' => 'str',
'password' => 'str', 'password' => 'str',
'num' => 'int',
], ],
'rows' => [ 'rows' => [
["jane.doe@example.com", ""], ["jane.doe@example.com", "",1],
["john.doe@example.com", ""], ["john.doe@example.com", "",2],
], ],
], ],
'arsse_sessions' => [ 'arsse_sessions' => [

View file

@ -19,10 +19,11 @@ trait SeriesFeed {
'columns' => [ 'columns' => [
'id' => 'str', 'id' => 'str',
'password' => 'str', 'password' => 'str',
'num' => 'int',
], ],
'rows' => [ 'rows' => [
["jane.doe@example.com", ""], ["jane.doe@example.com", "",1],
["john.doe@example.com", ""], ["john.doe@example.com", "",2],
], ],
], ],
'arsse_feeds' => [ 'arsse_feeds' => [

View file

@ -15,10 +15,11 @@ trait SeriesFolder {
'columns' => [ 'columns' => [
'id' => 'str', 'id' => 'str',
'password' => 'str', 'password' => 'str',
'num' => 'int',
], ],
'rows' => [ 'rows' => [
["jane.doe@example.com", ""], ["jane.doe@example.com", "",1],
["john.doe@example.com", ""], ["john.doe@example.com", "",2],
], ],
], ],
'arsse_folders' => [ 'arsse_folders' => [

View file

@ -17,12 +17,13 @@ trait SeriesLabel {
'columns' => [ 'columns' => [
'id' => 'str', 'id' => 'str',
'password' => 'str', 'password' => 'str',
'num' => 'int',
], ],
'rows' => [ 'rows' => [
["jane.doe@example.com", ""], ["jane.doe@example.com", "",1],
["john.doe@example.com", ""], ["john.doe@example.com", "",2],
["john.doe@example.org", ""], ["john.doe@example.org", "",3],
["john.doe@example.net", ""], ["john.doe@example.net", "",4],
], ],
], ],
'arsse_folders' => [ 'arsse_folders' => [

View file

@ -26,10 +26,11 @@ trait SeriesSession {
'columns' => [ 'columns' => [
'id' => 'str', 'id' => 'str',
'password' => 'str', 'password' => 'str',
'num' => 'int',
], ],
'rows' => [ 'rows' => [
["jane.doe@example.com", ""], ["jane.doe@example.com", "",1],
["john.doe@example.com", ""], ["john.doe@example.com", "",2],
], ],
], ],
'arsse_sessions' => [ 'arsse_sessions' => [

View file

@ -18,10 +18,11 @@ trait SeriesSubscription {
'columns' => [ 'columns' => [
'id' => 'str', 'id' => 'str',
'password' => 'str', 'password' => 'str',
'num' => 'int',
], ],
'rows' => [ 'rows' => [
["jane.doe@example.com", ""], ["jane.doe@example.com", "",1],
["john.doe@example.com", ""], ["john.doe@example.com", "",2],
], ],
], ],
'arsse_folders' => [ 'arsse_folders' => [

View file

@ -16,12 +16,13 @@ trait SeriesTag {
'columns' => [ 'columns' => [
'id' => 'str', 'id' => 'str',
'password' => 'str', 'password' => 'str',
'num' => 'int',
], ],
'rows' => [ 'rows' => [
["jane.doe@example.com", ""], ["jane.doe@example.com", "",1],
["john.doe@example.com", ""], ["john.doe@example.com", "",2],
["john.doe@example.org", ""], ["john.doe@example.org", "",3],
["john.doe@example.net", ""], ["john.doe@example.net", "",4],
], ],
], ],
'arsse_feeds' => [ 'arsse_feeds' => [

View file

@ -20,10 +20,11 @@ trait SeriesToken {
'columns' => [ 'columns' => [
'id' => 'str', 'id' => 'str',
'password' => 'str', 'password' => 'str',
'num' => 'int',
], ],
'rows' => [ 'rows' => [
["jane.doe@example.com", ""], ["jane.doe@example.com", "",1],
["john.doe@example.com", ""], ["john.doe@example.com", "",2],
], ],
], ],
'arsse_tokens' => [ 'arsse_tokens' => [

View file

@ -15,11 +15,12 @@ trait SeriesUser {
'columns' => [ 'columns' => [
'id' => 'str', 'id' => 'str',
'password' => 'str', 'password' => 'str',
'num' => 'int',
], ],
'rows' => [ 'rows' => [
["admin@example.net", '$2y$10$PbcG2ZR3Z8TuPzM7aHTF8.v61dtCjzjK78gdZJcp4UePE8T9jEgBW'], // password is hash of "secret" ["admin@example.net", '$2y$10$PbcG2ZR3Z8TuPzM7aHTF8.v61dtCjzjK78gdZJcp4UePE8T9jEgBW',1], // password is hash of "secret"
["jane.doe@example.com", ""], ["jane.doe@example.com", "",2],
["john.doe@example.com", ""], ["john.doe@example.com", "",3],
], ],
], ],
]; ];

View file

@ -134,4 +134,22 @@ class BaseUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
$this->drv->schemaUpdate(Database::SCHEMA_VERSION); $this->drv->schemaUpdate(Database::SCHEMA_VERSION);
$this->assertTrue($this->drv->maintenance()); $this->assertTrue($this->drv->maintenance());
} }
public function testUpdateTo7(): void {
$this->drv->schemaUpdate(6);
$this->drv->exec(<<<QUERY_TEXT
INSERT INTO arsse_users values('a', 'xyz');
INSERT INTO arsse_users values('b', 'abc');
INSERT INTO arsse_folders(owner,name) values('a', '1');
INSERT INTO arsse_folders(owner,name) values('b', '2');
QUERY_TEXT
);
$this->drv->schemaUpdate(7);
$exp = [
['id' => "a", 'password' => "xyz", 'num' => 1],
['id' => "b", 'password' => "abc", 'num' => 2],
];
$this->assertEquals($exp, $this->drv->query("SELECT id, password, num from arsse_users")->getAll());
$this->assertSame(2, (int) $this->drv->query("SELECT count(*) from arsse_folders")->getValue());
}
} }

View file

@ -46,10 +46,11 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest {
'columns' => [ 'columns' => [
'id' => 'str', 'id' => 'str',
'password' => 'str', 'password' => 'str',
'num' => 'int',
], ],
'rows' => [ 'rows' => [
["john.doe@example.com", ""], ["john.doe@example.com", "", 1],
["jane.doe@example.com", ""], ["jane.doe@example.com", "", 2],
], ],
], ],
'arsse_folders' => [ 'arsse_folders' => [