Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: check member table instead of principal table to decide whether to assing owner role for the new user (#4426)
Tianzhou (天舟)fb120db90c2d
diff --git a/backend/store/principal.go b/backend/store/principal.goindex 4c26dc94cc..82b250d11c 100644--- a/backend/store/principal.go+++ b/backend/store/principal.go@@ -370,19 +370,6 @@ func (s *Store) CreateUser(ctx context.Context, create *UserMessage, creatorID i}defer tx.Rollback()- var count int- if err := tx.QueryRowContext(ctx,- `SELECT COUNT(1) FROM principal WHERE type = $1`,- api.EndUser,- ).Scan(&count); err != nil {- return nil, err- }- role := api.Developer- // Grant the member Owner role if there is no existing Owner member.- if count == 0 {- role = api.Owner- }-set := []string{"creator_id", "updater_id", "email", "name", "type", "password_hash"}args := []interface{}{creatorID, creatorID, create.Email, create.Name, create.Type, create.PasswordHash}// Set idp fields into principal only when the related id is not null.@@ -420,6 +407,19 @@ func (s *Store) CreateUser(ctx context.Context, create *UserMessage, creatorID ireturn nil, FormatError(err)}+ var count int+ if err := tx.QueryRowContext(ctx,+ `SELECT COUNT(1) FROM member`,+ ).Scan(&count); err != nil {+ return nil, err+ }+ role := api.Developer+ firstMember := count == 0+ // Grant the member Owner role if there is no existing member.+ if firstMember {+ role = api.Owner+ }+if _, err := tx.ExecContext(ctx, `INSERT INTO member (creator_id,