mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-23 01:57:12 +00:00
The change was introduced in
https://github.com/zitadel/zitadel/pull/11178.
The fix is to prevent wiping the memberships because the projection did
not init yet.
### Changes
- Introduces a check to determine if the member role synchronization
should be executed based on the existence of a specific database table
(`projections.instance_members4`).
- Ensures that the synchronization process only runs if the required
table is present in the database.
(cherry picked from commit 1b54a9eb05)
39 lines
829 B
Go
39 lines
829 B
Go
package setup
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
_ "embed"
|
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
)
|
|
|
|
var (
|
|
//go:embed 67.sql
|
|
syncMemberRoleFields string
|
|
)
|
|
|
|
type SyncMemberRoleFields struct {
|
|
dbClient *database.DB
|
|
}
|
|
|
|
func (mig *SyncMemberRoleFields) Execute(ctx context.Context, _ eventstore.Event) error {
|
|
var exists bool
|
|
err := mig.dbClient.QueryRowContext(
|
|
ctx,
|
|
func(row *sql.Row) error {
|
|
return row.Scan(&exists)
|
|
},
|
|
"SELECT EXISTS(SELECT FROM pg_catalog.pg_tables WHERE schemaname = 'projections' and tablename = 'instance_members4')")
|
|
if err != nil || !exists {
|
|
return err
|
|
}
|
|
_, err = mig.dbClient.ExecContext(ctx, syncMemberRoleFields)
|
|
return err
|
|
}
|
|
|
|
func (mig *SyncMemberRoleFields) String() string {
|
|
return "67_sync_member_role_fields"
|
|
}
|