2025-03-26 20:26:16 +01:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2025-03-31 12:06:40 +02:00
|
|
|
"database/sql"
|
2025-03-26 20:26:16 +01:00
|
|
|
_ "embed"
|
2025-03-31 12:06:40 +02:00
|
|
|
"errors"
|
2025-03-26 20:26:16 +01:00
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2025-03-31 12:06:40 +02:00
|
|
|
//go:embed 52/alter.sql
|
2025-03-26 20:26:16 +01:00
|
|
|
renameTableIfNotExisting string
|
2025-03-31 12:06:40 +02:00
|
|
|
//go:embed 52/check.sql
|
|
|
|
checkIfTableIsExisting string
|
2025-03-26 20:26:16 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type IDPTemplate6LDAP2 struct {
|
|
|
|
dbClient *database.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mig *IDPTemplate6LDAP2) Execute(ctx context.Context, _ eventstore.Event) error {
|
2025-03-31 12:06:40 +02:00
|
|
|
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)
|
2025-03-26 20:26:16 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mig *IDPTemplate6LDAP2) String() string {
|
|
|
|
return "52_idp_templates6_ldap2"
|
|
|
|
}
|