mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 01:37:31 +00:00
feat(database): support for postgres (#3998)
* beginning with postgres statements * try pgx * use pgx * database * init works for postgres * arrays working * init for cockroach * init * start tests * tests * TESTS * ch * ch * chore: use go 1.18 * read stmts * fix typo * tests * connection string * add missing error handler * cleanup * start all apis * go mod tidy * old update * switch back to minute * on conflict * replace string slice with `database.StringArray` in db models * fix tests and start * update go version in dockerfile * setup go * clean up * remove notification migration * update * docs: add deploy guide for postgres * fix: revert sonyflake * use `database.StringArray` for daos * use `database.StringArray` every where * new tables * index naming, metadata primary key, project grant role key type * docs(postgres): change to beta * chore: correct compose * fix(defaults): add empty postgres config * refactor: remove unused code * docs: add postgres to self hosted * fix broken link * so? * change title * add mdx to link * fix stmt * update goreleaser in test-code * docs: improve postgres example * update more projections * fix: add beta log for postgres * revert index name change * prerelease * fix: add sequence to v1 "reduce paniced" * log if nil * add logging * fix: log output * fix(import): check if org exists and user * refactor: imports * fix(user): ignore malformed events * refactor: method naming * fix: test * refactor: correct errors.Is call * ci: don't build dev binaries on main * fix(go releaser): update version to 1.11.0 * fix(user): projection should not break * fix(user): handle error properly * docs: correct config example * Update .releaserc.js * Update .releaserc.js Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Elio Bischof <eliobischof@gmail.com>
This commit is contained in:
@@ -3,11 +3,12 @@ package eventstore
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
)
|
||||
|
||||
//SearchQueryBuilder represents the builder for your filter
|
||||
// SearchQueryBuilder represents the builder for your filter
|
||||
// if invalid data are set the filter will fail
|
||||
type SearchQueryBuilder struct {
|
||||
columns repository.Columns
|
||||
@@ -79,51 +80,51 @@ func (builder *SearchQueryBuilder) Matches(event Event, existingLen int) (matche
|
||||
return false
|
||||
}
|
||||
|
||||
//Columns defines which fields are set
|
||||
// Columns defines which fields are set
|
||||
func (builder *SearchQueryBuilder) Columns(columns Columns) *SearchQueryBuilder {
|
||||
builder.columns = repository.Columns(columns)
|
||||
return builder
|
||||
}
|
||||
|
||||
//Limit defines how many events are returned maximally.
|
||||
// Limit defines how many events are returned maximally.
|
||||
func (builder *SearchQueryBuilder) Limit(limit uint64) *SearchQueryBuilder {
|
||||
builder.limit = limit
|
||||
return builder
|
||||
}
|
||||
|
||||
//ResourceOwner defines the resource owner (org) of the events
|
||||
// ResourceOwner defines the resource owner (org) of the events
|
||||
func (builder *SearchQueryBuilder) ResourceOwner(resourceOwner string) *SearchQueryBuilder {
|
||||
builder.resourceOwner = resourceOwner
|
||||
return builder
|
||||
}
|
||||
|
||||
//InstanceID defines the instanceID (system) of the events
|
||||
// InstanceID defines the instanceID (system) of the events
|
||||
func (builder *SearchQueryBuilder) InstanceID(instanceID string) *SearchQueryBuilder {
|
||||
builder.instanceID = instanceID
|
||||
return builder
|
||||
}
|
||||
|
||||
//OrderDesc changes the sorting order of the returned events to descending
|
||||
// OrderDesc changes the sorting order of the returned events to descending
|
||||
func (builder *SearchQueryBuilder) OrderDesc() *SearchQueryBuilder {
|
||||
builder.desc = true
|
||||
return builder
|
||||
}
|
||||
|
||||
//OrderAsc changes the sorting order of the returned events to ascending
|
||||
// OrderAsc changes the sorting order of the returned events to ascending
|
||||
func (builder *SearchQueryBuilder) OrderAsc() *SearchQueryBuilder {
|
||||
builder.desc = false
|
||||
return builder
|
||||
}
|
||||
|
||||
//SetTx ensures that the eventstore library uses the existing transaction
|
||||
// SetTx ensures that the eventstore library uses the existing transaction
|
||||
func (builder *SearchQueryBuilder) SetTx(tx *sql.Tx) *SearchQueryBuilder {
|
||||
builder.tx = tx
|
||||
return builder
|
||||
}
|
||||
|
||||
//AddQuery creates a new sub query.
|
||||
//All fields in the sub query are AND-connected in the storage request.
|
||||
//Multiple sub queries are OR-connected in the storage request.
|
||||
// AddQuery creates a new sub query.
|
||||
// All fields in the sub query are AND-connected in the storage request.
|
||||
// Multiple sub queries are OR-connected in the storage request.
|
||||
func (builder *SearchQueryBuilder) AddQuery() *SearchQuery {
|
||||
query := &SearchQuery{
|
||||
builder: builder,
|
||||
@@ -133,61 +134,61 @@ func (builder *SearchQueryBuilder) AddQuery() *SearchQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
//Or creates a new sub query on the search query builder
|
||||
// Or creates a new sub query on the search query builder
|
||||
func (query SearchQuery) Or() *SearchQuery {
|
||||
return query.builder.AddQuery()
|
||||
}
|
||||
|
||||
//AggregateTypes filters for events with the given aggregate types
|
||||
// AggregateTypes filters for events with the given aggregate types
|
||||
func (query *SearchQuery) AggregateTypes(types ...AggregateType) *SearchQuery {
|
||||
query.aggregateTypes = types
|
||||
return query
|
||||
}
|
||||
|
||||
//SequenceGreater filters for events with sequence greater the requested sequence
|
||||
// SequenceGreater filters for events with sequence greater the requested sequence
|
||||
func (query *SearchQuery) SequenceGreater(sequence uint64) *SearchQuery {
|
||||
query.eventSequenceGreater = sequence
|
||||
return query
|
||||
}
|
||||
|
||||
//SequenceLess filters for events with sequence less the requested sequence
|
||||
// SequenceLess filters for events with sequence less the requested sequence
|
||||
func (query *SearchQuery) SequenceLess(sequence uint64) *SearchQuery {
|
||||
query.eventSequenceLess = sequence
|
||||
return query
|
||||
}
|
||||
|
||||
//AggregateIDs filters for events with the given aggregate id's
|
||||
// AggregateIDs filters for events with the given aggregate id's
|
||||
func (query *SearchQuery) AggregateIDs(ids ...string) *SearchQuery {
|
||||
query.aggregateIDs = ids
|
||||
return query
|
||||
}
|
||||
|
||||
//InstanceID filters for events with the given instanceID
|
||||
// InstanceID filters for events with the given instanceID
|
||||
func (query *SearchQuery) InstanceID(instanceID string) *SearchQuery {
|
||||
query.instanceID = instanceID
|
||||
return query
|
||||
}
|
||||
|
||||
//ExcludedInstanceID filters for events not having the given instanceIDs
|
||||
// ExcludedInstanceID filters for events not having the given instanceIDs
|
||||
func (query *SearchQuery) ExcludedInstanceID(instanceIDs ...string) *SearchQuery {
|
||||
query.excludedInstanceIDs = instanceIDs
|
||||
return query
|
||||
}
|
||||
|
||||
//EventTypes filters for events with the given event types
|
||||
// EventTypes filters for events with the given event types
|
||||
func (query *SearchQuery) EventTypes(types ...EventType) *SearchQuery {
|
||||
query.eventTypes = types
|
||||
return query
|
||||
}
|
||||
|
||||
//EventData filters for events with the given event data.
|
||||
//Use this call with care as it will be slower than the other filters.
|
||||
// EventData filters for events with the given event data.
|
||||
// Use this call with care as it will be slower than the other filters.
|
||||
func (query *SearchQuery) EventData(data map[string]interface{}) *SearchQuery {
|
||||
query.eventData = data
|
||||
return query
|
||||
}
|
||||
|
||||
//Builder returns the SearchQueryBuilder of the sub query
|
||||
// Builder returns the SearchQueryBuilder of the sub query
|
||||
func (query *SearchQuery) Builder() *SearchQueryBuilder {
|
||||
return query.builder
|
||||
}
|
||||
@@ -262,7 +263,7 @@ func (query *SearchQuery) aggregateIDFilter() *repository.Filter {
|
||||
if len(query.aggregateIDs) == 1 {
|
||||
return repository.NewFilter(repository.FieldAggregateID, query.aggregateIDs[0], repository.OperationEquals)
|
||||
}
|
||||
return repository.NewFilter(repository.FieldAggregateID, query.aggregateIDs, repository.OperationIn)
|
||||
return repository.NewFilter(repository.FieldAggregateID, database.StringArray(query.aggregateIDs), repository.OperationIn)
|
||||
}
|
||||
|
||||
func (query *SearchQuery) eventTypeFilter() *repository.Filter {
|
||||
@@ -272,9 +273,9 @@ func (query *SearchQuery) eventTypeFilter() *repository.Filter {
|
||||
if len(query.eventTypes) == 1 {
|
||||
return repository.NewFilter(repository.FieldEventType, repository.EventType(query.eventTypes[0]), repository.OperationEquals)
|
||||
}
|
||||
eventTypes := make([]repository.EventType, len(query.eventTypes))
|
||||
eventTypes := make(database.StringArray, len(query.eventTypes))
|
||||
for i, eventType := range query.eventTypes {
|
||||
eventTypes[i] = repository.EventType(eventType)
|
||||
eventTypes[i] = string(eventType)
|
||||
}
|
||||
return repository.NewFilter(repository.FieldEventType, eventTypes, repository.OperationIn)
|
||||
}
|
||||
@@ -286,9 +287,9 @@ func (query *SearchQuery) aggregateTypeFilter() *repository.Filter {
|
||||
if len(query.aggregateTypes) == 1 {
|
||||
return repository.NewFilter(repository.FieldAggregateType, repository.AggregateType(query.aggregateTypes[0]), repository.OperationEquals)
|
||||
}
|
||||
aggregateTypes := make([]repository.AggregateType, len(query.aggregateTypes))
|
||||
aggregateTypes := make(database.StringArray, len(query.aggregateTypes))
|
||||
for i, aggregateType := range query.aggregateTypes {
|
||||
aggregateTypes[i] = repository.AggregateType(aggregateType)
|
||||
aggregateTypes[i] = string(aggregateType)
|
||||
}
|
||||
return repository.NewFilter(repository.FieldAggregateType, aggregateTypes, repository.OperationIn)
|
||||
}
|
||||
@@ -326,7 +327,7 @@ func (query *SearchQuery) excludedInstanceIDFilter() *repository.Filter {
|
||||
if len(query.excludedInstanceIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
return repository.NewFilter(repository.FieldInstanceID, query.excludedInstanceIDs, repository.OperationNotIn)
|
||||
return repository.NewFilter(repository.FieldInstanceID, database.StringArray(query.excludedInstanceIDs), repository.OperationNotIn)
|
||||
}
|
||||
|
||||
func (builder *SearchQueryBuilder) resourceOwnerFilter() *repository.Filter {
|
||||
|
Reference in New Issue
Block a user