zitadel/internal/migration/command.go
Livio Amstutz 56b916a2b0
feat: projections auto create their tables (#3324)
* begin init checks for projections

* first projection checks

* debug notification providers with query fixes

* more projections and first index

* more projections

* more projections

* finish projections

* fix tests (remove db name)

* create tables in setup

* fix logging / error handling

* add tenant to views

* rename tenant to instance_id

* add instance_id to all projections

* add instance_id to all queries

* correct instance_id on projections

* add instance_id to failed_events

* use separate context for instance

* implement features projection

* implement features projection

* remove unique constraint from setup when migration failed

* add error to failed setup event

* add instance_id to primary keys

* fix IAM projection

* remove old migrations folder

* fix keysFromYAML test
2022-03-23 09:02:39 +01:00

78 lines
1.7 KiB
Go

package migration
import "github.com/caos/zitadel/internal/eventstore"
//SetupStep is the command pushed on the eventstore
type SetupStep struct {
typ eventstore.EventType
migration Migration
Name string `json:"name"`
Error error `json:"error,omitempty"`
done bool
}
func setupStartedCmd(migration Migration) eventstore.Command {
return &SetupStep{
migration: migration,
typ: startedType,
Name: migration.String(),
}
}
func setupDoneCmd(migration Migration, err error) eventstore.Command {
s := &SetupStep{
typ: doneType,
migration: migration,
Name: migration.String(),
}
if err != nil {
s.typ = failedType
s.Error = err
}
return s
}
func (s *SetupStep) Aggregate() eventstore.Aggregate {
return eventstore.Aggregate{
ID: aggregateID,
Type: aggregateType,
ResourceOwner: "SYSTEM",
Version: "v1",
}
}
func (s *SetupStep) EditorService() string {
return "system"
}
func (s *SetupStep) EditorUser() string {
return "system"
}
func (s *SetupStep) Type() eventstore.EventType {
return s.typ
}
func (s *SetupStep) Data() interface{} {
return s
}
func (s *SetupStep) UniqueConstraints() []*eventstore.EventUniqueConstraint {
switch s.typ {
case startedType:
return []*eventstore.EventUniqueConstraint{
eventstore.NewAddEventUniqueConstraint("migration_started", s.migration.String(), "Errors.Step.Started.AlreadyExists"),
}
case failedType:
return []*eventstore.EventUniqueConstraint{
eventstore.NewRemoveEventUniqueConstraint("migration_started", s.migration.String()),
}
default:
return []*eventstore.EventUniqueConstraint{
eventstore.NewAddEventUniqueConstraint("migration_done", s.migration.String(), "Errors.Step.Done.AlreadyExists"),
}
}
}