From 26e1b80c1c7d8ed9277fc465093f41209b657b6a Mon Sep 17 00:00:00 2001 From: Livio Amstutz Date: Fri, 16 Apr 2021 06:54:29 +0200 Subject: [PATCH] fix: drop unused column from current_sequences (#1592) --- .../repository/eventsourcing/view/sequence.go | 3 -- .../repository/eventsourcing/view/sequence.go | 2 -- .../repository/eventsourcing/view/sequence.go | 2 -- .../repository/eventsourcing/view/sequence.go | 2 -- .../repository/eventsourcing/view/sequence.go | 2 -- internal/view/model/view.go | 1 - internal/view/repository/sequence.go | 6 ++-- .../V1.37__current_sequence_table.sql | 31 +++++++++++++++++++ 8 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 migrations/cockroach/V1.37__current_sequence_table.sql diff --git a/internal/admin/repository/eventsourcing/view/sequence.go b/internal/admin/repository/eventsourcing/view/sequence.go index 5486ba1dd4e..b73461152b1 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 2ca2ca634b5..be0830c060e 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 806165af4cf..a19fa854c2c 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 f4f980929fb..58f792f94a5 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 0908432b8b7..ad1723cc545 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 5cb354a1b7d..6f766b912b1 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 c6b6d0354ab..7835fcb9736 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 00000000000..860b0a86224 --- /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