diff --git a/internal/admin/repository/eventsourcing/view/sequence.go b/internal/admin/repository/eventsourcing/view/sequence.go index 5486ba1dd4..b73461152b 100644 --- a/internal/admin/repository/eventsourcing/view/sequence.go +++ b/internal/admin/repository/eventsourcing/view/sequence.go @@ -32,9 +32,6 @@ func (v *View) updateSpoolerRunSequence(viewName string) error { currentSequence.ViewName = viewName } currentSequence.LastSuccessfulSpoolerRun = time.Now() - //update all aggregate types - //TODO: not sure if all scenarios work as expected - currentSequence.AggregateType = "" return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence) } diff --git a/internal/auth/repository/eventsourcing/view/sequence.go b/internal/auth/repository/eventsourcing/view/sequence.go index 2ca2ca634b..be0830c060 100644 --- a/internal/auth/repository/eventsourcing/view/sequence.go +++ b/internal/auth/repository/eventsourcing/view/sequence.go @@ -28,7 +28,5 @@ func (v *View) updateSpoolerRunSequence(viewName string) error { currentSequence.ViewName = viewName } currentSequence.LastSuccessfulSpoolerRun = time.Now() - //update all aggregate types - currentSequence.AggregateType = "" return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence) } diff --git a/internal/authz/repository/eventsourcing/view/sequence.go b/internal/authz/repository/eventsourcing/view/sequence.go index 806165af4c..a19fa854c2 100644 --- a/internal/authz/repository/eventsourcing/view/sequence.go +++ b/internal/authz/repository/eventsourcing/view/sequence.go @@ -28,7 +28,5 @@ func (v *View) updateSpoolerRunSequence(viewName string) error { currentSequence.ViewName = viewName } currentSequence.LastSuccessfulSpoolerRun = time.Now() - //update all aggregate types - currentSequence.AggregateType = "" return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence) } diff --git a/internal/management/repository/eventsourcing/view/sequence.go b/internal/management/repository/eventsourcing/view/sequence.go index f4f980929f..58f792f94a 100644 --- a/internal/management/repository/eventsourcing/view/sequence.go +++ b/internal/management/repository/eventsourcing/view/sequence.go @@ -28,7 +28,5 @@ func (v *View) updateSpoolerRunSequence(viewName string) error { currentSequence.ViewName = viewName } currentSequence.LastSuccessfulSpoolerRun = time.Now() - //update all aggregate types - currentSequence.AggregateType = "" return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence) } diff --git a/internal/notification/repository/eventsourcing/view/sequence.go b/internal/notification/repository/eventsourcing/view/sequence.go index 0908432b8b..ad1723cc54 100644 --- a/internal/notification/repository/eventsourcing/view/sequence.go +++ b/internal/notification/repository/eventsourcing/view/sequence.go @@ -28,7 +28,5 @@ func (v *View) updateSpoolerRunSequence(viewName string) error { currentSequence.ViewName = viewName } currentSequence.LastSuccessfulSpoolerRun = time.Now() - //update all aggregate types - currentSequence.AggregateType = "" return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence) } diff --git a/internal/view/model/view.go b/internal/view/model/view.go index 5cb354a1b7..6f766b912b 100644 --- a/internal/view/model/view.go +++ b/internal/view/model/view.go @@ -10,5 +10,4 @@ type View struct { CurrentSequence uint64 EventTimestamp time.Time LastSuccessfulSpoolerRun time.Time - AggregateType string } diff --git a/internal/view/repository/sequence.go b/internal/view/repository/sequence.go index c6b6d0354a..7835fcb973 100644 --- a/internal/view/repository/sequence.go +++ b/internal/view/repository/sequence.go @@ -1,12 +1,12 @@ package repository import ( - "github.com/caos/zitadel/internal/domain" "strings" "time" "github.com/jinzhu/gorm" + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" "github.com/caos/zitadel/internal/view/model" ) @@ -16,7 +16,6 @@ type CurrentSequence struct { CurrentSequence uint64 `gorm:"column:current_sequence"` EventTimestamp time.Time `gorm:"column:event_timestamp"` LastSuccessfulSpoolerRun time.Time `gorm:"column:last_successful_spooler_run"` - AggregateType string `gorm:"column:aggregate_type;primary_key"` } type currentSequenceViewWithSequence struct { @@ -76,12 +75,11 @@ func CurrentSequenceToModel(sequence *CurrentSequence) *model.View { CurrentSequence: sequence.CurrentSequence, EventTimestamp: sequence.EventTimestamp, LastSuccessfulSpoolerRun: sequence.LastSuccessfulSpoolerRun, - AggregateType: sequence.AggregateType, } } func SaveCurrentSequence(db *gorm.DB, table, viewName string, sequence uint64, eventTimestamp time.Time) error { - return UpdateCurrentSequence(db, table, &CurrentSequence{viewName, sequence, eventTimestamp, time.Now(), ""}) + return UpdateCurrentSequence(db, table, &CurrentSequence{viewName, sequence, eventTimestamp, time.Now()}) } func UpdateCurrentSequence(db *gorm.DB, table string, currentSequence *CurrentSequence) (err error) { diff --git a/migrations/cockroach/V1.37__current_sequence_table.sql b/migrations/cockroach/V1.37__current_sequence_table.sql new file mode 100644 index 0000000000..860b0a8622 --- /dev/null +++ b/migrations/cockroach/V1.37__current_sequence_table.sql @@ -0,0 +1,31 @@ +DELETE FROM management.current_sequences WHERE aggregate_type <> ''; +DELETE FROM auth.current_sequences WHERE aggregate_type <> ''; +DELETE FROM authz.current_sequences WHERE aggregate_type <> ''; +DELETE FROM adminapi.current_sequences WHERE aggregate_type <> ''; +DELETE FROM notification.current_sequences WHERE aggregate_type <> ''; + +BEGIN; + +ALTER TABLE management.current_sequences DROP CONSTRAINT "primary"; +ALTER TABLE auth.current_sequences DROP CONSTRAINT "primary"; +ALTER TABLE authz.current_sequences DROP CONSTRAINT "primary"; +ALTER TABLE adminapi.current_sequences DROP CONSTRAINT "primary"; +ALTER TABLE notification.current_sequences DROP CONSTRAINT "primary"; + +ALTER TABLE management.current_sequences ADD CONSTRAINT "primary" PRIMARY KEY (view_name); +ALTER TABLE auth.current_sequences ADD CONSTRAINT "primary" PRIMARY KEY (view_name); +ALTER TABLE authz.current_sequences ADD CONSTRAINT "primary" PRIMARY KEY (view_name); +ALTER TABLE adminapi.current_sequences ADD CONSTRAINT "primary" PRIMARY KEY (view_name); +ALTER TABLE notification.current_sequences ADD CONSTRAINT "primary" PRIMARY KEY (view_name); + +COMMIT; + +BEGIN; + +ALTER TABLE management.current_sequences DROP COLUMN aggregate_type; +ALTER TABLE auth.current_sequences DROP COLUMN aggregate_type; +ALTER TABLE authz.current_sequences DROP COLUMN aggregate_type; +ALTER TABLE adminapi.current_sequences DROP COLUMN aggregate_type; +ALTER TABLE notification.current_sequences DROP COLUMN aggregate_type; + +COMMIT; \ No newline at end of file