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

New schema for PostgreSQL and MySQL

This commit is contained in:
J. King 2020-10-30 19:00:11 -04:00
parent 4db1b95cf4
commit 16d2e01668
3 changed files with 33 additions and 2 deletions

View file

@ -256,7 +256,8 @@ 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,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; return true;
} }

View file

@ -2,5 +2,20 @@
-- 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
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'; update arsse_meta set value = '7' where "key" = 'schema_version';

View file

@ -2,6 +2,21 @@
-- 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
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'; update arsse_meta set value = '7' where "key" = 'schema_version';