-
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move user roles to separate database table
- Loading branch information
Showing
52 changed files
with
352 additions
and
339 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
komga/src/flyway/resources/db/migration/sqlite/V20250108115503__user_roles.sql
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,68 @@ | ||
CREATE TABLE USER_ROLE | ||
( | ||
USER_ID varchar NOT NULL, | ||
ROLE varchar NOT NULL, | ||
PRIMARY KEY (USER_ID, ROLE), | ||
FOREIGN KEY (USER_ID) REFERENCES USER (ID) | ||
); | ||
|
||
insert into USER_ROLE | ||
select id, "ADMIN" | ||
from user | ||
where ROLE_ADMIN = 1; | ||
|
||
insert into USER_ROLE | ||
select id, "KOREADER_SYNC" | ||
from user | ||
where ROLE_ADMIN = 1; | ||
|
||
insert into USER_ROLE | ||
select id, "FILE_DOWNLOAD" | ||
from user | ||
where ROLE_FILE_DOWNLOAD = 1; | ||
|
||
insert into USER_ROLE | ||
select id, "PAGE_STREAMING" | ||
from user | ||
where ROLE_PAGE_STREAMING = 1; | ||
|
||
insert into USER_ROLE | ||
select id, "KOBO_SYNC" | ||
from user | ||
where ROLE_KOBO_SYNC = 1; | ||
|
||
-- Remove columns ROLE_ADMIN, ROLE_FILE_DOWNLOAD, ROLE_PAGE_STREAMING, ROLE_KOBO_SYNC from USER | ||
PRAGMA foreign_keys= OFF; | ||
|
||
create table USER_dg_tmp | ||
( | ||
ID varchar not null | ||
primary key, | ||
CREATED_DATE datetime default CURRENT_TIMESTAMP not null, | ||
LAST_MODIFIED_DATE datetime default CURRENT_TIMESTAMP not null, | ||
EMAIL varchar not null | ||
unique, | ||
PASSWORD varchar not null, | ||
SHARED_ALL_LIBRARIES boolean default 1 not null, | ||
AGE_RESTRICTION integer, | ||
AGE_RESTRICTION_ALLOW_ONLY boolean | ||
); | ||
|
||
insert into USER_dg_tmp(ID, CREATED_DATE, LAST_MODIFIED_DATE, EMAIL, PASSWORD, SHARED_ALL_LIBRARIES, AGE_RESTRICTION, | ||
AGE_RESTRICTION_ALLOW_ONLY) | ||
select ID, | ||
CREATED_DATE, | ||
LAST_MODIFIED_DATE, | ||
EMAIL, | ||
PASSWORD, | ||
SHARED_ALL_LIBRARIES, | ||
AGE_RESTRICTION, | ||
AGE_RESTRICTION_ALLOW_ONLY | ||
from USER; | ||
|
||
drop table USER; | ||
|
||
alter table USER_dg_tmp | ||
rename to USER; | ||
|
||
PRAGMA foreign_keys= ON; |
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
26 changes: 26 additions & 0 deletions
26
komga/src/main/kotlin/org/gotson/komga/domain/model/UserRoles.kt
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,26 @@ | ||
package org.gotson.komga.domain.model | ||
|
||
enum class UserRoles { | ||
ADMIN, | ||
FILE_DOWNLOAD, | ||
PAGE_STREAMING, | ||
KOBO_SYNC, | ||
; | ||
|
||
companion object { | ||
/** | ||
* Returns a Set composed of the enum constant of this type with the specified name. | ||
* The string must match exactly an identifier used to declare an enum constant in this type. | ||
* (Extraneous whitespace characters are not permitted.) | ||
*/ | ||
fun valuesOf(roles: Iterable<String>): Set<UserRoles> = | ||
roles | ||
.mapNotNull { | ||
try { | ||
valueOf(it) | ||
} catch (_: Exception) { | ||
null | ||
} | ||
}.toSet() | ||
} | ||
} |
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
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
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
Oops, something went wrong.