-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
1 deletion.
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,34 @@ | ||
CREATE TABLE IF NOT EXISTS `user` ( | ||
`id` UUID default random_uuid() PRIMARY KEY, | ||
`login` VARCHAR, | ||
`password` VARCHAR, | ||
`email` VARCHAR, | ||
`lang_key` VARCHAR, | ||
`version` bigint | ||
); | ||
CREATE UNIQUE INDEX IF NOT EXISTS `uniq_idx_user_login` | ||
ON `user` (`login`); | ||
CREATE UNIQUE INDEX IF NOT EXISTS `uniq_idx_user_email` | ||
ON `user` (`email`); | ||
|
||
CREATE TABLE IF NOT EXISTS `authority`( | ||
`role` VARCHAR(50) PRIMARY KEY); | ||
MERGE INTO `authority` | ||
VALUES ('ADMIN'), | ||
('USER'), | ||
('ANONYMOUS'); | ||
|
||
CREATE TABLE IF NOT EXISTS `user_authority`( | ||
`id` IDENTITY NOT NULL PRIMARY KEY, | ||
`user_id` UUID, | ||
`role` VARCHAR, | ||
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE, | ||
FOREIGN KEY (`role`) REFERENCES `authority` (`role`) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE | ||
); | ||
|
||
CREATE UNIQUE INDEX IF NOT EXISTS `uniq_idx_user_authority` | ||
ON `user_authority` (`role`, `user_id`); |
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,59 @@ | ||
INSERT INTO `user` (login, password, email, lang_key, version) | ||
VALUES ('user', 'user', '[email protected]', 'fr', '0'), | ||
('admin', 'admin', '[email protected]', 'en', '0'); | ||
|
||
insert into `user_authority` (user_id, role) | ||
select u.id, 'USER' | ||
from `user` as u | ||
where u.login = 'user'; | ||
|
||
insert into `user_authority` (user_id, role) | ||
select u.id, 'USER' | ||
from `user` as u | ||
where u.login = 'admin'; | ||
|
||
insert into `user_authority` (user_id, role) | ||
select u.id, 'ADMIN' | ||
from `user` as u | ||
where u.login = 'admin'; | ||
|
||
select count(*) from `USER`; | ||
|
||
SELECT | ||
u.id, | ||
u.email, | ||
u.login, | ||
u.password, | ||
u.lang_key, | ||
u.version, | ||
GROUP_CONCAT(DISTINCT a.role) AS user_roles | ||
FROM `user` as u | ||
LEFT JOIN | ||
user_authority ua ON u.id = ua.user_id | ||
LEFT JOIN | ||
`authority` as a ON ua.role = a.role | ||
WHERE | ||
lower(u.email) = lower('user') OR lower(u.login) = lower('user') | ||
GROUP BY | ||
u.id, u.email, u.login; | ||
|
||
|
||
SELECT | ||
u.id, | ||
u.email, | ||
u.login, | ||
u.password, | ||
u.lang_key, | ||
u.version, | ||
GROUP_CONCAT(DISTINCT a.role) AS user_roles | ||
FROM `user` as u | ||
LEFT JOIN | ||
user_authority ua ON u.id = ua.user_id | ||
LEFT JOIN | ||
`authority` as a ON ua.role = a.role | ||
WHERE | ||
lower(u.email) = lower('admin') OR lower(u.login) = lower('admin') | ||
GROUP BY | ||
u.id, u.email, u.login; | ||
|
||
|