Skip to content

Commit

Permalink
fix: drop unused column from current_sequences (#1592)
Browse files Browse the repository at this point in the history
  • Loading branch information
livio-a committed Apr 16, 2021
1 parent 6a3a541 commit 26e1b80
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 16 deletions.
3 changes: 0 additions & 3 deletions internal/admin/repository/eventsourcing/view/sequence.go
Expand Up @@ -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)
}

Expand Down
2 changes: 0 additions & 2 deletions internal/auth/repository/eventsourcing/view/sequence.go
Expand Up @@ -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)
}
2 changes: 0 additions & 2 deletions internal/authz/repository/eventsourcing/view/sequence.go
Expand Up @@ -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)
}
2 changes: 0 additions & 2 deletions internal/management/repository/eventsourcing/view/sequence.go
Expand Up @@ -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)
}
Expand Up @@ -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)
}
1 change: 0 additions & 1 deletion internal/view/model/view.go
Expand Up @@ -10,5 +10,4 @@ type View struct {
CurrentSequence uint64
EventTimestamp time.Time
LastSuccessfulSpoolerRun time.Time
AggregateType string
}
6 changes: 2 additions & 4 deletions 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"
)
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
31 changes: 31 additions & 0 deletions 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;

0 comments on commit 26e1b80

Please sign in to comment.