mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Add numeric IDs and other Miniflux data to SQLite schema
This commit is contained in:
parent
3ac010d5b6
commit
4db1b95cf4
14 changed files with 84 additions and 31 deletions
|
@ -35,7 +35,7 @@ use JKingWeb\Arsse\Misc\URL;
|
|||
* deletes a user from the database, and labelArticlesSet() changes a label's
|
||||
* associations with articles. There has been an effort to keep public method
|
||||
* names consistent throughout, but protected methods, having different
|
||||
* concerns, will typicsally follow different conventions.
|
||||
* concerns, will typically follow different conventions.
|
||||
*/
|
||||
class Database {
|
||||
/** 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]);
|
||||
}
|
||||
$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;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,30 @@
|
|||
-- Copyright 2017 J. King, Dustin Wilson et al.
|
||||
-- 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
|
||||
pragma user_version = 7;
|
||||
|
|
|
@ -19,12 +19,13 @@ trait SeriesArticle {
|
|||
'columns' => [
|
||||
'id' => 'str',
|
||||
'password' => 'str',
|
||||
'num' => 'int',
|
||||
],
|
||||
'rows' => [
|
||||
["jane.doe@example.com", ""],
|
||||
["john.doe@example.com", ""],
|
||||
["john.doe@example.org", ""],
|
||||
["john.doe@example.net", ""],
|
||||
["jane.doe@example.com", "",1],
|
||||
["john.doe@example.com", "",2],
|
||||
["john.doe@example.org", "",3],
|
||||
["john.doe@example.net", "",4],
|
||||
],
|
||||
],
|
||||
'arsse_feeds' => [
|
||||
|
|
|
@ -30,10 +30,11 @@ trait SeriesCleanup {
|
|||
'columns' => [
|
||||
'id' => 'str',
|
||||
'password' => 'str',
|
||||
'num' => 'int',
|
||||
],
|
||||
'rows' => [
|
||||
["jane.doe@example.com", ""],
|
||||
["john.doe@example.com", ""],
|
||||
["jane.doe@example.com", "",1],
|
||||
["john.doe@example.com", "",2],
|
||||
],
|
||||
],
|
||||
'arsse_sessions' => [
|
||||
|
|
|
@ -19,10 +19,11 @@ trait SeriesFeed {
|
|||
'columns' => [
|
||||
'id' => 'str',
|
||||
'password' => 'str',
|
||||
'num' => 'int',
|
||||
],
|
||||
'rows' => [
|
||||
["jane.doe@example.com", ""],
|
||||
["john.doe@example.com", ""],
|
||||
["jane.doe@example.com", "",1],
|
||||
["john.doe@example.com", "",2],
|
||||
],
|
||||
],
|
||||
'arsse_feeds' => [
|
||||
|
|
|
@ -15,10 +15,11 @@ trait SeriesFolder {
|
|||
'columns' => [
|
||||
'id' => 'str',
|
||||
'password' => 'str',
|
||||
'num' => 'int',
|
||||
],
|
||||
'rows' => [
|
||||
["jane.doe@example.com", ""],
|
||||
["john.doe@example.com", ""],
|
||||
["jane.doe@example.com", "",1],
|
||||
["john.doe@example.com", "",2],
|
||||
],
|
||||
],
|
||||
'arsse_folders' => [
|
||||
|
|
|
@ -17,12 +17,13 @@ trait SeriesLabel {
|
|||
'columns' => [
|
||||
'id' => 'str',
|
||||
'password' => 'str',
|
||||
'num' => 'int',
|
||||
],
|
||||
'rows' => [
|
||||
["jane.doe@example.com", ""],
|
||||
["john.doe@example.com", ""],
|
||||
["john.doe@example.org", ""],
|
||||
["john.doe@example.net", ""],
|
||||
["jane.doe@example.com", "",1],
|
||||
["john.doe@example.com", "",2],
|
||||
["john.doe@example.org", "",3],
|
||||
["john.doe@example.net", "",4],
|
||||
],
|
||||
],
|
||||
'arsse_folders' => [
|
||||
|
|
|
@ -26,10 +26,11 @@ trait SeriesSession {
|
|||
'columns' => [
|
||||
'id' => 'str',
|
||||
'password' => 'str',
|
||||
'num' => 'int',
|
||||
],
|
||||
'rows' => [
|
||||
["jane.doe@example.com", ""],
|
||||
["john.doe@example.com", ""],
|
||||
["jane.doe@example.com", "",1],
|
||||
["john.doe@example.com", "",2],
|
||||
],
|
||||
],
|
||||
'arsse_sessions' => [
|
||||
|
|
|
@ -18,10 +18,11 @@ trait SeriesSubscription {
|
|||
'columns' => [
|
||||
'id' => 'str',
|
||||
'password' => 'str',
|
||||
'num' => 'int',
|
||||
],
|
||||
'rows' => [
|
||||
["jane.doe@example.com", ""],
|
||||
["john.doe@example.com", ""],
|
||||
["jane.doe@example.com", "",1],
|
||||
["john.doe@example.com", "",2],
|
||||
],
|
||||
],
|
||||
'arsse_folders' => [
|
||||
|
|
|
@ -16,12 +16,13 @@ trait SeriesTag {
|
|||
'columns' => [
|
||||
'id' => 'str',
|
||||
'password' => 'str',
|
||||
'num' => 'int',
|
||||
],
|
||||
'rows' => [
|
||||
["jane.doe@example.com", ""],
|
||||
["john.doe@example.com", ""],
|
||||
["john.doe@example.org", ""],
|
||||
["john.doe@example.net", ""],
|
||||
["jane.doe@example.com", "",1],
|
||||
["john.doe@example.com", "",2],
|
||||
["john.doe@example.org", "",3],
|
||||
["john.doe@example.net", "",4],
|
||||
],
|
||||
],
|
||||
'arsse_feeds' => [
|
||||
|
|
|
@ -20,10 +20,11 @@ trait SeriesToken {
|
|||
'columns' => [
|
||||
'id' => 'str',
|
||||
'password' => 'str',
|
||||
'num' => 'int',
|
||||
],
|
||||
'rows' => [
|
||||
["jane.doe@example.com", ""],
|
||||
["john.doe@example.com", ""],
|
||||
["jane.doe@example.com", "",1],
|
||||
["john.doe@example.com", "",2],
|
||||
],
|
||||
],
|
||||
'arsse_tokens' => [
|
||||
|
|
|
@ -15,11 +15,12 @@ trait SeriesUser {
|
|||
'columns' => [
|
||||
'id' => 'str',
|
||||
'password' => 'str',
|
||||
'num' => 'int',
|
||||
],
|
||||
'rows' => [
|
||||
["admin@example.net", '$2y$10$PbcG2ZR3Z8TuPzM7aHTF8.v61dtCjzjK78gdZJcp4UePE8T9jEgBW'], // password is hash of "secret"
|
||||
["jane.doe@example.com", ""],
|
||||
["john.doe@example.com", ""],
|
||||
["admin@example.net", '$2y$10$PbcG2ZR3Z8TuPzM7aHTF8.v61dtCjzjK78gdZJcp4UePE8T9jEgBW',1], // password is hash of "secret"
|
||||
["jane.doe@example.com", "",2],
|
||||
["john.doe@example.com", "",3],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
|
@ -134,4 +134,22 @@ class BaseUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
$this->drv->schemaUpdate(Database::SCHEMA_VERSION);
|
||||
$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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,10 +46,11 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
'columns' => [
|
||||
'id' => 'str',
|
||||
'password' => 'str',
|
||||
'num' => 'int',
|
||||
],
|
||||
'rows' => [
|
||||
["john.doe@example.com", ""],
|
||||
["jane.doe@example.com", ""],
|
||||
["john.doe@example.com", "", 1],
|
||||
["jane.doe@example.com", "", 2],
|
||||
],
|
||||
],
|
||||
'arsse_folders' => [
|
||||
|
|
Loading…
Reference in a new issue