mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 19:14:23 +00:00
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package setup
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
_ "embed"
|
|
"time"
|
|
|
|
"github.com/cockroachdb/cockroach-go/v2/crdb"
|
|
"github.com/zitadel/logging"
|
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
|
)
|
|
|
|
var (
|
|
//go:embed 10.sql
|
|
correctCreationDate10 string
|
|
)
|
|
|
|
type CorrectCreationDate struct {
|
|
dbClient *database.DB
|
|
FailAfter time.Duration
|
|
}
|
|
|
|
func (mig *CorrectCreationDate) Execute(ctx context.Context) (err error) {
|
|
ctx, cancel := context.WithTimeout(ctx, mig.FailAfter)
|
|
defer cancel()
|
|
|
|
for {
|
|
var affected int64
|
|
err = crdb.ExecuteTx(ctx, mig.dbClient.DB, nil, func(tx *sql.Tx) error {
|
|
if mig.dbClient.Type() == "cockroach" {
|
|
if _, err := tx.Exec("SET experimental_enable_temp_tables=on"); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
res, err := tx.ExecContext(ctx, correctCreationDate10)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
affected, _ = res.RowsAffected()
|
|
logging.WithFields("count", affected).Info("creation dates changed")
|
|
return nil
|
|
})
|
|
if affected == 0 || err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
func (mig *CorrectCreationDate) String() string {
|
|
return "10_correct_creation_date"
|
|
}
|