-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from sebadob/users-language-column
add language column to users table
- Loading branch information
Showing
5 changed files
with
207 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
alter table users | ||
add language varchar default 'en' not null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
alter table users | ||
rename to users_old; | ||
|
||
drop index users_email_uindex; | ||
|
||
create table users | ||
( | ||
id varchar not null | ||
constraint users_pk | ||
primary key, | ||
email varchar not null | ||
constraint users_email | ||
unique, | ||
given_name varchar not null, | ||
family_name varchar not null, | ||
password varchar, | ||
roles varchar not null, | ||
groups varchar, | ||
enabled boolean not null, | ||
email_verified boolean not null, | ||
password_expires int, | ||
created_at int not null, | ||
last_login int, | ||
last_failed_login int, | ||
failed_login_attempts int, | ||
mfa_app varchar, | ||
sec_key_1 varchar | ||
references webauthn, | ||
sec_key_2 varchar | ||
references webauthn, | ||
language varchar default 'en' not null | ||
); | ||
|
||
create unique index users_email_uindex | ||
on users (email); | ||
|
||
insert into users(id, email, given_name, family_name, password, roles, groups, enabled, email_verified, | ||
password_expires, created_at, last_login, last_failed_login, failed_login_attempts, mfa_app, | ||
sec_key_1, sec_key_2) | ||
select id, | ||
email, | ||
given_name, | ||
family_name, | ||
password, | ||
roles, | ||
groups, | ||
enabled, | ||
email_verified, | ||
password_expires, | ||
created_at, | ||
last_login, | ||
last_failed_login, | ||
failed_login_attempts, | ||
mfa_app, | ||
sec_key_1, | ||
sec_key_2 | ||
from users_old; | ||
|
||
-- recreate all tables with foreign keys to users | ||
|
||
alter table magic_links | ||
rename to magic_links_old; | ||
|
||
drop index magic_links_exp_index; | ||
drop index magic_links_user_id_index; | ||
|
||
create table magic_links | ||
( | ||
id varchar not null | ||
constraint magic_links_pk | ||
primary key, | ||
user_id varchar not null | ||
references users | ||
on delete cascade | ||
on update cascade, | ||
csrf_token varchar not null, | ||
cookie varchar, | ||
exp integer not null, | ||
used bool not null | ||
); | ||
|
||
create index magic_links_exp_index | ||
on magic_links (exp); | ||
|
||
create index magic_links_user_id_index | ||
on magic_links (user_id); | ||
|
||
insert into magic_links(id, user_id, csrf_token, cookie, exp, used) | ||
select id, user_id, csrf_token, cookie, exp, used | ||
from magic_links_old; | ||
|
||
drop table magic_links_old; | ||
|
||
-- | ||
|
||
alter table recent_passwords | ||
rename to recent_passwords_old; | ||
|
||
create table recent_passwords | ||
( | ||
user_id varchar not null | ||
references users | ||
on delete cascade | ||
on update cascade | ||
constraint recent_passwords_pk | ||
primary key, | ||
passwords varchar not null | ||
); | ||
|
||
insert into recent_passwords(user_id, passwords) | ||
select user_id, passwords | ||
from recent_passwords_old; | ||
|
||
drop table recent_passwords_old; | ||
|
||
-- | ||
|
||
alter table refresh_tokens | ||
rename to refresh_tokens_old; | ||
|
||
drop index refresh_tokens_exp_index; | ||
drop index refresh_tokens_user_id_index; | ||
|
||
create table refresh_tokens | ||
( | ||
id varchar not null | ||
constraint refresh_tokens_pk | ||
primary key, | ||
user_id varchar not null | ||
references users | ||
on delete cascade | ||
on update cascade, | ||
nbf integer not null, | ||
exp integer not null, | ||
scope varchar, | ||
is_mfa bool default false not null | ||
); | ||
|
||
create index refresh_tokens_exp_index | ||
on refresh_tokens (exp); | ||
|
||
create index refresh_tokens_user_id_index | ||
on refresh_tokens (user_id); | ||
|
||
insert into refresh_tokens(id, user_id, nbf, exp, scope, is_mfa) | ||
select id, user_id, nbf, exp, scope, is_mfa | ||
from refresh_tokens_old; | ||
|
||
drop table refresh_tokens_old; | ||
|
||
-- | ||
|
||
alter table sessions | ||
rename to sessions_old; | ||
|
||
drop index sessions_exp_index; | ||
|
||
create table sessions | ||
( | ||
id varchar not null | ||
constraint sessions_pk | ||
primary key, | ||
csrf_token varchar not null, | ||
user_id varchar | ||
references users | ||
on delete cascade | ||
on update cascade, | ||
roles varchar, | ||
groups varchar, | ||
is_mfa bool not null, | ||
state varchar not null, | ||
exp int not null, | ||
last_seen int not null | ||
); | ||
|
||
create index sessions_exp_index | ||
on sessions (exp); | ||
|
||
insert into sessions(id, csrf_token, user_id, roles, groups, is_mfa, state, exp, last_seen) | ||
select id, csrf_token, user_id, roles, groups, is_mfa, state, exp, last_seen | ||
from sessions_old; | ||
|
||
drop table sessions_old; | ||
|
||
-- finally drop the old users table | ||
|
||
drop table users_old; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters