fix: drop unused column from current_sequences (#1592)

This commit is contained in:
Livio Amstutz 2021-04-16 06:54:29 +02:00 committed by GitHub
parent 6a3a541848
commit 26e1b80c1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 16 deletions

View File

@ -32,9 +32,6 @@ func (v *View) updateSpoolerRunSequence(viewName string) error {
currentSequence.ViewName = viewName currentSequence.ViewName = viewName
} }
currentSequence.LastSuccessfulSpoolerRun = time.Now() 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) return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence)
} }

View File

@ -28,7 +28,5 @@ func (v *View) updateSpoolerRunSequence(viewName string) error {
currentSequence.ViewName = viewName currentSequence.ViewName = viewName
} }
currentSequence.LastSuccessfulSpoolerRun = time.Now() currentSequence.LastSuccessfulSpoolerRun = time.Now()
//update all aggregate types
currentSequence.AggregateType = ""
return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence) return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence)
} }

View File

@ -28,7 +28,5 @@ func (v *View) updateSpoolerRunSequence(viewName string) error {
currentSequence.ViewName = viewName currentSequence.ViewName = viewName
} }
currentSequence.LastSuccessfulSpoolerRun = time.Now() currentSequence.LastSuccessfulSpoolerRun = time.Now()
//update all aggregate types
currentSequence.AggregateType = ""
return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence) return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence)
} }

View File

@ -28,7 +28,5 @@ func (v *View) updateSpoolerRunSequence(viewName string) error {
currentSequence.ViewName = viewName currentSequence.ViewName = viewName
} }
currentSequence.LastSuccessfulSpoolerRun = time.Now() currentSequence.LastSuccessfulSpoolerRun = time.Now()
//update all aggregate types
currentSequence.AggregateType = ""
return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence) return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence)
} }

View File

@ -28,7 +28,5 @@ func (v *View) updateSpoolerRunSequence(viewName string) error {
currentSequence.ViewName = viewName currentSequence.ViewName = viewName
} }
currentSequence.LastSuccessfulSpoolerRun = time.Now() currentSequence.LastSuccessfulSpoolerRun = time.Now()
//update all aggregate types
currentSequence.AggregateType = ""
return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence) return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence)
} }

View File

@ -10,5 +10,4 @@ type View struct {
CurrentSequence uint64 CurrentSequence uint64
EventTimestamp time.Time EventTimestamp time.Time
LastSuccessfulSpoolerRun time.Time LastSuccessfulSpoolerRun time.Time
AggregateType string
} }

View File

@ -1,12 +1,12 @@
package repository package repository
import ( import (
"github.com/caos/zitadel/internal/domain"
"strings" "strings"
"time" "time"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
"github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors" caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/view/model" "github.com/caos/zitadel/internal/view/model"
) )
@ -16,7 +16,6 @@ type CurrentSequence struct {
CurrentSequence uint64 `gorm:"column:current_sequence"` CurrentSequence uint64 `gorm:"column:current_sequence"`
EventTimestamp time.Time `gorm:"column:event_timestamp"` EventTimestamp time.Time `gorm:"column:event_timestamp"`
LastSuccessfulSpoolerRun time.Time `gorm:"column:last_successful_spooler_run"` LastSuccessfulSpoolerRun time.Time `gorm:"column:last_successful_spooler_run"`
AggregateType string `gorm:"column:aggregate_type;primary_key"`
} }
type currentSequenceViewWithSequence struct { type currentSequenceViewWithSequence struct {
@ -76,12 +75,11 @@ func CurrentSequenceToModel(sequence *CurrentSequence) *model.View {
CurrentSequence: sequence.CurrentSequence, CurrentSequence: sequence.CurrentSequence,
EventTimestamp: sequence.EventTimestamp, EventTimestamp: sequence.EventTimestamp,
LastSuccessfulSpoolerRun: sequence.LastSuccessfulSpoolerRun, LastSuccessfulSpoolerRun: sequence.LastSuccessfulSpoolerRun,
AggregateType: sequence.AggregateType,
} }
} }
func SaveCurrentSequence(db *gorm.DB, table, viewName string, sequence uint64, eventTimestamp time.Time) error { 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) { func UpdateCurrentSequence(db *gorm.DB, table string, currentSequence *CurrentSequence) (err error) {

View File

@ -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;