diff --git a/internal/query/embed/userinfo_by_id.sql b/internal/query/embed/userinfo_by_id.sql index 9056e2fe6d..0926efe5cd 100644 --- a/internal/query/embed/userinfo_by_id.sql +++ b/internal/query/embed/userinfo_by_id.sql @@ -23,7 +23,7 @@ machine as ( metadata as ( select json_agg(row_to_json(r)) as metadata from ( select creation_date, change_date, sequence, resource_owner, key, encode(value, 'base64') as value - from projections.user_metadata4 + from projections.user_metadata5 where user_id = $1 and instance_id = $2 ) r diff --git a/internal/query/projection/user_metadata.go b/internal/query/projection/user_metadata.go index 326860cdf0..e1b155294c 100644 --- a/internal/query/projection/user_metadata.go +++ b/internal/query/projection/user_metadata.go @@ -13,7 +13,7 @@ import ( ) const ( - UserMetadataProjectionTable = "projections.user_metadata4" + UserMetadataProjectionTable = "projections.user_metadata5" UserMetadataColumnUserID = "user_id" UserMetadataColumnCreationDate = "creation_date" @@ -23,7 +23,6 @@ const ( UserMetadataColumnInstanceID = "instance_id" UserMetadataColumnKey = "key" UserMetadataColumnValue = "value" - UserMetadataColumnOwnerRemoved = "owner_removed" ) type userMetadataProjection struct{} @@ -47,11 +46,9 @@ func (*userMetadataProjection) Init() *old_handler.Check { handler.NewColumn(UserMetadataColumnInstanceID, handler.ColumnTypeText), handler.NewColumn(UserMetadataColumnKey, handler.ColumnTypeText), handler.NewColumn(UserMetadataColumnValue, handler.ColumnTypeBytes, handler.Nullable()), - handler.NewColumn(UserMetadataColumnOwnerRemoved, handler.ColumnTypeBool, handler.Default(false)), }, handler.NewPrimaryKey(UserMetadataColumnInstanceID, UserMetadataColumnUserID, UserMetadataColumnKey), handler.WithIndex(handler.NewIndex("resource_owner", []string{UserGrantResourceOwner})), - handler.WithIndex(handler.NewIndex("owner_removed", []string{UserMetadataColumnOwnerRemoved})), ), ) } diff --git a/internal/query/projection/user_metadata_test.go b/internal/query/projection/user_metadata_test.go index fcf8b26d2f..9d0bb60ce2 100644 --- a/internal/query/projection/user_metadata_test.go +++ b/internal/query/projection/user_metadata_test.go @@ -41,7 +41,7 @@ func TestUserMetadataProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.user_metadata4 (instance_id, user_id, key, resource_owner, creation_date, change_date, sequence, value) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT (instance_id, user_id, key) DO UPDATE SET (resource_owner, creation_date, change_date, sequence, value) = (EXCLUDED.resource_owner, EXCLUDED.creation_date, EXCLUDED.change_date, EXCLUDED.sequence, EXCLUDED.value)", + expectedStmt: "INSERT INTO projections.user_metadata5 (instance_id, user_id, key, resource_owner, creation_date, change_date, sequence, value) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT (instance_id, user_id, key) DO UPDATE SET (resource_owner, creation_date, change_date, sequence, value) = (EXCLUDED.resource_owner, EXCLUDED.creation_date, EXCLUDED.change_date, EXCLUDED.sequence, EXCLUDED.value)", expectedArgs: []interface{}{ "instance-id", "agg-id", @@ -76,7 +76,7 @@ func TestUserMetadataProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.user_metadata4 WHERE (user_id = $1) AND (key = $2) AND (instance_id = $3)", + expectedStmt: "DELETE FROM projections.user_metadata5 WHERE (user_id = $1) AND (key = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "agg-id", "key", @@ -104,7 +104,7 @@ func TestUserMetadataProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.user_metadata4 WHERE (user_id = $1) AND (instance_id = $2)", + expectedStmt: "DELETE FROM projections.user_metadata5 WHERE (user_id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -131,7 +131,7 @@ func TestUserMetadataProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.user_metadata4 WHERE (user_id = $1) AND (instance_id = $2)", + expectedStmt: "DELETE FROM projections.user_metadata5 WHERE (user_id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", "instance-id", @@ -158,7 +158,7 @@ func TestUserMetadataProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.user_metadata4 WHERE (instance_id = $1) AND (resource_owner = $2)", + expectedStmt: "DELETE FROM projections.user_metadata5 WHERE (instance_id = $1) AND (resource_owner = $2)", expectedArgs: []interface{}{ "instance-id", "agg-id", @@ -185,7 +185,7 @@ func TestUserMetadataProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.user_metadata4 WHERE (instance_id = $1)", + expectedStmt: "DELETE FROM projections.user_metadata5 WHERE (instance_id = $1)", expectedArgs: []interface{}{ "agg-id", }, diff --git a/internal/query/user_metadata.go b/internal/query/user_metadata.go index 74dba3528c..a4f0fd2e9f 100644 --- a/internal/query/user_metadata.go +++ b/internal/query/user_metadata.go @@ -74,10 +74,6 @@ var ( name: projection.UserMetadataColumnValue, table: userMetadataTable, } - UserMetadataOwnerRemovedCol = Column{ - name: projection.UserMetadataColumnOwnerRemoved, - table: userMetadataTable, - } ) func (q *Queries) GetUserMetadataByKey(ctx context.Context, shouldTriggerBulk bool, userID, key string, withOwnerRemoved bool, queries ...SearchQuery) (metadata *UserMetadata, err error) { @@ -100,9 +96,6 @@ func (q *Queries) GetUserMetadataByKey(ctx context.Context, shouldTriggerBulk bo UserMetadataKeyCol.identifier(): key, UserMetadataInstanceIDCol.identifier(): authz.GetInstance(ctx).InstanceID(), } - if !withOwnerRemoved { - eq[UserMetadataOwnerRemovedCol.identifier()] = false - } stmt, args, err := query.Where(eq).ToSql() if err != nil { return nil, errors.ThrowInternal(err, "QUERY-aDGG2", "Errors.Query.SQLStatment") @@ -131,9 +124,6 @@ func (q *Queries) SearchUserMetadata(ctx context.Context, shouldTriggerBulk bool UserMetadataUserIDCol.identifier(): userID, UserMetadataInstanceIDCol.identifier(): authz.GetInstance(ctx).InstanceID(), } - if !withOwnerRemoved { - eq[UserMetadataOwnerRemovedCol.identifier()] = false - } stmt, args, err := queries.toQuery(query).Where(eq).ToSql() if err != nil { return nil, errors.ThrowInternal(err, "QUERY-Egbgd", "Errors.Query.SQLStatment") diff --git a/internal/query/user_metadata_test.go b/internal/query/user_metadata_test.go index 62f7cfb6a3..1fbd04cc7b 100644 --- a/internal/query/user_metadata_test.go +++ b/internal/query/user_metadata_test.go @@ -12,13 +12,13 @@ import ( ) var ( - userMetadataQuery = `SELECT projections.user_metadata4.creation_date,` + - ` projections.user_metadata4.change_date,` + - ` projections.user_metadata4.resource_owner,` + - ` projections.user_metadata4.sequence,` + - ` projections.user_metadata4.key,` + - ` projections.user_metadata4.value` + - ` FROM projections.user_metadata4` + + userMetadataQuery = `SELECT projections.user_metadata5.creation_date,` + + ` projections.user_metadata5.change_date,` + + ` projections.user_metadata5.resource_owner,` + + ` projections.user_metadata5.sequence,` + + ` projections.user_metadata5.key,` + + ` projections.user_metadata5.value` + + ` FROM projections.user_metadata5` + ` AS OF SYSTEM TIME '-1 ms'` userMetadataCols = []string{ "creation_date", @@ -28,14 +28,14 @@ var ( "key", "value", } - userMetadataListQuery = `SELECT projections.user_metadata4.creation_date,` + - ` projections.user_metadata4.change_date,` + - ` projections.user_metadata4.resource_owner,` + - ` projections.user_metadata4.sequence,` + - ` projections.user_metadata4.key,` + - ` projections.user_metadata4.value,` + + userMetadataListQuery = `SELECT projections.user_metadata5.creation_date,` + + ` projections.user_metadata5.change_date,` + + ` projections.user_metadata5.resource_owner,` + + ` projections.user_metadata5.sequence,` + + ` projections.user_metadata5.key,` + + ` projections.user_metadata5.value,` + ` COUNT(*) OVER ()` + - ` FROM projections.user_metadata4` + ` FROM projections.user_metadata5` userMetadataListCols = []string{ "creation_date", "change_date",