mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-16 10:45:12 +00:00
feat(relational): implement session repository (#11109)
# Which Problems Are Solved As part of going to a relation storage model, we need to implement the repository for handling sessions and their events. # How the Problems Are Solved - Adds a migration step to create the necessary tables and types in the database. - Adds the repository implementation for sessions. - Implements a projection handler for session events to handle the events written by the old command handlers. - Updates the `Session` type and `SessionRepository` interface: - added `CreatorID` - Adjusted `Delete` method to return amount of affected columns - Removed sub-repository clumns from the main interface - Added `CreatorIDCondition`, `ExpirationCondition`, `ExistsFactor` and `ExistsMetadata` - Removed `SetUserAgent` - Methods of `SessionFactor` and `SessionChallenge` have been made public - fixed enumer on `SessionFactorType` - Adds a `JSON` type to the repository package to easy can JSON columns, resp. jsonb object inside a property of a `JSONArray` object. - Adds a `NoChange` interface, which can be implemented to signal that a `Change` interface implementation is not writing any changes to the statement builder, e.g. `CTEChange` # Additional Changes - Fixes the operators enums. `TextOperations` had wrong comments and `NumberOperations` additionally also had from comparisons. - Fixes downgrade of migration step 008. # Additional Context - closes https://github.com/zitadel/zitadel/issues/10212
This commit is contained in:
@@ -17,6 +17,12 @@ type Change interface {
|
||||
IsOnColumn(col Column) bool
|
||||
}
|
||||
|
||||
// NoChange can be implemented by Changes that might not result in any actual change,
|
||||
// resp. when the change has no set statement, e.g. [CTEChange] with no change function.
|
||||
type NoChange interface {
|
||||
NoChange() bool
|
||||
}
|
||||
|
||||
type change[V Value] struct {
|
||||
column Column
|
||||
value V
|
||||
@@ -88,15 +94,23 @@ func (c Changes) IsOnColumn(col Column) bool {
|
||||
}
|
||||
|
||||
// Write implements [Change].
|
||||
func (m Changes) Write(builder *StatementBuilder) error {
|
||||
for i, change := range m {
|
||||
if i > 0 {
|
||||
func (c Changes) Write(builder *StatementBuilder) error {
|
||||
var hadChanges bool
|
||||
for _, change := range c {
|
||||
ch, ok := change.(NoChange)
|
||||
hasChanges := !ok || !ch.NoChange()
|
||||
// if the previous change actually wrote a change to the builder
|
||||
// and this change has changes, add a comma
|
||||
if hadChanges && hasChanges {
|
||||
builder.WriteString(", ")
|
||||
}
|
||||
err := change.Write(builder)
|
||||
if err != nil {
|
||||
if err := change.Write(builder); err != nil {
|
||||
return err
|
||||
}
|
||||
// if the change had changes, mark that we had changes for the next iteration
|
||||
if hasChanges {
|
||||
hadChanges = hasChanges
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -123,6 +137,21 @@ func (c Changes) String() string {
|
||||
return "database.Changes"
|
||||
}
|
||||
|
||||
// NoChange implements [NoChange].
|
||||
// It returns false if any of the changes writes to the builder.
|
||||
func (c Changes) NoChange() bool {
|
||||
for _, change := range c {
|
||||
no, ok := change.(NoChange)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if no.NoChange() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var _ Change = Changes(nil)
|
||||
|
||||
func NewChangeToNull(col Column) Change {
|
||||
@@ -319,7 +348,7 @@ func (c *cteChange) Matches(x any) bool {
|
||||
return slices.Equal(expectedCTEBuilder.Args(), actualCTEBuilder.Args())
|
||||
}
|
||||
|
||||
// Name implements [CTEChange].
|
||||
// SetName implements [CTEChange].
|
||||
func (c *cteChange) SetName(name string) {
|
||||
c.name = name
|
||||
}
|
||||
@@ -342,3 +371,9 @@ func (c *cteChange) Write(builder *StatementBuilder) error {
|
||||
func (c *cteChange) WriteCTE(builder *StatementBuilder) {
|
||||
c.cte(builder)
|
||||
}
|
||||
|
||||
// NoChange implements [NoChange].
|
||||
// It returns true if there is no change function defined.
|
||||
func (c *cteChange) NoChange() bool {
|
||||
return c.change == nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user