mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 05:52:51 +00:00
Improves compatibility of eventstore and related database components with the new relational table package. ## Which problems are solved 1. **Incompatible Database Interfaces**: The existing eventstore was tightly coupled to the database package, which is incompatible with the new, more abstract relational table package in v3. This prevented the new command-side logic from pushing events to the legacy eventstore. 2. **Missing Health Checks**: The database interfaces in the new package lacked a Ping method, making it impossible to perform health checks on database connections. 3. **Event Publishing Logic**: The command handling logic in domain needed a way to collect and push events to the legacy eventstore after a command was successfully executed. ## How the problems are solved 1. **`LegacyEventstore` Interface**: * A new `LegacyEventstore` interface is introduced in the new `database/eventstore` . This interface exposes a `PushWithNewClient` method that accepts the new `database.QueryExecutor` interface, decoupling the v3 domain from the legacy implementation. * The `internal/eventstore.Eventstore` now implements this interface. A wrapper, PushWithClient, is added to convert the old database client types (`*sql.DB`, `*sql.Tx`) into the new `QueryExecutor` types before calling `PushWithNewClient`. 2. **Database Interface Updates**: * The `database.Pool` and `database.Client` interfaces in `storage/eventstore` have been updated to include a Ping method, allowing for consistent health checks across different database dialects. * The `postgres` and `sql` dialect implementations have been updated to support this new method. 3. **Command and Invoker Refactoring**: * The `Commander` interface in domain now includes an `Events() []legacy_es.Command` method. This allows commands to declare which events they will generate. * The `eventCollector` in the invoker logic has been redesigned. It now ensures a database transaction is started before executing a command. After successful execution, it calls the `Events()` method on the command to collect the generated events and appends them to a list. * The `eventStoreInvoker` then pushes all collected events to the legacy eventstore using the new `LegacyEventstore` interface, ensuring that events are only pushed if the entire command (and any sub-commands) executes successfully within the transaction. 4. **Testing**: * New unit tests have been added for the invoker to verify that events are correctly collected from single commands, batched commands, and nested commands. These changes create a clean bridge between the new v3 command-side logic and the existing v1 eventstore, allowing for incremental adoption of the new architecture while maintaining full functionality. ## Additional Information closes https://github.com/zitadel/zitadel/issues/10442
174 lines
5.6 KiB
Go
174 lines
5.6 KiB
Go
// Code generated by MockGen. DO NOT EDIT.
|
|
// Source: github.com/zitadel/zitadel/internal/eventstore (interfaces: Querier,Pusher)
|
|
//
|
|
// Generated by this command:
|
|
//
|
|
// mockgen -package mock -destination ./repository.mock.go github.com/zitadel/zitadel/internal/eventstore Querier,Pusher
|
|
//
|
|
|
|
// Package mock is a generated GoMock package.
|
|
package mock
|
|
|
|
import (
|
|
context "context"
|
|
reflect "reflect"
|
|
|
|
decimal "github.com/shopspring/decimal"
|
|
database "github.com/zitadel/zitadel/backend/v3/storage/database"
|
|
database0 "github.com/zitadel/zitadel/internal/database"
|
|
eventstore "github.com/zitadel/zitadel/internal/eventstore"
|
|
gomock "go.uber.org/mock/gomock"
|
|
)
|
|
|
|
// MockQuerier is a mock of Querier interface.
|
|
type MockQuerier struct {
|
|
ctrl *gomock.Controller
|
|
recorder *MockQuerierMockRecorder
|
|
}
|
|
|
|
// MockQuerierMockRecorder is the mock recorder for MockQuerier.
|
|
type MockQuerierMockRecorder struct {
|
|
mock *MockQuerier
|
|
}
|
|
|
|
// NewMockQuerier creates a new mock instance.
|
|
func NewMockQuerier(ctrl *gomock.Controller) *MockQuerier {
|
|
mock := &MockQuerier{ctrl: ctrl}
|
|
mock.recorder = &MockQuerierMockRecorder{mock}
|
|
return mock
|
|
}
|
|
|
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
|
func (m *MockQuerier) EXPECT() *MockQuerierMockRecorder {
|
|
return m.recorder
|
|
}
|
|
|
|
// Client mocks base method.
|
|
func (m *MockQuerier) Client() *database0.DB {
|
|
m.ctrl.T.Helper()
|
|
ret := m.ctrl.Call(m, "Client")
|
|
ret0, _ := ret[0].(*database0.DB)
|
|
return ret0
|
|
}
|
|
|
|
// Client indicates an expected call of Client.
|
|
func (mr *MockQuerierMockRecorder) Client() *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Client", reflect.TypeOf((*MockQuerier)(nil).Client))
|
|
}
|
|
|
|
// FilterToReducer mocks base method.
|
|
func (m *MockQuerier) FilterToReducer(arg0 context.Context, arg1 *eventstore.SearchQueryBuilder, arg2 eventstore.Reducer) error {
|
|
m.ctrl.T.Helper()
|
|
ret := m.ctrl.Call(m, "FilterToReducer", arg0, arg1, arg2)
|
|
ret0, _ := ret[0].(error)
|
|
return ret0
|
|
}
|
|
|
|
// FilterToReducer indicates an expected call of FilterToReducer.
|
|
func (mr *MockQuerierMockRecorder) FilterToReducer(arg0, arg1, arg2 any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilterToReducer", reflect.TypeOf((*MockQuerier)(nil).FilterToReducer), arg0, arg1, arg2)
|
|
}
|
|
|
|
// Health mocks base method.
|
|
func (m *MockQuerier) Health(arg0 context.Context) error {
|
|
m.ctrl.T.Helper()
|
|
ret := m.ctrl.Call(m, "Health", arg0)
|
|
ret0, _ := ret[0].(error)
|
|
return ret0
|
|
}
|
|
|
|
// Health indicates an expected call of Health.
|
|
func (mr *MockQuerierMockRecorder) Health(arg0 any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Health", reflect.TypeOf((*MockQuerier)(nil).Health), arg0)
|
|
}
|
|
|
|
// InstanceIDs mocks base method.
|
|
func (m *MockQuerier) InstanceIDs(arg0 context.Context, arg1 *eventstore.SearchQueryBuilder) ([]string, error) {
|
|
m.ctrl.T.Helper()
|
|
ret := m.ctrl.Call(m, "InstanceIDs", arg0, arg1)
|
|
ret0, _ := ret[0].([]string)
|
|
ret1, _ := ret[1].(error)
|
|
return ret0, ret1
|
|
}
|
|
|
|
// InstanceIDs indicates an expected call of InstanceIDs.
|
|
func (mr *MockQuerierMockRecorder) InstanceIDs(arg0, arg1 any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InstanceIDs", reflect.TypeOf((*MockQuerier)(nil).InstanceIDs), arg0, arg1)
|
|
}
|
|
|
|
// LatestPosition mocks base method.
|
|
func (m *MockQuerier) LatestPosition(arg0 context.Context, arg1 *eventstore.SearchQueryBuilder) (decimal.Decimal, error) {
|
|
m.ctrl.T.Helper()
|
|
ret := m.ctrl.Call(m, "LatestPosition", arg0, arg1)
|
|
ret0, _ := ret[0].(decimal.Decimal)
|
|
ret1, _ := ret[1].(error)
|
|
return ret0, ret1
|
|
}
|
|
|
|
// LatestPosition indicates an expected call of LatestPosition.
|
|
func (mr *MockQuerierMockRecorder) LatestPosition(arg0, arg1 any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LatestPosition", reflect.TypeOf((*MockQuerier)(nil).LatestPosition), arg0, arg1)
|
|
}
|
|
|
|
// MockPusher is a mock of Pusher interface.
|
|
type MockPusher struct {
|
|
ctrl *gomock.Controller
|
|
recorder *MockPusherMockRecorder
|
|
}
|
|
|
|
// MockPusherMockRecorder is the mock recorder for MockPusher.
|
|
type MockPusherMockRecorder struct {
|
|
mock *MockPusher
|
|
}
|
|
|
|
// NewMockPusher creates a new mock instance.
|
|
func NewMockPusher(ctrl *gomock.Controller) *MockPusher {
|
|
mock := &MockPusher{ctrl: ctrl}
|
|
mock.recorder = &MockPusherMockRecorder{mock}
|
|
return mock
|
|
}
|
|
|
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
|
func (m *MockPusher) EXPECT() *MockPusherMockRecorder {
|
|
return m.recorder
|
|
}
|
|
|
|
// Health mocks base method.
|
|
func (m *MockPusher) Health(arg0 context.Context) error {
|
|
m.ctrl.T.Helper()
|
|
ret := m.ctrl.Call(m, "Health", arg0)
|
|
ret0, _ := ret[0].(error)
|
|
return ret0
|
|
}
|
|
|
|
// Health indicates an expected call of Health.
|
|
func (mr *MockPusherMockRecorder) Health(arg0 any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Health", reflect.TypeOf((*MockPusher)(nil).Health), arg0)
|
|
}
|
|
|
|
// Push mocks base method.
|
|
func (m *MockPusher) Push(arg0 context.Context, arg1 database.QueryExecutor, arg2 ...eventstore.Command) ([]eventstore.Event, error) {
|
|
m.ctrl.T.Helper()
|
|
varargs := []any{arg0, arg1}
|
|
for _, a := range arg2 {
|
|
varargs = append(varargs, a)
|
|
}
|
|
ret := m.ctrl.Call(m, "Push", varargs...)
|
|
ret0, _ := ret[0].([]eventstore.Event)
|
|
ret1, _ := ret[1].(error)
|
|
return ret0, ret1
|
|
}
|
|
|
|
// Push indicates an expected call of Push.
|
|
func (mr *MockPusherMockRecorder) Push(arg0, arg1 any, arg2 ...any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
varargs := append([]any{arg0, arg1}, arg2...)
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Push", reflect.TypeOf((*MockPusher)(nil).Push), varargs...)
|
|
}
|