From 12b78e5a364a1e64ab412a451201aeefb4e9c997 Mon Sep 17 00:00:00 2001 From: Stefan Benz <46600784+stebenz@users.noreply.github.com> Date: Wed, 26 Mar 2025 20:26:16 +0100 Subject: [PATCH] fix: rename idp_templates6_ldap3 to ldap2 if necessary (#9565) # Which Problems Are Solved Zitadel setup with v2.71.0 could result in errors regarding the idp_templates6_ldap3 subtable. # How the Problems Are Solved Rename the subtable idp_templates6_ldap3 to idp_templates6_ldap2 if no idp_templates6_ldap2 is existing and rename column `rootCA` to `root_ca`. # Additional Changes None # Additional Context Related PR #9292 --------- Co-authored-by: Silvan <27845747+adlerhurst@users.noreply.github.com> (cherry picked from commit 6b23c33cb6cdb2b93bcca4e23cfb3f73dfa7c263) --- cmd/setup/52.go | 27 +++++++++++++++++++++++++++ cmd/setup/52.sql | 2 ++ cmd/setup/config.go | 1 + cmd/setup/setup.go | 2 ++ 4 files changed, 32 insertions(+) create mode 100644 cmd/setup/52.go create mode 100644 cmd/setup/52.sql diff --git a/cmd/setup/52.go b/cmd/setup/52.go new file mode 100644 index 0000000000..5b86ba1bad --- /dev/null +++ b/cmd/setup/52.go @@ -0,0 +1,27 @@ +package setup + +import ( + "context" + _ "embed" + + "github.com/zitadel/zitadel/internal/database" + "github.com/zitadel/zitadel/internal/eventstore" +) + +var ( + //go:embed 52.sql + renameTableIfNotExisting string +) + +type IDPTemplate6LDAP2 struct { + dbClient *database.DB +} + +func (mig *IDPTemplate6LDAP2) Execute(ctx context.Context, _ eventstore.Event) error { + _, err := mig.dbClient.ExecContext(ctx, renameTableIfNotExisting) + return err +} + +func (mig *IDPTemplate6LDAP2) String() string { + return "52_idp_templates6_ldap2" +} diff --git a/cmd/setup/52.sql b/cmd/setup/52.sql new file mode 100644 index 0000000000..1414b6386c --- /dev/null +++ b/cmd/setup/52.sql @@ -0,0 +1,2 @@ +ALTER TABLE IF EXISTS projections.idp_templates6_ldap3 RENAME COLUMN rootCA TO root_ca; +ALTER TABLE IF EXISTS projections.idp_templates6_ldap3 RENAME TO idp_templates6_ldap2; diff --git a/cmd/setup/config.go b/cmd/setup/config.go index 3f6c67a910..2b74fb2dbc 100644 --- a/cmd/setup/config.go +++ b/cmd/setup/config.go @@ -140,6 +140,7 @@ type Steps struct { s49InitPermittedOrgsFunction *InitPermittedOrgsFunction s50IDPTemplate6UsePKCE *IDPTemplate6UsePKCE s51IDPTemplate6RootCA *IDPTemplate6RootCA + s52IDPTemplate6LDAP2 *IDPTemplate6LDAP2 } func MustNewSteps(v *viper.Viper) *Steps { diff --git a/cmd/setup/setup.go b/cmd/setup/setup.go index bbabe07122..f13802ffa0 100644 --- a/cmd/setup/setup.go +++ b/cmd/setup/setup.go @@ -178,6 +178,7 @@ func Setup(ctx context.Context, config *Config, steps *Steps, masterKey string) steps.s49InitPermittedOrgsFunction = &InitPermittedOrgsFunction{eventstoreClient: dbClient} steps.s50IDPTemplate6UsePKCE = &IDPTemplate6UsePKCE{dbClient: dbClient} steps.s51IDPTemplate6RootCA = &IDPTemplate6RootCA{dbClient: dbClient} + steps.s52IDPTemplate6LDAP2 = &IDPTemplate6LDAP2{dbClient: dbClient} err = projection.Create(ctx, dbClient, eventstoreClient, config.Projections, nil, nil, nil) logging.OnError(err).Fatal("unable to start projections") @@ -218,6 +219,7 @@ func Setup(ctx context.Context, config *Config, steps *Steps, masterKey string) steps.s49InitPermittedOrgsFunction, steps.s50IDPTemplate6UsePKCE, steps.s51IDPTemplate6RootCA, + steps.s52IDPTemplate6LDAP2, } { mustExecuteMigration(ctx, eventstoreClient, step, "migration failed") }