mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:07:30 +00:00
fix(migration): check if ldap2 already exists (#9674)
# Which Problems Are Solved With v2.71.0 the `idp_templates6_ldap3` projection was created but never filled, as it was a subtable. To fix this we altered the `idp_templates6_ldap3` to `idp_templates6_ldap2` with v2.71.5. This was unfortunately without a check that the `idp_templates_ldap2`was already existing, which resulted in an error in the setup step. # How the Problems Are Solved Add check if `idp_templates6_ldap2` is already existing, before renaming `idp_templates6_ldap3` -> `idp_templates6_ldap2`. # Additional Changes None # Additional Context Closes #9669
This commit is contained in:
@@ -2,15 +2,19 @@ package setup
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/database"
|
"github.com/zitadel/zitadel/internal/database"
|
||||||
"github.com/zitadel/zitadel/internal/eventstore"
|
"github.com/zitadel/zitadel/internal/eventstore"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//go:embed 52.sql
|
//go:embed 52/alter.sql
|
||||||
renameTableIfNotExisting string
|
renameTableIfNotExisting string
|
||||||
|
//go:embed 52/check.sql
|
||||||
|
checkIfTableIsExisting string
|
||||||
)
|
)
|
||||||
|
|
||||||
type IDPTemplate6LDAP2 struct {
|
type IDPTemplate6LDAP2 struct {
|
||||||
@@ -18,7 +22,23 @@ type IDPTemplate6LDAP2 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mig *IDPTemplate6LDAP2) Execute(ctx context.Context, _ eventstore.Event) error {
|
func (mig *IDPTemplate6LDAP2) Execute(ctx context.Context, _ eventstore.Event) error {
|
||||||
_, err := mig.dbClient.ExecContext(ctx, renameTableIfNotExisting)
|
var count int
|
||||||
|
err := mig.dbClient.QueryRowContext(ctx,
|
||||||
|
func(row *sql.Row) error {
|
||||||
|
if err := row.Scan(&count); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return row.Err()
|
||||||
|
},
|
||||||
|
checkIfTableIsExisting,
|
||||||
|
)
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if !errors.Is(err, sql.ErrNoRows) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = mig.dbClient.ExecContext(ctx, renameTableIfNotExisting)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
cmd/setup/52/check.sql
Normal file
4
cmd/setup/52/check.sql
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
SELECT 1
|
||||||
|
FROM information_schema.tables
|
||||||
|
WHERE table_schema = 'projections'
|
||||||
|
AND table_name = 'idp_templates6_ldap2';
|
Reference in New Issue
Block a user