diff --git a/backend/v3/domain/instance_domain.go b/backend/v3/domain/instance_domain.go index 402a261d3c..0877f286ae 100644 --- a/backend/v3/domain/instance_domain.go +++ b/backend/v3/domain/instance_domain.go @@ -8,10 +8,15 @@ import ( ) type InstanceDomain struct { - InstanceID string `json:"instanceId,omitempty" db:"instance_id"` - Domain string `json:"domain,omitempty" db:"domain"` - IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"` - Type DomainType `json:"type,omitempty" db:"type"` + InstanceID string `json:"instanceId,omitempty" db:"instance_id"` + Domain string `json:"domain,omitempty" db:"domain"` + // IsPrimary indicates if the domain is the primary domain of the instance. + // It is only set for custom domains. + IsPrimary *bool `json:"isPrimary,omitempty" db:"is_primary"` + // IsGenerated indicates if the domain is a generated domain. + // It is only set for custom domains. + IsGenerated *bool `json:"isGenerated,omitempty" db:"is_generated"` + Type DomainType `json:"type,omitempty" db:"type"` CreatedAt time.Time `json:"createdAt,omitzero" db:"created_at"` UpdatedAt time.Time `json:"updatedAt,omitzero" db:"updated_at"` @@ -20,16 +25,16 @@ type InstanceDomain struct { type AddInstanceDomain struct { InstanceID string `json:"instanceId,omitempty" db:"instance_id"` Domain string `json:"domain,omitempty" db:"domain"` - IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"` - IsGenerated bool `json:"isGenerated,omitempty" db:"is_generated"` + IsPrimary *bool `json:"isPrimary,omitempty" db:"is_primary"` + IsGenerated *bool `json:"isGenerated,omitempty" db:"is_generated"` Type DomainType `json:"type,omitempty" db:"type"` // CreatedAt is the time when the domain was added. // It is set by the repository and should not be set by the caller. - CreatedAt *time.Time `json:"createdAt,omitzero" db:"created_at"` + CreatedAt time.Time `json:"createdAt,omitzero" db:"created_at"` // UpdatedAt is the time when the domain was last updated. // It is set by the repository and should not be set by the caller. - UpdatedAt *time.Time `json:"updatedAt,omitzero" db:"updated_at"` + UpdatedAt time.Time `json:"updatedAt,omitzero" db:"updated_at"` } type instanceDomainColumns interface { diff --git a/backend/v3/storage/database/dialect/postgres/migration/003_domains_table/up.sql b/backend/v3/storage/database/dialect/postgres/migration/003_domains_table/up.sql index cfa651f1f7..fb8ae476b3 100644 --- a/backend/v3/storage/database/dialect/postgres/migration/003_domains_table/up.sql +++ b/backend/v3/storage/database/dialect/postgres/migration/003_domains_table/up.sql @@ -15,8 +15,8 @@ CREATE TABLE zitadel.instance_domains( , is_generated BOOLEAN , type zitadel.domain_type NOT NULL - , created_at TIMESTAMPTZ DEFAULT NOW() - , updated_at TIMESTAMPTZ DEFAULT NOW() + , created_at TIMESTAMPTZ DEFAULT NOW() NOT NULL + , updated_at TIMESTAMPTZ DEFAULT NOW() NOT NULL , PRIMARY KEY (domain) @@ -24,7 +24,7 @@ CREATE TABLE zitadel.instance_domains( , CONSTRAINT primary_cannot_be_trusted CHECK (is_primary IS NULL OR type != 'trusted') , CONSTRAINT generated_cannot_be_trusted CHECK (is_generated IS NULL OR type != 'trusted') - , CONSTRAINT custom_values_set CHECK (type = 'custom' AND is_primary IS NOT NULL AND is_generated IS NOT NULL) + , CONSTRAINT custom_values_set CHECK ((is_primary IS NOT NULL AND is_generated IS NOT NULL) OR type != 'custom') ); CREATE INDEX idx_instance_domain_instance ON zitadel.instance_domains(instance_id); @@ -37,8 +37,8 @@ CREATE TABLE zitadel.org_domains( , is_primary BOOLEAN NOT NULL DEFAULT FALSE , validation_type zitadel.domain_validation_type - , created_at TIMESTAMPTZ DEFAULT NOW() - , updated_at TIMESTAMPTZ DEFAULT NOW() + , created_at TIMESTAMPTZ DEFAULT NOW() NOT NULL + , updated_at TIMESTAMPTZ DEFAULT NOW() NOT NULL , PRIMARY KEY (instance_id, org_id, domain) diff --git a/backend/v3/storage/database/events_testing/instance_domain_test.go b/backend/v3/storage/database/events_testing/instance_domain_test.go index de968e0707..db3c0a969c 100644 --- a/backend/v3/storage/database/events_testing/instance_domain_test.go +++ b/backend/v3/storage/database/events_testing/instance_domain_test.go @@ -3,7 +3,6 @@ package events_test import ( - "log" "testing" "time" @@ -11,6 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/zitadel/zitadel/backend/v3/domain" "github.com/zitadel/zitadel/backend/v3/storage/database" "github.com/zitadel/zitadel/backend/v3/storage/database/repository" "github.com/zitadel/zitadel/internal/integration" @@ -42,7 +42,7 @@ func TestServer_TestInstanceDomainReduces(t *testing.T) { assert.NoError(ttt, err) }, retryDuration, tick) - t.Run("test instance domain add reduces", func(t *testing.T) { + t.Run("test instance custom domain add reduces", func(t *testing.T) { // Add a domain to the instance domainName := gofakeit.DomainName() beforeAdd := time.Now() @@ -71,6 +71,7 @@ func TestServer_TestInstanceDomainReduces(t *testing.T) { database.And( instanceDomainRepo.InstanceIDCondition(instance.Instance.Id), instanceDomainRepo.DomainCondition(database.TextOperationEqual, domainName), + instanceDomainRepo.TypeCondition(domain.DomainTypeCustom), ), ), ) @@ -78,15 +79,13 @@ func TestServer_TestInstanceDomainReduces(t *testing.T) { // event instance.domain.added assert.Equal(ttt, domainName, domain.Domain) assert.Equal(ttt, instance.Instance.Id, domain.InstanceID) - assert.False(ttt, domain.IsPrimary) - log.Printf("created at %v\n", domain.CreatedAt) - log.Printf("after %v\n", afterAdd) - log.Printf("before %v\n", beforeAdd) + assert.False(ttt, *domain.IsPrimary) assert.WithinRange(ttt, domain.CreatedAt, beforeAdd, afterAdd) assert.WithinRange(ttt, domain.UpdatedAt, beforeAdd, afterAdd) }, retryDuration, tick) }) - t.Run("test instance domain set primary reduces", func(t *testing.T) { + + t.Run("test instance custom domain set primary reduces", func(t *testing.T) { // Add a domain to the instance domainName := gofakeit.DomainName() _, err := instance.Client.InstanceV2Beta.AddCustomDomain(CTX, &v2beta.AddCustomDomainRequest{ @@ -101,6 +100,7 @@ func TestServer_TestInstanceDomainReduces(t *testing.T) { database.WithCondition( database.And( instanceDomainRepo.InstanceIDCondition(instance.Instance.Id), + instanceDomainRepo.TypeCondition(domain.DomainTypeCustom), instanceDomainRepo.IsPrimaryCondition(false), ), ), @@ -129,11 +129,13 @@ func TestServer_TestInstanceDomainReduces(t *testing.T) { database.WithCondition( database.And( instanceDomainRepo.InstanceIDCondition(instance.Instance.Id), - instanceDomainRepo.DomainCondition(database.TextOperationEqual, domainName)), + instanceDomainRepo.DomainCondition(database.TextOperationEqual, domainName), + instanceDomainRepo.TypeCondition(domain.DomainTypeCustom), + ), ), ) require.NoError(ttt, err) - require.False(ttt, domain.IsPrimary) + require.False(ttt, *domain.IsPrimary) assert.Equal(ttt, domainName, domain.Domain) }, retryDuration, tick) @@ -154,18 +156,19 @@ func TestServer_TestInstanceDomainReduces(t *testing.T) { database.And( instanceDomainRepo.InstanceIDCondition(instance.Instance.Id), instanceDomainRepo.IsPrimaryCondition(true), + instanceDomainRepo.TypeCondition(domain.DomainTypeCustom), ), ), ) require.NoError(ttt, err) // event instance.domain.primary.set assert.Equal(ttt, domainName, domain.Domain) - assert.True(ttt, domain.IsPrimary) + assert.True(ttt, *domain.IsPrimary) assert.WithinRange(ttt, domain.UpdatedAt, beforeSetPrimary, afterSetPrimary) }, retryDuration, tick) }) - t.Run("test instance domain remove reduces", func(t *testing.T) { + t.Run("test instance custom domain remove reduces", func(t *testing.T) { // Add a domain to the instance domainName := gofakeit.DomainName() _, err := instance.Client.InstanceV2Beta.AddCustomDomain(CTX, &v2beta.AddCustomDomainRequest{ @@ -174,16 +177,6 @@ func TestServer_TestInstanceDomainReduces(t *testing.T) { }) require.NoError(t, err) - t.Cleanup(func() { - _, err := instance.Client.InstanceV2Beta.RemoveCustomDomain(CTX, &v2beta.RemoveCustomDomainRequest{ - InstanceId: instance.Instance.Id, - Domain: domainName, - }) - if err != nil { - t.Logf("Failed to delete instance domain on cleanup: %v", err) - } - }) - // Wait for domain to be created and verify it exists retryDuration, tick = integration.WaitForAndTickWithMaxDuration(CTX, time.Minute) assert.EventuallyWithT(t, func(ttt *assert.CollectT) { @@ -192,6 +185,7 @@ func TestServer_TestInstanceDomainReduces(t *testing.T) { database.And( instanceDomainRepo.InstanceIDCondition(instance.Instance.Id), instanceDomainRepo.DomainCondition(database.TextOperationEqual, domainName), + instanceDomainRepo.TypeCondition(domain.DomainTypeCustom), ), ), ) @@ -199,7 +193,7 @@ func TestServer_TestInstanceDomainReduces(t *testing.T) { }, retryDuration, tick) // Remove the domain - _, err = SystemClient.RemoveDomain(CTX, &system.RemoveDomainRequest{ + _, err = instance.Client.InstanceV2Beta.RemoveCustomDomain(CTX, &v2beta.RemoveCustomDomainRequest{ InstanceId: instance.Instance.Id, Domain: domainName, }) @@ -213,6 +207,98 @@ func TestServer_TestInstanceDomainReduces(t *testing.T) { database.And( instanceDomainRepo.InstanceIDCondition(instance.Instance.Id), instanceDomainRepo.DomainCondition(database.TextOperationEqual, domainName), + instanceDomainRepo.TypeCondition(domain.DomainTypeCustom), + ), + ), + ) + // event instance.domain.removed + assert.Nil(ttt, domain) + require.ErrorIs(ttt, err, new(database.NoRowFoundError)) + }, retryDuration, tick) + }) + + t.Run("test instance trusted domain add reduces", func(t *testing.T) { + // Add a domain to the instance + domainName := gofakeit.DomainName() + beforeAdd := time.Now() + _, err := instance.Client.InstanceV2Beta.AddTrustedDomain(CTX, &v2beta.AddTrustedDomainRequest{ + InstanceId: instance.Instance.Id, + Domain: domainName, + }) + require.NoError(t, err) + afterAdd := time.Now() + + t.Cleanup(func() { + _, err := instance.Client.InstanceV2Beta.RemoveTrustedDomain(CTX, &v2beta.RemoveTrustedDomainRequest{ + InstanceId: instance.Instance.Id, + Domain: domainName, + }) + if err != nil { + t.Logf("Failed to delete instance domain on cleanup: %v", err) + } + }) + + // Test that domain add reduces + retryDuration, tick = integration.WaitForAndTickWithMaxDuration(CTX, time.Minute) + assert.EventuallyWithT(t, func(ttt *assert.CollectT) { + domain, err := instanceDomainRepo.Get(CTX, + database.WithCondition( + database.And( + instanceDomainRepo.InstanceIDCondition(instance.Instance.Id), + instanceDomainRepo.DomainCondition(database.TextOperationEqual, domainName), + instanceDomainRepo.TypeCondition(domain.DomainTypeTrusted), + ), + ), + ) + require.NoError(ttt, err) + // event instance.domain.added + assert.Equal(ttt, domainName, domain.Domain) + assert.Equal(ttt, instance.Instance.Id, domain.InstanceID) + assert.WithinRange(ttt, domain.CreatedAt, beforeAdd, afterAdd) + assert.WithinRange(ttt, domain.UpdatedAt, beforeAdd, afterAdd) + }, retryDuration, tick) + }) + + t.Run("test instance trusted domain remove reduces", func(t *testing.T) { + // Add a domain to the instance + domainName := gofakeit.DomainName() + _, err := instance.Client.InstanceV2Beta.AddTrustedDomain(CTX, &v2beta.AddTrustedDomainRequest{ + InstanceId: instance.Instance.Id, + Domain: domainName, + }) + require.NoError(t, err) + + // Wait for domain to be created and verify it exists + retryDuration, tick = integration.WaitForAndTickWithMaxDuration(CTX, time.Minute) + assert.EventuallyWithT(t, func(ttt *assert.CollectT) { + _, err := instanceDomainRepo.Get(CTX, + database.WithCondition( + database.And( + instanceDomainRepo.InstanceIDCondition(instance.Instance.Id), + instanceDomainRepo.DomainCondition(database.TextOperationEqual, domainName), + instanceDomainRepo.TypeCondition(domain.DomainTypeTrusted), + ), + ), + ) + require.NoError(ttt, err) + }, retryDuration, tick) + + // Remove the domain + _, err = instance.Client.InstanceV2Beta.RemoveTrustedDomain(CTX, &v2beta.RemoveTrustedDomainRequest{ + InstanceId: instance.Instance.Id, + Domain: domainName, + }) + require.NoError(t, err) + + // Test that domain remove reduces + retryDuration, tick = integration.WaitForAndTickWithMaxDuration(CTX, time.Minute) + assert.EventuallyWithT(t, func(ttt *assert.CollectT) { + domain, err := instanceDomainRepo.Get(CTX, + database.WithCondition( + database.And( + instanceDomainRepo.InstanceIDCondition(instance.Instance.Id), + instanceDomainRepo.DomainCondition(database.TextOperationEqual, domainName), + instanceDomainRepo.TypeCondition(domain.DomainTypeTrusted), ), ), ) diff --git a/backend/v3/storage/database/repository/instance_domain.go b/backend/v3/storage/database/repository/instance_domain.go index 0a0c970fe7..5ce4c12e7b 100644 --- a/backend/v3/storage/database/repository/instance_domain.go +++ b/backend/v3/storage/database/repository/instance_domain.go @@ -54,13 +54,22 @@ func (i *instanceDomain) List(ctx context.Context, opts ...database.QueryOption) // Add implements [domain.InstanceDomainRepository]. func (i *instanceDomain) Add(ctx context.Context, domain *domain.AddInstanceDomain) error { - var builder database.StatementBuilder + var ( + builder database.StatementBuilder + createdAt, updatedAt any = database.DefaultInstruction, database.DefaultInstruction + ) + if !domain.CreatedAt.IsZero() { + createdAt = domain.CreatedAt + } + if !domain.UpdatedAt.IsZero() { + updatedAt = domain.UpdatedAt + } builder.WriteString(`INSERT INTO zitadel.instance_domains (instance_id, domain, is_primary, is_generated, type, created_at, updated_at) VALUES (`) - builder.WriteArgs(domain.InstanceID, domain.Domain, domain.IsPrimary, domain.IsGenerated, domain.Type, domain.CreatedAt, domain.UpdatedAt) + builder.WriteArgs(domain.InstanceID, domain.Domain, domain.IsPrimary, domain.IsGenerated, domain.Type, createdAt, updatedAt) builder.WriteString(`) RETURNING created_at, updated_at`) - return i.client.QueryRow(ctx, builder.String(), builder.Args()...).Scan(domain.CreatedAt, domain.UpdatedAt) + return i.client.QueryRow(ctx, builder.String(), builder.Args()...).Scan(&domain.CreatedAt, &domain.UpdatedAt) } // Remove implements [domain.InstanceDomainRepository]. diff --git a/backend/v3/storage/database/repository/instance_domain_test.go b/backend/v3/storage/database/repository/instance_domain_test.go index 168af16b27..27f594155f 100644 --- a/backend/v3/storage/database/repository/instance_domain_test.go +++ b/backend/v3/storage/database/repository/instance_domain_test.go @@ -3,8 +3,10 @@ package repository_test import ( "context" "testing" + "time" "github.com/brianvoe/gofakeit/v6" + "github.com/muhlemmer/gu" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -38,25 +40,31 @@ func TestAddInstanceDomain(t *testing.T) { { name: "happy path", instanceDomain: domain.AddInstanceDomain{ - InstanceID: instanceID, - Domain: gofakeit.DomainName(), - IsPrimary: false, + InstanceID: instanceID, + Domain: gofakeit.DomainName(), + Type: domain.DomainTypeCustom, + IsPrimary: gu.Ptr(false), + IsGenerated: gu.Ptr(false), }, }, { name: "add primary domain", instanceDomain: domain.AddInstanceDomain{ - InstanceID: instanceID, - Domain: gofakeit.DomainName(), - IsPrimary: true, + InstanceID: instanceID, + Domain: gofakeit.DomainName(), + Type: domain.DomainTypeCustom, + IsPrimary: gu.Ptr(true), + IsGenerated: gu.Ptr(false), }, }, { name: "add domain without domain name", instanceDomain: domain.AddInstanceDomain{ - InstanceID: instanceID, - Domain: "", - IsPrimary: false, + InstanceID: instanceID, + Domain: "", + Type: domain.DomainTypeCustom, + IsPrimary: gu.Ptr(false), + IsGenerated: gu.Ptr(false), }, err: new(database.CheckError), }, @@ -66,9 +74,11 @@ func TestAddInstanceDomain(t *testing.T) { domainName := gofakeit.DomainName() instanceDomain := &domain.AddInstanceDomain{ - InstanceID: instanceID, - Domain: domainName, - IsPrimary: false, + InstanceID: instanceID, + Domain: domainName, + Type: domain.DomainTypeCustom, + IsPrimary: gu.Ptr(false), + IsGenerated: gu.Ptr(false), } err := domainRepo.Add(ctx, instanceDomain) @@ -76,9 +86,11 @@ func TestAddInstanceDomain(t *testing.T) { // return same domain again return &domain.AddInstanceDomain{ - InstanceID: instanceID, - Domain: domainName, - IsPrimary: true, + InstanceID: instanceID, + Domain: domainName, + Type: domain.DomainTypeCustom, + IsPrimary: gu.Ptr(true), + IsGenerated: gu.Ptr(false), } }, err: new(database.UniqueError), @@ -86,17 +98,21 @@ func TestAddInstanceDomain(t *testing.T) { { name: "add domain with non-existent instance", instanceDomain: domain.AddInstanceDomain{ - InstanceID: "non-existent-instance", - Domain: gofakeit.DomainName(), - IsPrimary: false, + InstanceID: "non-existent-instance", + Domain: gofakeit.DomainName(), + Type: domain.DomainTypeCustom, + IsPrimary: gu.Ptr(false), + IsGenerated: gu.Ptr(false), }, err: new(database.ForeignKeyError), }, { name: "add domain without instance id", instanceDomain: domain.AddInstanceDomain{ - Domain: gofakeit.DomainName(), - IsPrimary: false, + Domain: gofakeit.DomainName(), + Type: domain.DomainTypeCustom, + IsPrimary: gu.Ptr(false), + IsGenerated: gu.Ptr(false), }, err: new(database.ForeignKeyError), }, @@ -106,6 +122,8 @@ func TestAddInstanceDomain(t *testing.T) { t.Run(test.name, func(t *testing.T) { ctx := t.Context() + // we take now here because the timestamp of the transaction is used to set the createdAt and updatedAt fields + beforeAdd := time.Now() tx, err := pool.Begin(t.Context(), nil) require.NoError(t, err) defer func() { @@ -122,6 +140,7 @@ func TestAddInstanceDomain(t *testing.T) { } err = domainRepo.Add(ctx, instanceDomain) + afterAdd := time.Now() if test.err != nil { assert.ErrorIs(t, err, test.err) return @@ -130,6 +149,8 @@ func TestAddInstanceDomain(t *testing.T) { require.NoError(t, err) assert.NotZero(t, instanceDomain.CreatedAt) assert.NotZero(t, instanceDomain.UpdatedAt) + assert.WithinRange(t, instanceDomain.CreatedAt, beforeAdd, afterAdd) + assert.WithinRange(t, instanceDomain.UpdatedAt, beforeAdd, afterAdd) }) } } @@ -161,14 +182,18 @@ func TestGetInstanceDomain(t *testing.T) { domainName2 := gofakeit.DomainName() domain1 := &domain.AddInstanceDomain{ - InstanceID: instanceID, - Domain: domainName1, - IsPrimary: true, + InstanceID: instanceID, + Domain: domainName1, + IsPrimary: gu.Ptr(true), + IsGenerated: gu.Ptr(false), + Type: domain.DomainTypeCustom, } domain2 := &domain.AddInstanceDomain{ - InstanceID: instanceID, - Domain: domainName2, - IsPrimary: false, + InstanceID: instanceID, + Domain: domainName2, + IsPrimary: gu.Ptr(false), + IsGenerated: gu.Ptr(false), + Type: domain.DomainTypeCustom, } err = domainRepo.Add(t.Context(), domain1) @@ -190,7 +215,7 @@ func TestGetInstanceDomain(t *testing.T) { expected: &domain.InstanceDomain{ InstanceID: instanceID, Domain: domainName1, - IsPrimary: true, + IsPrimary: gu.Ptr(true), }, }, { @@ -201,7 +226,7 @@ func TestGetInstanceDomain(t *testing.T) { expected: &domain.InstanceDomain{ InstanceID: instanceID, Domain: domainName2, - IsPrimary: false, + IsPrimary: gu.Ptr(false), }, }, { @@ -259,19 +284,25 @@ func TestListInstanceDomains(t *testing.T) { domainRepo := instanceRepo.Domains(false) domains := []domain.AddInstanceDomain{ { - InstanceID: instanceID, - Domain: gofakeit.DomainName(), - IsPrimary: true, + InstanceID: instanceID, + Domain: gofakeit.DomainName(), + IsPrimary: gu.Ptr(true), + IsGenerated: gu.Ptr(false), + Type: domain.DomainTypeCustom, }, { - InstanceID: instanceID, - Domain: gofakeit.DomainName(), - IsPrimary: false, + InstanceID: instanceID, + Domain: gofakeit.DomainName(), + IsPrimary: gu.Ptr(false), + IsGenerated: gu.Ptr(false), + Type: domain.DomainTypeCustom, }, { - InstanceID: instanceID, - Domain: gofakeit.DomainName(), - IsPrimary: false, + InstanceID: instanceID, + Domain: gofakeit.DomainName(), + IsPrimary: gu.Ptr(false), + IsGenerated: gu.Ptr(false), + Type: domain.DomainTypeCustom, }, } @@ -358,9 +389,11 @@ func TestUpdateInstanceDomain(t *testing.T) { domainRepo := instanceRepo.Domains(false) domainName := gofakeit.DomainName() instanceDomain := &domain.AddInstanceDomain{ - InstanceID: instanceID, - Domain: domainName, - IsPrimary: false, + InstanceID: instanceID, + Domain: domainName, + IsPrimary: gu.Ptr(false), + IsGenerated: gu.Ptr(false), + Type: domain.DomainTypeCustom, } err = domainRepo.Add(t.Context(), instanceDomain) @@ -445,17 +478,20 @@ func TestRemoveInstanceDomain(t *testing.T) { // add domains domainRepo := instanceRepo.Domains(false) domainName1 := gofakeit.DomainName() - domainName2 := gofakeit.DomainName() domain1 := &domain.AddInstanceDomain{ - InstanceID: instanceID, - Domain: domainName1, - IsPrimary: true, + InstanceID: instanceID, + Domain: domainName1, + IsPrimary: gu.Ptr(true), + IsGenerated: gu.Ptr(false), + Type: domain.DomainTypeCustom, } domain2 := &domain.AddInstanceDomain{ - InstanceID: instanceID, - Domain: domainName2, - IsPrimary: false, + InstanceID: instanceID, + Domain: gofakeit.DomainName(), + IsPrimary: gu.Ptr(false), + IsGenerated: gu.Ptr(false), + Type: domain.DomainTypeCustom, } err = domainRepo.Add(t.Context(), domain1) diff --git a/backend/v3/storage/database/statement.go b/backend/v3/storage/database/statement.go index 7e20fcf4f0..2858feae43 100644 --- a/backend/v3/storage/database/statement.go +++ b/backend/v3/storage/database/statement.go @@ -8,8 +8,9 @@ import ( type Instruction string const ( - NowInstruction Instruction = "NOW()" - NullInstruction Instruction = "NULL" + DefaultInstruction Instruction = "DEFAULT" + NowInstruction Instruction = "NOW()" + NullInstruction Instruction = "NULL" ) // StatementBuilder is a helper to build SQL statement. diff --git a/internal/query/projection/instance_domain_relational.go b/internal/query/projection/instance_domain_relational.go index 111996de59..0c8f0c597c 100644 --- a/internal/query/projection/instance_domain_relational.go +++ b/internal/query/projection/instance_domain_relational.go @@ -69,10 +69,11 @@ func (p *instanceDomainRelationalProjection) reduceCustomDomainAdded(event event return repository.InstanceRepository(v3_sql.SQLTx(tx)).Domains(false).Add(ctx, &domain.AddInstanceDomain{ InstanceID: e.Aggregate().InstanceID, Domain: e.Domain, - IsGenerated: e.Generated, + IsPrimary: gu.Ptr(false), + IsGenerated: &e.Generated, Type: domain.DomainTypeCustom, - CreatedAt: gu.Ptr(e.CreationDate()), - UpdatedAt: gu.Ptr(e.CreationDate()), + CreatedAt: e.CreationDate(), + UpdatedAt: e.CreationDate(), }) }), nil } @@ -136,9 +137,9 @@ func (p *instanceDomainRelationalProjection) reduceTrustedDomainAdded(event even return repository.InstanceRepository(v3_sql.SQLTx(tx)).Domains(false).Add(ctx, &domain.AddInstanceDomain{ InstanceID: e.Aggregate().InstanceID, Domain: e.Domain, - Type: domain.DomainTypeCustom, - CreatedAt: gu.Ptr(e.CreationDate()), - UpdatedAt: gu.Ptr(e.CreationDate()), + Type: domain.DomainTypeTrusted, + CreatedAt: e.CreationDate(), + UpdatedAt: e.CreationDate(), }) }), nil }