mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 19:47:34 +00:00
fixup! feat(db): adding relational instance table
This commit is contained in:
@@ -1,11 +1,15 @@
|
|||||||
|
-- the projection for instances happens before md/setup/54.go is run,
|
||||||
|
-- hence why the zitadel schema is added below
|
||||||
|
CREATE SCHEMA IF NOT EXISTS zitadel;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS zitadel.instances(
|
CREATE TABLE IF NOT EXISTS zitadel.instances(
|
||||||
id TEXT NOT NULL PRIMARY KEY,
|
id TEXT NOT NULL PRIMARY KEY,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
default_org_id TEXT NOT NULL,
|
default_org_id TEXT, -- NOT NULL,
|
||||||
iam_project_id TEXT NOT NULL,
|
iam_project_id TEXT, -- NOT NULL,
|
||||||
console_client_id TEXT NOT NULL,
|
console_client_id TEXT, -- NOT NULL,
|
||||||
console_app_id TEXT NOT NULL,
|
console_app_id TEXT, -- NOT NULL,
|
||||||
default_language TEXT REFERENCES languages(code),
|
default_language TEXT, -- NOT NULL,
|
||||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||||
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
||||||
deleted_at TIMESTAMPTZ DEFAULT NULL
|
deleted_at TIMESTAMPTZ DEFAULT NULL
|
||||||
|
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/zitadel/zitadel/internal/zerrors"
|
"github.com/zitadel/zitadel/internal/zerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const InstanceRelationalTable = "zitadel.instances"
|
const InstanceRelationalProjectionTable = "zitadel.instances"
|
||||||
|
|
||||||
type instanceRelationalProjection struct{}
|
type instanceRelationalProjection struct{}
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ func newInstanceRelationalProjection(ctx context.Context, config handler.Config)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (*instanceRelationalProjection) Name() string {
|
func (*instanceRelationalProjection) Name() string {
|
||||||
return InstanceRelationalTable
|
return InstanceRelationalProjectionTable
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*instanceRelationalProjection) Init() *old_handler.Check {
|
func (*instanceRelationalProjection) Init() *old_handler.Check {
|
||||||
@@ -47,38 +47,38 @@ func (p *instanceRelationalProjection) Reducers() []handler.AggregateReducer {
|
|||||||
EventReducers: []handler.EventReducer{
|
EventReducers: []handler.EventReducer{
|
||||||
{
|
{
|
||||||
Event: instance.InstanceAddedEventType,
|
Event: instance.InstanceAddedEventType,
|
||||||
Reduce: p.reduceInstanceRelationalAdded,
|
Reduce: p.reduceInstanceAdded,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: instance.InstanceChangedEventType,
|
||||||
|
Reduce: p.reduceInstanceChanged,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: instance.InstanceRemovedEventType,
|
||||||
|
Reduce: p.reduceInstanceDelete,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: instance.DefaultOrgSetEventType,
|
||||||
|
Reduce: p.reduceDefaultOrgSet,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: instance.ProjectSetEventType,
|
||||||
|
Reduce: p.reduceIAMProjectSet,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: instance.ConsoleSetEventType,
|
||||||
|
Reduce: p.reduceConsoleSet,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: instance.DefaultLanguageSetEventType,
|
||||||
|
Reduce: p.reduceDefaultLanguageSet,
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// Event: instance.InstanceChangedEventType,
|
|
||||||
// Reduce: p.reduceInstanceChanged,
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// Event: instance.InstanceRemovedEventType,
|
|
||||||
// Reduce: reduceInstanceRemovedHelper(InstanceColumnID),
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// Event: instance.DefaultOrgSetEventType,
|
|
||||||
// Reduce: p.reduceDefaultOrgSet,
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// Event: instance.ProjectSetEventType,
|
|
||||||
// Reduce: p.reduceIAMProjectSet,
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// Event: instance.ConsoleSetEventType,
|
|
||||||
// Reduce: p.reduceConsoleSet,
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// Event: instance.DefaultLanguageSetEventType,
|
|
||||||
// Reduce: p.reduceDefaultLanguageSet,
|
|
||||||
// },
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *instanceRelationalProjection) reduceInstanceRelationalAdded(event eventstore.Event) (*handler.Statement, error) {
|
func (p *instanceRelationalProjection) reduceInstanceAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||||
e, ok := event.(*instance.InstanceAddedEvent)
|
e, ok := event.(*instance.InstanceAddedEvent)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-29nRr", "reduce.wrong.event.type %s", instance.InstanceAddedEventType)
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-29nRr", "reduce.wrong.event.type %s", instance.InstanceAddedEventType)
|
||||||
@@ -87,116 +87,111 @@ func (p *instanceRelationalProjection) reduceInstanceRelationalAdded(event event
|
|||||||
e,
|
e,
|
||||||
[]handler.Column{
|
[]handler.Column{
|
||||||
handler.NewCol(InstanceColumnID, e.Aggregate().InstanceID),
|
handler.NewCol(InstanceColumnID, e.Aggregate().InstanceID),
|
||||||
handler.NewCol(InstanceColumnCreationDate, e.CreationDate()),
|
|
||||||
handler.NewCol(InstanceColumnChangeDate, e.CreationDate()),
|
|
||||||
handler.NewCol(InstanceColumnSequence, e.Sequence()),
|
|
||||||
handler.NewCol(InstanceColumnName, e.Name),
|
handler.NewCol(InstanceColumnName, e.Name),
|
||||||
|
handler.NewCol(CreatedAt, e.CreationDate()),
|
||||||
|
handler.NewCol(UpdatedAt, e.CreationDate()),
|
||||||
},
|
},
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// func reduceInstanceRemovedHelper(instanceIDCol string) func(event eventstore.Event) (*handler.Statement, error) {
|
func (p *instanceRelationalProjection) reduceInstanceChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// return func(event eventstore.Event) (*handler.Statement, error) {
|
e, ok := event.(*instance.InstanceChangedEvent)
|
||||||
// e, ok := event.(*instance.InstanceRemovedEvent)
|
if !ok {
|
||||||
// if !ok {
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-so2am1", "reduce.wrong.event.type %s", instance.InstanceChangedEventType)
|
||||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-22nlS", "reduce.wrong.event.type %s", instance.InstanceRemovedEventType)
|
}
|
||||||
// }
|
return handler.NewUpdateStatement(
|
||||||
// return handler.NewDeleteStatement(
|
e,
|
||||||
// e,
|
[]handler.Column{
|
||||||
// []handler.Condition{
|
handler.NewCol(InstanceColumnName, e.Name),
|
||||||
// handler.NewCond(instanceIDCol, e.Aggregate().ID),
|
handler.NewCol(UpdatedAt, e.CreationDate()),
|
||||||
// },
|
},
|
||||||
// ), nil
|
[]handler.Condition{
|
||||||
// }
|
handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
|
||||||
// }
|
},
|
||||||
|
), nil
|
||||||
|
}
|
||||||
|
|
||||||
// func (p *instanceRelationalProjection) reduceInstanceChanged(event eventstore.Event) (*handler.Statement, error) {
|
func (p *instanceRelationalProjection) reduceInstanceDelete(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// e, ok := event.(*instance.InstanceChangedEvent)
|
e, ok := event.(*instance.InstanceChangedEvent)
|
||||||
// if !ok {
|
if !ok {
|
||||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-so2am1", "reduce.wrong.event.type %s", instance.InstanceChangedEventType)
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-so2am1", "reduce.wrong.event.type %s", instance.InstanceChangedEventType)
|
||||||
// }
|
}
|
||||||
// return handler.NewUpdateStatement(
|
return handler.NewUpdateStatement(
|
||||||
// e,
|
e,
|
||||||
// []handler.Column{
|
[]handler.Column{
|
||||||
// handler.NewCol(InstanceColumnName, e.Name),
|
handler.NewCol(DeletedAt, e.CreationDate()),
|
||||||
// handler.NewCol(InstanceColumnChangeDate, e.CreationDate()),
|
},
|
||||||
// handler.NewCol(InstanceColumnSequence, e.Sequence()),
|
[]handler.Condition{
|
||||||
// },
|
handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
|
||||||
// []handler.Condition{
|
},
|
||||||
// handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
|
), nil
|
||||||
// },
|
}
|
||||||
// ), nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (p *instanceRelationalProjection) reduceDefaultOrgSet(event eventstore.Event) (*handler.Statement, error) {
|
func (p *instanceRelationalProjection) reduceDefaultOrgSet(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// e, ok := event.(*instance.DefaultOrgSetEvent)
|
e, ok := event.(*instance.DefaultOrgSetEvent)
|
||||||
// if !ok {
|
if !ok {
|
||||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-2n9f2", "reduce.wrong.event.type %s", instance.DefaultOrgSetEventType)
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-2n9f2", "reduce.wrong.event.type %s", instance.DefaultOrgSetEventType)
|
||||||
// }
|
}
|
||||||
// return handler.NewUpdateStatement(
|
return handler.NewUpdateStatement(
|
||||||
// e,
|
e,
|
||||||
// []handler.Column{
|
[]handler.Column{
|
||||||
// handler.NewCol(InstanceColumnChangeDate, e.CreationDate()),
|
handler.NewCol(UpdatedAt, e.CreationDate()),
|
||||||
// handler.NewCol(InstanceColumnSequence, e.Sequence()),
|
handler.NewCol(InstanceColumnDefaultOrgID, e.OrgID),
|
||||||
// handler.NewCol(InstanceColumnDefaultOrgID, e.OrgID),
|
},
|
||||||
// },
|
[]handler.Condition{
|
||||||
// []handler.Condition{
|
handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
|
||||||
// handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
|
},
|
||||||
// },
|
), nil
|
||||||
// ), nil
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// func (p *instanceRelationalProjection) reduceIAMProjectSet(event eventstore.Event) (*handler.Statement, error) {
|
func (p *instanceRelationalProjection) reduceIAMProjectSet(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// e, ok := event.(*instance.ProjectSetEvent)
|
e, ok := event.(*instance.ProjectSetEvent)
|
||||||
// if !ok {
|
if !ok {
|
||||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-30o0e", "reduce.wrong.event.type %s", instance.ProjectSetEventType)
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-30o0e", "reduce.wrong.event.type %s", instance.ProjectSetEventType)
|
||||||
// }
|
}
|
||||||
// return handler.NewUpdateStatement(
|
return handler.NewUpdateStatement(
|
||||||
// e,
|
e,
|
||||||
// []handler.Column{
|
[]handler.Column{
|
||||||
// handler.NewCol(InstanceColumnChangeDate, e.CreationDate()),
|
handler.NewCol(UpdatedAt, e.CreationDate()),
|
||||||
// handler.NewCol(InstanceColumnSequence, e.Sequence()),
|
handler.NewCol(InstanceColumnProjectID, e.ProjectID),
|
||||||
// handler.NewCol(InstanceColumnProjectID, e.ProjectID),
|
},
|
||||||
// },
|
[]handler.Condition{
|
||||||
// []handler.Condition{
|
handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
|
||||||
// handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
|
},
|
||||||
// },
|
), nil
|
||||||
// ), nil
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// func (p *instanceRelationalProjection) reduceConsoleSet(event eventstore.Event) (*handler.Statement, error) {
|
func (p *instanceRelationalProjection) reduceConsoleSet(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// e, ok := event.(*instance.ConsoleSetEvent)
|
e, ok := event.(*instance.ConsoleSetEvent)
|
||||||
// if !ok {
|
if !ok {
|
||||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Dgf11", "reduce.wrong.event.type %s", instance.ConsoleSetEventType)
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Dgf11", "reduce.wrong.event.type %s", instance.ConsoleSetEventType)
|
||||||
// }
|
}
|
||||||
// return handler.NewUpdateStatement(
|
return handler.NewUpdateStatement(
|
||||||
// e,
|
e,
|
||||||
// []handler.Column{
|
[]handler.Column{
|
||||||
// handler.NewCol(InstanceColumnChangeDate, e.CreationDate()),
|
handler.NewCol(UpdatedAt, e.CreationDate()),
|
||||||
// handler.NewCol(InstanceColumnSequence, e.Sequence()),
|
handler.NewCol(InstanceColumnConsoleID, e.ClientID),
|
||||||
// handler.NewCol(InstanceColumnConsoleID, e.ClientID),
|
handler.NewCol(InstanceColumnConsoleAppID, e.AppID),
|
||||||
// handler.NewCol(InstanceColumnConsoleAppID, e.AppID),
|
},
|
||||||
// },
|
[]handler.Condition{
|
||||||
// []handler.Condition{
|
handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
|
||||||
// handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
|
},
|
||||||
// },
|
), nil
|
||||||
// ), nil
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// func (p *instanceRelationalProjection) reduceDefaultLanguageSet(event eventstore.Event) (*handler.Statement, error) {
|
func (p *instanceRelationalProjection) reduceDefaultLanguageSet(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// e, ok := event.(*instance.DefaultLanguageSetEvent)
|
e, ok := event.(*instance.DefaultLanguageSetEvent)
|
||||||
// if !ok {
|
if !ok {
|
||||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-30o0e", "reduce.wrong.event.type %s", instance.DefaultLanguageSetEventType)
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-30o0e", "reduce.wrong.event.type %s", instance.DefaultLanguageSetEventType)
|
||||||
// }
|
}
|
||||||
// return handler.NewUpdateStatement(
|
return handler.NewUpdateStatement(
|
||||||
// e,
|
e,
|
||||||
// []handler.Column{
|
[]handler.Column{
|
||||||
// handler.NewCol(InstanceColumnChangeDate, e.CreationDate()),
|
handler.NewCol(UpdatedAt, e.CreationDate()),
|
||||||
// handler.NewCol(InstanceColumnSequence, e.Sequence()),
|
handler.NewCol(InstanceColumnDefaultLanguage, e.Language.String()),
|
||||||
// handler.NewCol(InstanceColumnDefaultLanguage, e.Language.String()),
|
},
|
||||||
// },
|
[]handler.Condition{
|
||||||
// []handler.Condition{
|
handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
|
||||||
// handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
|
},
|
||||||
// },
|
), nil
|
||||||
// ), nil
|
}
|
||||||
// }
|
|
||||||
|
@@ -55,6 +55,7 @@ var (
|
|||||||
UserMetadataProjection *handler.Handler
|
UserMetadataProjection *handler.Handler
|
||||||
UserAuthMethodProjection *handler.Handler
|
UserAuthMethodProjection *handler.Handler
|
||||||
InstanceProjection *handler.Handler
|
InstanceProjection *handler.Handler
|
||||||
|
InstanceRelationalProjection *handler.Handler
|
||||||
SecretGeneratorProjection *handler.Handler
|
SecretGeneratorProjection *handler.Handler
|
||||||
SMTPConfigProjection *handler.Handler
|
SMTPConfigProjection *handler.Handler
|
||||||
SMSConfigProjection *handler.Handler
|
SMSConfigProjection *handler.Handler
|
||||||
@@ -150,6 +151,7 @@ func Create(ctx context.Context, sqlClient *database.DB, es handler.EventStore,
|
|||||||
UserMetadataProjection = newUserMetadataProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["user_metadata"]))
|
UserMetadataProjection = newUserMetadataProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["user_metadata"]))
|
||||||
UserAuthMethodProjection = newUserAuthMethodProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["user_auth_method"]))
|
UserAuthMethodProjection = newUserAuthMethodProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["user_auth_method"]))
|
||||||
InstanceProjection = newInstanceProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["instances"]))
|
InstanceProjection = newInstanceProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["instances"]))
|
||||||
|
InstanceRelationalProjection = newInstanceRelationalProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["instances_relational"]))
|
||||||
SecretGeneratorProjection = newSecretGeneratorProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["secret_generators"]))
|
SecretGeneratorProjection = newSecretGeneratorProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["secret_generators"]))
|
||||||
SMTPConfigProjection = newSMTPConfigProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["smtp_configs"]))
|
SMTPConfigProjection = newSMTPConfigProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["smtp_configs"]))
|
||||||
SMSConfigProjection = newSMSConfigProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["sms_config"]))
|
SMSConfigProjection = newSMSConfigProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["sms_config"]))
|
||||||
@@ -304,6 +306,7 @@ func newProjectionsList() {
|
|||||||
UserMetadataProjection,
|
UserMetadataProjection,
|
||||||
UserAuthMethodProjection,
|
UserAuthMethodProjection,
|
||||||
InstanceProjection,
|
InstanceProjection,
|
||||||
|
InstanceRelationalProjection,
|
||||||
SecretGeneratorProjection,
|
SecretGeneratorProjection,
|
||||||
SMTPConfigProjection,
|
SMTPConfigProjection,
|
||||||
SMSConfigProjection,
|
SMSConfigProjection,
|
||||||
|
Reference in New Issue
Block a user