diff --git a/lib/Database.php b/lib/Database.php index 6c038ab5..b7b44881 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -256,7 +256,8 @@ 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,num) values(?, ?, coalesce((select max(num) from arsse_users), 0) + 1)", "str", "str")->runArray([$user,$hash]); + // NOTE: This roundabout construction (with 'select' rather than 'values') is required by MySQL, because MySQL is riddled with pitfalls and exceptions + $this->db->prepare("INSERT INTO arsse_users(id,password,num) select ?, ?, ((select max(num) from arsse_users) + 1)", "str", "str")->runArray([$user,$hash]); return true; } diff --git a/sql/MySQL/6.sql b/sql/MySQL/6.sql index fff57671..e16375cc 100644 --- a/sql/MySQL/6.sql +++ b/sql/MySQL/6.sql @@ -2,5 +2,20 @@ -- Copyright 2017 J. King, Dustin Wilson et al. -- See LICENSE and AUTHORS files for details +alter table arsse_users add column num bigint unsigned unique; +alter table arsse_users add column admin boolean not null default 0; +alter table arsse_users add column lang longtext; +alter table arsse_users add column tz varchar(44) not null default 'Etc/UTC'; +alter table arsse_users add column soort_asc boolean not null default 0; +create temporary table arsse_users_existing( + id text not null, + num serial primary key +) character set utf8mb4 collate utf8mb4_unicode_ci; +insert into arsse_users_existing(id) select id from arsse_users; +update arsse_users as u, arsse_users_existing as n + set u.num = n.num +where u.id = n.id; +drop table arsse_users_existing; +alter table arsse_users modify num bigint unsigned not null; update arsse_meta set value = '7' where "key" = 'schema_version'; diff --git a/sql/PostgreSQL/6.sql b/sql/PostgreSQL/6.sql index 4d86e98c..6099e8d5 100644 --- a/sql/PostgreSQL/6.sql +++ b/sql/PostgreSQL/6.sql @@ -2,6 +2,21 @@ -- Copyright 2017 J. King, Dustin Wilson et al. -- See LICENSE and AUTHORS files for details - +alter table arsse_users add column num bigint unique; +alter table arsse_users add column admin smallint not null default 0; +alter table arsse_users add column lang text; +alter table arsse_users add column tz text not null default 'Etc/UTC'; +alter table arsse_users add column soort_asc smallint not null default 0; +create temp table arsse_users_existing( + id text not null, + num bigserial +); +insert into arsse_users_existing(id) select id from arsse_users; +update arsse_users as u + set num = e.num +from arsse_users_existing as e +where u.id = e.id; +drop table arsse_users_existing; +alter table arsse_users alter column num set not null; update arsse_meta set value = '7' where "key" = 'schema_version';