fix: join on instanceIDs in queries (#4612)

This commit is contained in:
Livio Spring 2022-10-27 08:08:36 +02:00 committed by GitHub
parent d721f725fd
commit 441f215513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
61 changed files with 555 additions and 1243 deletions

View File

@ -20,7 +20,8 @@ const (
var ( var (
actionTable = table{ actionTable = table{
name: projection.ActionTable, name: projection.ActionTable,
instanceIDCol: projection.ActionInstanceIDCol,
} }
ActionColumnID = Column{ ActionColumnID = Column{
name: projection.ActionIDCol, name: projection.ActionIDCol,

View File

@ -15,7 +15,8 @@ import (
var ( var (
flowsTriggersTable = table{ flowsTriggersTable = table{
name: projection.FlowTriggerTable, name: projection.FlowTriggerTable,
instanceIDCol: projection.FlowInstanceIDCol,
} }
FlowsTriggersColumnFlowType = Column{ FlowsTriggersColumnFlowType = Column{
name: projection.FlowTypeCol, name: projection.FlowTypeCol,

View File

@ -83,7 +83,8 @@ func (q *AppSearchQueries) toQuery(query sq.SelectBuilder) sq.SelectBuilder {
var ( var (
appsTable = table{ appsTable = table{
name: projection.AppProjectionTable, name: projection.AppProjectionTable,
instanceIDCol: projection.AppColumnInstanceID,
} }
AppColumnID = Column{ AppColumnID = Column{
name: projection.AppColumnID, name: projection.AppColumnID,
@ -125,7 +126,8 @@ var (
var ( var (
appSAMLConfigsTable = table{ appSAMLConfigsTable = table{
name: projection.AppSAMLTable, name: projection.AppSAMLTable,
instanceIDCol: projection.AppSAMLConfigColumnInstanceID,
} }
AppSAMLConfigColumnAppID = Column{ AppSAMLConfigColumnAppID = Column{
name: projection.AppSAMLConfigColumnAppID, name: projection.AppSAMLConfigColumnAppID,
@ -147,7 +149,8 @@ var (
var ( var (
appAPIConfigsTable = table{ appAPIConfigsTable = table{
name: projection.AppAPITable, name: projection.AppAPITable,
instanceIDCol: projection.AppAPIConfigColumnInstanceID,
} }
AppAPIConfigColumnAppID = Column{ AppAPIConfigColumnAppID = Column{
name: projection.AppAPIConfigColumnAppID, name: projection.AppAPIConfigColumnAppID,
@ -165,7 +168,8 @@ var (
var ( var (
appOIDCConfigsTable = table{ appOIDCConfigsTable = table{
name: projection.AppOIDCTable, name: projection.AppOIDCTable,
instanceIDCol: projection.AppOIDCConfigColumnInstanceID,
} }
AppOIDCConfigColumnAppID = Column{ AppOIDCConfigColumnAppID = Column{
name: projection.AppOIDCConfigColumnAppID, name: projection.AppOIDCConfigColumnAppID,

View File

@ -50,9 +50,9 @@ var (
` projections.apps3_saml_configs.metadata,` + ` projections.apps3_saml_configs.metadata,` +
` projections.apps3_saml_configs.metadata_url` + ` projections.apps3_saml_configs.metadata_url` +
` FROM projections.apps3` + ` FROM projections.apps3` +
` LEFT JOIN projections.apps3_api_configs ON projections.apps3.id = projections.apps3_api_configs.app_id` + ` LEFT JOIN projections.apps3_api_configs ON projections.apps3.id = projections.apps3_api_configs.app_id AND projections.apps3.instance_id = projections.apps3_api_configs.instance_id` +
` LEFT JOIN projections.apps3_oidc_configs ON projections.apps3.id = projections.apps3_oidc_configs.app_id` + ` LEFT JOIN projections.apps3_oidc_configs ON projections.apps3.id = projections.apps3_oidc_configs.app_id AND projections.apps3.instance_id = projections.apps3_oidc_configs.instance_id` +
` LEFT JOIN projections.apps3_saml_configs ON projections.apps3.id = projections.apps3_saml_configs.app_id`) ` LEFT JOIN projections.apps3_saml_configs ON projections.apps3.id = projections.apps3_saml_configs.app_id AND projections.apps3.instance_id = projections.apps3_saml_configs.instance_id`)
expectedAppsQuery = regexp.QuoteMeta(`SELECT projections.apps3.id,` + expectedAppsQuery = regexp.QuoteMeta(`SELECT projections.apps3.id,` +
` projections.apps3.name,` + ` projections.apps3.name,` +
` projections.apps3.project_id,` + ` projections.apps3.project_id,` +
@ -89,19 +89,19 @@ var (
` projections.apps3_saml_configs.metadata_url,` + ` projections.apps3_saml_configs.metadata_url,` +
` COUNT(*) OVER ()` + ` COUNT(*) OVER ()` +
` FROM projections.apps3` + ` FROM projections.apps3` +
` LEFT JOIN projections.apps3_api_configs ON projections.apps3.id = projections.apps3_api_configs.app_id` + ` LEFT JOIN projections.apps3_api_configs ON projections.apps3.id = projections.apps3_api_configs.app_id AND projections.apps3.instance_id = projections.apps3_api_configs.instance_id` +
` LEFT JOIN projections.apps3_oidc_configs ON projections.apps3.id = projections.apps3_oidc_configs.app_id` + ` LEFT JOIN projections.apps3_oidc_configs ON projections.apps3.id = projections.apps3_oidc_configs.app_id AND projections.apps3.instance_id = projections.apps3_oidc_configs.instance_id` +
` LEFT JOIN projections.apps3_saml_configs ON projections.apps3.id = projections.apps3_saml_configs.app_id`) ` LEFT JOIN projections.apps3_saml_configs ON projections.apps3.id = projections.apps3_saml_configs.app_id AND projections.apps3.instance_id = projections.apps3_saml_configs.instance_id`)
expectedAppIDsQuery = regexp.QuoteMeta(`SELECT projections.apps3_api_configs.client_id,` + expectedAppIDsQuery = regexp.QuoteMeta(`SELECT projections.apps3_api_configs.client_id,` +
` projections.apps3_oidc_configs.client_id` + ` projections.apps3_oidc_configs.client_id` +
` FROM projections.apps3` + ` FROM projections.apps3` +
` LEFT JOIN projections.apps3_api_configs ON projections.apps3.id = projections.apps3_api_configs.app_id` + ` LEFT JOIN projections.apps3_api_configs ON projections.apps3.id = projections.apps3_api_configs.app_id AND projections.apps3.instance_id = projections.apps3_api_configs.instance_id` +
` LEFT JOIN projections.apps3_oidc_configs ON projections.apps3.id = projections.apps3_oidc_configs.app_id`) ` LEFT JOIN projections.apps3_oidc_configs ON projections.apps3.id = projections.apps3_oidc_configs.app_id AND projections.apps3.instance_id = projections.apps3_oidc_configs.instance_id`)
expectedProjectIDByAppQuery = regexp.QuoteMeta(`SELECT projections.apps3.project_id` + expectedProjectIDByAppQuery = regexp.QuoteMeta(`SELECT projections.apps3.project_id` +
` FROM projections.apps3` + ` FROM projections.apps3` +
` LEFT JOIN projections.apps3_api_configs ON projections.apps3.id = projections.apps3_api_configs.app_id` + ` LEFT JOIN projections.apps3_api_configs ON projections.apps3.id = projections.apps3_api_configs.app_id AND projections.apps3.instance_id = projections.apps3_api_configs.instance_id` +
` LEFT JOIN projections.apps3_oidc_configs ON projections.apps3.id = projections.apps3_oidc_configs.app_id` + ` LEFT JOIN projections.apps3_oidc_configs ON projections.apps3.id = projections.apps3_oidc_configs.app_id AND projections.apps3.instance_id = projections.apps3_oidc_configs.instance_id` +
` LEFT JOIN projections.apps3_saml_configs ON projections.apps3.id = projections.apps3_saml_configs.app_id`) ` LEFT JOIN projections.apps3_saml_configs ON projections.apps3.id = projections.apps3_saml_configs.app_id AND projections.apps3.instance_id = projections.apps3_saml_configs.instance_id`)
expectedProjectByAppQuery = regexp.QuoteMeta(`SELECT projections.projects2.id,` + expectedProjectByAppQuery = regexp.QuoteMeta(`SELECT projections.projects2.id,` +
` projections.projects2.creation_date,` + ` projections.projects2.creation_date,` +
` projections.projects2.change_date,` + ` projections.projects2.change_date,` +
@ -114,10 +114,10 @@ var (
` projections.projects2.has_project_check,` + ` projections.projects2.has_project_check,` +
` projections.projects2.private_labeling_setting` + ` projections.projects2.private_labeling_setting` +
` FROM projections.projects2` + ` FROM projections.projects2` +
` JOIN projections.apps3 ON projections.projects2.id = projections.apps3.project_id` + ` JOIN projections.apps3 ON projections.projects2.id = projections.apps3.project_id AND projections.projects2.instance_id = projections.apps3.instance_id` +
` LEFT JOIN projections.apps3_api_configs ON projections.apps3.id = projections.apps3_api_configs.app_id` + ` LEFT JOIN projections.apps3_api_configs ON projections.apps3.id = projections.apps3_api_configs.app_id AND projections.apps3.instance_id = projections.apps3_api_configs.instance_id` +
` LEFT JOIN projections.apps3_oidc_configs ON projections.apps3.id = projections.apps3_oidc_configs.app_id` + ` LEFT JOIN projections.apps3_oidc_configs ON projections.apps3.id = projections.apps3_oidc_configs.app_id AND projections.apps3.instance_id = projections.apps3_oidc_configs.instance_id` +
` LEFT JOIN projections.apps3_saml_configs ON projections.apps3.id = projections.apps3_saml_configs.app_id`) ` LEFT JOIN projections.apps3_saml_configs ON projections.apps3.id = projections.apps3_saml_configs.app_id AND projections.apps3.instance_id = projections.apps3_saml_configs.instance_id`)
appCols = database.StringArray{ appCols = database.StringArray{
"id", "id",

View File

@ -17,7 +17,8 @@ import (
var ( var (
authNKeyTable = table{ authNKeyTable = table{
name: projection.AuthNKeyTable, name: projection.AuthNKeyTable,
instanceIDCol: projection.AuthNKeyInstanceIDCol,
} }
AuthNKeyColumnID = Column{ AuthNKeyColumnID = Column{
name: projection.AuthNKeyIDCol, name: projection.AuthNKeyIDCol,

View File

@ -47,7 +47,8 @@ func (c *rsaCertificate) Certificate() []byte {
var ( var (
certificateTable = table{ certificateTable = table{
name: projection.CertificateTable, name: projection.CertificateTable,
instanceIDCol: projection.CertificateColumnInstanceID,
} }
CertificateColID = Column{ CertificateColID = Column{
name: projection.CertificateColumnID, name: projection.CertificateColumnID,

View File

@ -41,8 +41,8 @@ func Test_CertificatePrepares(t *testing.T) {
` projections.keys3_private.key,`+ ` projections.keys3_private.key,`+
` COUNT(*) OVER ()`+ ` COUNT(*) OVER ()`+
` FROM projections.keys3`+ ` FROM projections.keys3`+
` LEFT JOIN projections.keys3_certificate ON projections.keys3.id = projections.keys3_certificate.id`+ ` LEFT JOIN projections.keys3_certificate ON projections.keys3.id = projections.keys3_certificate.id AND projections.keys3.instance_id = projections.keys3_certificate.instance_id`+
` LEFT JOIN projections.keys3_private ON projections.keys3.id = projections.keys3_private.id`), ` LEFT JOIN projections.keys3_private ON projections.keys3.id = projections.keys3_private.id AND projections.keys3.instance_id = projections.keys3_private.instance_id`),
nil, nil,
nil, nil,
), ),
@ -72,8 +72,8 @@ func Test_CertificatePrepares(t *testing.T) {
` projections.keys3_private.key,`+ ` projections.keys3_private.key,`+
` COUNT(*) OVER ()`+ ` COUNT(*) OVER ()`+
` FROM projections.keys3`+ ` FROM projections.keys3`+
` LEFT JOIN projections.keys3_certificate ON projections.keys3.id = projections.keys3_certificate.id`+ ` LEFT JOIN projections.keys3_certificate ON projections.keys3.id = projections.keys3_certificate.id AND projections.keys3.instance_id = projections.keys3_certificate.instance_id`+
` LEFT JOIN projections.keys3_private ON projections.keys3.id = projections.keys3_private.id`), ` LEFT JOIN projections.keys3_private ON projections.keys3.id = projections.keys3_private.id AND projections.keys3.instance_id = projections.keys3_private.instance_id`),
[]string{ []string{
"id", "id",
"creation_date", "creation_date",
@ -147,8 +147,8 @@ func Test_CertificatePrepares(t *testing.T) {
` projections.keys3_private.key,`+ ` projections.keys3_private.key,`+
` COUNT(*) OVER ()`+ ` COUNT(*) OVER ()`+
` FROM projections.keys3`+ ` FROM projections.keys3`+
` LEFT JOIN projections.keys3_certificate ON projections.keys3.id = projections.keys3_certificate.id`+ ` LEFT JOIN projections.keys3_certificate ON projections.keys3.id = projections.keys3_certificate.id AND projections.keys3.instance_id = projections.keys3_certificate.instance_id`+
` LEFT JOIN projections.keys3_private ON projections.keys3.id = projections.keys3_private.id`), ` LEFT JOIN projections.keys3_private ON projections.keys3.id = projections.keys3_private.id AND projections.keys3.instance_id = projections.keys3_private.instance_id`),
sql.ErrConnDone, sql.ErrConnDone,
), ),
err: func(err error) (error, bool) { err: func(err error) (error, bool) {

View File

@ -249,7 +249,8 @@ func prepareCurrentSequencesQuery() (sq.SelectBuilder, func(*sql.Rows) (*Current
var ( var (
currentSequencesTable = table{ currentSequencesTable = table{
name: projection.CurrentSeqTable, name: projection.CurrentSeqTable,
instanceIDCol: "instance_id",
} }
CurrentSequenceColAggregateType = Column{ CurrentSequenceColAggregateType = Column{
name: "aggregate_type", name: "aggregate_type",
@ -275,7 +276,8 @@ var (
var ( var (
locksTable = table{ locksTable = table{
name: projection.LocksTable, name: projection.LocksTable,
instanceIDCol: "instance_id",
} }
LocksColLockerID = Column{ LocksColLockerID = Column{
name: "locker_id", name: "locker_id",

View File

@ -39,7 +39,8 @@ type CustomText struct {
var ( var (
customTextTable = table{ customTextTable = table{
name: projection.CustomTextTable, name: projection.CustomTextTable,
instanceIDCol: projection.CustomTextInstanceIDCol,
} }
CustomTextColAggregateID = Column{ CustomTextColAggregateID = Column{
name: projection.CustomTextAggregateIDCol, name: projection.CustomTextAggregateIDCol,

View File

@ -32,7 +32,8 @@ type DomainPolicy struct {
var ( var (
domainPolicyTable = table{ domainPolicyTable = table{
name: projection.DomainPolicyTable, name: projection.DomainPolicyTable,
instanceIDCol: projection.DomainPolicyInstanceIDCol,
} }
DomainPolicyColID = Column{ DomainPolicyColID = Column{
name: projection.DomainPolicyIDCol, name: projection.DomainPolicyIDCol,

View File

@ -21,7 +21,8 @@ const (
var ( var (
failedEventsTable = table{ failedEventsTable = table{
name: projection.FailedEventsTable, name: projection.FailedEventsTable,
instanceIDCol: failedEventsColumnInstanceID,
} }
FailedEventsColumnProjectionName = Column{ FailedEventsColumnProjectionName = Column{
name: failedEventsColumnProjectionName, name: failedEventsColumnProjectionName,
@ -39,10 +40,6 @@ var (
name: failedEventsColumnError, name: failedEventsColumnError,
table: failedEventsTable, table: failedEventsTable,
} }
FailedEventsColumnInstanceID = Column{
name: failedEventsColumnInstanceID,
table: failedEventsTable,
}
) )
type FailedEvents struct { type FailedEvents struct {

View File

@ -14,8 +14,9 @@ import (
var ( var (
instanceMemberTable = table{ instanceMemberTable = table{
name: projection.InstanceMemberProjectionTable, name: projection.InstanceMemberProjectionTable,
alias: "members", alias: "members",
instanceIDCol: projection.MemberInstanceID,
} }
InstanceMemberUserID = Column{ InstanceMemberUserID = Column{
name: projection.MemberUserIDCol, name: projection.MemberUserIDCol,

View File

@ -29,11 +29,11 @@ var (
", COUNT(*) OVER () " + ", COUNT(*) OVER () " +
"FROM projections.instance_members2 AS members " + "FROM projections.instance_members2 AS members " +
"LEFT JOIN projections.users4_humans " + "LEFT JOIN projections.users4_humans " +
"ON members.user_id = projections.users4_humans.user_id " + "ON members.user_id = projections.users4_humans.user_id AND members.instance_id = projections.users4_humans.instance_id " +
"LEFT JOIN projections.users4_machines " + "LEFT JOIN projections.users4_machines " +
"ON members.user_id = projections.users4_machines.user_id " + "ON members.user_id = projections.users4_machines.user_id AND members.instance_id = projections.users4_machines.instance_id " +
"LEFT JOIN projections.login_names " + "LEFT JOIN projections.login_names " +
"ON members.user_id = projections.login_names.user_id " + "ON members.user_id = projections.login_names.user_id AND members.instance_id = projections.login_names.instance_id " +
"WHERE projections.login_names.is_primary = $1") "WHERE projections.login_names.is_primary = $1")
instanceMembersColumns = []string{ instanceMembersColumns = []string{
"creation_date", "creation_date",

View File

@ -59,7 +59,8 @@ type JWTIDP struct {
var ( var (
idpTable = table{ idpTable = table{
name: projection.IDPTable, name: projection.IDPTable,
instanceIDCol: projection.IDPInstanceIDCol,
} }
IDPIDCol = Column{ IDPIDCol = Column{
name: projection.IDPIDCol, name: projection.IDPIDCol,
@ -113,7 +114,8 @@ var (
var ( var (
oidcIDPTable = table{ oidcIDPTable = table{
name: projection.IDPOIDCTable, name: projection.IDPOIDCTable,
instanceIDCol: projection.OIDCConfigInstanceIDCol,
} }
OIDCIDPColIDPID = Column{ OIDCIDPColIDPID = Column{
name: projection.OIDCConfigIDPIDCol, name: projection.OIDCConfigIDPIDCol,
@ -155,7 +157,8 @@ var (
var ( var (
jwtIDPTable = table{ jwtIDPTable = table{
name: projection.IDPJWTTable, name: projection.IDPJWTTable,
instanceIDCol: projection.JWTConfigInstanceIDCol,
} }
JWTIDPColIDPID = Column{ JWTIDPColIDPID = Column{
name: projection.JWTConfigIDPIDCol, name: projection.JWTConfigIDPIDCol,
@ -179,7 +182,7 @@ var (
} }
) )
//IDPByIDAndResourceOwner searches for the requested id in the context of the resource owner and IAM // IDPByIDAndResourceOwner searches for the requested id in the context of the resource owner and IAM
func (q *Queries) IDPByIDAndResourceOwner(ctx context.Context, shouldTriggerBulk bool, id, resourceOwner string) (*IDP, error) { func (q *Queries) IDPByIDAndResourceOwner(ctx context.Context, shouldTriggerBulk bool, id, resourceOwner string) (*IDP, error) {
if shouldTriggerBulk { if shouldTriggerBulk {
projection.IDPProjection.Trigger(ctx) projection.IDPProjection.Trigger(ctx)
@ -210,7 +213,7 @@ func (q *Queries) IDPByIDAndResourceOwner(ctx context.Context, shouldTriggerBulk
return scan(row) return scan(row)
} }
//IDPs searches idps matching the query // IDPs searches idps matching the query
func (q *Queries) IDPs(ctx context.Context, queries *IDPSearchQueries) (idps *IDPs, err error) { func (q *Queries) IDPs(ctx context.Context, queries *IDPSearchQueries) (idps *IDPs, err error) {
query, scan := prepareIDPsQuery() query, scan := prepareIDPsQuery()
stmt, args, err := queries.toQuery(query). stmt, args, err := queries.toQuery(query).

View File

@ -38,7 +38,8 @@ func (q *IDPLoginPolicyLinksSearchQuery) toQuery(query sq.SelectBuilder) sq.Sele
var ( var (
idpLoginPolicyLinkTable = table{ idpLoginPolicyLinkTable = table{
name: projection.IDPLoginPolicyLinkTable, name: projection.IDPLoginPolicyLinkTable,
instanceIDCol: projection.IDPLoginPolicyLinkInstanceIDCol,
} }
IDPLoginPolicyLinkIDPIDCol = Column{ IDPLoginPolicyLinkIDPIDCol = Column{
name: projection.IDPLoginPolicyLinkIDPIDCol, name: projection.IDPLoginPolicyLinkIDPIDCol,

View File

@ -14,6 +14,121 @@ import (
errs "github.com/zitadel/zitadel/internal/errors" errs "github.com/zitadel/zitadel/internal/errors"
) )
var (
idpQuery = `SELECT projections.idps2.id,` +
` projections.idps2.resource_owner,` +
` projections.idps2.creation_date,` +
` projections.idps2.change_date,` +
` projections.idps2.sequence,` +
` projections.idps2.state,` +
` projections.idps2.name,` +
` projections.idps2.styling_type,` +
` projections.idps2.owner_type,` +
` projections.idps2.auto_register,` +
` projections.idps2_oidc_config.idp_id,` +
` projections.idps2_oidc_config.client_id,` +
` projections.idps2_oidc_config.client_secret,` +
` projections.idps2_oidc_config.issuer,` +
` projections.idps2_oidc_config.scopes,` +
` projections.idps2_oidc_config.display_name_mapping,` +
` projections.idps2_oidc_config.username_mapping,` +
` projections.idps2_oidc_config.authorization_endpoint,` +
` projections.idps2_oidc_config.token_endpoint,` +
` projections.idps2_jwt_config.idp_id,` +
` projections.idps2_jwt_config.issuer,` +
` projections.idps2_jwt_config.keys_endpoint,` +
` projections.idps2_jwt_config.header_name,` +
` projections.idps2_jwt_config.endpoint` +
` FROM projections.idps2` +
` LEFT JOIN projections.idps2_oidc_config ON projections.idps2.id = projections.idps2_oidc_config.idp_id AND projections.idps2.instance_id = projections.idps2_oidc_config.instance_id` +
` LEFT JOIN projections.idps2_jwt_config ON projections.idps2.id = projections.idps2_jwt_config.idp_id AND projections.idps2.instance_id = projections.idps2_jwt_config.instance_id`
idpCols = []string{
"id",
"resource_owner",
"creation_date",
"change_date",
"sequence",
"state",
"name",
"styling_type",
"owner_type",
"auto_register",
// oidc config
"idp_id",
"client_id",
"client_secret",
"issuer",
"scopes",
"display_name_mapping",
"username_mapping",
"authorization_endpoint",
"token_endpoint",
// jwt config
"idp_id",
"issuer",
"keys_endpoint",
"header_name",
"endpoint",
}
idpsQuery = `SELECT projections.idps2.id,` +
` projections.idps2.resource_owner,` +
` projections.idps2.creation_date,` +
` projections.idps2.change_date,` +
` projections.idps2.sequence,` +
` projections.idps2.state,` +
` projections.idps2.name,` +
` projections.idps2.styling_type,` +
` projections.idps2.owner_type,` +
` projections.idps2.auto_register,` +
` projections.idps2_oidc_config.idp_id,` +
` projections.idps2_oidc_config.client_id,` +
` projections.idps2_oidc_config.client_secret,` +
` projections.idps2_oidc_config.issuer,` +
` projections.idps2_oidc_config.scopes,` +
` projections.idps2_oidc_config.display_name_mapping,` +
` projections.idps2_oidc_config.username_mapping,` +
` projections.idps2_oidc_config.authorization_endpoint,` +
` projections.idps2_oidc_config.token_endpoint,` +
` projections.idps2_jwt_config.idp_id,` +
` projections.idps2_jwt_config.issuer,` +
` projections.idps2_jwt_config.keys_endpoint,` +
` projections.idps2_jwt_config.header_name,` +
` projections.idps2_jwt_config.endpoint,` +
` COUNT(*) OVER ()` +
` FROM projections.idps2` +
` LEFT JOIN projections.idps2_oidc_config ON projections.idps2.id = projections.idps2_oidc_config.idp_id AND projections.idps2.instance_id = projections.idps2_oidc_config.instance_id` +
` LEFT JOIN projections.idps2_jwt_config ON projections.idps2.id = projections.idps2_jwt_config.idp_id AND projections.idps2.instance_id = projections.idps2_jwt_config.instance_id`
idpsCols = []string{
"id",
"resource_owner",
"creation_date",
"change_date",
"sequence",
"state",
"name",
"styling_type",
"owner_type",
"auto_register",
// oidc config
"idp_id",
"client_id",
"client_secret",
"issuer",
"scopes",
"display_name_mapping",
"username_mapping",
"authorization_endpoint",
"token_endpoint",
// jwt config
"idp_id",
"issuer",
"keys_endpoint",
"header_name",
"endpoint",
"count",
}
)
func Test_IDPPrepares(t *testing.T) { func Test_IDPPrepares(t *testing.T) {
type want struct { type want struct {
sqlExpectations sqlExpectation sqlExpectations sqlExpectation
@ -30,33 +145,7 @@ func Test_IDPPrepares(t *testing.T) {
prepare: prepareIDPByIDQuery, prepare: prepareIDPByIDQuery,
want: want{ want: want{
sqlExpectations: mockQuery( sqlExpectations: mockQuery(
regexp.QuoteMeta(`SELECT projections.idps2.id,`+ regexp.QuoteMeta(idpQuery),
` projections.idps2.resource_owner,`+
` projections.idps2.creation_date,`+
` projections.idps2.change_date,`+
` projections.idps2.sequence,`+
` projections.idps2.state,`+
` projections.idps2.name,`+
` projections.idps2.styling_type,`+
` projections.idps2.owner_type,`+
` projections.idps2.auto_register,`+
` projections.idps2_oidc_config.idp_id,`+
` projections.idps2_oidc_config.client_id,`+
` projections.idps2_oidc_config.client_secret,`+
` projections.idps2_oidc_config.issuer,`+
` projections.idps2_oidc_config.scopes,`+
` projections.idps2_oidc_config.display_name_mapping,`+
` projections.idps2_oidc_config.username_mapping,`+
` projections.idps2_oidc_config.authorization_endpoint,`+
` projections.idps2_oidc_config.token_endpoint,`+
` projections.idps2_jwt_config.idp_id,`+
` projections.idps2_jwt_config.issuer,`+
` projections.idps2_jwt_config.keys_endpoint,`+
` projections.idps2_jwt_config.header_name,`+
` projections.idps2_jwt_config.endpoint`+
` FROM projections.idps2`+
` LEFT JOIN projections.idps2_oidc_config ON projections.idps2.id = projections.idps2_oidc_config.idp_id`+
` LEFT JOIN projections.idps2_jwt_config ON projections.idps2.id = projections.idps2_jwt_config.idp_id`),
nil, nil,
nil, nil,
), ),
@ -74,61 +163,8 @@ func Test_IDPPrepares(t *testing.T) {
prepare: prepareIDPByIDQuery, prepare: prepareIDPByIDQuery,
want: want{ want: want{
sqlExpectations: mockQuery( sqlExpectations: mockQuery(
regexp.QuoteMeta(`SELECT projections.idps2.id,`+ regexp.QuoteMeta(idpQuery),
` projections.idps2.resource_owner,`+ idpCols,
` projections.idps2.creation_date,`+
` projections.idps2.change_date,`+
` projections.idps2.sequence,`+
` projections.idps2.state,`+
` projections.idps2.name,`+
` projections.idps2.styling_type,`+
` projections.idps2.owner_type,`+
` projections.idps2.auto_register,`+
` projections.idps2_oidc_config.idp_id,`+
` projections.idps2_oidc_config.client_id,`+
` projections.idps2_oidc_config.client_secret,`+
` projections.idps2_oidc_config.issuer,`+
` projections.idps2_oidc_config.scopes,`+
` projections.idps2_oidc_config.display_name_mapping,`+
` projections.idps2_oidc_config.username_mapping,`+
` projections.idps2_oidc_config.authorization_endpoint,`+
` projections.idps2_oidc_config.token_endpoint,`+
` projections.idps2_jwt_config.idp_id,`+
` projections.idps2_jwt_config.issuer,`+
` projections.idps2_jwt_config.keys_endpoint,`+
` projections.idps2_jwt_config.header_name,`+
` projections.idps2_jwt_config.endpoint`+
` FROM projections.idps2`+
` LEFT JOIN projections.idps2_oidc_config ON projections.idps2.id = projections.idps2_oidc_config.idp_id`+
` LEFT JOIN projections.idps2_jwt_config ON projections.idps2.id = projections.idps2_jwt_config.idp_id`),
[]string{
"id",
"resource_owner",
"creation_date",
"change_date",
"sequence",
"state",
"name",
"styling_type",
"owner_type",
"auto_register",
// oidc config
"idp_id",
"client_id",
"client_secret",
"issuer",
"scopes",
"display_name_mapping",
"username_mapping",
"authorization_endpoint",
"token_endpoint",
// jwt config
"idp_id",
"issuer",
"keys_endpoint",
"header_name",
"endpoint",
},
[]driver.Value{ []driver.Value{
"idp-id", "idp-id",
"ro", "ro",
@ -188,61 +224,8 @@ func Test_IDPPrepares(t *testing.T) {
prepare: prepareIDPByIDQuery, prepare: prepareIDPByIDQuery,
want: want{ want: want{
sqlExpectations: mockQuery( sqlExpectations: mockQuery(
regexp.QuoteMeta(`SELECT projections.idps2.id,`+ regexp.QuoteMeta(idpQuery),
` projections.idps2.resource_owner,`+ idpCols,
` projections.idps2.creation_date,`+
` projections.idps2.change_date,`+
` projections.idps2.sequence,`+
` projections.idps2.state,`+
` projections.idps2.name,`+
` projections.idps2.styling_type,`+
` projections.idps2.owner_type,`+
` projections.idps2.auto_register,`+
` projections.idps2_oidc_config.idp_id,`+
` projections.idps2_oidc_config.client_id,`+
` projections.idps2_oidc_config.client_secret,`+
` projections.idps2_oidc_config.issuer,`+
` projections.idps2_oidc_config.scopes,`+
` projections.idps2_oidc_config.display_name_mapping,`+
` projections.idps2_oidc_config.username_mapping,`+
` projections.idps2_oidc_config.authorization_endpoint,`+
` projections.idps2_oidc_config.token_endpoint,`+
` projections.idps2_jwt_config.idp_id,`+
` projections.idps2_jwt_config.issuer,`+
` projections.idps2_jwt_config.keys_endpoint,`+
` projections.idps2_jwt_config.header_name,`+
` projections.idps2_jwt_config.endpoint`+
` FROM projections.idps2`+
` LEFT JOIN projections.idps2_oidc_config ON projections.idps2.id = projections.idps2_oidc_config.idp_id`+
` LEFT JOIN projections.idps2_jwt_config ON projections.idps2.id = projections.idps2_jwt_config.idp_id`),
[]string{
"id",
"resource_owner",
"creation_date",
"change_date",
"sequence",
"state",
"name",
"styling_type",
"owner_type",
"auto_register",
// oidc config
"idp_id",
"client_id",
"client_secret",
"issuer",
"scopes",
"display_name_mapping",
"username_mapping",
"authorization_endpoint",
"token_endpoint",
// jwt config
"idp_id",
"issuer",
"keys_endpoint",
"header_name",
"endpoint",
},
[]driver.Value{ []driver.Value{
"idp-id", "idp-id",
"ro", "ro",
@ -298,61 +281,8 @@ func Test_IDPPrepares(t *testing.T) {
prepare: prepareIDPByIDQuery, prepare: prepareIDPByIDQuery,
want: want{ want: want{
sqlExpectations: mockQuery( sqlExpectations: mockQuery(
regexp.QuoteMeta(`SELECT projections.idps2.id,`+ regexp.QuoteMeta(idpQuery),
` projections.idps2.resource_owner,`+ idpCols,
` projections.idps2.creation_date,`+
` projections.idps2.change_date,`+
` projections.idps2.sequence,`+
` projections.idps2.state,`+
` projections.idps2.name,`+
` projections.idps2.styling_type,`+
` projections.idps2.owner_type,`+
` projections.idps2.auto_register,`+
` projections.idps2_oidc_config.idp_id,`+
` projections.idps2_oidc_config.client_id,`+
` projections.idps2_oidc_config.client_secret,`+
` projections.idps2_oidc_config.issuer,`+
` projections.idps2_oidc_config.scopes,`+
` projections.idps2_oidc_config.display_name_mapping,`+
` projections.idps2_oidc_config.username_mapping,`+
` projections.idps2_oidc_config.authorization_endpoint,`+
` projections.idps2_oidc_config.token_endpoint,`+
` projections.idps2_jwt_config.idp_id,`+
` projections.idps2_jwt_config.issuer,`+
` projections.idps2_jwt_config.keys_endpoint,`+
` projections.idps2_jwt_config.header_name,`+
` projections.idps2_jwt_config.endpoint`+
` FROM projections.idps2`+
` LEFT JOIN projections.idps2_oidc_config ON projections.idps2.id = projections.idps2_oidc_config.idp_id`+
` LEFT JOIN projections.idps2_jwt_config ON projections.idps2.id = projections.idps2_jwt_config.idp_id`),
[]string{
"id",
"resource_owner",
"creation_date",
"change_date",
"sequence",
"state",
"name",
"styling_type",
"owner_type",
"auto_register",
// oidc config
"idp_id",
"client_id",
"client_secret",
"issuer",
"scopes",
"display_name_mapping",
"username_mapping",
"authorization_endpoint",
"token_endpoint",
// jwt config
"idp_id",
"issuer",
"keys_endpoint",
"header_name",
"endpoint",
},
[]driver.Value{ []driver.Value{
"idp-id", "idp-id",
"ro", "ro",
@ -401,33 +331,7 @@ func Test_IDPPrepares(t *testing.T) {
prepare: prepareIDPByIDQuery, prepare: prepareIDPByIDQuery,
want: want{ want: want{
sqlExpectations: mockQueryErr( sqlExpectations: mockQueryErr(
regexp.QuoteMeta(`SELECT projections.idps2.id,`+ regexp.QuoteMeta(idpQuery),
` projections.idps2.resource_owner,`+
` projections.idps2.creation_date,`+
` projections.idps2.change_date,`+
` projections.idps2.sequence,`+
` projections.idps2.state,`+
` projections.idps2.name,`+
` projections.idps2.styling_type,`+
` projections.idps2.owner_type,`+
` projections.idps2.auto_register,`+
` projections.idps2_oidc_config.idp_id,`+
` projections.idps2_oidc_config.client_id,`+
` projections.idps2_oidc_config.client_secret,`+
` projections.idps2_oidc_config.issuer,`+
` projections.idps2_oidc_config.scopes,`+
` projections.idps2_oidc_config.display_name_mapping,`+
` projections.idps2_oidc_config.username_mapping,`+
` projections.idps2_oidc_config.authorization_endpoint,`+
` projections.idps2_oidc_config.token_endpoint,`+
` projections.idps2_jwt_config.idp_id,`+
` projections.idps2_jwt_config.issuer,`+
` projections.idps2_jwt_config.keys_endpoint,`+
` projections.idps2_jwt_config.header_name,`+
` projections.idps2_jwt_config.endpoint`+
` FROM projections.idps2`+
` LEFT JOIN projections.idps2_oidc_config ON projections.idps2.id = projections.idps2_oidc_config.idp_id`+
` LEFT JOIN projections.idps2_jwt_config ON projections.idps2.id = projections.idps2_jwt_config.idp_id`),
sql.ErrConnDone, sql.ErrConnDone,
), ),
err: func(err error) (error, bool) { err: func(err error) (error, bool) {
@ -444,34 +348,7 @@ func Test_IDPPrepares(t *testing.T) {
prepare: prepareIDPsQuery, prepare: prepareIDPsQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.idps2.id,`+ regexp.QuoteMeta(idpsQuery),
` projections.idps2.resource_owner,`+
` projections.idps2.creation_date,`+
` projections.idps2.change_date,`+
` projections.idps2.sequence,`+
` projections.idps2.state,`+
` projections.idps2.name,`+
` projections.idps2.styling_type,`+
` projections.idps2.owner_type,`+
` projections.idps2.auto_register,`+
` projections.idps2_oidc_config.idp_id,`+
` projections.idps2_oidc_config.client_id,`+
` projections.idps2_oidc_config.client_secret,`+
` projections.idps2_oidc_config.issuer,`+
` projections.idps2_oidc_config.scopes,`+
` projections.idps2_oidc_config.display_name_mapping,`+
` projections.idps2_oidc_config.username_mapping,`+
` projections.idps2_oidc_config.authorization_endpoint,`+
` projections.idps2_oidc_config.token_endpoint,`+
` projections.idps2_jwt_config.idp_id,`+
` projections.idps2_jwt_config.issuer,`+
` projections.idps2_jwt_config.keys_endpoint,`+
` projections.idps2_jwt_config.header_name,`+
` projections.idps2_jwt_config.endpoint,`+
` COUNT(*) OVER ()`+
` FROM projections.idps2`+
` LEFT JOIN projections.idps2_oidc_config ON projections.idps2.id = projections.idps2_oidc_config.idp_id`+
` LEFT JOIN projections.idps2_jwt_config ON projections.idps2.id = projections.idps2_jwt_config.idp_id`),
nil, nil,
nil, nil,
), ),
@ -489,63 +366,8 @@ func Test_IDPPrepares(t *testing.T) {
prepare: prepareIDPsQuery, prepare: prepareIDPsQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.idps2.id,`+ regexp.QuoteMeta(idpsQuery),
` projections.idps2.resource_owner,`+ idpsCols,
` projections.idps2.creation_date,`+
` projections.idps2.change_date,`+
` projections.idps2.sequence,`+
` projections.idps2.state,`+
` projections.idps2.name,`+
` projections.idps2.styling_type,`+
` projections.idps2.owner_type,`+
` projections.idps2.auto_register,`+
` projections.idps2_oidc_config.idp_id,`+
` projections.idps2_oidc_config.client_id,`+
` projections.idps2_oidc_config.client_secret,`+
` projections.idps2_oidc_config.issuer,`+
` projections.idps2_oidc_config.scopes,`+
` projections.idps2_oidc_config.display_name_mapping,`+
` projections.idps2_oidc_config.username_mapping,`+
` projections.idps2_oidc_config.authorization_endpoint,`+
` projections.idps2_oidc_config.token_endpoint,`+
` projections.idps2_jwt_config.idp_id,`+
` projections.idps2_jwt_config.issuer,`+
` projections.idps2_jwt_config.keys_endpoint,`+
` projections.idps2_jwt_config.header_name,`+
` projections.idps2_jwt_config.endpoint,`+
` COUNT(*) OVER ()`+
` FROM projections.idps2`+
` LEFT JOIN projections.idps2_oidc_config ON projections.idps2.id = projections.idps2_oidc_config.idp_id`+
` LEFT JOIN projections.idps2_jwt_config ON projections.idps2.id = projections.idps2_jwt_config.idp_id`),
[]string{
"id",
"resource_owner",
"creation_date",
"change_date",
"sequence",
"state",
"name",
"styling_type",
"owner_type",
"auto_register",
// oidc config
"idp_id",
"client_id",
"client_secret",
"issuer",
"scopes",
"display_name_mapping",
"username_mapping",
"authorization_endpoint",
"token_endpoint",
// jwt config
"idp_id",
"issuer",
"keys_endpoint",
"header_name",
"endpoint",
"count",
},
[][]driver.Value{ [][]driver.Value{
{ {
"idp-id", "idp-id",
@ -614,62 +436,8 @@ func Test_IDPPrepares(t *testing.T) {
prepare: prepareIDPsQuery, prepare: prepareIDPsQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.idps2.id,`+ regexp.QuoteMeta(idpsQuery),
` projections.idps2.resource_owner,`+ idpsCols,
` projections.idps2.creation_date,`+
` projections.idps2.change_date,`+
` projections.idps2.sequence,`+
` projections.idps2.state,`+
` projections.idps2.name,`+
` projections.idps2.styling_type,`+
` projections.idps2.owner_type,`+
` projections.idps2.auto_register,`+
` projections.idps2_oidc_config.idp_id,`+
` projections.idps2_oidc_config.client_id,`+
` projections.idps2_oidc_config.client_secret,`+
` projections.idps2_oidc_config.issuer,`+
` projections.idps2_oidc_config.scopes,`+
` projections.idps2_oidc_config.display_name_mapping,`+
` projections.idps2_oidc_config.username_mapping,`+
` projections.idps2_oidc_config.authorization_endpoint,`+
` projections.idps2_oidc_config.token_endpoint,`+
` projections.idps2_jwt_config.idp_id,`+
` projections.idps2_jwt_config.issuer,`+
` projections.idps2_jwt_config.keys_endpoint,`+
` projections.idps2_jwt_config.header_name,`+
` projections.idps2_jwt_config.endpoint,`+
` COUNT(*) OVER ()`+
` FROM projections.idps2`+
` LEFT JOIN projections.idps2_oidc_config ON projections.idps2.id = projections.idps2_oidc_config.idp_id`+
` LEFT JOIN projections.idps2_jwt_config ON projections.idps2.id = projections.idps2_jwt_config.idp_id`),
[]string{
"id",
"resource_owner",
"creation_date",
"change_date",
"sequence",
"state",
"name",
"styling_type",
"owner_type",
"auto_register",
// oidc config
"idp_id",
"client_id",
"client_secret",
"issuer",
"scopes",
"display_name_mapping",
"username_mapping",
"authorization_endpoint",
"token_endpoint",
"idp_id",
"issuer",
"keys_endpoint",
"header_name",
"endpoint",
"count",
},
[][]driver.Value{ [][]driver.Value{
{ {
"idp-id", "idp-id",
@ -734,62 +502,8 @@ func Test_IDPPrepares(t *testing.T) {
prepare: prepareIDPsQuery, prepare: prepareIDPsQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.idps2.id,`+ regexp.QuoteMeta(idpsQuery),
` projections.idps2.resource_owner,`+ idpsCols,
` projections.idps2.creation_date,`+
` projections.idps2.change_date,`+
` projections.idps2.sequence,`+
` projections.idps2.state,`+
` projections.idps2.name,`+
` projections.idps2.styling_type,`+
` projections.idps2.owner_type,`+
` projections.idps2.auto_register,`+
` projections.idps2_oidc_config.idp_id,`+
` projections.idps2_oidc_config.client_id,`+
` projections.idps2_oidc_config.client_secret,`+
` projections.idps2_oidc_config.issuer,`+
` projections.idps2_oidc_config.scopes,`+
` projections.idps2_oidc_config.display_name_mapping,`+
` projections.idps2_oidc_config.username_mapping,`+
` projections.idps2_oidc_config.authorization_endpoint,`+
` projections.idps2_oidc_config.token_endpoint,`+
` projections.idps2_jwt_config.idp_id,`+
` projections.idps2_jwt_config.issuer,`+
` projections.idps2_jwt_config.keys_endpoint,`+
` projections.idps2_jwt_config.header_name,`+
` projections.idps2_jwt_config.endpoint,`+
` COUNT(*) OVER ()`+
` FROM projections.idps2`+
` LEFT JOIN projections.idps2_oidc_config ON projections.idps2.id = projections.idps2_oidc_config.idp_id`+
` LEFT JOIN projections.idps2_jwt_config ON projections.idps2.id = projections.idps2_jwt_config.idp_id`),
[]string{
"id",
"resource_owner",
"creation_date",
"change_date",
"sequence",
"state",
"name",
"styling_type",
"owner_type",
"auto_register",
// oidc config
"idp_id",
"client_id",
"client_secret",
"issuer",
"scopes",
"display_name_mapping",
"username_mapping",
"authorization_endpoint",
"token_endpoint",
"idp_id",
"issuer",
"keys_endpoint",
"header_name",
"endpoint",
"count",
},
[][]driver.Value{ [][]driver.Value{
{ {
"idp-id", "idp-id",
@ -847,62 +561,8 @@ func Test_IDPPrepares(t *testing.T) {
prepare: prepareIDPsQuery, prepare: prepareIDPsQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.idps2.id,`+ regexp.QuoteMeta(idpsQuery),
` projections.idps2.resource_owner,`+ idpsCols,
` projections.idps2.creation_date,`+
` projections.idps2.change_date,`+
` projections.idps2.sequence,`+
` projections.idps2.state,`+
` projections.idps2.name,`+
` projections.idps2.styling_type,`+
` projections.idps2.owner_type,`+
` projections.idps2.auto_register,`+
` projections.idps2_oidc_config.idp_id,`+
` projections.idps2_oidc_config.client_id,`+
` projections.idps2_oidc_config.client_secret,`+
` projections.idps2_oidc_config.issuer,`+
` projections.idps2_oidc_config.scopes,`+
` projections.idps2_oidc_config.display_name_mapping,`+
` projections.idps2_oidc_config.username_mapping,`+
` projections.idps2_oidc_config.authorization_endpoint,`+
` projections.idps2_oidc_config.token_endpoint,`+
` projections.idps2_jwt_config.idp_id,`+
` projections.idps2_jwt_config.issuer,`+
` projections.idps2_jwt_config.keys_endpoint,`+
` projections.idps2_jwt_config.header_name,`+
` projections.idps2_jwt_config.endpoint,`+
` COUNT(*) OVER ()`+
` FROM projections.idps2`+
` LEFT JOIN projections.idps2_oidc_config ON projections.idps2.id = projections.idps2_oidc_config.idp_id`+
` LEFT JOIN projections.idps2_jwt_config ON projections.idps2.id = projections.idps2_jwt_config.idp_id`),
[]string{
"id",
"resource_owner",
"creation_date",
"change_date",
"sequence",
"state",
"name",
"styling_type",
"owner_type",
"auto_register",
// oidc config
"idp_id",
"client_id",
"client_secret",
"issuer",
"scopes",
"display_name_mapping",
"username_mapping",
"authorization_endpoint",
"token_endpoint",
"idp_id",
"issuer",
"keys_endpoint",
"header_name",
"endpoint",
"count",
},
[][]driver.Value{ [][]driver.Value{
{ {
"idp-id-1", "idp-id-1",
@ -1058,34 +718,7 @@ func Test_IDPPrepares(t *testing.T) {
prepare: prepareIDPsQuery, prepare: prepareIDPsQuery,
want: want{ want: want{
sqlExpectations: mockQueryErr( sqlExpectations: mockQueryErr(
regexp.QuoteMeta(`SELECT projections.idps2.id,`+ regexp.QuoteMeta(idpsQuery),
` projections.idps2.resource_owner,`+
` projections.idps2.creation_date,`+
` projections.idps2.change_date,`+
` projections.idps2.sequence,`+
` projections.idps2.state,`+
` projections.idps2.name,`+
` projections.idps2.styling_type,`+
` projections.idps2.owner_type,`+
` projections.idps2.auto_register,`+
` projections.idps2_oidc_config.idp_id,`+
` projections.idps2_oidc_config.client_id,`+
` projections.idps2_oidc_config.client_secret,`+
` projections.idps2_oidc_config.issuer,`+
` projections.idps2_oidc_config.scopes,`+
` projections.idps2_oidc_config.display_name_mapping,`+
` projections.idps2_oidc_config.username_mapping,`+
` projections.idps2_oidc_config.authorization_endpoint,`+
` projections.idps2_oidc_config.token_endpoint,`+
` projections.idps2_jwt_config.idp_id,`+
` projections.idps2_jwt_config.issuer,`+
` projections.idps2_jwt_config.keys_endpoint,`+
` projections.idps2_jwt_config.header_name,`+
` projections.idps2_jwt_config.endpoint,`+
` COUNT(*) OVER ()`+
` FROM projections.idps2`+
` LEFT JOIN projections.idps2_oidc_config ON projections.idps2.id = projections.idps2_oidc_config.idp_id`+
` LEFT JOIN projections.idps2_jwt_config ON projections.idps2.id = projections.idps2_jwt_config.idp_id`),
sql.ErrConnDone, sql.ErrConnDone,
), ),
err: func(err error) (error, bool) { err: func(err error) (error, bool) {

View File

@ -42,7 +42,8 @@ func (q *IDPUserLinksSearchQuery) toQuery(query sq.SelectBuilder) sq.SelectBuild
var ( var (
idpUserLinkTable = table{ idpUserLinkTable = table{
name: projection.IDPUserLinkTable, name: projection.IDPUserLinkTable,
instanceIDCol: projection.IDPUserLinkInstanceIDCol,
} }
IDPUserLinkIDPIDCol = Column{ IDPUserLinkIDPIDCol = Column{
name: projection.IDPUserLinkIDPIDCol, name: projection.IDPUserLinkIDPIDCol,

View File

@ -21,7 +21,8 @@ const (
var ( var (
instanceTable = table{ instanceTable = table{
name: projection.InstanceProjectionTable, name: projection.InstanceProjectionTable,
instanceIDCol: projection.InstanceColumnID,
} }
InstanceColumnID = Column{ InstanceColumnID = Column{
name: projection.InstanceColumnID, name: projection.InstanceColumnID,

View File

@ -139,7 +139,8 @@ func prepareInstanceDomainsQuery() (sq.SelectBuilder, func(*sql.Rows) (*Instance
var ( var (
instanceDomainsTable = table{ instanceDomainsTable = table{
name: projection.InstanceDomainTable, name: projection.InstanceDomainTable,
instanceIDCol: projection.InstanceDomainInstanceIDCol,
} }
InstanceDomainCreationDateCol = Column{ InstanceDomainCreationDateCol = Column{

View File

@ -14,6 +14,68 @@ import (
errs "github.com/zitadel/zitadel/internal/errors" errs "github.com/zitadel/zitadel/internal/errors"
) )
var (
instanceQuery = `SELECT projections.instances.id,` +
` projections.instances.creation_date,` +
` projections.instances.change_date,` +
` projections.instances.sequence,` +
` projections.instances.default_org_id,` +
` projections.instances.iam_project_id,` +
` projections.instances.console_client_id,` +
` projections.instances.console_app_id,` +
` projections.instances.default_language` +
` FROM projections.instances`
instanceCols = []string{
"id",
"creation_date",
"change_date",
"sequence",
"default_org_id",
"iam_project_id",
"console_client_id",
"console_app_id",
"default_language",
}
instancesQuery = `SELECT f.count, f.id,` +
` projections.instances.creation_date,` +
` projections.instances.change_date,` +
` projections.instances.sequence,` +
` projections.instances.name,` +
` projections.instances.default_org_id,` +
` projections.instances.iam_project_id,` +
` projections.instances.console_client_id,` +
` projections.instances.console_app_id,` +
` projections.instances.default_language,` +
` projections.instance_domains.domain,` +
` projections.instance_domains.is_primary,` +
` projections.instance_domains.is_generated,` +
` projections.instance_domains.creation_date,` +
` projections.instance_domains.change_date, ` +
` projections.instance_domains.sequence` +
` FROM (SELECT projections.instances.id, COUNT(*) OVER () FROM projections.instances) AS f` +
` LEFT JOIN projections.instances ON f.id = projections.instances.id AND f.id = projections.instances.id` +
` LEFT JOIN projections.instance_domains ON f.id = projections.instance_domains.instance_id AND f.id = projections.instance_domains.instance_id`
instancesCols = []string{
"count",
"id",
"creation_date",
"change_date",
"sequence",
"name",
"default_org_id",
"iam_project_id",
"console_client_id",
"console_app_id",
"default_language",
"domain",
"is_primary",
"is_generated",
"creation_date",
"change_date",
"sequence",
}
)
func Test_InstancePrepares(t *testing.T) { func Test_InstancePrepares(t *testing.T) {
type want struct { type want struct {
sqlExpectations sqlExpectation sqlExpectations sqlExpectation
@ -32,16 +94,7 @@ func Test_InstancePrepares(t *testing.T) {
}, },
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.instances.id,`+ regexp.QuoteMeta(instanceQuery),
` projections.instances.creation_date,`+
` projections.instances.change_date,`+
` projections.instances.sequence,`+
` projections.instances.default_org_id,`+
` projections.instances.iam_project_id,`+
` projections.instances.console_client_id,`+
` projections.instances.console_app_id,`+
` projections.instances.default_language`+
` FROM projections.instances`),
nil, nil,
nil, nil,
), ),
@ -61,27 +114,8 @@ func Test_InstancePrepares(t *testing.T) {
}, },
want: want{ want: want{
sqlExpectations: mockQuery( sqlExpectations: mockQuery(
regexp.QuoteMeta(`SELECT projections.instances.id,`+ regexp.QuoteMeta(instanceQuery),
` projections.instances.creation_date,`+ instanceCols,
` projections.instances.change_date,`+
` projections.instances.sequence,`+
` projections.instances.default_org_id,`+
` projections.instances.iam_project_id,`+
` projections.instances.console_client_id,`+
` projections.instances.console_app_id,`+
` projections.instances.default_language`+
` FROM projections.instances`),
[]string{
"id",
"creation_date",
"change_date",
"sequence",
"default_org_id",
"iam_project_id",
"console_client_id",
"console_app_id",
"default_language",
},
[]driver.Value{ []driver.Value{
"id", "id",
testNow, testNow,
@ -114,16 +148,7 @@ func Test_InstancePrepares(t *testing.T) {
}, },
want: want{ want: want{
sqlExpectations: mockQueryErr( sqlExpectations: mockQueryErr(
regexp.QuoteMeta(`SELECT projections.instances.id,`+ regexp.QuoteMeta(instanceQuery),
` projections.instances.creation_date,`+
` projections.instances.change_date,`+
` projections.instances.sequence,`+
` projections.instances.default_org_id,`+
` projections.instances.iam_project_id,`+
` projections.instances.console_client_id,`+
` projections.instances.console_app_id,`+
` projections.instances.default_language`+
` FROM projections.instances`),
sql.ErrConnDone, sql.ErrConnDone,
), ),
err: func(err error) (error, bool) { err: func(err error) (error, bool) {
@ -143,25 +168,7 @@ func Test_InstancePrepares(t *testing.T) {
}, },
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT f.count, f.id,`+ regexp.QuoteMeta(instancesQuery),
` projections.instances.creation_date,`+
` projections.instances.change_date,`+
` projections.instances.sequence,`+
` projections.instances.name,`+
` projections.instances.default_org_id,`+
` projections.instances.iam_project_id,`+
` projections.instances.console_client_id,`+
` projections.instances.console_app_id,`+
` projections.instances.default_language,`+
` projections.instance_domains.domain,`+
` projections.instance_domains.is_primary,`+
` projections.instance_domains.is_generated,`+
` projections.instance_domains.creation_date,`+
` projections.instance_domains.change_date, `+
` projections.instance_domains.sequence`+
` FROM (SELECT projections.instances.id, COUNT(*) OVER () FROM projections.instances) AS f`+
` LEFT JOIN projections.instances ON f.id = projections.instances.id`+
` LEFT JOIN projections.instance_domains ON f.id = projections.instance_domains.instance_id`),
nil, nil,
nil, nil,
), ),
@ -176,44 +183,8 @@ func Test_InstancePrepares(t *testing.T) {
}, },
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT f.count, f.id,`+ regexp.QuoteMeta(instancesQuery),
` projections.instances.creation_date,`+ instancesCols,
` projections.instances.change_date,`+
` projections.instances.sequence,`+
` projections.instances.name,`+
` projections.instances.default_org_id,`+
` projections.instances.iam_project_id,`+
` projections.instances.console_client_id,`+
` projections.instances.console_app_id,`+
` projections.instances.default_language,`+
` projections.instance_domains.domain,`+
` projections.instance_domains.is_primary,`+
` projections.instance_domains.is_generated,`+
` projections.instance_domains.creation_date,`+
` projections.instance_domains.change_date, `+
` projections.instance_domains.sequence`+
` FROM (SELECT projections.instances.id, COUNT(*) OVER () FROM projections.instances) AS f`+
` LEFT JOIN projections.instances ON f.id = projections.instances.id`+
` LEFT JOIN projections.instance_domains ON f.id = projections.instance_domains.instance_id`),
[]string{
"count",
"id",
"creation_date",
"change_date",
"sequence",
"name",
"default_org_id",
"iam_project_id",
"console_client_id",
"console_app_id",
"default_language",
"domain",
"is_primary",
"is_generated",
"creation_date",
"change_date",
"sequence",
},
[][]driver.Value{ [][]driver.Value{
{ {
"1", "1",
@ -276,44 +247,8 @@ func Test_InstancePrepares(t *testing.T) {
}, },
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT f.count, f.id,`+ regexp.QuoteMeta(instancesQuery),
` projections.instances.creation_date,`+ instancesCols,
` projections.instances.change_date,`+
` projections.instances.sequence,`+
` projections.instances.name,`+
` projections.instances.default_org_id,`+
` projections.instances.iam_project_id,`+
` projections.instances.console_client_id,`+
` projections.instances.console_app_id,`+
` projections.instances.default_language,`+
` projections.instance_domains.domain,`+
` projections.instance_domains.is_primary,`+
` projections.instance_domains.is_generated,`+
` projections.instance_domains.creation_date,`+
` projections.instance_domains.change_date, `+
` projections.instance_domains.sequence`+
` FROM (SELECT projections.instances.id, COUNT(*) OVER () FROM projections.instances) AS f`+
` LEFT JOIN projections.instances ON f.id = projections.instances.id`+
` LEFT JOIN projections.instance_domains ON f.id = projections.instance_domains.instance_id`),
[]string{
"count",
"id",
"creation_date",
"change_date",
"sequence",
"name",
"default_org_id",
"iam_project_id",
"console_client_id",
"console_app_id",
"default_language",
"domain",
"is_primary",
"is_generated",
"creation_date",
"change_date",
"sequence",
},
[][]driver.Value{ [][]driver.Value{
{ {
2, 2,
@ -445,25 +380,7 @@ func Test_InstancePrepares(t *testing.T) {
}, },
want: want{ want: want{
sqlExpectations: mockQueryErr( sqlExpectations: mockQueryErr(
regexp.QuoteMeta(`SELECT f.count, f.id,`+ regexp.QuoteMeta(instancesQuery),
` projections.instances.creation_date,`+
` projections.instances.change_date,`+
` projections.instances.sequence,`+
` projections.instances.name,`+
` projections.instances.default_org_id,`+
` projections.instances.iam_project_id,`+
` projections.instances.console_client_id,`+
` projections.instances.console_app_id,`+
` projections.instances.default_language,`+
` projections.instance_domains.domain,`+
` projections.instance_domains.is_primary,`+
` projections.instance_domains.is_generated,`+
` projections.instance_domains.creation_date,`+
` projections.instance_domains.change_date, `+
` projections.instance_domains.sequence`+
` FROM (SELECT projections.instances.id, COUNT(*) OVER () FROM projections.instances) AS f`+
` LEFT JOIN projections.instances ON f.id = projections.instances.id`+
` LEFT JOIN projections.instance_domains ON f.id = projections.instance_domains.instance_id`),
sql.ErrConnDone, sql.ErrConnDone,
), ),
err: func(err error) (error, bool) { err: func(err error) (error, bool) {

View File

@ -101,7 +101,8 @@ func (r *rsaPublicKey) Key() interface{} {
var ( var (
keyTable = table{ keyTable = table{
name: projection.KeyProjectionTable, name: projection.KeyProjectionTable,
instanceIDCol: projection.KeyColumnInstanceID,
} }
KeyColID = Column{ KeyColID = Column{
name: projection.KeyColumnID, name: projection.KeyColumnID,
@ -139,7 +140,8 @@ var (
var ( var (
keyPrivateTable = table{ keyPrivateTable = table{
name: projection.KeyPrivateTable, name: projection.KeyPrivateTable,
instanceIDCol: projection.KeyPrivateColumnInstanceID,
} }
KeyPrivateColID = Column{ KeyPrivateColID = Column{
name: projection.KeyPrivateColumnID, name: projection.KeyPrivateColumnID,
@ -157,7 +159,8 @@ var (
var ( var (
keyPublicTable = table{ keyPublicTable = table{
name: projection.KeyPublicTable, name: projection.KeyPublicTable,
instanceIDCol: projection.KeyPrivateColumnInstanceID,
} }
KeyPublicColID = Column{ KeyPublicColID = Column{
name: projection.KeyPublicColumnID, name: projection.KeyPublicColumnID,

View File

@ -130,7 +130,8 @@ func (q *Queries) DefaultPreviewLabelPolicy(ctx context.Context) (*LabelPolicy,
var ( var (
labelPolicyTable = table{ labelPolicyTable = table{
name: projection.LabelPolicyTable, name: projection.LabelPolicyTable,
instanceIDCol: projection.LabelPolicyInstanceIDCol,
} }
LabelPolicyColCreationDate = Column{ LabelPolicyColCreationDate = Column{
name: projection.LabelPolicyCreationDateCol, name: projection.LabelPolicyCreationDateCol,

View File

@ -31,7 +31,8 @@ type LockoutPolicy struct {
var ( var (
lockoutTable = table{ lockoutTable = table{
name: projection.LockoutPolicyTable, name: projection.LockoutPolicyTable,
instanceIDCol: projection.LockoutPolicyInstanceIDCol,
} }
LockoutColID = Column{ LockoutColID = Column{
name: projection.LockoutPolicyIDCol, name: projection.LockoutPolicyIDCol,

View File

@ -4,7 +4,8 @@ import "github.com/zitadel/zitadel/internal/query/projection"
var ( var (
loginNameTable = table{ loginNameTable = table{
name: projection.LoginNameProjectionTable, name: projection.LoginNameProjectionTable,
instanceIDCol: projection.LoginNameUserInstanceIDCol,
} }
LoginNameUserIDCol = Column{ LoginNameUserIDCol = Column{
name: "user_id", name: "user_id",

View File

@ -54,7 +54,8 @@ type MultiFactors struct {
var ( var (
loginPolicyTable = table{ loginPolicyTable = table{
name: projection.LoginPolicyTable, name: projection.LoginPolicyTable,
instanceIDCol: projection.LoginPolicyInstanceIDCol,
} }
LoginPolicyColumnOrgID = Column{ LoginPolicyColumnOrgID = Column{
name: projection.LoginPolicyIDCol, name: projection.LoginPolicyIDCol,

View File

@ -14,6 +14,70 @@ import (
errs "github.com/zitadel/zitadel/internal/errors" errs "github.com/zitadel/zitadel/internal/errors"
) )
var (
loginPolicyQuery = `SELECT projections.login_policies3.aggregate_id,` +
` projections.login_policies3.creation_date,` +
` projections.login_policies3.change_date,` +
` projections.login_policies3.sequence,` +
` projections.login_policies3.allow_register,` +
` projections.login_policies3.allow_username_password,` +
` projections.login_policies3.allow_external_idps,` +
` projections.login_policies3.force_mfa,` +
` projections.login_policies3.second_factors,` +
` projections.login_policies3.multi_factors,` +
` projections.login_policies3.passwordless_type,` +
` projections.login_policies3.is_default,` +
` projections.login_policies3.hide_password_reset,` +
` projections.login_policies3.ignore_unknown_usernames,` +
` projections.login_policies3.allow_domain_discovery,` +
` projections.login_policies3.disable_login_with_email,` +
` projections.login_policies3.disable_login_with_phone,` +
` projections.login_policies3.default_redirect_uri,` +
` projections.login_policies3.password_check_lifetime,` +
` projections.login_policies3.external_login_check_lifetime,` +
` projections.login_policies3.mfa_init_skip_lifetime,` +
` projections.login_policies3.second_factor_check_lifetime,` +
` projections.login_policies3.multi_factor_check_lifetime,` +
` projections.idp_login_policy_links3.idp_id,` +
` projections.idps2.name,` +
` projections.idps2.type` +
` FROM projections.login_policies3` +
` LEFT JOIN projections.idp_login_policy_links3 ON ` +
` projections.login_policies3.aggregate_id = projections.idp_login_policy_links3.aggregate_id` +
` AND projections.login_policies3.instance_id = projections.idp_login_policy_links3.instance_id` +
` LEFT JOIN projections.idps2 ON` +
` projections.idp_login_policy_links3.idp_id = projections.idps2.id` +
` AND projections.idp_login_policy_links3.instance_id = projections.idps2.instance_id`
loginPolicyCols = []string{
"aggregate_id",
"creation_date",
"change_date",
"sequence",
"allow_register",
"allow_username_password",
"allow_external_idps",
"force_mfa",
"second_factors",
"multi_factors",
"passwordless_type",
"is_default",
"hide_password_reset",
"ignore_unknown_usernames",
"allow_domain_discovery",
"disable_login_with_email",
"disable_login_with_phone",
"default_redirect_uri",
"password_check_lifetime",
"external_login_check_lifetime",
"mfa_init_skip_lifetime",
"second_factor_check_lifetime",
"multi_factor_check_lifetime",
"idp_id",
"name",
"type",
}
)
func Test_LoginPolicyPrepares(t *testing.T) { func Test_LoginPolicyPrepares(t *testing.T) {
type want struct { type want struct {
sqlExpectations sqlExpectation sqlExpectations sqlExpectation
@ -30,37 +94,7 @@ func Test_LoginPolicyPrepares(t *testing.T) {
prepare: prepareLoginPolicyQuery, prepare: prepareLoginPolicyQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.login_policies3.aggregate_id,`+ regexp.QuoteMeta(loginPolicyQuery),
` projections.login_policies3.creation_date,`+
` projections.login_policies3.change_date,`+
` projections.login_policies3.sequence,`+
` projections.login_policies3.allow_register,`+
` projections.login_policies3.allow_username_password,`+
` projections.login_policies3.allow_external_idps,`+
` projections.login_policies3.force_mfa,`+
` projections.login_policies3.second_factors,`+
` projections.login_policies3.multi_factors,`+
` projections.login_policies3.passwordless_type,`+
` projections.login_policies3.is_default,`+
` projections.login_policies3.hide_password_reset,`+
` projections.login_policies3.ignore_unknown_usernames,`+
` projections.login_policies3.allow_domain_discovery,`+
` projections.login_policies3.disable_login_with_email,`+
` projections.login_policies3.disable_login_with_phone,`+
` projections.login_policies3.default_redirect_uri,`+
` projections.login_policies3.password_check_lifetime,`+
` projections.login_policies3.external_login_check_lifetime,`+
` projections.login_policies3.mfa_init_skip_lifetime,`+
` projections.login_policies3.second_factor_check_lifetime,`+
` projections.login_policies3.multi_factor_check_lifetime,`+
` projections.idp_login_policy_links3.idp_id,`+
` projections.idps2.name,`+
` projections.idps2.type`+
` FROM projections.login_policies3`+
` LEFT JOIN projections.idp_login_policy_links3 ON `+
` projections.login_policies3.aggregate_id = projections.idp_login_policy_links3.aggregate_id`+
` LEFT JOIN projections.idps2 ON`+
` projections.idp_login_policy_links3.idp_id = projections.idps2.id`),
nil, nil,
nil, nil,
), ),
@ -78,65 +112,8 @@ func Test_LoginPolicyPrepares(t *testing.T) {
prepare: prepareLoginPolicyQuery, prepare: prepareLoginPolicyQuery,
want: want{ want: want{
sqlExpectations: mockQuery( sqlExpectations: mockQuery(
regexp.QuoteMeta(`SELECT projections.login_policies3.aggregate_id,`+ regexp.QuoteMeta(loginPolicyQuery),
` projections.login_policies3.creation_date,`+ loginPolicyCols,
` projections.login_policies3.change_date,`+
` projections.login_policies3.sequence,`+
` projections.login_policies3.allow_register,`+
` projections.login_policies3.allow_username_password,`+
` projections.login_policies3.allow_external_idps,`+
` projections.login_policies3.force_mfa,`+
` projections.login_policies3.second_factors,`+
` projections.login_policies3.multi_factors,`+
` projections.login_policies3.passwordless_type,`+
` projections.login_policies3.is_default,`+
` projections.login_policies3.hide_password_reset,`+
` projections.login_policies3.ignore_unknown_usernames,`+
` projections.login_policies3.allow_domain_discovery,`+
` projections.login_policies3.disable_login_with_email,`+
` projections.login_policies3.disable_login_with_phone,`+
` projections.login_policies3.default_redirect_uri,`+
` projections.login_policies3.password_check_lifetime,`+
` projections.login_policies3.external_login_check_lifetime,`+
` projections.login_policies3.mfa_init_skip_lifetime,`+
` projections.login_policies3.second_factor_check_lifetime,`+
` projections.login_policies3.multi_factor_check_lifetime,`+
` projections.idp_login_policy_links3.idp_id,`+
` projections.idps2.name,`+
` projections.idps2.type`+
` FROM projections.login_policies3`+
` LEFT JOIN projections.idp_login_policy_links3 ON `+
` projections.login_policies3.aggregate_id = projections.idp_login_policy_links3.aggregate_id`+
` LEFT JOIN projections.idps2 ON`+
` projections.idp_login_policy_links3.idp_id = projections.idps2.id`),
[]string{
"aggregate_id",
"creation_date",
"change_date",
"sequence",
"allow_register",
"allow_username_password",
"allow_external_idps",
"force_mfa",
"second_factors",
"multi_factors",
"passwordless_type",
"is_default",
"hide_password_reset",
"ignore_unknown_usernames",
"allow_domain_discovery",
"disable_login_with_email",
"disable_login_with_phone",
"default_redirect_uri",
"password_check_lifetime",
"external_login_check_lifetime",
"mfa_init_skip_lifetime",
"second_factor_check_lifetime",
"multi_factor_check_lifetime",
"idp_id",
"name",
"type",
},
[]driver.Value{ []driver.Value{
"ro", "ro",
testNow, testNow,
@ -205,37 +182,7 @@ func Test_LoginPolicyPrepares(t *testing.T) {
prepare: prepareLoginPolicyQuery, prepare: prepareLoginPolicyQuery,
want: want{ want: want{
sqlExpectations: mockQueryErr( sqlExpectations: mockQueryErr(
regexp.QuoteMeta(`SELECT projections.login_policies3.aggregate_id,`+ regexp.QuoteMeta(loginPolicyQuery),
` projections.login_policies3.creation_date,`+
` projections.login_policies3.change_date,`+
` projections.login_policies3.sequence,`+
` projections.login_policies3.allow_register,`+
` projections.login_policies3.allow_username_password,`+
` projections.login_policies3.allow_external_idps,`+
` projections.login_policies3.force_mfa,`+
` projections.login_policies3.second_factors,`+
` projections.login_policies3.multi_factors,`+
` projections.login_policies3.passwordless_type,`+
` projections.login_policies3.is_default,`+
` projections.login_policies3.hide_password_reset,`+
` projections.login_policies3.ignore_unknown_usernames,`+
` projections.login_policies3.allow_domain_discovery,`+
` projections.login_policies3.disable_login_with_email,`+
` projections.login_policies3.disable_login_with_phone,`+
` projections.login_policies3.default_redirect_uri,`+
` projections.login_policies3.password_check_lifetime,`+
` projections.login_policies3.external_login_check_lifetime,`+
` projections.login_policies3.mfa_init_skip_lifetime,`+
` projections.login_policies3.second_factor_check_lifetime,`+
` projections.login_policies3.multi_factor_check_lifetime,`+
` projections.idp_login_policy_links3.idp_id,`+
` projections.idps2.name,`+
` projections.idps2.type`+
` FROM projections.login_policies3`+
` LEFT JOIN projections.idp_login_policy_links3 ON `+
` projections.login_policies3.aggregate_id = projections.idp_login_policy_links3.aggregate_id`+
` LEFT JOIN projections.idps2 ON`+
` projections.idp_login_policy_links3.idp_id = projections.idps2.id`),
sql.ErrConnDone, sql.ErrConnDone,
), ),
err: func(err error) (error, bool) { err: func(err error) (error, bool) {

View File

@ -27,7 +27,8 @@ type MailTemplate struct {
var ( var (
mailTemplateTable = table{ mailTemplateTable = table{
name: projection.MailTemplateTable, name: projection.MailTemplateTable,
instanceIDCol: projection.MailTemplateInstanceIDCol,
} }
MailTemplateColAggregateID = Column{ MailTemplateColAggregateID = Column{
name: projection.MailTemplateAggregateIDCol, name: projection.MailTemplateAggregateIDCol,

View File

@ -64,8 +64,9 @@ type Member struct {
var ( var (
memberTableAlias = table{ memberTableAlias = table{
name: "members", name: "members",
alias: "members", alias: "members",
instanceIDCol: projection.MemberInstanceID,
} }
memberUserID = Column{ memberUserID = Column{
name: projection.MemberUserIDCol, name: projection.MemberUserIDCol,

View File

@ -53,7 +53,8 @@ type MessageText struct {
var ( var (
messageTextTable = table{ messageTextTable = table{
name: projection.MessageTextTable, name: projection.MessageTextTable,
instanceIDCol: projection.MessageTextInstanceIDCol,
} }
MessageTextColAggregateID = Column{ MessageTextColAggregateID = Column{
name: projection.MessageTextAggregateIDCol, name: projection.MessageTextAggregateIDCol,

View File

@ -28,7 +28,8 @@ type DebugNotificationProvider struct {
var ( var (
notificationProviderTable = table{ notificationProviderTable = table{
name: projection.DebugNotificationProviderTable, name: projection.DebugNotificationProviderTable,
instanceIDCol: projection.DebugNotificationProviderInstanceIDCol,
} }
NotificationProviderColumnAggID = Column{ NotificationProviderColumnAggID = Column{
name: projection.DebugNotificationProviderAggIDCol, name: projection.DebugNotificationProviderAggIDCol,

View File

@ -15,7 +15,8 @@ import (
var ( var (
oidcSettingsTable = table{ oidcSettingsTable = table{
name: projection.OIDCSettingsProjectionTable, name: projection.OIDCSettingsProjectionTable,
instanceIDCol: projection.OIDCSettingsColumnInstanceID,
} }
OIDCSettingsColumnAggregateID = Column{ OIDCSettingsColumnAggregateID = Column{
name: projection.OIDCSettingsColumnAggregateID, name: projection.OIDCSettingsColumnAggregateID,

View File

@ -16,7 +16,8 @@ import (
var ( var (
orgsTable = table{ orgsTable = table{
name: projection.OrgProjectionTable, name: projection.OrgProjectionTable,
instanceIDCol: projection.OrgColumnInstanceID,
} }
OrgColumnID = Column{ OrgColumnID = Column{
name: projection.OrgColumnID, name: projection.OrgColumnID,

View File

@ -125,7 +125,8 @@ func prepareDomainsQuery() (sq.SelectBuilder, func(*sql.Rows) (*Domains, error))
var ( var (
orgDomainsTable = table{ orgDomainsTable = table{
name: projection.OrgDomainTable, name: projection.OrgDomainTable,
instanceIDCol: projection.OrgDomainInstanceIDCol,
} }
OrgDomainCreationDateCol = Column{ OrgDomainCreationDateCol = Column{

View File

@ -13,8 +13,9 @@ import (
var ( var (
orgMemberTable = table{ orgMemberTable = table{
name: projection.OrgMemberProjectionTable, name: projection.OrgMemberProjectionTable,
alias: "members", alias: "members",
instanceIDCol: projection.MemberInstanceID,
} }
OrgMemberUserID = Column{ OrgMemberUserID = Column{
name: projection.MemberUserIDCol, name: projection.MemberUserIDCol,

View File

@ -30,10 +30,13 @@ var (
"FROM projections.org_members2 AS members " + "FROM projections.org_members2 AS members " +
"LEFT JOIN projections.users4_humans " + "LEFT JOIN projections.users4_humans " +
"ON members.user_id = projections.users4_humans.user_id " + "ON members.user_id = projections.users4_humans.user_id " +
"AND members.instance_id = projections.users4_humans.instance_id " +
"LEFT JOIN projections.users4_machines " + "LEFT JOIN projections.users4_machines " +
"ON members.user_id = projections.users4_machines.user_id " + "ON members.user_id = projections.users4_machines.user_id " +
"AND members.instance_id = projections.users4_machines.instance_id " +
"LEFT JOIN projections.login_names " + "LEFT JOIN projections.login_names " +
"ON members.user_id = projections.login_names.user_id " + "ON members.user_id = projections.login_names.user_id " +
"AND members.instance_id = projections.login_names.instance_id " +
"WHERE projections.login_names.is_primary = $1") "WHERE projections.login_names.is_primary = $1")
orgMembersColumns = []string{ orgMembersColumns = []string{
"creation_date", "creation_date",

View File

@ -34,7 +34,8 @@ type OrgMetadataSearchQueries struct {
var ( var (
orgMetadataTable = table{ orgMetadataTable = table{
name: projection.OrgMetadataProjectionTable, name: projection.OrgMetadataProjectionTable,
instanceIDCol: projection.OrgMetadataColumnInstanceID,
} }
OrgMetadataOrgIDCol = Column{ OrgMetadataOrgIDCol = Column{
name: projection.OrgMetadataColumnOrgID, name: projection.OrgMetadataColumnOrgID,

View File

@ -30,7 +30,8 @@ type PasswordAgePolicy struct {
var ( var (
passwordAgeTable = table{ passwordAgeTable = table{
name: projection.PasswordAgeTable, name: projection.PasswordAgeTable,
instanceIDCol: projection.AgePolicyInstanceIDCol,
} }
PasswordAgeColID = Column{ PasswordAgeColID = Column{
name: projection.AgePolicyIDCol, name: projection.AgePolicyIDCol,

View File

@ -83,7 +83,8 @@ func (q *Queries) DefaultPasswordComplexityPolicy(ctx context.Context, shouldTri
var ( var (
passwordComplexityTable = table{ passwordComplexityTable = table{
name: projection.PasswordComplexityTable, name: projection.PasswordComplexityTable,
instanceIDCol: projection.ComplexityPolicyInstanceIDCol,
} }
PasswordComplexityColID = Column{ PasswordComplexityColID = Column{
name: projection.ComplexityPolicyIDCol, name: projection.ComplexityPolicyIDCol,

View File

@ -31,7 +31,8 @@ type PrivacyPolicy struct {
var ( var (
privacyTable = table{ privacyTable = table{
name: projection.PrivacyPolicyTable, name: projection.PrivacyPolicyTable,
instanceIDCol: projection.PrivacyPolicyInstanceIDCol,
} }
PrivacyColID = Column{ PrivacyColID = Column{
name: projection.PrivacyPolicyIDCol, name: projection.PrivacyPolicyIDCol,

View File

@ -17,7 +17,8 @@ import (
var ( var (
projectsTable = table{ projectsTable = table{
name: projection.ProjectProjectionTable, name: projection.ProjectProjectionTable,
instanceIDCol: projection.ProjectColumnInstanceID,
} }
ProjectColumnID = Column{ ProjectColumnID = Column{
name: projection.ProjectColumnID, name: projection.ProjectColumnID,

View File

@ -23,7 +23,8 @@ const (
var ( var (
projectGrantsTable = table{ projectGrantsTable = table{
name: projection.ProjectGrantProjectionTable, name: projection.ProjectGrantProjectionTable,
instanceIDCol: projection.ProjectGrantColumnInstanceID,
} }
ProjectGrantColumnCreationDate = Column{ ProjectGrantColumnCreationDate = Column{
name: projection.ProjectGrantColumnCreationDate, name: projection.ProjectGrantColumnCreationDate,

View File

@ -14,8 +14,9 @@ import (
var ( var (
projectGrantMemberTable = table{ projectGrantMemberTable = table{
name: projection.ProjectGrantMemberProjectionTable, name: projection.ProjectGrantMemberProjectionTable,
alias: "members", alias: "members",
instanceIDCol: projection.MemberInstanceID,
} }
ProjectGrantMemberUserID = Column{ ProjectGrantMemberUserID = Column{
name: projection.MemberUserIDCol, name: projection.MemberUserIDCol,

View File

@ -30,12 +30,16 @@ var (
"FROM projections.project_grant_members2 AS members " + "FROM projections.project_grant_members2 AS members " +
"LEFT JOIN projections.users4_humans " + "LEFT JOIN projections.users4_humans " +
"ON members.user_id = projections.users4_humans.user_id " + "ON members.user_id = projections.users4_humans.user_id " +
"AND members.instance_id = projections.users4_humans.instance_id " +
"LEFT JOIN projections.users4_machines " + "LEFT JOIN projections.users4_machines " +
"ON members.user_id = projections.users4_machines.user_id " + "ON members.user_id = projections.users4_machines.user_id " +
"AND members.instance_id = projections.users4_machines.instance_id " +
"LEFT JOIN projections.login_names " + "LEFT JOIN projections.login_names " +
"ON members.user_id = projections.login_names.user_id " + "ON members.user_id = projections.login_names.user_id " +
"AND members.instance_id = projections.login_names.instance_id " +
"LEFT JOIN projections.project_grants2 " + "LEFT JOIN projections.project_grants2 " +
"ON members.grant_id = projections.project_grants2.grant_id " + "ON members.grant_id = projections.project_grants2.grant_id " +
"AND members.instance_id = projections.project_grants2.instance_id " +
"WHERE projections.login_names.is_primary = $1") "WHERE projections.login_names.is_primary = $1")
projectGrantMembersColumns = []string{ projectGrantMembersColumns = []string{
"creation_date", "creation_date",

View File

@ -13,6 +13,71 @@ import (
errs "github.com/zitadel/zitadel/internal/errors" errs "github.com/zitadel/zitadel/internal/errors"
) )
var (
projectGrantsQuery = `SELECT projections.project_grants2.project_id,` +
` projections.project_grants2.grant_id,` +
` projections.project_grants2.creation_date,` +
` projections.project_grants2.change_date,` +
` projections.project_grants2.resource_owner,` +
` projections.project_grants2.state,` +
` projections.project_grants2.sequence,` +
` projections.projects2.name,` +
` projections.project_grants2.granted_org_id,` +
` o.name,` +
` projections.project_grants2.granted_role_keys,` +
` r.name,` +
` COUNT(*) OVER () ` +
` FROM projections.project_grants2 ` +
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id AND projections.project_grants2.instance_id = projections.projects2.instance_id ` +
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id AND projections.project_grants2.instance_id = r.instance_id` +
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id AND projections.project_grants2.instance_id = o.instance_id`
projectGrantsCols = []string{
"project_id",
"grant_id",
"creation_date",
"change_date",
"resource_owner",
"state",
"sequence",
"name",
"granted_org_id",
"name",
"granted_role_keys",
"name",
"count",
}
projectGrantQuery = `SELECT projections.project_grants2.project_id,` +
` projections.project_grants2.grant_id,` +
` projections.project_grants2.creation_date,` +
` projections.project_grants2.change_date,` +
` projections.project_grants2.resource_owner,` +
` projections.project_grants2.state,` +
` projections.project_grants2.sequence,` +
` projections.projects2.name,` +
` projections.project_grants2.granted_org_id,` +
` o.name,` +
` projections.project_grants2.granted_role_keys,` +
` r.name` +
` FROM projections.project_grants2 ` +
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id AND projections.project_grants2.instance_id = projections.projects2.instance_id ` +
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id AND projections.project_grants2.instance_id = r.instance_id` +
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id AND projections.project_grants2.instance_id = o.instance_id`
projectGrantCols = []string{
"project_id",
"grant_id",
"creation_date",
"change_date",
"resource_owner",
"state",
"sequence",
"name",
"granted_org_id",
"name",
"granted_role_keys",
"name",
}
)
func Test_ProjectGrantPrepares(t *testing.T) { func Test_ProjectGrantPrepares(t *testing.T) {
type want struct { type want struct {
sqlExpectations sqlExpectation sqlExpectations sqlExpectation
@ -29,23 +94,7 @@ func Test_ProjectGrantPrepares(t *testing.T) {
prepare: prepareProjectGrantsQuery, prepare: prepareProjectGrantsQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(` SELECT projections.project_grants2.project_id,`+ regexp.QuoteMeta(projectGrantsQuery),
` projections.project_grants2.grant_id,`+
` projections.project_grants2.creation_date,`+
` projections.project_grants2.change_date,`+
` projections.project_grants2.resource_owner,`+
` projections.project_grants2.state,`+
` projections.project_grants2.sequence,`+
` projections.projects2.name,`+
` projections.project_grants2.granted_org_id,`+
` o.name,`+
` projections.project_grants2.granted_role_keys,`+
` r.name,`+
` COUNT(*) OVER () `+
` FROM projections.project_grants2 `+
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id `+
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id`+
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id`),
nil, nil,
nil, nil,
), ),
@ -57,38 +106,8 @@ func Test_ProjectGrantPrepares(t *testing.T) {
prepare: prepareProjectGrantsQuery, prepare: prepareProjectGrantsQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(` SELECT projections.project_grants2.project_id,`+ regexp.QuoteMeta(projectGrantsQuery),
` projections.project_grants2.grant_id,`+ projectGrantsCols,
` projections.project_grants2.creation_date,`+
` projections.project_grants2.change_date,`+
` projections.project_grants2.resource_owner,`+
` projections.project_grants2.state,`+
` projections.project_grants2.sequence,`+
` projections.projects2.name,`+
` projections.project_grants2.granted_org_id,`+
` o.name,`+
` projections.project_grants2.granted_role_keys,`+
` r.name,`+
` COUNT(*) OVER ()`+
` FROM projections.project_grants2`+
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id`+
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id`+
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id`),
[]string{
"project_id",
"grant_id",
"creation_date",
"change_date",
"resource_owner",
"state",
"sequence",
"name",
"granted_org_id",
"name",
"granted_role_keys",
"name",
"count",
},
[][]driver.Value{ [][]driver.Value{
{ {
"project-id", "project-id",
@ -134,38 +153,8 @@ func Test_ProjectGrantPrepares(t *testing.T) {
prepare: prepareProjectGrantsQuery, prepare: prepareProjectGrantsQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(` SELECT projections.project_grants2.project_id,`+ regexp.QuoteMeta(projectGrantsQuery),
` projections.project_grants2.grant_id,`+ projectGrantsCols,
` projections.project_grants2.creation_date,`+
` projections.project_grants2.change_date,`+
` projections.project_grants2.resource_owner,`+
` projections.project_grants2.state,`+
` projections.project_grants2.sequence,`+
` projections.projects2.name,`+
` projections.project_grants2.granted_org_id,`+
` o.name,`+
` projections.project_grants2.granted_role_keys,`+
` r.name,`+
` COUNT(*) OVER () `+
` FROM projections.project_grants2 `+
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id `+
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id`+
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id`),
[]string{
"project_id",
"grant_id",
"creation_date",
"change_date",
"resource_owner",
"state",
"sequence",
"name",
"granted_org_id",
"name",
"granted_role_keys",
"name",
"count",
},
[][]driver.Value{ [][]driver.Value{
{ {
"project-id", "project-id",
@ -211,38 +200,8 @@ func Test_ProjectGrantPrepares(t *testing.T) {
prepare: prepareProjectGrantsQuery, prepare: prepareProjectGrantsQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(` SELECT projections.project_grants2.project_id,`+ regexp.QuoteMeta(projectGrantsQuery),
` projections.project_grants2.grant_id,`+ projectGrantsCols,
` projections.project_grants2.creation_date,`+
` projections.project_grants2.change_date,`+
` projections.project_grants2.resource_owner,`+
` projections.project_grants2.state,`+
` projections.project_grants2.sequence,`+
` projections.projects2.name,`+
` projections.project_grants2.granted_org_id,`+
` o.name,`+
` projections.project_grants2.granted_role_keys,`+
` r.name,`+
` COUNT(*) OVER () `+
` FROM projections.project_grants2 `+
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id `+
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id`+
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id`),
[]string{
"project_id",
"grant_id",
"creation_date",
"change_date",
"resource_owner",
"state",
"sequence",
"name",
"granted_org_id",
"name",
"granted_role_keys",
"name",
"count",
},
[][]driver.Value{ [][]driver.Value{
{ {
"project-id", "project-id",
@ -288,38 +247,8 @@ func Test_ProjectGrantPrepares(t *testing.T) {
prepare: prepareProjectGrantsQuery, prepare: prepareProjectGrantsQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(` SELECT projections.project_grants2.project_id,`+ regexp.QuoteMeta(projectGrantsQuery),
` projections.project_grants2.grant_id,`+ projectGrantsCols,
` projections.project_grants2.creation_date,`+
` projections.project_grants2.change_date,`+
` projections.project_grants2.resource_owner,`+
` projections.project_grants2.state,`+
` projections.project_grants2.sequence,`+
` projections.projects2.name,`+
` projections.project_grants2.granted_org_id,`+
` o.name,`+
` projections.project_grants2.granted_role_keys,`+
` r.name,`+
` COUNT(*) OVER () `+
` FROM projections.project_grants2 `+
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id `+
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id`+
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id`),
[]string{
"project_id",
"grant_id",
"creation_date",
"change_date",
"resource_owner",
"state",
"sequence",
"name",
"granted_org_id",
"name",
"granted_role_keys",
"name",
"count",
},
[][]driver.Value{ [][]driver.Value{
{ {
"project-id", "project-id",
@ -365,38 +294,8 @@ func Test_ProjectGrantPrepares(t *testing.T) {
prepare: prepareProjectGrantsQuery, prepare: prepareProjectGrantsQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(` SELECT projections.project_grants2.project_id,`+ regexp.QuoteMeta(projectGrantsQuery),
` projections.project_grants2.grant_id,`+ projectGrantsCols,
` projections.project_grants2.creation_date,`+
` projections.project_grants2.change_date,`+
` projections.project_grants2.resource_owner,`+
` projections.project_grants2.state,`+
` projections.project_grants2.sequence,`+
` projections.projects2.name,`+
` projections.project_grants2.granted_org_id,`+
` o.name,`+
` projections.project_grants2.granted_role_keys,`+
` r.name,`+
` COUNT(*) OVER () `+
` FROM projections.project_grants2 `+
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id `+
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id`+
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id`),
[]string{
"project_id",
"grant_id",
"creation_date",
"change_date",
"resource_owner",
"state",
"sequence",
"name",
"granted_org_id",
"name",
"granted_role_keys",
"name",
"count",
},
[][]driver.Value{ [][]driver.Value{
{ {
"project-id", "project-id",
@ -470,23 +369,7 @@ func Test_ProjectGrantPrepares(t *testing.T) {
prepare: prepareProjectGrantsQuery, prepare: prepareProjectGrantsQuery,
want: want{ want: want{
sqlExpectations: mockQueryErr( sqlExpectations: mockQueryErr(
regexp.QuoteMeta(` SELECT projections.project_grants2.project_id,`+ regexp.QuoteMeta(projectGrantsQuery),
` projections.project_grants2.grant_id,`+
` projections.project_grants2.creation_date,`+
` projections.project_grants2.change_date,`+
` projections.project_grants2.resource_owner,`+
` projections.project_grants2.state,`+
` projections.project_grants2.sequence,`+
` projections.projects2.name,`+
` projections.project_grants2.granted_org_id,`+
` o.name,`+
` projections.project_grants2.granted_role_keys,`+
` r.name,`+
` COUNT(*) OVER () `+
` FROM projections.project_grants2 `+
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id `+
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id`+
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id`),
sql.ErrConnDone, sql.ErrConnDone,
), ),
err: func(err error) (error, bool) { err: func(err error) (error, bool) {
@ -503,22 +386,7 @@ func Test_ProjectGrantPrepares(t *testing.T) {
prepare: prepareProjectGrantQuery, prepare: prepareProjectGrantQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(` SELECT projections.project_grants2.project_id,`+ regexp.QuoteMeta(projectGrantQuery),
` projections.project_grants2.grant_id,`+
` projections.project_grants2.creation_date,`+
` projections.project_grants2.change_date,`+
` projections.project_grants2.resource_owner,`+
` projections.project_grants2.state,`+
` projections.project_grants2.sequence,`+
` projections.projects2.name,`+
` projections.project_grants2.granted_org_id,`+
` o.name,`+
` projections.project_grants2.granted_role_keys,`+
` r.name`+
` FROM projections.project_grants2 `+
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id `+
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id`+
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id`),
nil, nil,
nil, nil,
), ),
@ -536,36 +404,8 @@ func Test_ProjectGrantPrepares(t *testing.T) {
prepare: prepareProjectGrantQuery, prepare: prepareProjectGrantQuery,
want: want{ want: want{
sqlExpectations: mockQuery( sqlExpectations: mockQuery(
regexp.QuoteMeta(` SELECT projections.project_grants2.project_id,`+ regexp.QuoteMeta(projectGrantQuery),
` projections.project_grants2.grant_id,`+ projectGrantCols,
` projections.project_grants2.creation_date,`+
` projections.project_grants2.change_date,`+
` projections.project_grants2.resource_owner,`+
` projections.project_grants2.state,`+
` projections.project_grants2.sequence,`+
` projections.projects2.name,`+
` projections.project_grants2.granted_org_id,`+
` o.name,`+
` projections.project_grants2.granted_role_keys,`+
` r.name`+
` FROM projections.project_grants2 `+
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id `+
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id`+
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id`),
[]string{
"project_id",
"grant_id",
"creation_date",
"change_date",
"resource_owner",
"state",
"sequence",
"name",
"granted_org_id",
"name",
"granted_role_keys",
"name",
},
[]driver.Value{ []driver.Value{
"project-id", "project-id",
"grant-id", "grant-id",
@ -602,36 +442,8 @@ func Test_ProjectGrantPrepares(t *testing.T) {
prepare: prepareProjectGrantQuery, prepare: prepareProjectGrantQuery,
want: want{ want: want{
sqlExpectations: mockQuery( sqlExpectations: mockQuery(
regexp.QuoteMeta(` SELECT projections.project_grants2.project_id,`+ regexp.QuoteMeta(projectGrantQuery),
` projections.project_grants2.grant_id,`+ projectGrantCols,
` projections.project_grants2.creation_date,`+
` projections.project_grants2.change_date,`+
` projections.project_grants2.resource_owner,`+
` projections.project_grants2.state,`+
` projections.project_grants2.sequence,`+
` projections.projects2.name,`+
` projections.project_grants2.granted_org_id,`+
` o.name,`+
` projections.project_grants2.granted_role_keys,`+
` r.name`+
` FROM projections.project_grants2 `+
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id `+
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id`+
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id`),
[]string{
"project_id",
"grant_id",
"creation_date",
"change_date",
"resource_owner",
"state",
"sequence",
"name",
"granted_org_id",
"name",
"granted_role_keys",
"name",
},
[]driver.Value{ []driver.Value{
"project-id", "project-id",
"grant-id", "grant-id",
@ -668,36 +480,8 @@ func Test_ProjectGrantPrepares(t *testing.T) {
prepare: prepareProjectGrantQuery, prepare: prepareProjectGrantQuery,
want: want{ want: want{
sqlExpectations: mockQuery( sqlExpectations: mockQuery(
regexp.QuoteMeta(` SELECT projections.project_grants2.project_id,`+ regexp.QuoteMeta(projectGrantQuery),
` projections.project_grants2.grant_id,`+ projectGrantCols,
` projections.project_grants2.creation_date,`+
` projections.project_grants2.change_date,`+
` projections.project_grants2.resource_owner,`+
` projections.project_grants2.state,`+
` projections.project_grants2.sequence,`+
` projections.projects2.name,`+
` projections.project_grants2.granted_org_id,`+
` o.name,`+
` projections.project_grants2.granted_role_keys,`+
` r.name`+
` FROM projections.project_grants2 `+
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id `+
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id`+
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id`),
[]string{
"project_id",
"grant_id",
"creation_date",
"change_date",
"resource_owner",
"state",
"sequence",
"name",
"granted_org_id",
"name",
"granted_role_keys",
"name",
},
[]driver.Value{ []driver.Value{
"project-id", "project-id",
"grant-id", "grant-id",
@ -734,36 +518,8 @@ func Test_ProjectGrantPrepares(t *testing.T) {
prepare: prepareProjectGrantQuery, prepare: prepareProjectGrantQuery,
want: want{ want: want{
sqlExpectations: mockQuery( sqlExpectations: mockQuery(
regexp.QuoteMeta(` SELECT projections.project_grants2.project_id,`+ regexp.QuoteMeta(projectGrantQuery),
` projections.project_grants2.grant_id,`+ projectGrantCols,
` projections.project_grants2.creation_date,`+
` projections.project_grants2.change_date,`+
` projections.project_grants2.resource_owner,`+
` projections.project_grants2.state,`+
` projections.project_grants2.sequence,`+
` projections.projects2.name,`+
` projections.project_grants2.granted_org_id,`+
` o.name,`+
` projections.project_grants2.granted_role_keys,`+
` r.name`+
` FROM projections.project_grants2 `+
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id `+
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id`+
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id`),
[]string{
"project_id",
"grant_id",
"creation_date",
"change_date",
"resource_owner",
"state",
"sequence",
"name",
"granted_org_id",
"name",
"granted_role_keys",
"name",
},
[]driver.Value{ []driver.Value{
"project-id", "project-id",
"grant-id", "grant-id",
@ -800,22 +556,7 @@ func Test_ProjectGrantPrepares(t *testing.T) {
prepare: prepareProjectGrantQuery, prepare: prepareProjectGrantQuery,
want: want{ want: want{
sqlExpectations: mockQueryErr( sqlExpectations: mockQueryErr(
regexp.QuoteMeta(` SELECT projections.project_grants2.project_id,`+ regexp.QuoteMeta(projectGrantQuery),
` projections.project_grants2.grant_id,`+
` projections.project_grants2.creation_date,`+
` projections.project_grants2.change_date,`+
` projections.project_grants2.resource_owner,`+
` projections.project_grants2.state,`+
` projections.project_grants2.sequence,`+
` projections.projects2.name,`+
` projections.project_grants2.granted_org_id,`+
` o.name,`+
` projections.project_grants2.granted_role_keys,`+
` r.name`+
` FROM projections.project_grants2 `+
` LEFT JOIN projections.projects2 ON projections.project_grants2.project_id = projections.projects2.id `+
` LEFT JOIN projections.orgs AS r ON projections.project_grants2.resource_owner = r.id`+
` LEFT JOIN projections.orgs AS o ON projections.project_grants2.granted_org_id = o.id`),
sql.ErrConnDone, sql.ErrConnDone,
), ),
err: func(err error) (error, bool) { err: func(err error) (error, bool) {

View File

@ -14,8 +14,9 @@ import (
var ( var (
projectMemberTable = table{ projectMemberTable = table{
name: projection.ProjectMemberProjectionTable, name: projection.ProjectMemberProjectionTable,
alias: "members", alias: "members",
instanceIDCol: projection.MemberInstanceID,
} }
ProjectMemberUserID = Column{ ProjectMemberUserID = Column{
name: projection.MemberUserIDCol, name: projection.MemberUserIDCol,

View File

@ -30,10 +30,13 @@ var (
"FROM projections.project_members2 AS members " + "FROM projections.project_members2 AS members " +
"LEFT JOIN projections.users4_humans " + "LEFT JOIN projections.users4_humans " +
"ON members.user_id = projections.users4_humans.user_id " + "ON members.user_id = projections.users4_humans.user_id " +
"AND members.instance_id = projections.users4_humans.instance_id " +
"LEFT JOIN projections.users4_machines " + "LEFT JOIN projections.users4_machines " +
"ON members.user_id = projections.users4_machines.user_id " + "ON members.user_id = projections.users4_machines.user_id " +
"AND members.instance_id = projections.users4_machines.instance_id " +
"LEFT JOIN projections.login_names " + "LEFT JOIN projections.login_names " +
"ON members.user_id = projections.login_names.user_id " + "ON members.user_id = projections.login_names.user_id " +
"AND members.instance_id = projections.login_names.instance_id " +
"WHERE projections.login_names.is_primary = $1") "WHERE projections.login_names.is_primary = $1")
projectMembersColumns = []string{ projectMembersColumns = []string{
"creation_date", "creation_date",

View File

@ -14,7 +14,8 @@ import (
var ( var (
projectRolesTable = table{ projectRolesTable = table{
name: projection.ProjectRoleProjectionTable, name: projection.ProjectRoleProjectionTable,
instanceIDCol: projection.ProjectRoleColumnInstanceID,
} }
ProjectRoleColumnCreationDate = Column{ ProjectRoleColumnCreationDate = Column{
name: projection.ProjectRoleColumnCreationDate, name: projection.ProjectRoleColumnCreationDate,

View File

@ -365,8 +365,9 @@ var (
) )
type table struct { type table struct {
name string name string
alias string alias string
instanceIDCol string
} }
func (t table) setAlias(a string) table { func (t table) setAlias(a string) table {
@ -385,6 +386,13 @@ func (t table) isZero() bool {
return t.name == "" return t.name == ""
} }
func (t table) InstanceIDIdentifier() string {
if t.alias != "" {
return t.alias + "." + t.instanceIDCol
}
return t.name + "." + t.instanceIDCol
}
type Column struct { type Column struct {
name string name string
table table table table
@ -418,7 +426,7 @@ func (c Column) isZero() bool {
} }
func join(join, from Column) string { func join(join, from Column) string {
return join.table.identifier() + " ON " + from.identifier() + " = " + join.identifier() return join.table.identifier() + " ON " + from.identifier() + " = " + join.identifier() + " AND " + from.table.InstanceIDIdentifier() + " = " + join.table.InstanceIDIdentifier()
} }
type listContains struct { type listContains struct {

View File

@ -6,13 +6,15 @@ import (
"testing" "testing"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/domain"
) )
var ( var (
testTable = table{ testTable = table{
name: "test_table", name: "test_table",
alias: "test_table", alias: "test_table",
instanceIDCol: "instance_id",
} }
testCol = Column{ testCol = Column{
name: "test_col", name: "test_col",

View File

@ -19,7 +19,8 @@ import (
var ( var (
secretGeneratorsTable = table{ secretGeneratorsTable = table{
name: projection.SecretGeneratorProjectionTable, name: projection.SecretGeneratorProjectionTable,
instanceIDCol: projection.SecretGeneratorColumnInstanceID,
} }
SecretGeneratorColumnAggregateID = Column{ SecretGeneratorColumnAggregateID = Column{
name: projection.SecretGeneratorColumnAggregateID, name: projection.SecretGeneratorColumnAggregateID,

View File

@ -53,7 +53,8 @@ func (q *SMSConfigsSearchQueries) toQuery(query sq.SelectBuilder) sq.SelectBuild
var ( var (
smsConfigsTable = table{ smsConfigsTable = table{
name: projection.SMSConfigProjectionTable, name: projection.SMSConfigProjectionTable,
instanceIDCol: projection.SMSColumnInstanceID,
} }
SMSConfigColumnID = Column{ SMSConfigColumnID = Column{
name: projection.SMSColumnID, name: projection.SMSColumnID,
@ -91,7 +92,8 @@ var (
var ( var (
smsTwilioConfigsTable = table{ smsTwilioConfigsTable = table{
name: projection.SMSTwilioTable, name: projection.SMSTwilioTable,
instanceIDCol: projection.SMSTwilioColumnInstanceID,
} }
SMSTwilioConfigColumnSMSID = Column{ SMSTwilioConfigColumnSMSID = Column{
name: projection.SMSTwilioConfigColumnSMSID, name: projection.SMSTwilioConfigColumnSMSID,

View File

@ -18,7 +18,8 @@ import (
var ( var (
smtpConfigsTable = table{ smtpConfigsTable = table{
name: projection.SMTPConfigProjectionTable, name: projection.SMTPConfigProjectionTable,
instanceIDCol: projection.SMTPConfigColumnInstanceID,
} }
SMTPConfigColumnAggregateID = Column{ SMTPConfigColumnAggregateID = Column{
name: projection.SMTPConfigColumnAggregateID, name: projection.SMTPConfigColumnAggregateID,

View File

@ -122,7 +122,8 @@ type UserSearchQueries struct {
var ( var (
userTable = table{ userTable = table{
name: projection.UserTable, name: projection.UserTable,
instanceIDCol: projection.UserInstanceIDCol,
} }
UserIDCol = Column{ UserIDCol = Column{
name: projection.UserIDCol, name: projection.UserIDCol,
@ -179,7 +180,8 @@ var (
var ( var (
humanTable = table{ humanTable = table{
name: projection.UserHumanTable, name: projection.UserHumanTable,
instanceIDCol: projection.HumanUserInstanceIDCol,
} }
// profile // profile
HumanUserIDCol = Column{ HumanUserIDCol = Column{
@ -243,7 +245,8 @@ var (
var ( var (
machineTable = table{ machineTable = table{
name: projection.UserMachineTable, name: projection.UserMachineTable,
instanceIDCol: projection.MachineUserInstanceIDCol,
} }
MachineUserIDCol = Column{ MachineUserIDCol = Column{
name: projection.MachineUserIDCol, name: projection.MachineUserIDCol,
@ -262,7 +265,8 @@ var (
var ( var (
notifyTable = table{ notifyTable = table{
name: projection.UserNotifyTable, name: projection.UserNotifyTable,
instanceIDCol: projection.NotifyInstanceIDCol,
} }
NotifyUserIDCol = Column{ NotifyUserIDCol = Column{
name: projection.NotifyUserIDCol, name: projection.NotifyUserIDCol,

View File

@ -15,7 +15,8 @@ import (
var ( var (
userAuthMethodTable = table{ userAuthMethodTable = table{
name: projection.UserAuthMethodTable, name: projection.UserAuthMethodTable,
instanceIDCol: projection.UserAuthMethodInstanceIDCol,
} }
UserAuthMethodColumnTokenID = Column{ UserAuthMethodColumnTokenID = Column{
name: projection.UserAuthMethodTokenIDCol, name: projection.UserAuthMethodTokenIDCol,

View File

@ -143,7 +143,8 @@ func NewUserGrantContainsRolesSearchQuery(roles ...string) (SearchQuery, error)
var ( var (
userGrantTable = table{ userGrantTable = table{
name: projection.UserGrantProjectionTable, name: projection.UserGrantProjectionTable,
instanceIDCol: projection.UserGrantInstanceID,
} }
UserGrantID = Column{ UserGrantID = Column{
name: projection.UserGrantID, name: projection.UserGrantID,

View File

@ -38,11 +38,11 @@ var (
", projections.user_grants2.project_id" + ", projections.user_grants2.project_id" +
", projections.projects2.name" + ", projections.projects2.name" +
" FROM projections.user_grants2" + " FROM projections.user_grants2" +
" LEFT JOIN projections.users4 ON projections.user_grants2.user_id = projections.users4.id" + " LEFT JOIN projections.users4 ON projections.user_grants2.user_id = projections.users4.id AND projections.user_grants2.instance_id = projections.users4.instance_id" +
" LEFT JOIN projections.users4_humans ON projections.user_grants2.user_id = projections.users4_humans.user_id" + " LEFT JOIN projections.users4_humans ON projections.user_grants2.user_id = projections.users4_humans.user_id AND projections.user_grants2.instance_id = projections.users4_humans.instance_id" +
" LEFT JOIN projections.orgs ON projections.user_grants2.resource_owner = projections.orgs.id" + " LEFT JOIN projections.orgs ON projections.user_grants2.resource_owner = projections.orgs.id AND projections.user_grants2.instance_id = projections.orgs.instance_id" +
" LEFT JOIN projections.projects2 ON projections.user_grants2.project_id = projections.projects2.id" + " LEFT JOIN projections.projects2 ON projections.user_grants2.project_id = projections.projects2.id AND projections.user_grants2.instance_id = projections.projects2.instance_id" +
" LEFT JOIN projections.login_names ON projections.user_grants2.user_id = projections.login_names.user_id" + " LEFT JOIN projections.login_names ON projections.user_grants2.user_id = projections.login_names.user_id AND projections.user_grants2.instance_id = projections.login_names.instance_id" +
" WHERE projections.login_names.is_primary = $1") " WHERE projections.login_names.is_primary = $1")
userGrantCols = []string{ userGrantCols = []string{
"id", "id",
@ -93,11 +93,11 @@ var (
", projections.projects2.name" + ", projections.projects2.name" +
", COUNT(*) OVER ()" + ", COUNT(*) OVER ()" +
" FROM projections.user_grants2" + " FROM projections.user_grants2" +
" LEFT JOIN projections.users4 ON projections.user_grants2.user_id = projections.users4.id" + " LEFT JOIN projections.users4 ON projections.user_grants2.user_id = projections.users4.id AND projections.user_grants2.instance_id = projections.users4.instance_id" +
" LEFT JOIN projections.users4_humans ON projections.user_grants2.user_id = projections.users4_humans.user_id" + " LEFT JOIN projections.users4_humans ON projections.user_grants2.user_id = projections.users4_humans.user_id AND projections.user_grants2.instance_id = projections.users4_humans.instance_id" +
" LEFT JOIN projections.orgs ON projections.user_grants2.resource_owner = projections.orgs.id" + " LEFT JOIN projections.orgs ON projections.user_grants2.resource_owner = projections.orgs.id AND projections.user_grants2.instance_id = projections.orgs.instance_id" +
" LEFT JOIN projections.projects2 ON projections.user_grants2.project_id = projections.projects2.id" + " LEFT JOIN projections.projects2 ON projections.user_grants2.project_id = projections.projects2.id AND projections.user_grants2.instance_id = projections.projects2.instance_id" +
" LEFT JOIN projections.login_names ON projections.user_grants2.user_id = projections.login_names.user_id" + " LEFT JOIN projections.login_names ON projections.user_grants2.user_id = projections.login_names.user_id AND projections.user_grants2.instance_id = projections.login_names.instance_id" +
" WHERE projections.login_names.is_primary = $1") " WHERE projections.login_names.is_primary = $1")
userGrantsCols = append( userGrantsCols = append(
userGrantCols, userGrantCols,

View File

@ -132,7 +132,8 @@ func (q *Queries) Memberships(ctx context.Context, queries *MembershipSearchQuer
var ( var (
//membershipAlias is a hack to satisfy checks in the queries //membershipAlias is a hack to satisfy checks in the queries
membershipAlias = table{ membershipAlias = table{
name: "memberships", name: "memberships",
instanceIDCol: projection.MemberInstanceID,
} }
membershipUserID = Column{ membershipUserID = Column{
name: projection.MemberUserIDCol, name: projection.MemberUserIDCol,

View File

@ -80,9 +80,9 @@ var (
", members.grant_id" + ", members.grant_id" +
" FROM projections.project_grant_members2 AS members" + " FROM projections.project_grant_members2 AS members" +
") AS memberships" + ") AS memberships" +
" LEFT JOIN projections.projects2 ON memberships.project_id = projections.projects2.id" + " LEFT JOIN projections.projects2 ON memberships.project_id = projections.projects2.id AND memberships.instance_id = projections.projects2.instance_id" +
" LEFT JOIN projections.orgs ON memberships.org_id = projections.orgs.id" + " LEFT JOIN projections.orgs ON memberships.org_id = projections.orgs.id AND memberships.instance_id = projections.orgs.instance_id" +
" LEFT JOIN projections.project_grants2 ON memberships.grant_id = projections.project_grants2.grant_id") " LEFT JOIN projections.project_grants2 ON memberships.grant_id = projections.project_grants2.grant_id AND memberships.instance_id = projections.project_grants2.instance_id")
membershipCols = []string{ membershipCols = []string{
"user_id", "user_id",
"roles", "roles",

View File

@ -35,7 +35,8 @@ type UserMetadataSearchQueries struct {
var ( var (
userMetadataTable = table{ userMetadataTable = table{
name: projection.UserMetadataProjectionTable, name: projection.UserMetadataProjectionTable,
instanceIDCol: projection.UserMetadataColumnInstanceID,
} }
UserMetadataUserIDCol = Column{ UserMetadataUserIDCol = Column{
name: projection.UserMetadataColumnUserID, name: projection.UserMetadataColumnUserID,

View File

@ -18,7 +18,8 @@ import (
var ( var (
personalAccessTokensTable = table{ personalAccessTokensTable = table{
name: projection.PersonalAccessTokenProjectionTable, name: projection.PersonalAccessTokenProjectionTable,
instanceIDCol: projection.PersonalAccessTokenColumnInstanceID,
} }
PersonalAccessTokenColumnID = Column{ PersonalAccessTokenColumnID = Column{
name: projection.PersonalAccessTokenColumnID, name: projection.PersonalAccessTokenColumnID,

View File

@ -44,8 +44,8 @@ var (
` projections.users4_machines.description,` + ` projections.users4_machines.description,` +
` COUNT(*) OVER ()` + ` COUNT(*) OVER ()` +
` FROM projections.users4` + ` FROM projections.users4` +
` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id` + ` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id AND projections.users4.instance_id = projections.users4_humans.instance_id` +
` LEFT JOIN projections.users4_machines ON projections.users4.id = projections.users4_machines.user_id` + ` LEFT JOIN projections.users4_machines ON projections.users4.id = projections.users4_machines.user_id AND projections.users4.instance_id = projections.users4_machines.instance_id` +
` LEFT JOIN` + ` LEFT JOIN` +
` (SELECT login_names.user_id, ARRAY_AGG(login_names.login_name)::TEXT[] AS loginnames` + ` (SELECT login_names.user_id, ARRAY_AGG(login_names.login_name)::TEXT[] AS loginnames` +
` FROM projections.login_names AS login_names` + ` FROM projections.login_names AS login_names` +
@ -99,7 +99,7 @@ var (
` projections.users4_humans.gender,` + ` projections.users4_humans.gender,` +
` projections.users4_humans.avatar_key` + ` projections.users4_humans.avatar_key` +
` FROM projections.users4` + ` FROM projections.users4` +
` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id` ` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id AND projections.users4.instance_id = projections.users4_humans.instance_id`
profileCols = []string{ profileCols = []string{
"id", "id",
"creation_date", "creation_date",
@ -124,7 +124,7 @@ var (
` projections.users4_humans.email,` + ` projections.users4_humans.email,` +
` projections.users4_humans.is_email_verified` + ` projections.users4_humans.is_email_verified` +
` FROM projections.users4` + ` FROM projections.users4` +
` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id` ` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id AND projections.users4.instance_id = projections.users4_humans.instance_id`
emailCols = []string{ emailCols = []string{
"id", "id",
"creation_date", "creation_date",
@ -144,7 +144,7 @@ var (
` projections.users4_humans.phone,` + ` projections.users4_humans.phone,` +
` projections.users4_humans.is_phone_verified` + ` projections.users4_humans.is_phone_verified` +
` FROM projections.users4` + ` FROM projections.users4` +
` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id` ` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id AND projections.users4.instance_id = projections.users4_humans.instance_id`
phoneCols = []string{ phoneCols = []string{
"id", "id",
"creation_date", "creation_date",
@ -162,7 +162,7 @@ var (
` projections.users4_humans.email,` + ` projections.users4_humans.email,` +
` projections.users4_humans.is_email_verified` + ` projections.users4_humans.is_email_verified` +
` FROM projections.users4` + ` FROM projections.users4` +
` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id` ` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id AND projections.users4.instance_id = projections.users4_humans.instance_id`
userUniqueCols = []string{ userUniqueCols = []string{
"id", "id",
"state", "state",
@ -197,8 +197,8 @@ var (
` projections.users4_notifications.password_set,` + ` projections.users4_notifications.password_set,` +
` COUNT(*) OVER ()` + ` COUNT(*) OVER ()` +
` FROM projections.users4` + ` FROM projections.users4` +
` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id` + ` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id AND projections.users4.instance_id = projections.users4_humans.instance_id` +
` LEFT JOIN projections.users4_notifications ON projections.users4.id = projections.users4_notifications.user_id` + ` LEFT JOIN projections.users4_notifications ON projections.users4.id = projections.users4_notifications.user_id AND projections.users4.instance_id = projections.users4_notifications.instance_id` +
` LEFT JOIN` + ` LEFT JOIN` +
` (SELECT login_names.user_id, ARRAY_AGG(login_names.login_name) AS loginnames` + ` (SELECT login_names.user_id, ARRAY_AGG(login_names.login_name) AS loginnames` +
` FROM projections.login_names AS login_names` + ` FROM projections.login_names AS login_names` +
@ -264,8 +264,8 @@ var (
` projections.users4_machines.description,` + ` projections.users4_machines.description,` +
` COUNT(*) OVER ()` + ` COUNT(*) OVER ()` +
` FROM projections.users4` + ` FROM projections.users4` +
` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id` + ` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id AND projections.users4.instance_id = projections.users4_humans.instance_id` +
` LEFT JOIN projections.users4_machines ON projections.users4.id = projections.users4_machines.user_id` + ` LEFT JOIN projections.users4_machines ON projections.users4.id = projections.users4_machines.user_id AND projections.users4.instance_id = projections.users4_machines.instance_id` +
` LEFT JOIN` + ` LEFT JOIN` +
` (SELECT login_names.user_id, ARRAY_AGG(login_names.login_name) AS loginnames` + ` (SELECT login_names.user_id, ARRAY_AGG(login_names.login_name) AS loginnames` +
` FROM projections.login_names AS login_names` + ` FROM projections.login_names AS login_names` +