mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 11:27:33 +00:00
fixup! Merge branch 'instance_table_2' into org_table
This commit is contained in:
@@ -17,11 +17,11 @@ const (
|
||||
type Organization struct {
|
||||
ID string `json:"id,omitempty" db:"id"`
|
||||
Name string `json:"name,omitempty" db:"name"`
|
||||
InstanceID string `json:"instance_id,omitempty" db:"instance_id"`
|
||||
InstanceID string `json:"instanceId,omitempty" db:"instance_id"`
|
||||
State State `json:"state,omitempty" db:"state"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty" db:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty" db:"updated_at"`
|
||||
DeletedAt *time.Time `json:"deleted_at,omitempty" db:"deleted_at"`
|
||||
CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"`
|
||||
UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"`
|
||||
DeletedAt *time.Time `json:"deletedAt,omitempty" db:"deleted_at"`
|
||||
}
|
||||
|
||||
// organizationColumns define all the columns of the instance table.
|
||||
@@ -48,12 +48,15 @@ type organizationConditions interface {
|
||||
IDCondition(instanceID string) database.Condition
|
||||
// NameCondition returns a filter on the name field.
|
||||
NameCondition(op database.TextOperation, name string) database.Condition
|
||||
// StateCondition returns a filter on the name field.
|
||||
StateCondition(state State) database.Condition
|
||||
}
|
||||
|
||||
// organizationChanges define all the changes for the instance table.
|
||||
type organizationChanges interface {
|
||||
// SetName sets the name column.
|
||||
SetName(name string) database.Change
|
||||
// SetState sets the name column.
|
||||
SetState(state State) database.Change
|
||||
}
|
||||
|
||||
|
@@ -12,3 +12,9 @@ CREATE TABLE zitadel.organizations(
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
deleted_at TIMESTAMPTZ DEFAULT NULL
|
||||
);
|
||||
|
||||
CREATE TRIGGER trigger_set_updated_at
|
||||
BEFORE UPDATE ON zitadel.organizations
|
||||
FOR EACH ROW
|
||||
WHEN (OLD.updated_at IS NOT DISTINCT FROM NEW.updated_at)
|
||||
EXECUTE FUNCTION zitadel.set_updated_at();
|
||||
|
@@ -28,7 +28,7 @@ func TestServer_TestOrganizationAddReduces(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
afterCreate := time.Now()
|
||||
|
||||
orgRepo := repository.OrgRepository(pool)
|
||||
orgRepo := repository.OrganizationRepository(pool)
|
||||
|
||||
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Minute)
|
||||
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||
@@ -66,7 +66,7 @@ func TestServer_TestOrganizationChangeReduces(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
afterCreate := time.Now()
|
||||
|
||||
orgRepo := repository.OrgRepository(pool)
|
||||
orgRepo := repository.OrganizationRepository(pool)
|
||||
|
||||
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Minute)
|
||||
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||
@@ -96,7 +96,7 @@ func TestServer_TestOrganizationDeactivateReduces(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
afterCreate := time.Now()
|
||||
|
||||
orgRepo := repository.OrgRepository(pool)
|
||||
orgRepo := repository.OrganizationRepository(pool)
|
||||
|
||||
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Minute)
|
||||
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||
@@ -131,7 +131,7 @@ func TestServer_TestOrganizationActivateReduces(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
afterCreate := time.Now()
|
||||
|
||||
orgRepo := repository.OrgRepository(pool)
|
||||
orgRepo := repository.OrganizationRepository(pool)
|
||||
|
||||
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Minute)
|
||||
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||
@@ -157,7 +157,7 @@ func TestServer_TestOrganizationRemoveReduces(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// 2. check org retrivable
|
||||
orgRepo := repository.OrgRepository(pool)
|
||||
orgRepo := repository.OrganizationRepository(pool)
|
||||
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Minute)
|
||||
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||
organization, err := orgRepo.Get(CTX,
|
||||
|
@@ -96,6 +96,9 @@ func (i *instance) Create(ctx context.Context, instance *domain.Instance) error
|
||||
|
||||
// Update implements [domain.InstanceRepository].
|
||||
func (i instance) Update(ctx context.Context, condition database.Condition, changes ...database.Change) (int64, error) {
|
||||
if changes == nil {
|
||||
return 0, nil
|
||||
}
|
||||
var builder database.StatementBuilder
|
||||
|
||||
builder.WriteString(`UPDATE zitadel.instances SET `)
|
||||
|
@@ -340,7 +340,6 @@ func TestGetInstance(t *testing.T) {
|
||||
require.Nil(t, instance, returnedInstance)
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, returnedInstance.ID, instance.ID)
|
||||
require.Equal(t, returnedInstance.Name, instance.Name)
|
||||
|
@@ -20,7 +20,7 @@ type org struct {
|
||||
repository
|
||||
}
|
||||
|
||||
func OrgRepository(client database.QueryExecutor) domain.OrganizationRepository {
|
||||
func OrganizationRepository(client database.QueryExecutor) domain.OrganizationRepository {
|
||||
return &org{
|
||||
repository: repository{
|
||||
client: client,
|
||||
@@ -110,10 +110,16 @@ func (o *org) Create(ctx context.Context, organization *domain.Organization) err
|
||||
|
||||
// Update implements [domain.OrganizationRepository].
|
||||
func (o org) Update(ctx context.Context, condition database.Condition, changes ...database.Change) (int64, error) {
|
||||
if changes == nil {
|
||||
return 0, nil
|
||||
}
|
||||
builder := database.StatementBuilder{}
|
||||
builder.WriteString(`UPDATE zitadel.organizations SET `)
|
||||
|
||||
// don't update deleted instances
|
||||
conditions := []database.Condition{condition, database.IsNull(o.DeletedAtColumn())}
|
||||
database.Changes(changes).Write(&builder)
|
||||
o.writeCondition(&builder, condition)
|
||||
o.writeCondition(&builder, database.And(conditions...))
|
||||
|
||||
stmt := builder.String()
|
||||
|
||||
@@ -163,6 +169,11 @@ func (o org) NameCondition(op database.TextOperation, name string) database.Cond
|
||||
return database.NewTextCondition(o.NameColumn(), op, name)
|
||||
}
|
||||
|
||||
// StateCondition implements [domain.organizationConditions].
|
||||
func (o org) StateCondition(state domain.State) database.Condition {
|
||||
return database.NewTextCondition(o.StateColumn(), database.TextOperationEqual, state)
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// columns
|
||||
// -------------------------------------------------------------
|
||||
|
File diff suppressed because it is too large
Load Diff
2
go.mod
2
go.mod
@@ -28,6 +28,7 @@ require (
|
||||
github.com/fatih/color v1.18.0
|
||||
github.com/fergusstrange/embedded-postgres v1.30.0
|
||||
github.com/gabriel-vasile/mimetype v1.4.9
|
||||
github.com/georgysavva/scany/v2 v2.1.4
|
||||
github.com/go-chi/chi/v5 v5.2.1
|
||||
github.com/go-jose/go-jose/v4 v4.1.0
|
||||
github.com/go-ldap/ldap/v3 v3.4.11
|
||||
@@ -125,7 +126,6 @@ require (
|
||||
github.com/crewjam/httperr v0.2.0 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
|
||||
github.com/georgysavva/scany/v2 v2.1.4 // indirect
|
||||
github.com/go-ini/ini v1.67.0 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
|
8
go.sum
8
go.sum
@@ -233,6 +233,8 @@ github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv
|
||||
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
|
||||
github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY=
|
||||
github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok=
|
||||
github.com/georgysavva/scany/v2 v2.1.4 h1:nrzHEJ4oQVRoiKmocRqA1IyGOmM/GQOEsg9UjMR5Ip4=
|
||||
github.com/georgysavva/scany/v2 v2.1.4/go.mod h1:fqp9yHZzM/PFVa3/rYEC57VmDx+KDch0LoqrJzkvtos=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
|
||||
@@ -308,8 +310,9 @@ github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXe
|
||||
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
|
||||
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
|
||||
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
|
||||
github.com/golang/geo v0.0.0-20200319012246-673a6f80352d/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
|
||||
@@ -764,6 +767,8 @@ github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3
|
||||
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
@@ -1122,4 +1127,3 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
|
||||
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
|
||||
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
|
||||
|
||||
|
@@ -6,7 +6,6 @@ import (
|
||||
repoDomain "github.com/zitadel/zitadel/backend/v3/domain"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
@@ -27,25 +26,6 @@ func newOrgRelationalProjection(ctx context.Context, config handler.Config) *han
|
||||
return handler.NewHandler(ctx, &config, new(orgRelationalProjection))
|
||||
}
|
||||
|
||||
// Init implements [handler.initializer]
|
||||
func (p *orgRelationalProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(OrgColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgColumnName, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(State, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(CreatedAt, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(UpdatedAt, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(DeletedAt, handler.ColumnTypeTimestamp),
|
||||
},
|
||||
handler.NewPrimaryKey(OrgColumnInstanceID, OrgColumnID),
|
||||
// handler.WithIndex(handler.NewIndex("domain", []string{OrgColumnDomain})),
|
||||
handler.WithIndex(handler.NewIndex("name", []string{OrgColumnName})),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
func (p *orgRelationalProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
|
Reference in New Issue
Block a user