mirror of
https://github.com/zitadel/zitadel.git
synced 2025-03-04 03:05:13 +00:00
fix(eventstore): add created_at
column (#5818)
### Definition of Ready - [x] I am happy with the code - [ ] Short description of the feature/issue is added in the pr description - [ ] PR is linked to the corresponding user story - [ ] Acceptance criteria are met - [ ] All open todos and follow ups are defined in a new ticket and justified - [ ] Deviations from the acceptance criteria and design are agreed with the PO and documented. - [ ] No debug or dead code - [ ] Critical parts are tested automatically - [ ] Where possible E2E tests are implemented - [ ] Documentation/examples are up-to-date - [ ] All non-functional requirements are met - [ ] Functionality of the acceptance criteria is checked manually on the dev system.
This commit is contained in:
commit
a77f299168
@ -13,11 +13,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//go:embed 10_create_temp_table.sql
|
//go:embed 10/10_create_temp_table.sql
|
||||||
correctCreationDate10CreateTable string
|
correctCreationDate10CreateTable string
|
||||||
//go:embed 10_fill_table.sql
|
//go:embed 10/10_fill_table.sql
|
||||||
correctCreationDate10FillTable string
|
correctCreationDate10FillTable string
|
||||||
//go:embed 10_update.sql
|
//go:embed 10/10_update.sql
|
||||||
correctCreationDate10Update string
|
correctCreationDate10Update string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
32
cmd/setup/11.go
Normal file
32
cmd/setup/11.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package setup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
_ "embed"
|
||||||
|
|
||||||
|
"github.com/zitadel/zitadel/internal/database"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
//go:embed 11.sql
|
||||||
|
addEventCreatedAt string
|
||||||
|
)
|
||||||
|
|
||||||
|
type AddEventCreatedAt struct {
|
||||||
|
step10 *CorrectCreationDate
|
||||||
|
dbClient *database.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mig *AddEventCreatedAt) Execute(ctx context.Context) error {
|
||||||
|
// execute step 10 again because events created after the first execution of step 10
|
||||||
|
// could still have the wrong ordering of sequences and creation date
|
||||||
|
if err := mig.step10.Execute(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err := mig.dbClient.ExecContext(ctx, addEventCreatedAt)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mig *AddEventCreatedAt) String() string {
|
||||||
|
return "11_event_created_at"
|
||||||
|
}
|
15
cmd/setup/11.sql
Normal file
15
cmd/setup/11.sql
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
BEGIN;
|
||||||
|
-- create table with empty created_at
|
||||||
|
ALTER TABLE eventstore.events ADD COLUMN created_at TIMESTAMPTZ DEFAULT NULL;
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
-- backfill created_at
|
||||||
|
UPDATE eventstore.events SET created_at = creation_date WHERE created_at IS NULL;
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
-- set column rules
|
||||||
|
ALTER TABLE eventstore.events ALTER COLUMN created_at SET DEFAULT clock_timestamp();
|
||||||
|
ALTER TABLE eventstore.events ALTER COLUMN created_at SET NOT NULL;
|
||||||
|
COMMIT;
|
@ -66,6 +66,7 @@ type Steps struct {
|
|||||||
s8AuthTokens *AuthTokenIndexes
|
s8AuthTokens *AuthTokenIndexes
|
||||||
s9EventstoreIndexes2 *EventstoreIndexesNew
|
s9EventstoreIndexes2 *EventstoreIndexesNew
|
||||||
CorrectCreationDate *CorrectCreationDate
|
CorrectCreationDate *CorrectCreationDate
|
||||||
|
s11AddEventCreatedAt *AddEventCreatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
type encryptionKeyConfig struct {
|
type encryptionKeyConfig struct {
|
||||||
|
@ -91,6 +91,7 @@ func Setup(config *Config, steps *Steps, masterKey string) {
|
|||||||
steps.s8AuthTokens = &AuthTokenIndexes{dbClient: dbClient}
|
steps.s8AuthTokens = &AuthTokenIndexes{dbClient: dbClient}
|
||||||
steps.s9EventstoreIndexes2 = New09(dbClient)
|
steps.s9EventstoreIndexes2 = New09(dbClient)
|
||||||
steps.CorrectCreationDate.dbClient = dbClient
|
steps.CorrectCreationDate.dbClient = dbClient
|
||||||
|
steps.s11AddEventCreatedAt = &AddEventCreatedAt{dbClient: dbClient, step10: steps.CorrectCreationDate}
|
||||||
|
|
||||||
err = projection.Create(ctx, dbClient, eventstoreClient, config.Projections, nil, nil)
|
err = projection.Create(ctx, dbClient, eventstoreClient, config.Projections, nil, nil)
|
||||||
logging.OnError(err).Fatal("unable to start projections")
|
logging.OnError(err).Fatal("unable to start projections")
|
||||||
@ -128,6 +129,8 @@ func Setup(config *Config, steps *Steps, masterKey string) {
|
|||||||
logging.OnError(err).Fatal("unable to migrate step 9")
|
logging.OnError(err).Fatal("unable to migrate step 9")
|
||||||
err = migration.Migrate(ctx, eventstoreClient, steps.CorrectCreationDate)
|
err = migration.Migrate(ctx, eventstoreClient, steps.CorrectCreationDate)
|
||||||
logging.OnError(err).Fatal("unable to migrate step 10")
|
logging.OnError(err).Fatal("unable to migrate step 10")
|
||||||
|
err = migration.Migrate(ctx, eventstoreClient, steps.s11AddEventCreatedAt)
|
||||||
|
logging.OnError(err).Fatal("unable to migrate step 11")
|
||||||
|
|
||||||
for _, repeatableStep := range repeatableSteps {
|
for _, repeatableStep := range repeatableSteps {
|
||||||
err = migration.Migrate(ctx, eventstoreClient, repeatableStep)
|
err = migration.Migrate(ctx, eventstoreClient, repeatableStep)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user