mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-19 03:35:12 +00:00
* refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * migration versioning * refactor: use const for login name table name
323 lines
7.4 KiB
PL/PgSQL
323 lines
7.4 KiB
PL/PgSQL
-- --------------------------------------------------------
|
|
-- only default domain
|
|
-- --------------------------------------------------------
|
|
BEGIN;
|
|
|
|
INSERT INTO zitadel.projections.login_names_users (
|
|
id
|
|
, user_name
|
|
, resource_owner
|
|
) VALUES
|
|
('h', 'human', 'org')
|
|
, ('m', 'machine', 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_domains (
|
|
name
|
|
, is_primary
|
|
, resource_owner
|
|
) VALUES
|
|
('org-ch.localhost', true, 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_policies (
|
|
must_be_domain
|
|
, is_default
|
|
, resource_owner
|
|
) VALUES
|
|
(true, true, 'IAM')
|
|
;
|
|
|
|
SELECT * FROM zitadel.projections.login_names WHERE user_id IN ('h', 'm');
|
|
ROLLBACK;
|
|
|
|
-- --------------------------------------------------------
|
|
-- default and additional domain verified
|
|
-- --------------------------------------------------------
|
|
BEGIN;
|
|
|
|
INSERT INTO zitadel.projections.login_names_users (
|
|
id
|
|
, user_name
|
|
, resource_owner
|
|
) VALUES
|
|
('h', 'human', 'org')
|
|
, ('m', 'machine', 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_domains (
|
|
name
|
|
, is_primary
|
|
, resource_owner
|
|
) VALUES
|
|
('org-ch.localhost', true, 'org')
|
|
, ('custom.ch', false, 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_policies (
|
|
must_be_domain
|
|
, is_default
|
|
, resource_owner
|
|
) VALUES
|
|
(true, true, 'IAM')
|
|
;
|
|
|
|
-- default and custom login name => 4 login names default is primary
|
|
SELECT * FROM zitadel.projections.login_names WHERE user_id IN ('h', 'm');
|
|
ROLLBACK;
|
|
|
|
-- --------------------------------------------------------
|
|
-- default and additional domain verified and primary
|
|
-- --------------------------------------------------------
|
|
BEGIN;
|
|
|
|
INSERT INTO zitadel.projections.login_names_users (
|
|
id
|
|
, user_name
|
|
, resource_owner
|
|
) VALUES
|
|
('h', 'human', 'org')
|
|
, ('m', 'machine', 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_domains (
|
|
name
|
|
, is_primary
|
|
, resource_owner
|
|
) VALUES
|
|
('org-ch.localhost', false, 'org')
|
|
, ('custom.ch', true, 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_policies (
|
|
must_be_domain
|
|
, is_default
|
|
, resource_owner
|
|
) VALUES
|
|
(true, true, 'IAM')
|
|
;
|
|
|
|
-- default and custom login name => 2 login names default is primary
|
|
SELECT * FROM zitadel.projections.login_names WHERE user_id IN ('h', 'm');
|
|
ROLLBACK;
|
|
|
|
-- --------------------------------------------------------
|
|
-- custom policy (must_be_domain=false) no domain
|
|
-- --------------------------------------------------------
|
|
BEGIN;
|
|
|
|
INSERT INTO zitadel.projections.login_names_users (
|
|
id
|
|
, user_name
|
|
, resource_owner
|
|
) VALUES
|
|
('h', 'human', 'org')
|
|
, ('m', 'machine', 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_domains (
|
|
name
|
|
, is_primary
|
|
, resource_owner
|
|
) VALUES
|
|
-- only default for org
|
|
('org-ch.localhost', true, 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_policies (
|
|
must_be_domain
|
|
, is_default
|
|
, resource_owner
|
|
) VALUES
|
|
(true, true, 'IAM')
|
|
, (false, false, 'org')
|
|
;
|
|
|
|
-- default and custom login name => 1 login name machine=user_name human=user_name(=email)
|
|
SELECT * FROM zitadel.projections.login_names WHERE user_id IN ('h', 'm');
|
|
ROLLBACK;
|
|
|
|
-- --------------------------------------------------------
|
|
-- custom policy (must_be_domain=false) verified domain
|
|
-- --------------------------------------------------------
|
|
BEGIN;
|
|
|
|
INSERT INTO zitadel.projections.login_names_users (
|
|
id
|
|
, user_name
|
|
, resource_owner
|
|
) VALUES
|
|
('h', 'human', 'org')
|
|
, ('m', 'machine', 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_domains (
|
|
name
|
|
, is_primary
|
|
, resource_owner
|
|
) VALUES
|
|
-- default and unverified for org
|
|
('org-ch.localhost', true, 'org')
|
|
, ('custom.ch', false, 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_policies (
|
|
must_be_domain
|
|
, is_default
|
|
, resource_owner
|
|
) VALUES
|
|
(true, true, 'IAM')
|
|
, (false, false, 'org')
|
|
;
|
|
|
|
-- 1 login name machine=user_name human=user_name(=email)
|
|
SELECT * FROM zitadel.projections.login_names WHERE user_id IN ('h', 'm');
|
|
ROLLBACK;
|
|
|
|
-- --------------------------------------------------------
|
|
-- custom policy (must_be_domain=false) verified, primary domain
|
|
-- --------------------------------------------------------
|
|
BEGIN;
|
|
|
|
INSERT INTO zitadel.projections.login_names_users (
|
|
id
|
|
, user_name
|
|
, resource_owner
|
|
) VALUES
|
|
('h', 'human', 'org')
|
|
, ('m', 'machine', 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_domains (
|
|
name
|
|
, is_primary
|
|
, resource_owner
|
|
) VALUES
|
|
-- default and unverified for org
|
|
('org-ch.localhost', false, 'org')
|
|
, ('custom.ch', true, 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_policies (
|
|
must_be_domain
|
|
, is_default
|
|
, resource_owner
|
|
) VALUES
|
|
(true, true, 'IAM')
|
|
, (false, false, 'org')
|
|
;
|
|
|
|
-- 1 login name machine=user_name human=user_name(=email)
|
|
SELECT * FROM zitadel.projections.login_names WHERE user_id IN ('h', 'm');
|
|
ROLLBACK;
|
|
|
|
-- --------------------------------------------------------
|
|
-- custom policy (must_be_domain=true) no domain
|
|
-- --------------------------------------------------------
|
|
BEGIN;
|
|
|
|
INSERT INTO zitadel.projections.login_names_users (
|
|
id
|
|
, user_name
|
|
, resource_owner
|
|
) VALUES
|
|
('h', 'human', 'org')
|
|
, ('m', 'machine', 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_domains (
|
|
name
|
|
, is_primary
|
|
, resource_owner
|
|
) VALUES
|
|
-- only default for org
|
|
('org-ch.localhost', true, 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_policies (
|
|
must_be_domain
|
|
, is_default
|
|
, resource_owner
|
|
) VALUES
|
|
(true, true, 'IAM')
|
|
, (true, false, 'org')
|
|
;
|
|
|
|
-- one login per user
|
|
SELECT * FROM zitadel.projections.login_names WHERE user_id IN ('h', 'm');
|
|
ROLLBACK;
|
|
|
|
-- --------------------------------------------------------
|
|
-- custom policy (must_be_domain=true) verified domain
|
|
-- --------------------------------------------------------
|
|
BEGIN;
|
|
|
|
INSERT INTO zitadel.projections.login_names_users (
|
|
id
|
|
, user_name
|
|
, resource_owner
|
|
) VALUES
|
|
('h', 'human', 'org')
|
|
, ('m', 'machine', 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_domains (
|
|
name
|
|
, is_primary
|
|
, resource_owner
|
|
) VALUES
|
|
-- default and unverified for org
|
|
('org-ch.localhost', true, 'org')
|
|
, ('custom.ch', false, 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_policies (
|
|
must_be_domain
|
|
, is_default
|
|
, resource_owner
|
|
) VALUES
|
|
(true, true, 'IAM')
|
|
, (true, false, 'org')
|
|
;
|
|
|
|
-- 2 login names per user
|
|
SELECT * FROM zitadel.projections.login_names WHERE user_id IN ('h', 'm');
|
|
ROLLBACK;
|
|
|
|
-- --------------------------------------------------------
|
|
-- custom policy (must_be_domain=true) verified, primary domain
|
|
-- --------------------------------------------------------
|
|
BEGIN;
|
|
|
|
INSERT INTO zitadel.projections.login_names_users (
|
|
id
|
|
, user_name
|
|
, resource_owner
|
|
) VALUES
|
|
('h', 'human', 'org')
|
|
, ('m', 'machine', 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_domains (
|
|
name
|
|
, is_primary
|
|
, resource_owner
|
|
) VALUES
|
|
-- default and unverified for org
|
|
('org-ch.localhost', false, 'org')
|
|
, ('custom.ch', true, 'org')
|
|
;
|
|
|
|
INSERT INTO zitadel.projections.login_names_policies (
|
|
must_be_domain
|
|
, is_default
|
|
, resource_owner
|
|
) VALUES
|
|
(true, true, 'IAM')
|
|
, (true, false, 'org')
|
|
;
|
|
|
|
-- 2 login names per user
|
|
explain analyze SELECT * FROM zitadel.projections.login_names WHERE user_id = 'h';
|
|
ROLLBACK;
|