refactor(v2): init eventstore package (#7806)

* refactor(v2): init database package

* refactor(v2): init eventstore package

* add mock package

* test query constructors

* option based push analog to query
This commit is contained in:
Silvan
2024-04-26 17:05:21 +02:00
committed by GitHub
parent 2254434692
commit 5811a7b6a5
16 changed files with 5681 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
package postgres
import (
"github.com/zitadel/logging"
"github.com/zitadel/zitadel/internal/v2/eventstore"
)
type intent struct {
*eventstore.PushAggregate
sequence uint32
}
func makeIntents(pushIntent *eventstore.PushIntent) []*intent {
res := make([]*intent, len(pushIntent.Aggregates()))
for i, aggregate := range pushIntent.Aggregates() {
res[i] = &intent{PushAggregate: aggregate}
}
return res
}
func intentByAggregate(intents []*intent, aggregate *eventstore.Aggregate) *intent {
for _, intent := range intents {
if intent.PushAggregate.Aggregate().Equals(aggregate) {
return intent
}
}
logging.WithFields("instance", aggregate.Instance, "owner", aggregate.Owner, "type", aggregate.Type, "id", aggregate.ID).Panic("no intent found")
return nil
}
func checkSequences(intents []*intent) bool {
for _, intent := range intents {
if !eventstore.CheckSequence(intent.sequence, intent.PushAggregate.CurrentSequence()) {
return false
}
}
return true
}