diff --git a/internal/query/iam_member_test.go b/internal/query/iam_member_test.go index f5b77e219..cec9415a3 100644 --- a/internal/query/iam_member_test.go +++ b/internal/query/iam_member_test.go @@ -20,18 +20,18 @@ var ( ", members.user_id" + ", members.roles" + ", projections.login_names.login_name" + - ", projections.users4_humans.email" + - ", projections.users4_humans.first_name" + - ", projections.users4_humans.last_name" + - ", projections.users4_humans.display_name" + - ", projections.users4_machines.name" + - ", projections.users4_humans.avatar_key" + + ", projections.users5_humans.email" + + ", projections.users5_humans.first_name" + + ", projections.users5_humans.last_name" + + ", projections.users5_humans.display_name" + + ", projections.users5_machines.name" + + ", projections.users5_humans.avatar_key" + ", COUNT(*) OVER () " + "FROM projections.instance_members2 AS members " + - "LEFT JOIN projections.users4_humans " + - "ON members.user_id = projections.users4_humans.user_id AND members.instance_id = projections.users4_humans.instance_id " + - "LEFT JOIN projections.users4_machines " + - "ON members.user_id = projections.users4_machines.user_id AND members.instance_id = projections.users4_machines.instance_id " + + "LEFT JOIN projections.users5_humans " + + "ON members.user_id = projections.users5_humans.user_id AND members.instance_id = projections.users5_humans.instance_id " + + "LEFT JOIN projections.users5_machines " + + "ON members.user_id = projections.users5_machines.user_id AND members.instance_id = projections.users5_machines.instance_id " + "LEFT JOIN projections.login_names " + "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") diff --git a/internal/query/instance_test.go b/internal/query/instance_test.go index a6473960c..552b558a4 100644 --- a/internal/query/instance_test.go +++ b/internal/query/instance_test.go @@ -53,8 +53,8 @@ var ( ` 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` + ` LEFT JOIN projections.instances ON f.id = projections.instances.id` + + ` LEFT JOIN projections.instance_domains ON f.id = projections.instance_domains.instance_id` instancesCols = []string{ "count", "id", diff --git a/internal/query/org_member_test.go b/internal/query/org_member_test.go index d632652b1..fe3b5c4ae 100644 --- a/internal/query/org_member_test.go +++ b/internal/query/org_member_test.go @@ -20,20 +20,20 @@ var ( ", members.user_id" + ", members.roles" + ", projections.login_names.login_name" + - ", projections.users4_humans.email" + - ", projections.users4_humans.first_name" + - ", projections.users4_humans.last_name" + - ", projections.users4_humans.display_name" + - ", projections.users4_machines.name" + - ", projections.users4_humans.avatar_key" + + ", projections.users5_humans.email" + + ", projections.users5_humans.first_name" + + ", projections.users5_humans.last_name" + + ", projections.users5_humans.display_name" + + ", projections.users5_machines.name" + + ", projections.users5_humans.avatar_key" + ", COUNT(*) OVER () " + "FROM projections.org_members2 AS members " + - "LEFT JOIN projections.users4_humans " + - "ON members.user_id = projections.users4_humans.user_id " + - "AND members.instance_id = projections.users4_humans.instance_id " + - "LEFT JOIN projections.users4_machines " + - "ON members.user_id = projections.users4_machines.user_id " + - "AND members.instance_id = projections.users4_machines.instance_id " + + "LEFT JOIN projections.users5_humans " + + "ON members.user_id = projections.users5_humans.user_id " + + "AND members.instance_id = projections.users5_humans.instance_id " + + "LEFT JOIN projections.users5_machines " + + "ON members.user_id = projections.users5_machines.user_id " + + "AND members.instance_id = projections.users5_machines.instance_id " + "LEFT JOIN projections.login_names " + "ON members.user_id = projections.login_names.user_id " + "AND members.instance_id = projections.login_names.instance_id " + diff --git a/internal/query/project_grant_member_test.go b/internal/query/project_grant_member_test.go index 6840afd29..5bd2b1cfc 100644 --- a/internal/query/project_grant_member_test.go +++ b/internal/query/project_grant_member_test.go @@ -20,20 +20,20 @@ var ( ", members.user_id" + ", members.roles" + ", projections.login_names.login_name" + - ", projections.users4_humans.email" + - ", projections.users4_humans.first_name" + - ", projections.users4_humans.last_name" + - ", projections.users4_humans.display_name" + - ", projections.users4_machines.name" + - ", projections.users4_humans.avatar_key" + + ", projections.users5_humans.email" + + ", projections.users5_humans.first_name" + + ", projections.users5_humans.last_name" + + ", projections.users5_humans.display_name" + + ", projections.users5_machines.name" + + ", projections.users5_humans.avatar_key" + ", COUNT(*) OVER () " + "FROM projections.project_grant_members2 AS members " + - "LEFT JOIN projections.users4_humans " + - "ON members.user_id = projections.users4_humans.user_id " + - "AND members.instance_id = projections.users4_humans.instance_id " + - "LEFT JOIN projections.users4_machines " + - "ON members.user_id = projections.users4_machines.user_id " + - "AND members.instance_id = projections.users4_machines.instance_id " + + "LEFT JOIN projections.users5_humans " + + "ON members.user_id = projections.users5_humans.user_id " + + "AND members.instance_id = projections.users5_humans.instance_id " + + "LEFT JOIN projections.users5_machines " + + "ON members.user_id = projections.users5_machines.user_id " + + "AND members.instance_id = projections.users5_machines.instance_id " + "LEFT JOIN projections.login_names " + "ON members.user_id = projections.login_names.user_id " + "AND members.instance_id = projections.login_names.instance_id " + diff --git a/internal/query/project_member_test.go b/internal/query/project_member_test.go index 1d09ebdb0..55d70a6c7 100644 --- a/internal/query/project_member_test.go +++ b/internal/query/project_member_test.go @@ -20,20 +20,20 @@ var ( ", members.user_id" + ", members.roles" + ", projections.login_names.login_name" + - ", projections.users4_humans.email" + - ", projections.users4_humans.first_name" + - ", projections.users4_humans.last_name" + - ", projections.users4_humans.display_name" + - ", projections.users4_machines.name" + - ", projections.users4_humans.avatar_key" + + ", projections.users5_humans.email" + + ", projections.users5_humans.first_name" + + ", projections.users5_humans.last_name" + + ", projections.users5_humans.display_name" + + ", projections.users5_machines.name" + + ", projections.users5_humans.avatar_key" + ", COUNT(*) OVER () " + "FROM projections.project_members2 AS members " + - "LEFT JOIN projections.users4_humans " + - "ON members.user_id = projections.users4_humans.user_id " + - "AND members.instance_id = projections.users4_humans.instance_id " + - "LEFT JOIN projections.users4_machines " + - "ON members.user_id = projections.users4_machines.user_id " + - "AND members.instance_id = projections.users4_machines.instance_id " + + "LEFT JOIN projections.users5_humans " + + "ON members.user_id = projections.users5_humans.user_id " + + "AND members.instance_id = projections.users5_humans.instance_id " + + "LEFT JOIN projections.users5_machines " + + "ON members.user_id = projections.users5_machines.user_id " + + "AND members.instance_id = projections.users5_machines.instance_id " + "LEFT JOIN projections.login_names " + "ON members.user_id = projections.login_names.user_id " + "AND members.instance_id = projections.login_names.instance_id " + diff --git a/internal/query/projection/user.go b/internal/query/projection/user.go index 5fe55d876..ed890ea45 100644 --- a/internal/query/projection/user.go +++ b/internal/query/projection/user.go @@ -18,7 +18,7 @@ type userProjection struct { } const ( - UserTable = "projections.users4" + UserTable = "projections.users5" UserHumanTable = UserTable + "_" + UserHumanSuffix UserMachineTable = UserTable + "_" + UserMachineSuffix UserNotifyTable = UserTable + "_" + UserNotifySuffix @@ -89,9 +89,8 @@ func newUserProjection(ctx context.Context, config crdb.StatementHandlerConfig) crdb.NewColumn(UserTypeCol, crdb.ColumnTypeEnum), }, crdb.NewPrimaryKey(UserIDCol, UserInstanceIDCol), - crdb.WithIndex(crdb.NewIndex("username_idx4", []string{UserUsernameCol})), - crdb.WithIndex(crdb.NewIndex("user_ro_idx4", []string{UserResourceOwnerCol})), - crdb.WithConstraint(crdb.NewConstraint("user_id_unique4", []string{UserIDCol})), + crdb.WithIndex(crdb.NewIndex("username_idx5", []string{UserUsernameCol})), + crdb.WithIndex(crdb.NewIndex("user_ro_idx5", []string{UserResourceOwnerCol})), ), crdb.NewSuffixedTable([]*crdb.Column{ crdb.NewColumn(HumanUserIDCol, crdb.ColumnTypeText), @@ -110,7 +109,7 @@ func newUserProjection(ctx context.Context, config crdb.StatementHandlerConfig) }, crdb.NewPrimaryKey(HumanUserIDCol, HumanUserInstanceIDCol), UserHumanSuffix, - crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys("fk_human_ref_user4")), + crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys("fk_human_ref_user5")), ), crdb.NewSuffixedTable([]*crdb.Column{ crdb.NewColumn(MachineUserIDCol, crdb.ColumnTypeText), @@ -120,7 +119,7 @@ func newUserProjection(ctx context.Context, config crdb.StatementHandlerConfig) }, crdb.NewPrimaryKey(MachineUserIDCol, MachineUserInstanceIDCol), UserMachineSuffix, - crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys("fk_machine_ref_user4")), + crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys("fk_machine_ref_user5")), ), crdb.NewSuffixedTable([]*crdb.Column{ crdb.NewColumn(NotifyUserIDCol, crdb.ColumnTypeText), @@ -133,7 +132,7 @@ func newUserProjection(ctx context.Context, config crdb.StatementHandlerConfig) }, crdb.NewPrimaryKey(NotifyUserIDCol, NotifyInstanceIDCol), UserNotifySuffix, - crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys("fk_notify_ref_user4")), + crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys("fk_notify_ref_user5")), ), ) p.StatementHandler = crdb.NewStatementHandler(ctx, config) diff --git a/internal/query/projection/user_test.go b/internal/query/projection/user_test.go index 81b0bff3d..a8860ed84 100644 --- a/internal/query/projection/user_test.go +++ b/internal/query/projection/user_test.go @@ -50,7 +50,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.users4 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", + expectedStmt: "INSERT INTO projections.users5 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", expectedArgs: []interface{}{ "agg-id", anyArg{}, @@ -64,7 +64,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.users4_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", + expectedStmt: "INSERT INTO projections.users5_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -79,7 +79,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.users4_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)", + expectedStmt: "INSERT INTO projections.users5_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -119,7 +119,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.users4 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", + expectedStmt: "INSERT INTO projections.users5 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", expectedArgs: []interface{}{ "agg-id", anyArg{}, @@ -133,7 +133,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.users4_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", + expectedStmt: "INSERT INTO projections.users5_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -148,7 +148,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.users4_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)", + expectedStmt: "INSERT INTO projections.users5_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -183,7 +183,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.users4 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", + expectedStmt: "INSERT INTO projections.users5 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", expectedArgs: []interface{}{ "agg-id", anyArg{}, @@ -197,7 +197,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.users4_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", + expectedStmt: "INSERT INTO projections.users5_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -212,7 +212,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.users4_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)", + expectedStmt: "INSERT INTO projections.users5_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -252,7 +252,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.users4 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", + expectedStmt: "INSERT INTO projections.users5 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", expectedArgs: []interface{}{ "agg-id", anyArg{}, @@ -266,7 +266,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.users4_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", + expectedStmt: "INSERT INTO projections.users5_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -281,7 +281,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.users4_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)", + expectedStmt: "INSERT INTO projections.users5_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -321,7 +321,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.users4 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", + expectedStmt: "INSERT INTO projections.users5 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", expectedArgs: []interface{}{ "agg-id", anyArg{}, @@ -335,7 +335,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.users4_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", + expectedStmt: "INSERT INTO projections.users5_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -350,7 +350,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.users4_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)", + expectedStmt: "INSERT INTO projections.users5_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -385,7 +385,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.users4 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", + expectedStmt: "INSERT INTO projections.users5 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", expectedArgs: []interface{}{ "agg-id", anyArg{}, @@ -399,7 +399,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.users4_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", + expectedStmt: "INSERT INTO projections.users5_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -414,7 +414,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.users4_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)", + expectedStmt: "INSERT INTO projections.users5_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -444,7 +444,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET state = $1 WHERE (id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5 SET state = $1 WHERE (id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ domain.UserStateInitial, "agg-id", @@ -472,7 +472,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET state = $1 WHERE (id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5 SET state = $1 WHERE (id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ domain.UserStateInitial, "agg-id", @@ -500,7 +500,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET state = $1 WHERE (id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5 SET state = $1 WHERE (id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ domain.UserStateActive, "agg-id", @@ -528,7 +528,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET state = $1 WHERE (id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5 SET state = $1 WHERE (id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ domain.UserStateActive, "agg-id", @@ -556,7 +556,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, state, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedStmt: "UPDATE projections.users5 SET (change_date, state, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, domain.UserStateLocked, @@ -586,7 +586,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, state, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedStmt: "UPDATE projections.users5 SET (change_date, state, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, domain.UserStateActive, @@ -616,7 +616,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, state, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedStmt: "UPDATE projections.users5 SET (change_date, state, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, domain.UserStateInactive, @@ -646,7 +646,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, state, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedStmt: "UPDATE projections.users5 SET (change_date, state, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, domain.UserStateActive, @@ -676,7 +676,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.users4 WHERE (id = $1) AND (instance_id = $2)", + expectedStmt: "DELETE FROM projections.users5 WHERE (id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -705,7 +705,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, username, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedStmt: "UPDATE projections.users5 SET (change_date, username, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, "username", @@ -737,7 +737,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, username, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedStmt: "UPDATE projections.users5 SET (change_date, username, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, "id@temporary.domain", @@ -774,7 +774,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -783,7 +783,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_humans SET (first_name, last_name, nick_name, display_name, preferred_language, gender) = ($1, $2, $3, $4, $5, $6) WHERE (user_id = $7) AND (instance_id = $8)", + expectedStmt: "UPDATE projections.users5_humans SET (first_name, last_name, nick_name, display_name, preferred_language, gender) = ($1, $2, $3, $4, $5, $6) WHERE (user_id = $7) AND (instance_id = $8)", expectedArgs: []interface{}{ "first-name", "last-name", @@ -823,7 +823,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -832,7 +832,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_humans SET (first_name, last_name, nick_name, display_name, preferred_language, gender) = ($1, $2, $3, $4, $5, $6) WHERE (user_id = $7) AND (instance_id = $8)", + expectedStmt: "UPDATE projections.users5_humans SET (first_name, last_name, nick_name, display_name, preferred_language, gender) = ($1, $2, $3, $4, $5, $6) WHERE (user_id = $7) AND (instance_id = $8)", expectedArgs: []interface{}{ "first-name", "last-name", @@ -867,7 +867,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -876,7 +876,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_humans SET (phone, is_phone_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5_humans SET (phone, is_phone_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ "+41 00 000 00 00", false, @@ -885,7 +885,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_notifications SET last_phone = $1 WHERE (user_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5_notifications SET last_phone = $1 WHERE (user_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ &sql.NullString{String: "+41 00 000 00 00", Valid: true}, "agg-id", @@ -915,7 +915,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -924,7 +924,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_humans SET (phone, is_phone_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5_humans SET (phone, is_phone_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ "+41 00 000 00 00", false, @@ -933,7 +933,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_notifications SET last_phone = $1 WHERE (user_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5_notifications SET last_phone = $1 WHERE (user_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ &sql.NullString{String: "+41 00 000 00 00", Valid: true}, "agg-id", @@ -961,7 +961,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -970,7 +970,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_humans SET (phone, is_phone_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5_humans SET (phone, is_phone_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ nil, nil, @@ -979,7 +979,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_notifications SET (last_phone, verified_phone) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5_notifications SET (last_phone, verified_phone) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ nil, nil, @@ -1008,7 +1008,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -1017,7 +1017,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_humans SET (phone, is_phone_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5_humans SET (phone, is_phone_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ nil, nil, @@ -1026,7 +1026,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_notifications SET (last_phone, verified_phone) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5_notifications SET (last_phone, verified_phone) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ nil, nil, @@ -1055,7 +1055,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -1064,7 +1064,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_humans SET is_phone_verified = $1 WHERE (user_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5_humans SET is_phone_verified = $1 WHERE (user_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ true, "agg-id", @@ -1072,7 +1072,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_notifications SET verified_phone = last_phone WHERE (user_id = $1) AND (instance_id = $2)", + expectedStmt: "UPDATE projections.users5_notifications SET verified_phone = last_phone WHERE (user_id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -1099,7 +1099,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -1108,7 +1108,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_humans SET is_phone_verified = $1 WHERE (user_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5_humans SET is_phone_verified = $1 WHERE (user_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ true, "agg-id", @@ -1116,7 +1116,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_notifications SET verified_phone = last_phone WHERE (user_id = $1) AND (instance_id = $2)", + expectedStmt: "UPDATE projections.users5_notifications SET verified_phone = last_phone WHERE (user_id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -1145,7 +1145,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -1154,7 +1154,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_humans SET (email, is_email_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5_humans SET (email, is_email_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ "email@zitadel.com", false, @@ -1163,7 +1163,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_notifications SET last_email = $1 WHERE (user_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5_notifications SET last_email = $1 WHERE (user_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ &sql.NullString{String: "email@zitadel.com", Valid: true}, "agg-id", @@ -1193,7 +1193,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -1202,7 +1202,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_humans SET (email, is_email_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5_humans SET (email, is_email_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ "email@zitadel.com", false, @@ -1211,7 +1211,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_notifications SET last_email = $1 WHERE (user_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5_notifications SET last_email = $1 WHERE (user_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ &sql.NullString{String: "email@zitadel.com", Valid: true}, "agg-id", @@ -1239,7 +1239,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -1248,7 +1248,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_humans SET is_email_verified = $1 WHERE (user_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5_humans SET is_email_verified = $1 WHERE (user_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ true, "agg-id", @@ -1256,7 +1256,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_notifications SET verified_email = last_email WHERE (user_id = $1) AND (instance_id = $2)", + expectedStmt: "UPDATE projections.users5_notifications SET verified_email = last_email WHERE (user_id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -1283,7 +1283,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -1292,7 +1292,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_humans SET is_email_verified = $1 WHERE (user_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5_humans SET is_email_verified = $1 WHERE (user_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ true, "agg-id", @@ -1300,7 +1300,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_notifications SET verified_email = last_email WHERE (user_id = $1) AND (instance_id = $2)", + expectedStmt: "UPDATE projections.users5_notifications SET verified_email = last_email WHERE (user_id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -1329,7 +1329,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -1338,7 +1338,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_humans SET avatar_key = $1 WHERE (user_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5_humans SET avatar_key = $1 WHERE (user_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "users/agg-id/avatar", "agg-id", @@ -1366,7 +1366,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -1375,7 +1375,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_humans SET avatar_key = $1 WHERE (user_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5_humans SET avatar_key = $1 WHERE (user_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ nil, "agg-id", @@ -1406,7 +1406,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.users4 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", + expectedStmt: "INSERT INTO projections.users5 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", expectedArgs: []interface{}{ "agg-id", anyArg{}, @@ -1420,7 +1420,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.users4_machines (user_id, instance_id, name, description) VALUES ($1, $2, $3, $4)", + expectedStmt: "INSERT INTO projections.users5_machines (user_id, instance_id, name, description) VALUES ($1, $2, $3, $4)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -1453,7 +1453,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.users4 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", + expectedStmt: "INSERT INTO projections.users5 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", expectedArgs: []interface{}{ "agg-id", anyArg{}, @@ -1467,7 +1467,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.users4_machines (user_id, instance_id, name, description) VALUES ($1, $2, $3, $4)", + expectedStmt: "INSERT INTO projections.users5_machines (user_id, instance_id, name, description) VALUES ($1, $2, $3, $4)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -1499,7 +1499,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -1508,7 +1508,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_machines SET (name, description) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5_machines SET (name, description) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ "machine-name", "description", @@ -1539,7 +1539,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -1548,7 +1548,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_machines SET name = $1 WHERE (user_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5_machines SET name = $1 WHERE (user_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "machine-name", "agg-id", @@ -1578,7 +1578,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.users4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedStmt: "UPDATE projections.users5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -1587,7 +1587,7 @@ func TestUserProjection_reduces(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.users4_machines SET description = $1 WHERE (user_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.users5_machines SET description = $1 WHERE (user_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "description", "agg-id", @@ -1634,7 +1634,7 @@ func TestUserProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.users4 WHERE (instance_id = $1)", + expectedStmt: "DELETE FROM projections.users5 WHERE (instance_id = $1)", expectedArgs: []interface{}{ "agg-id", }, diff --git a/internal/query/search_query.go b/internal/query/search_query.go index 50529a663..0f4314dd0 100644 --- a/internal/query/search_query.go +++ b/internal/query/search_query.go @@ -511,6 +511,9 @@ func (c Column) isZero() bool { } func join(join, from Column) string { + if join.identifier() == join.table.InstanceIDIdentifier() { + 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() } diff --git a/internal/query/user.go b/internal/query/user.go index 6a9ab7f39..5b24f8dc8 100644 --- a/internal/query/user.go +++ b/internal/query/user.go @@ -302,14 +302,13 @@ func (q *Queries) GetUserByID(ctx context.Context, shouldTriggerBulk bool, userI projection.LoginNameProjection.Trigger(ctx) } - instanceID := authz.GetInstance(ctx).InstanceID() - query, scan := prepareUserQuery(instanceID) + query, scan := prepareUserQuery() for _, q := range queries { query = q.toQuery(query) } stmt, args, err := query.Where(sq.Eq{ UserIDCol.identifier(): userID, - UserInstanceIDCol.identifier(): instanceID, + UserInstanceIDCol.identifier(): authz.GetInstance(ctx).InstanceID(), }).ToSql() if err != nil { return nil, errors.ThrowInternal(err, "QUERY-FBg21", "Errors.Query.SQLStatment") @@ -325,13 +324,12 @@ func (q *Queries) GetUser(ctx context.Context, shouldTriggerBulk bool, queries . projection.LoginNameProjection.Trigger(ctx) } - instanceID := authz.GetInstance(ctx).InstanceID() - query, scan := prepareUserQuery(instanceID) + query, scan := prepareUserQuery() for _, q := range queries { query = q.toQuery(query) } stmt, args, err := query.Where(sq.Eq{ - UserInstanceIDCol.identifier(): instanceID, + UserInstanceIDCol.identifier(): authz.GetInstance(ctx).InstanceID(), }).ToSql() if err != nil { return nil, errors.ThrowInternal(err, "QUERY-Dnhr2", "Errors.Query.SQLStatment") @@ -398,14 +396,13 @@ func (q *Queries) GetNotifyUserByID(ctx context.Context, shouldTriggered bool, u projection.LoginNameProjection.Trigger(ctx) } - instanceID := authz.GetInstance(ctx).InstanceID() - query, scan := prepareNotifyUserQuery(instanceID) + query, scan := prepareNotifyUserQuery() for _, q := range queries { query = q.toQuery(query) } stmt, args, err := query.Where(sq.Eq{ UserIDCol.identifier(): userID, - UserInstanceIDCol.identifier(): instanceID, + UserInstanceIDCol.identifier(): authz.GetInstance(ctx).InstanceID(), }).ToSql() if err != nil { return nil, errors.ThrowInternal(err, "QUERY-Err3g", "Errors.Query.SQLStatment") @@ -421,13 +418,12 @@ func (q *Queries) GetNotifyUser(ctx context.Context, shouldTriggered bool, queri projection.LoginNameProjection.Trigger(ctx) } - instanceID := authz.GetInstance(ctx).InstanceID() - query, scan := prepareNotifyUserQuery(instanceID) + query, scan := prepareNotifyUserQuery() for _, q := range queries { query = q.toQuery(query) } stmt, args, err := query.Where(sq.Eq{ - UserInstanceIDCol.identifier(): instanceID, + UserInstanceIDCol.identifier(): authz.GetInstance(ctx).InstanceID(), }).ToSql() if err != nil { return nil, errors.ThrowInternal(err, "QUERY-Err3g", "Errors.Query.SQLStatment") @@ -442,7 +438,8 @@ func (q *Queries) SearchUsers(ctx context.Context, queries *UserSearchQueries) ( stmt, args, err := queries.toQuery(query). Where(sq.Eq{ UserInstanceIDCol.identifier(): authz.GetInstance(ctx).InstanceID(), - }).ToSql() + }). + ToSql() if err != nil { return nil, errors.ThrowInternal(err, "QUERY-Dgbg2", "Errors.Query.SQLStatment") } @@ -597,26 +594,27 @@ func NewUserLoginNameExistsQuery(value string, comparison TextComparison) (Searc ) } -func prepareUserQuery(instanceID string) (sq.SelectBuilder, func(*sql.Row) (*User, error)) { - loginNamesQuery, loginNamesArgs, err := sq.Select( +func prepareUserQuery() (sq.SelectBuilder, func(*sql.Row) (*User, error)) { + loginNamesQuery, _, err := sq.Select( userLoginNamesUserIDCol.identifier(), - "ARRAY_AGG("+userLoginNamesNameCol.identifier()+")::TEXT[] AS "+userLoginNamesListCol.name). + "ARRAY_AGG("+userLoginNamesNameCol.identifier()+") AS "+userLoginNamesListCol.name, + userLoginNamesInstanceIDCol.identifier()). From(userLoginNamesTable.identifier()). - GroupBy(userLoginNamesUserIDCol.identifier()). - Where(sq.Eq{ - userLoginNamesInstanceIDCol.identifier(): instanceID, - }).ToSql() + GroupBy(userLoginNamesUserIDCol.identifier(), userLoginNamesInstanceIDCol.identifier()). + ToSql() if err != nil { return sq.SelectBuilder{}, nil } preferredLoginNameQuery, preferredLoginNameArgs, err := sq.Select( userPreferredLoginNameUserIDCol.identifier(), - userPreferredLoginNameCol.identifier()). + userPreferredLoginNameCol.identifier(), + userPreferredLoginNameInstanceIDCol.identifier()). From(userPreferredLoginNameTable.identifier()). - Where(sq.Eq{ - userPreferredLoginNameIsPrimaryCol.identifier(): true, - userPreferredLoginNameInstanceIDCol.identifier(): instanceID, - }).ToSql() + Where( + sq.Eq{ + userPreferredLoginNameIsPrimaryCol.identifier(): true, + }). + ToSql() if err != nil { return sq.SelectBuilder{}, nil } @@ -651,8 +649,13 @@ func prepareUserQuery(instanceID string) (sq.SelectBuilder, func(*sql.Row) (*Use From(userTable.identifier()). LeftJoin(join(HumanUserIDCol, UserIDCol)). LeftJoin(join(MachineUserIDCol, UserIDCol)). - LeftJoin("("+loginNamesQuery+") AS "+userLoginNamesTable.alias+" ON "+userLoginNamesUserIDCol.identifier()+" = "+UserIDCol.identifier(), loginNamesArgs...). - LeftJoin("("+preferredLoginNameQuery+") AS "+userPreferredLoginNameTable.alias+" ON "+userPreferredLoginNameUserIDCol.identifier()+" = "+UserIDCol.identifier(), preferredLoginNameArgs...). + LeftJoin("("+loginNamesQuery+") AS "+userLoginNamesTable.alias+" ON "+ + userLoginNamesUserIDCol.identifier()+" = "+UserIDCol.identifier()+" AND "+ + userLoginNamesInstanceIDCol.identifier()+" = "+UserInstanceIDCol.identifier()). + LeftJoin("("+preferredLoginNameQuery+") AS "+userPreferredLoginNameTable.alias+" ON "+ + userPreferredLoginNameUserIDCol.identifier()+" = "+UserIDCol.identifier()+" AND "+ + userPreferredLoginNameInstanceIDCol.identifier()+" = "+UserInstanceIDCol.identifier(), + preferredLoginNameArgs...). PlaceholderFormat(sq.Dollar), func(row *sql.Row) (*User, error) { u := new(User) @@ -898,26 +901,27 @@ func preparePhoneQuery() (sq.SelectBuilder, func(*sql.Row) (*Phone, error)) { } } -func prepareNotifyUserQuery(instanceID string) (sq.SelectBuilder, func(*sql.Row) (*NotifyUser, error)) { - loginNamesQuery, loginNamesArgs, err := sq.Select( +func prepareNotifyUserQuery() (sq.SelectBuilder, func(*sql.Row) (*NotifyUser, error)) { + loginNamesQuery, _, err := sq.Select( userLoginNamesUserIDCol.identifier(), - "ARRAY_AGG("+userLoginNamesNameCol.identifier()+") AS "+userLoginNamesListCol.name). + "ARRAY_AGG("+userLoginNamesNameCol.identifier()+") AS "+userLoginNamesListCol.name, + userLoginNamesInstanceIDCol.identifier()). From(userLoginNamesTable.identifier()). - GroupBy(userLoginNamesUserIDCol.identifier()). - Where(sq.Eq{ - userLoginNamesInstanceIDCol.identifier(): instanceID, - }).ToSql() + GroupBy(userLoginNamesUserIDCol.identifier(), userLoginNamesInstanceIDCol.identifier()). + ToSql() if err != nil { return sq.SelectBuilder{}, nil } preferredLoginNameQuery, preferredLoginNameArgs, err := sq.Select( userPreferredLoginNameUserIDCol.identifier(), - userPreferredLoginNameCol.identifier()). + userPreferredLoginNameCol.identifier(), + userPreferredLoginNameInstanceIDCol.identifier()). From(userPreferredLoginNameTable.identifier()). - Where(sq.Eq{ - userPreferredLoginNameIsPrimaryCol.identifier(): true, - userPreferredLoginNameInstanceIDCol.identifier(): instanceID, - }).ToSql() + Where( + sq.Eq{ + userPreferredLoginNameIsPrimaryCol.identifier(): true, + }). + ToSql() if err != nil { return sq.SelectBuilder{}, nil } @@ -951,8 +955,13 @@ func prepareNotifyUserQuery(instanceID string) (sq.SelectBuilder, func(*sql.Row) From(userTable.identifier()). LeftJoin(join(HumanUserIDCol, UserIDCol)). LeftJoin(join(NotifyUserIDCol, UserIDCol)). - LeftJoin("("+loginNamesQuery+") AS "+userLoginNamesTable.alias+" ON "+userLoginNamesUserIDCol.identifier()+" = "+UserIDCol.identifier(), loginNamesArgs...). - LeftJoin("("+preferredLoginNameQuery+") AS "+userPreferredLoginNameTable.alias+" ON "+userPreferredLoginNameUserIDCol.identifier()+" = "+UserIDCol.identifier(), preferredLoginNameArgs...). + LeftJoin("("+loginNamesQuery+") AS "+userLoginNamesTable.alias+" ON "+ + userLoginNamesUserIDCol.identifier()+" = "+UserIDCol.identifier()+" AND "+ + userLoginNamesInstanceIDCol.identifier()+" = "+UserInstanceIDCol.identifier()). + LeftJoin("("+preferredLoginNameQuery+") AS "+userPreferredLoginNameTable.alias+" ON "+ + userPreferredLoginNameUserIDCol.identifier()+" = "+UserIDCol.identifier()+" AND "+ + userPreferredLoginNameInstanceIDCol.identifier()+" = "+UserInstanceIDCol.identifier(), + preferredLoginNameArgs...). PlaceholderFormat(sq.Dollar), func(row *sql.Row) (*NotifyUser, error) { u := new(NotifyUser) @@ -1078,21 +1087,24 @@ func prepareUserUniqueQuery() (sq.SelectBuilder, func(*sql.Row) (bool, error)) { func prepareUsersQuery() (sq.SelectBuilder, func(*sql.Rows) (*Users, error)) { loginNamesQuery, _, err := sq.Select( userLoginNamesUserIDCol.identifier(), - "ARRAY_AGG("+userLoginNamesNameCol.identifier()+") AS "+userLoginNamesListCol.name). + "ARRAY_AGG("+userLoginNamesNameCol.identifier()+") AS "+userLoginNamesListCol.name, + userLoginNamesInstanceIDCol.identifier()). From(userLoginNamesTable.identifier()). - GroupBy(userLoginNamesUserIDCol.identifier()). + GroupBy(userLoginNamesUserIDCol.identifier(), userLoginNamesInstanceIDCol.identifier()). ToSql() if err != nil { return sq.SelectBuilder{}, nil } preferredLoginNameQuery, preferredLoginNameArgs, err := sq.Select( userPreferredLoginNameUserIDCol.identifier(), - userPreferredLoginNameCol.identifier()). + userPreferredLoginNameCol.identifier(), + userPreferredLoginNameInstanceIDCol.identifier()). From(userPreferredLoginNameTable.identifier()). Where( sq.Eq{ userPreferredLoginNameIsPrimaryCol.identifier(): true, - }).ToSql() + }). + ToSql() if err != nil { return sq.SelectBuilder{}, nil } @@ -1126,8 +1138,13 @@ func prepareUsersQuery() (sq.SelectBuilder, func(*sql.Rows) (*Users, error)) { From(userTable.identifier()). LeftJoin(join(HumanUserIDCol, UserIDCol)). LeftJoin(join(MachineUserIDCol, UserIDCol)). - LeftJoin("("+loginNamesQuery+") AS "+userLoginNamesTable.alias+" ON "+userLoginNamesUserIDCol.identifier()+" = "+UserIDCol.identifier()). - LeftJoin("("+preferredLoginNameQuery+") AS "+userPreferredLoginNameTable.alias+" ON "+userPreferredLoginNameUserIDCol.identifier()+" = "+UserIDCol.identifier(), preferredLoginNameArgs...). + LeftJoin("("+loginNamesQuery+") AS "+userLoginNamesTable.alias+" ON "+ + userLoginNamesUserIDCol.identifier()+" = "+UserIDCol.identifier()+" AND "+ + userLoginNamesInstanceIDCol.identifier()+" = "+UserInstanceIDCol.identifier()). + LeftJoin("("+preferredLoginNameQuery+") AS "+userPreferredLoginNameTable.alias+" ON "+ + userPreferredLoginNameUserIDCol.identifier()+" = "+UserIDCol.identifier()+" AND "+ + userPreferredLoginNameInstanceIDCol.identifier()+" = "+UserInstanceIDCol.identifier(), + preferredLoginNameArgs...). PlaceholderFormat(sq.Dollar), func(rows *sql.Rows) (*Users, error) { users := make([]*User, 0) diff --git a/internal/query/user_grant_test.go b/internal/query/user_grant_test.go index b178d726c..ab2cc6aa7 100644 --- a/internal/query/user_grant_test.go +++ b/internal/query/user_grant_test.go @@ -23,14 +23,14 @@ var ( ", projections.user_grants2.roles" + ", projections.user_grants2.state" + ", projections.user_grants2.user_id" + - ", projections.users4.username" + - ", projections.users4.type" + - ", projections.users4.resource_owner" + - ", projections.users4_humans.first_name" + - ", projections.users4_humans.last_name" + - ", projections.users4_humans.email" + - ", projections.users4_humans.display_name" + - ", projections.users4_humans.avatar_key" + + ", projections.users5.username" + + ", projections.users5.type" + + ", projections.users5.resource_owner" + + ", projections.users5_humans.first_name" + + ", projections.users5_humans.last_name" + + ", projections.users5_humans.email" + + ", projections.users5_humans.display_name" + + ", projections.users5_humans.avatar_key" + ", projections.login_names.login_name" + ", projections.user_grants2.resource_owner" + ", projections.orgs.name" + @@ -38,8 +38,8 @@ var ( ", projections.user_grants2.project_id" + ", projections.projects2.name" + " FROM projections.user_grants2" + - " 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 AND projections.user_grants2.instance_id = projections.users4_humans.instance_id" + + " LEFT JOIN projections.users5 ON projections.user_grants2.user_id = projections.users5.id AND projections.user_grants2.instance_id = projections.users5.instance_id" + + " LEFT JOIN projections.users5_humans ON projections.user_grants2.user_id = projections.users5_humans.user_id AND projections.user_grants2.instance_id = projections.users5_humans.instance_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 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 AND projections.user_grants2.instance_id = projections.login_names.instance_id" + @@ -77,14 +77,14 @@ var ( ", projections.user_grants2.roles" + ", projections.user_grants2.state" + ", projections.user_grants2.user_id" + - ", projections.users4.username" + - ", projections.users4.type" + - ", projections.users4.resource_owner" + - ", projections.users4_humans.first_name" + - ", projections.users4_humans.last_name" + - ", projections.users4_humans.email" + - ", projections.users4_humans.display_name" + - ", projections.users4_humans.avatar_key" + + ", projections.users5.username" + + ", projections.users5.type" + + ", projections.users5.resource_owner" + + ", projections.users5_humans.first_name" + + ", projections.users5_humans.last_name" + + ", projections.users5_humans.email" + + ", projections.users5_humans.display_name" + + ", projections.users5_humans.avatar_key" + ", projections.login_names.login_name" + ", projections.user_grants2.resource_owner" + ", projections.orgs.name" + @@ -93,8 +93,8 @@ var ( ", projections.projects2.name" + ", COUNT(*) OVER ()" + " FROM projections.user_grants2" + - " 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 AND projections.user_grants2.instance_id = projections.users4_humans.instance_id" + + " LEFT JOIN projections.users5 ON projections.user_grants2.user_id = projections.users5.id AND projections.user_grants2.instance_id = projections.users5.instance_id" + + " LEFT JOIN projections.users5_humans ON projections.user_grants2.user_id = projections.users5_humans.user_id AND projections.user_grants2.instance_id = projections.users5_humans.instance_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 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 AND projections.user_grants2.instance_id = projections.login_names.instance_id" + diff --git a/internal/query/user_test.go b/internal/query/user_test.go index c4fe5ef63..56d5267c0 100644 --- a/internal/query/user_test.go +++ b/internal/query/user_test.go @@ -17,44 +17,45 @@ import ( ) var ( - userQuery = `SELECT projections.users4.id,` + - ` projections.users4.creation_date,` + - ` projections.users4.change_date,` + - ` projections.users4.resource_owner,` + - ` projections.users4.sequence,` + - ` projections.users4.state,` + - ` projections.users4.type,` + - ` projections.users4.username,` + + userQuery = `SELECT projections.users5.id,` + + ` projections.users5.creation_date,` + + ` projections.users5.change_date,` + + ` projections.users5.resource_owner,` + + ` projections.users5.sequence,` + + ` projections.users5.state,` + + ` projections.users5.type,` + + ` projections.users5.username,` + ` login_names.loginnames,` + ` preferred_login_name.login_name,` + - ` projections.users4_humans.user_id,` + - ` projections.users4_humans.first_name,` + - ` projections.users4_humans.last_name,` + - ` projections.users4_humans.nick_name,` + - ` projections.users4_humans.display_name,` + - ` projections.users4_humans.preferred_language,` + - ` projections.users4_humans.gender,` + - ` projections.users4_humans.avatar_key,` + - ` projections.users4_humans.email,` + - ` projections.users4_humans.is_email_verified,` + - ` projections.users4_humans.phone,` + - ` projections.users4_humans.is_phone_verified,` + - ` projections.users4_machines.user_id,` + - ` projections.users4_machines.name,` + - ` projections.users4_machines.description,` + + ` projections.users5_humans.user_id,` + + ` projections.users5_humans.first_name,` + + ` projections.users5_humans.last_name,` + + ` projections.users5_humans.nick_name,` + + ` projections.users5_humans.display_name,` + + ` projections.users5_humans.preferred_language,` + + ` projections.users5_humans.gender,` + + ` projections.users5_humans.avatar_key,` + + ` projections.users5_humans.email,` + + ` projections.users5_humans.is_email_verified,` + + ` projections.users5_humans.phone,` + + ` projections.users5_humans.is_phone_verified,` + + ` projections.users5_machines.user_id,` + + ` projections.users5_machines.name,` + + ` projections.users5_machines.description,` + ` COUNT(*) OVER ()` + - ` FROM projections.users4` + - ` 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 AND projections.users4.instance_id = projections.users4_machines.instance_id` + + ` FROM projections.users5` + + ` LEFT JOIN projections.users5_humans ON projections.users5.id = projections.users5_humans.user_id AND projections.users5.instance_id = projections.users5_humans.instance_id` + + ` LEFT JOIN projections.users5_machines ON projections.users5.id = projections.users5_machines.user_id AND projections.users5.instance_id = projections.users5_machines.instance_id` + ` 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) AS loginnames, login_names.instance_id` + ` FROM projections.login_names AS login_names` + - ` WHERE login_names.instance_id = $1` + - ` GROUP BY login_names.user_id) AS login_names` + - ` ON login_names.user_id = projections.users4.id` + + ` GROUP BY login_names.user_id, login_names.instance_id) AS login_names` + + ` ON login_names.user_id = projections.users5.id AND login_names.instance_id = projections.users5.instance_id` + ` LEFT JOIN` + - ` (SELECT preferred_login_name.user_id, preferred_login_name.login_name FROM projections.login_names AS preferred_login_name WHERE preferred_login_name.instance_id = $2 AND preferred_login_name.is_primary = $3) AS preferred_login_name` + - ` ON preferred_login_name.user_id = projections.users4.id` + ` (SELECT preferred_login_name.user_id, preferred_login_name.login_name, preferred_login_name.instance_id` + + ` FROM projections.login_names AS preferred_login_name` + + ` WHERE preferred_login_name.is_primary = $1) AS preferred_login_name` + + ` ON preferred_login_name.user_id = projections.users5.id AND preferred_login_name.instance_id = projections.users5.instance_id` userCols = []string{ "id", "creation_date", @@ -85,21 +86,21 @@ var ( "description", "count", } - profileQuery = `SELECT projections.users4.id,` + - ` projections.users4.creation_date,` + - ` projections.users4.change_date,` + - ` projections.users4.resource_owner,` + - ` projections.users4.sequence,` + - ` projections.users4_humans.user_id,` + - ` projections.users4_humans.first_name,` + - ` projections.users4_humans.last_name,` + - ` projections.users4_humans.nick_name,` + - ` projections.users4_humans.display_name,` + - ` projections.users4_humans.preferred_language,` + - ` projections.users4_humans.gender,` + - ` projections.users4_humans.avatar_key` + - ` FROM projections.users4` + - ` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id AND projections.users4.instance_id = projections.users4_humans.instance_id` + profileQuery = `SELECT projections.users5.id,` + + ` projections.users5.creation_date,` + + ` projections.users5.change_date,` + + ` projections.users5.resource_owner,` + + ` projections.users5.sequence,` + + ` projections.users5_humans.user_id,` + + ` projections.users5_humans.first_name,` + + ` projections.users5_humans.last_name,` + + ` projections.users5_humans.nick_name,` + + ` projections.users5_humans.display_name,` + + ` projections.users5_humans.preferred_language,` + + ` projections.users5_humans.gender,` + + ` projections.users5_humans.avatar_key` + + ` FROM projections.users5` + + ` LEFT JOIN projections.users5_humans ON projections.users5.id = projections.users5_humans.user_id AND projections.users5.instance_id = projections.users5_humans.instance_id` profileCols = []string{ "id", "creation_date", @@ -115,16 +116,16 @@ var ( "gender", "avatar_key", } - emailQuery = `SELECT projections.users4.id,` + - ` projections.users4.creation_date,` + - ` projections.users4.change_date,` + - ` projections.users4.resource_owner,` + - ` projections.users4.sequence,` + - ` projections.users4_humans.user_id,` + - ` projections.users4_humans.email,` + - ` projections.users4_humans.is_email_verified` + - ` FROM projections.users4` + - ` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id AND projections.users4.instance_id = projections.users4_humans.instance_id` + emailQuery = `SELECT projections.users5.id,` + + ` projections.users5.creation_date,` + + ` projections.users5.change_date,` + + ` projections.users5.resource_owner,` + + ` projections.users5.sequence,` + + ` projections.users5_humans.user_id,` + + ` projections.users5_humans.email,` + + ` projections.users5_humans.is_email_verified` + + ` FROM projections.users5` + + ` LEFT JOIN projections.users5_humans ON projections.users5.id = projections.users5_humans.user_id AND projections.users5.instance_id = projections.users5_humans.instance_id` emailCols = []string{ "id", "creation_date", @@ -135,16 +136,16 @@ var ( "email", "is_email_verified", } - phoneQuery = `SELECT projections.users4.id,` + - ` projections.users4.creation_date,` + - ` projections.users4.change_date,` + - ` projections.users4.resource_owner,` + - ` projections.users4.sequence,` + - ` projections.users4_humans.user_id,` + - ` projections.users4_humans.phone,` + - ` projections.users4_humans.is_phone_verified` + - ` FROM projections.users4` + - ` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id AND projections.users4.instance_id = projections.users4_humans.instance_id` + phoneQuery = `SELECT projections.users5.id,` + + ` projections.users5.creation_date,` + + ` projections.users5.change_date,` + + ` projections.users5.resource_owner,` + + ` projections.users5.sequence,` + + ` projections.users5_humans.user_id,` + + ` projections.users5_humans.phone,` + + ` projections.users5_humans.is_phone_verified` + + ` FROM projections.users5` + + ` LEFT JOIN projections.users5_humans ON projections.users5.id = projections.users5_humans.user_id AND projections.users5.instance_id = projections.users5_humans.instance_id` phoneCols = []string{ "id", "creation_date", @@ -155,14 +156,14 @@ var ( "phone", "is_phone_verified", } - userUniqueQuery = `SELECT projections.users4.id,` + - ` projections.users4.state,` + - ` projections.users4.username,` + - ` projections.users4_humans.user_id,` + - ` projections.users4_humans.email,` + - ` projections.users4_humans.is_email_verified` + - ` FROM projections.users4` + - ` LEFT JOIN projections.users4_humans ON projections.users4.id = projections.users4_humans.user_id AND projections.users4.instance_id = projections.users4_humans.instance_id` + userUniqueQuery = `SELECT projections.users5.id,` + + ` projections.users5.state,` + + ` projections.users5.username,` + + ` projections.users5_humans.user_id,` + + ` projections.users5_humans.email,` + + ` projections.users5_humans.is_email_verified` + + ` FROM projections.users5` + + ` LEFT JOIN projections.users5_humans ON projections.users5.id = projections.users5_humans.user_id AND projections.users5.instance_id = projections.users5_humans.instance_id` userUniqueCols = []string{ "id", "state", @@ -171,43 +172,44 @@ var ( "email", "is_email_verified", } - notifyUserQuery = `SELECT projections.users4.id,` + - ` projections.users4.creation_date,` + - ` projections.users4.change_date,` + - ` projections.users4.resource_owner,` + - ` projections.users4.sequence,` + - ` projections.users4.state,` + - ` projections.users4.type,` + - ` projections.users4.username,` + + notifyUserQuery = `SELECT projections.users5.id,` + + ` projections.users5.creation_date,` + + ` projections.users5.change_date,` + + ` projections.users5.resource_owner,` + + ` projections.users5.sequence,` + + ` projections.users5.state,` + + ` projections.users5.type,` + + ` projections.users5.username,` + ` login_names.loginnames,` + ` preferred_login_name.login_name,` + - ` projections.users4_humans.user_id,` + - ` projections.users4_humans.first_name,` + - ` projections.users4_humans.last_name,` + - ` projections.users4_humans.nick_name,` + - ` projections.users4_humans.display_name,` + - ` projections.users4_humans.preferred_language,` + - ` projections.users4_humans.gender,` + - ` projections.users4_humans.avatar_key,` + - ` projections.users4_notifications.user_id,` + - ` projections.users4_notifications.last_email,` + - ` projections.users4_notifications.verified_email,` + - ` projections.users4_notifications.last_phone,` + - ` projections.users4_notifications.verified_phone,` + - ` projections.users4_notifications.password_set,` + + ` projections.users5_humans.user_id,` + + ` projections.users5_humans.first_name,` + + ` projections.users5_humans.last_name,` + + ` projections.users5_humans.nick_name,` + + ` projections.users5_humans.display_name,` + + ` projections.users5_humans.preferred_language,` + + ` projections.users5_humans.gender,` + + ` projections.users5_humans.avatar_key,` + + ` projections.users5_notifications.user_id,` + + ` projections.users5_notifications.last_email,` + + ` projections.users5_notifications.verified_email,` + + ` projections.users5_notifications.last_phone,` + + ` projections.users5_notifications.verified_phone,` + + ` projections.users5_notifications.password_set,` + ` COUNT(*) OVER ()` + - ` FROM projections.users4` + - ` 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 AND projections.users4.instance_id = projections.users4_notifications.instance_id` + + ` FROM projections.users5` + + ` LEFT JOIN projections.users5_humans ON projections.users5.id = projections.users5_humans.user_id AND projections.users5.instance_id = projections.users5_humans.instance_id` + + ` LEFT JOIN projections.users5_notifications ON projections.users5.id = projections.users5_notifications.user_id AND projections.users5.instance_id = projections.users5_notifications.instance_id` + ` 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, login_names.instance_id` + ` FROM projections.login_names AS login_names` + - ` WHERE login_names.instance_id = $1` + - ` GROUP BY login_names.user_id) AS login_names` + - ` ON login_names.user_id = projections.users4.id` + + ` GROUP BY login_names.user_id, login_names.instance_id) AS login_names` + + ` ON login_names.user_id = projections.users5.id AND login_names.instance_id = projections.users5.instance_id` + ` LEFT JOIN` + - ` (SELECT preferred_login_name.user_id, preferred_login_name.login_name FROM projections.login_names AS preferred_login_name WHERE preferred_login_name.instance_id = $2 AND preferred_login_name.is_primary = $3) AS preferred_login_name` + - ` ON preferred_login_name.user_id = projections.users4.id` + ` (SELECT preferred_login_name.user_id, preferred_login_name.login_name, preferred_login_name.instance_id` + + ` FROM projections.login_names AS preferred_login_name` + + ` WHERE preferred_login_name.is_primary = $1) AS preferred_login_name` + + ` ON preferred_login_name.user_id = projections.users5.id AND preferred_login_name.instance_id = projections.users5.instance_id` notifyUserCols = []string{ "id", "creation_date", @@ -237,43 +239,45 @@ var ( "password_set", "count", } - usersQuery = `SELECT projections.users4.id,` + - ` projections.users4.creation_date,` + - ` projections.users4.change_date,` + - ` projections.users4.resource_owner,` + - ` projections.users4.sequence,` + - ` projections.users4.state,` + - ` projections.users4.type,` + - ` projections.users4.username,` + + usersQuery = `SELECT projections.users5.id,` + + ` projections.users5.creation_date,` + + ` projections.users5.change_date,` + + ` projections.users5.resource_owner,` + + ` projections.users5.sequence,` + + ` projections.users5.state,` + + ` projections.users5.type,` + + ` projections.users5.username,` + ` login_names.loginnames,` + ` preferred_login_name.login_name,` + - ` projections.users4_humans.user_id,` + - ` projections.users4_humans.first_name,` + - ` projections.users4_humans.last_name,` + - ` projections.users4_humans.nick_name,` + - ` projections.users4_humans.display_name,` + - ` projections.users4_humans.preferred_language,` + - ` projections.users4_humans.gender,` + - ` projections.users4_humans.avatar_key,` + - ` projections.users4_humans.email,` + - ` projections.users4_humans.is_email_verified,` + - ` projections.users4_humans.phone,` + - ` projections.users4_humans.is_phone_verified,` + - ` projections.users4_machines.user_id,` + - ` projections.users4_machines.name,` + - ` projections.users4_machines.description,` + + ` projections.users5_humans.user_id,` + + ` projections.users5_humans.first_name,` + + ` projections.users5_humans.last_name,` + + ` projections.users5_humans.nick_name,` + + ` projections.users5_humans.display_name,` + + ` projections.users5_humans.preferred_language,` + + ` projections.users5_humans.gender,` + + ` projections.users5_humans.avatar_key,` + + ` projections.users5_humans.email,` + + ` projections.users5_humans.is_email_verified,` + + ` projections.users5_humans.phone,` + + ` projections.users5_humans.is_phone_verified,` + + ` projections.users5_machines.user_id,` + + ` projections.users5_machines.name,` + + ` projections.users5_machines.description,` + ` COUNT(*) OVER ()` + - ` FROM projections.users4` + - ` 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 AND projections.users4.instance_id = projections.users4_machines.instance_id` + + ` FROM projections.users5` + + ` LEFT JOIN projections.users5_humans ON projections.users5.id = projections.users5_humans.user_id AND projections.users5.instance_id = projections.users5_humans.instance_id` + + ` LEFT JOIN projections.users5_machines ON projections.users5.id = projections.users5_machines.user_id AND projections.users5.instance_id = projections.users5_machines.instance_id` + ` 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, login_names.instance_id` + ` FROM projections.login_names AS login_names` + - ` GROUP BY login_names.user_id) AS login_names` + - ` ON login_names.user_id = projections.users4.id` + + ` GROUP BY login_names.user_id, login_names.instance_id) AS login_names` + + ` ON login_names.user_id = projections.users5.id AND login_names.instance_id = projections.users5.instance_id` + ` LEFT JOIN` + - ` (SELECT preferred_login_name.user_id, preferred_login_name.login_name FROM projections.login_names AS preferred_login_name WHERE preferred_login_name.is_primary = $1) AS preferred_login_name` + - ` ON preferred_login_name.user_id = projections.users4.id` + ` (SELECT preferred_login_name.user_id, preferred_login_name.login_name, preferred_login_name.instance_id` + + ` FROM projections.login_names AS preferred_login_name` + + ` WHERE preferred_login_name.is_primary = $1) AS preferred_login_name` + + ` ON preferred_login_name.user_id = projections.users5.id AND preferred_login_name.instance_id = projections.users5.instance_id` usersCols = []string{ "id", "creation_date", @@ -320,7 +324,7 @@ func Test_UserPrepares(t *testing.T) { { name: "prepareUserQuery no result", prepare: func() (sq.SelectBuilder, func(*sql.Row) (*User, error)) { - return prepareUserQuery("instanceID") + return prepareUserQuery() }, want: want{ sqlExpectations: mockQuery( @@ -340,7 +344,7 @@ func Test_UserPrepares(t *testing.T) { { name: "prepareUserQuery human found", prepare: func() (sq.SelectBuilder, func(*sql.Row) (*User, error)) { - return prepareUserQuery("instanceID") + return prepareUserQuery() }, want: want{ sqlExpectations: mockQuery( @@ -407,7 +411,7 @@ func Test_UserPrepares(t *testing.T) { { name: "prepareUserQuery machine found", prepare: func() (sq.SelectBuilder, func(*sql.Row) (*User, error)) { - return prepareUserQuery("instanceID") + return prepareUserQuery() }, want: want{ sqlExpectations: mockQuery( @@ -465,7 +469,7 @@ func Test_UserPrepares(t *testing.T) { { name: "prepareUserQuery sql err", prepare: func() (sq.SelectBuilder, func(*sql.Row) (*User, error)) { - return prepareUserQuery("instanceID") + return prepareUserQuery() }, want: want{ sqlExpectations: mockQueryErr( @@ -832,7 +836,7 @@ func Test_UserPrepares(t *testing.T) { { name: "prepareNotifyUserQuery no result", prepare: func() (sq.SelectBuilder, func(*sql.Row) (*NotifyUser, error)) { - return prepareNotifyUserQuery("instanceID") + return prepareNotifyUserQuery() }, want: want{ sqlExpectations: mockQuery( @@ -852,7 +856,7 @@ func Test_UserPrepares(t *testing.T) { { name: "prepareNotifyUserQuery notify found", prepare: func() (sq.SelectBuilder, func(*sql.Row) (*NotifyUser, error)) { - return prepareNotifyUserQuery("instanceID") + return prepareNotifyUserQuery() }, want: want{ sqlExpectations: mockQuery( @@ -917,7 +921,7 @@ func Test_UserPrepares(t *testing.T) { { name: "prepareNotifyUserQuery not notify found (error)", prepare: func() (sq.SelectBuilder, func(*sql.Row) (*NotifyUser, error)) { - return prepareNotifyUserQuery("instanceID") + return prepareNotifyUserQuery() }, want: want{ sqlExpectations: mockQuery( @@ -964,7 +968,7 @@ func Test_UserPrepares(t *testing.T) { { name: "prepareNotifyUserQuery sql err", prepare: func() (sq.SelectBuilder, func(*sql.Row) (*NotifyUser, error)) { - return prepareNotifyUserQuery("instanceID") + return prepareNotifyUserQuery() }, want: want{ sqlExpectations: mockQueryErr( @@ -981,8 +985,10 @@ func Test_UserPrepares(t *testing.T) { object: nil, }, { - name: "prepareUsersQuery no result", - prepare: prepareUsersQuery, + name: "prepareUsersQuery no result", + prepare: func() (sq.SelectBuilder, func(*sql.Rows) (*Users, error)) { + return prepareUsersQuery() + }, want: want{ sqlExpectations: mockQueries( regexp.QuoteMeta(usersQuery), @@ -999,8 +1005,10 @@ func Test_UserPrepares(t *testing.T) { object: &Users{Users: []*User{}}, }, { - name: "prepareUsersQuery one result", - prepare: prepareUsersQuery, + name: "prepareUsersQuery one result", + prepare: func() (sq.SelectBuilder, func(*sql.Rows) (*Users, error)) { + return prepareUsersQuery() + }, want: want{ sqlExpectations: mockQueries( regexp.QuoteMeta(usersQuery), @@ -1072,8 +1080,10 @@ func Test_UserPrepares(t *testing.T) { }, }, { - name: "prepareUsersQuery multiple results", - prepare: prepareUsersQuery, + name: "prepareUsersQuery multiple results", + prepare: func() (sq.SelectBuilder, func(*sql.Rows) (*Users, error)) { + return prepareUsersQuery() + }, want: want{ sqlExpectations: mockQueries( regexp.QuoteMeta(usersQuery), @@ -1190,8 +1200,10 @@ func Test_UserPrepares(t *testing.T) { }, }, { - name: "prepareUsersQuery sql err", - prepare: prepareUsersQuery, + name: "prepareUsersQuery sql err", + prepare: func() (sq.SelectBuilder, func(*sql.Rows) (*Users, error)) { + return prepareUsersQuery() + }, want: want{ sqlExpectations: mockQueryErr( regexp.QuoteMeta(usersQuery),