mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:27:42 +00:00
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
This commit is contained in:
26
internal/auth_request/repository/cache/cache.go
vendored
26
internal/auth_request/repository/cache/cache.go
vendored
@@ -26,38 +26,38 @@ func (c *AuthRequestCache) Health(ctx context.Context) error {
|
||||
return c.client.PingContext(ctx)
|
||||
}
|
||||
|
||||
func (c *AuthRequestCache) GetAuthRequestByID(_ context.Context, id string) (*domain.AuthRequest, error) {
|
||||
return c.getAuthRequest("id", id)
|
||||
func (c *AuthRequestCache) GetAuthRequestByID(_ context.Context, id, instanceID string) (*domain.AuthRequest, error) {
|
||||
return c.getAuthRequest("id", id, instanceID)
|
||||
}
|
||||
|
||||
func (c *AuthRequestCache) GetAuthRequestByCode(_ context.Context, code string) (*domain.AuthRequest, error) {
|
||||
return c.getAuthRequest("code", code)
|
||||
func (c *AuthRequestCache) GetAuthRequestByCode(_ context.Context, code, instanceID string) (*domain.AuthRequest, error) {
|
||||
return c.getAuthRequest("code", code, instanceID)
|
||||
}
|
||||
|
||||
func (c *AuthRequestCache) SaveAuthRequest(_ context.Context, request *domain.AuthRequest) error {
|
||||
return c.saveAuthRequest(request, "INSERT INTO auth.auth_requests (id, request, creation_date, change_date, request_type) VALUES($1, $2, $3, $3, $4)", request.CreationDate, request.Request.Type())
|
||||
return c.saveAuthRequest(request, "INSERT INTO auth.auth_requests (id, request, instance_id, creation_date, change_date, request_type) VALUES($1, $2, $3, $3, $4, $5)", request.CreationDate, request.InstanceID, request.Request.Type())
|
||||
}
|
||||
|
||||
func (c *AuthRequestCache) UpdateAuthRequest(_ context.Context, request *domain.AuthRequest) error {
|
||||
if request.ChangeDate.IsZero() {
|
||||
request.ChangeDate = time.Now()
|
||||
}
|
||||
return c.saveAuthRequest(request, "UPDATE auth.auth_requests SET request = $2, change_date = $3, code = $4 WHERE id = $1", request.ChangeDate, request.Code)
|
||||
return c.saveAuthRequest(request, "UPDATE auth.auth_requests SET request = $2, instance_id = $3 change_date = $4, code = $5 WHERE id = $1", request.ChangeDate, request.InstanceID, request.Code)
|
||||
}
|
||||
|
||||
func (c *AuthRequestCache) DeleteAuthRequest(_ context.Context, id string) error {
|
||||
_, err := c.client.Exec("DELETE FROM auth.auth_requests WHERE id = $1", id)
|
||||
func (c *AuthRequestCache) DeleteAuthRequest(_ context.Context, id, instanceID string) error {
|
||||
_, err := c.client.Exec("DELETE FROM auth.auth_requests WHERE instance = $1 and id = $2", instanceID, id)
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "CACHE-dsHw3", "unable to delete auth request")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *AuthRequestCache) getAuthRequest(key, value string) (*domain.AuthRequest, error) {
|
||||
func (c *AuthRequestCache) getAuthRequest(key, value, instanceID string) (*domain.AuthRequest, error) {
|
||||
var b []byte
|
||||
var requestType domain.AuthRequestType
|
||||
query := fmt.Sprintf("SELECT request, request_type FROM auth.auth_requests WHERE %s = $1", key)
|
||||
err := c.client.QueryRow(query, value).Scan(&b, &requestType)
|
||||
query := fmt.Sprintf("SELECT request, request_type FROM auth.auth_requests WHERE instance = $1 and %s = $2", key)
|
||||
err := c.client.QueryRow(query, instanceID, value).Scan(&b, &requestType)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, caos_errs.ThrowNotFound(err, "CACHE-d24aD", "Errors.AuthRequest.NotFound")
|
||||
@@ -74,7 +74,7 @@ func (c *AuthRequestCache) getAuthRequest(key, value string) (*domain.AuthReques
|
||||
return request, nil
|
||||
}
|
||||
|
||||
func (c *AuthRequestCache) saveAuthRequest(request *domain.AuthRequest, query string, date time.Time, param interface{}) error {
|
||||
func (c *AuthRequestCache) saveAuthRequest(request *domain.AuthRequest, query string, date time.Time, instanceID string, param interface{}) error {
|
||||
b, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "CACHE-os0GH", "Errors.Internal")
|
||||
@@ -83,7 +83,7 @@ func (c *AuthRequestCache) saveAuthRequest(request *domain.AuthRequest, query st
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "CACHE-su3GK", "Errors.Internal")
|
||||
}
|
||||
_, err = stmt.Exec(request.ID, b, date, param)
|
||||
_, err = stmt.Exec(request.ID, b, date, instanceID, param)
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "CACHE-sj8iS", "Errors.Internal")
|
||||
}
|
||||
|
@@ -6,79 +6,80 @@ package mock
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
domain "github.com/caos/zitadel/internal/domain"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// MockAuthRequestCache is a mock of AuthRequestCache interface
|
||||
// MockAuthRequestCache is a mock of AuthRequestCache interface.
|
||||
type MockAuthRequestCache struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockAuthRequestCacheMockRecorder
|
||||
}
|
||||
|
||||
// MockAuthRequestCacheMockRecorder is the mock recorder for MockAuthRequestCache
|
||||
// MockAuthRequestCacheMockRecorder is the mock recorder for MockAuthRequestCache.
|
||||
type MockAuthRequestCacheMockRecorder struct {
|
||||
mock *MockAuthRequestCache
|
||||
}
|
||||
|
||||
// NewMockAuthRequestCache creates a new mock instance
|
||||
// NewMockAuthRequestCache creates a new mock instance.
|
||||
func NewMockAuthRequestCache(ctrl *gomock.Controller) *MockAuthRequestCache {
|
||||
mock := &MockAuthRequestCache{ctrl: ctrl}
|
||||
mock.recorder = &MockAuthRequestCacheMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockAuthRequestCache) EXPECT() *MockAuthRequestCacheMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// DeleteAuthRequest mocks base method
|
||||
func (m *MockAuthRequestCache) DeleteAuthRequest(arg0 context.Context, arg1 string) error {
|
||||
// DeleteAuthRequest mocks base method.
|
||||
func (m *MockAuthRequestCache) DeleteAuthRequest(arg0 context.Context, arg1, arg2 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DeleteAuthRequest", arg0, arg1)
|
||||
ret := m.ctrl.Call(m, "DeleteAuthRequest", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// DeleteAuthRequest indicates an expected call of DeleteAuthRequest
|
||||
func (mr *MockAuthRequestCacheMockRecorder) DeleteAuthRequest(arg0, arg1 interface{}) *gomock.Call {
|
||||
// DeleteAuthRequest indicates an expected call of DeleteAuthRequest.
|
||||
func (mr *MockAuthRequestCacheMockRecorder) DeleteAuthRequest(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteAuthRequest", reflect.TypeOf((*MockAuthRequestCache)(nil).DeleteAuthRequest), arg0, arg1)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteAuthRequest", reflect.TypeOf((*MockAuthRequestCache)(nil).DeleteAuthRequest), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// GetAuthRequestByCode mocks base method
|
||||
func (m *MockAuthRequestCache) GetAuthRequestByCode(arg0 context.Context, arg1 string) (*domain.AuthRequest, error) {
|
||||
// GetAuthRequestByCode mocks base method.
|
||||
func (m *MockAuthRequestCache) GetAuthRequestByCode(arg0 context.Context, arg1, arg2 string) (*domain.AuthRequest, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetAuthRequestByCode", arg0, arg1)
|
||||
ret := m.ctrl.Call(m, "GetAuthRequestByCode", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(*domain.AuthRequest)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetAuthRequestByCode indicates an expected call of GetAuthRequestByCode
|
||||
func (mr *MockAuthRequestCacheMockRecorder) GetAuthRequestByCode(arg0, arg1 interface{}) *gomock.Call {
|
||||
// GetAuthRequestByCode indicates an expected call of GetAuthRequestByCode.
|
||||
func (mr *MockAuthRequestCacheMockRecorder) GetAuthRequestByCode(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAuthRequestByCode", reflect.TypeOf((*MockAuthRequestCache)(nil).GetAuthRequestByCode), arg0, arg1)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAuthRequestByCode", reflect.TypeOf((*MockAuthRequestCache)(nil).GetAuthRequestByCode), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// GetAuthRequestByID mocks base method
|
||||
func (m *MockAuthRequestCache) GetAuthRequestByID(arg0 context.Context, arg1 string) (*domain.AuthRequest, error) {
|
||||
// GetAuthRequestByID mocks base method.
|
||||
func (m *MockAuthRequestCache) GetAuthRequestByID(arg0 context.Context, arg1, arg2 string) (*domain.AuthRequest, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetAuthRequestByID", arg0, arg1)
|
||||
ret := m.ctrl.Call(m, "GetAuthRequestByID", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(*domain.AuthRequest)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetAuthRequestByID indicates an expected call of GetAuthRequestByID
|
||||
func (mr *MockAuthRequestCacheMockRecorder) GetAuthRequestByID(arg0, arg1 interface{}) *gomock.Call {
|
||||
// GetAuthRequestByID indicates an expected call of GetAuthRequestByID.
|
||||
func (mr *MockAuthRequestCacheMockRecorder) GetAuthRequestByID(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAuthRequestByID", reflect.TypeOf((*MockAuthRequestCache)(nil).GetAuthRequestByID), arg0, arg1)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAuthRequestByID", reflect.TypeOf((*MockAuthRequestCache)(nil).GetAuthRequestByID), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// Health mocks base method
|
||||
// Health mocks base method.
|
||||
func (m *MockAuthRequestCache) Health(arg0 context.Context) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Health", arg0)
|
||||
@@ -86,13 +87,13 @@ func (m *MockAuthRequestCache) Health(arg0 context.Context) error {
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Health indicates an expected call of Health
|
||||
// Health indicates an expected call of Health.
|
||||
func (mr *MockAuthRequestCacheMockRecorder) Health(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Health", reflect.TypeOf((*MockAuthRequestCache)(nil).Health), arg0)
|
||||
}
|
||||
|
||||
// SaveAuthRequest mocks base method
|
||||
// SaveAuthRequest mocks base method.
|
||||
func (m *MockAuthRequestCache) SaveAuthRequest(arg0 context.Context, arg1 *domain.AuthRequest) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SaveAuthRequest", arg0, arg1)
|
||||
@@ -100,13 +101,13 @@ func (m *MockAuthRequestCache) SaveAuthRequest(arg0 context.Context, arg1 *domai
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SaveAuthRequest indicates an expected call of SaveAuthRequest
|
||||
// SaveAuthRequest indicates an expected call of SaveAuthRequest.
|
||||
func (mr *MockAuthRequestCacheMockRecorder) SaveAuthRequest(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SaveAuthRequest", reflect.TypeOf((*MockAuthRequestCache)(nil).SaveAuthRequest), arg0, arg1)
|
||||
}
|
||||
|
||||
// UpdateAuthRequest mocks base method
|
||||
// UpdateAuthRequest mocks base method.
|
||||
func (m *MockAuthRequestCache) UpdateAuthRequest(arg0 context.Context, arg1 *domain.AuthRequest) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "UpdateAuthRequest", arg0, arg1)
|
||||
@@ -114,7 +115,7 @@ func (m *MockAuthRequestCache) UpdateAuthRequest(arg0 context.Context, arg1 *dom
|
||||
return ret0
|
||||
}
|
||||
|
||||
// UpdateAuthRequest indicates an expected call of UpdateAuthRequest
|
||||
// UpdateAuthRequest indicates an expected call of UpdateAuthRequest.
|
||||
func (mr *MockAuthRequestCacheMockRecorder) UpdateAuthRequest(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateAuthRequest", reflect.TypeOf((*MockAuthRequestCache)(nil).UpdateAuthRequest), arg0, arg1)
|
||||
|
@@ -2,15 +2,16 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
)
|
||||
|
||||
type AuthRequestCache interface {
|
||||
Health(ctx context.Context) error
|
||||
|
||||
GetAuthRequestByID(ctx context.Context, id string) (*domain.AuthRequest, error)
|
||||
GetAuthRequestByCode(ctx context.Context, code string) (*domain.AuthRequest, error)
|
||||
GetAuthRequestByID(ctx context.Context, id, instanceID string) (*domain.AuthRequest, error)
|
||||
GetAuthRequestByCode(ctx context.Context, code, instanceID string) (*domain.AuthRequest, error)
|
||||
SaveAuthRequest(ctx context.Context, request *domain.AuthRequest) error
|
||||
UpdateAuthRequest(ctx context.Context, request *domain.AuthRequest) error
|
||||
DeleteAuthRequest(ctx context.Context, id string) error
|
||||
DeleteAuthRequest(ctx context.Context, id, instanceID string) error
|
||||
}
|
||||
|
Reference in New Issue
Block a user