From cb25c96ba94425f4f2a4df932511edaca6ba17b0 Mon Sep 17 00:00:00 2001 From: Iraq Jaber Date: Tue, 17 Jun 2025 09:21:12 +0200 Subject: [PATCH] fixup! fixup! fixup! fixup! fixup! fixup! Merge branch 'clean-transactional-propsal' into instance_table --- backend/v3/storage/database/database.go | 1 + .../migration/001_instance_table/up.sql | 2 +- .../storage/database/dialect/postgres/pool.go | 5 ----- .../database/repository/instance_test.go | 9 ++++----- .../database/repository/repository_test.go | 4 ++-- .../query/projection/instance_relational.go | 20 ------------------- 6 files changed, 8 insertions(+), 33 deletions(-) diff --git a/backend/v3/storage/database/database.go b/backend/v3/storage/database/database.go index 8d890b2637..7dd8d490ba 100644 --- a/backend/v3/storage/database/database.go +++ b/backend/v3/storage/database/database.go @@ -16,6 +16,7 @@ type Pool interface { type PoolTest interface { Pool + // MigrateTest is the same as [Migrator] but executes the migrations multiple times instead of only once. MigrateTest(ctx context.Context) error } diff --git a/backend/v3/storage/database/dialect/postgres/migration/001_instance_table/up.sql b/backend/v3/storage/database/dialect/postgres/migration/001_instance_table/up.sql index 5edc3fe689..111719632c 100644 --- a/backend/v3/storage/database/dialect/postgres/migration/001_instance_table/up.sql +++ b/backend/v3/storage/database/dialect/postgres/migration/001_instance_table/up.sql @@ -22,5 +22,5 @@ $$ LANGUAGE plpgsql; CREATE TRIGGER trigger_set_updated_at BEFORE UPDATE ON zitadel.instances FOR EACH ROW -WHEN (OLD.* IS DISTINCT FROM NEW.*) +WHEN (OLD.updated_at IS NOT DISTINCT FROM NEW.updated_at) EXECUTE FUNCTION zitadel.set_updated_at(); diff --git a/backend/v3/storage/database/dialect/postgres/pool.go b/backend/v3/storage/database/dialect/postgres/pool.go index 74927e0956..4179f9398b 100644 --- a/backend/v3/storage/database/dialect/postgres/pool.go +++ b/backend/v3/storage/database/dialect/postgres/pool.go @@ -83,11 +83,6 @@ func (c *pgxPool) Migrate(ctx context.Context) error { // Migrate implements [database.PoolTest]. func (c *pgxPool) MigrateTest(ctx context.Context) error { - // allow multiple migrations - // if isMigrated { - // return nil - // } - client, err := c.Pool.Acquire(ctx) if err != nil { return err diff --git a/backend/v3/storage/database/repository/instance_test.go b/backend/v3/storage/database/repository/instance_test.go index 58696b3c80..a7f4c9add1 100644 --- a/backend/v3/storage/database/repository/instance_test.go +++ b/backend/v3/storage/database/repository/instance_test.go @@ -123,6 +123,8 @@ func TestCreateInstance(t *testing.T) { instance, err = instanceRepo.Get(ctx, instanceRepo.NameCondition(database.TextOperationEqual, instance.Name), ) + require.NoError(t, err) + require.Equal(t, tt.instance.ID, instance.ID) require.Equal(t, tt.instance.Name, instance.Name) require.Equal(t, tt.instance.DefaultOrgID, instance.DefaultOrgID) @@ -133,7 +135,6 @@ func TestCreateInstance(t *testing.T) { require.WithinRange(t, instance.CreatedAt, beforeCreate, afterCreate) require.WithinRange(t, instance.UpdatedAt, beforeCreate, afterCreate) require.Nil(t, instance.DeletedAt) - require.NoError(t, err) }) } } @@ -339,6 +340,7 @@ 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) @@ -347,14 +349,13 @@ func TestGetInstance(t *testing.T) { require.Equal(t, returnedInstance.ConsoleClientID, instance.ConsoleClientID) require.Equal(t, returnedInstance.ConsoleAppID, instance.ConsoleAppID) require.Equal(t, returnedInstance.DefaultLanguage, instance.DefaultLanguage) - require.NoError(t, err) }) } } func TestListInstance(t *testing.T) { ctx := context.Background() - pool, stop, err := newEmbeededDB(ctx) + pool, stop, err := newEmbeddedDB(ctx) require.NoError(t, err) defer stop() @@ -488,7 +489,6 @@ func TestListInstance(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - // ctx := context.Background() t.Cleanup(func() { _, err := pool.Exec(ctx, "DELETE FROM zitadel.instances") require.NoError(t, err) @@ -517,7 +517,6 @@ func TestListInstance(t *testing.T) { require.Equal(t, returnedInstances[i].ConsoleClientID, instance.ConsoleClientID) require.Equal(t, returnedInstances[i].ConsoleAppID, instance.ConsoleAppID) require.Equal(t, returnedInstances[i].DefaultLanguage, instance.DefaultLanguage) - require.NoError(t, err) } }) } diff --git a/backend/v3/storage/database/repository/repository_test.go b/backend/v3/storage/database/repository/repository_test.go index 6faac5d1a9..36c28c22e2 100644 --- a/backend/v3/storage/database/repository/repository_test.go +++ b/backend/v3/storage/database/repository/repository_test.go @@ -21,7 +21,7 @@ func runTests(m *testing.M) int { var stop func() var err error ctx := context.Background() - pool, stop, err = newEmbeededDB(ctx) + pool, stop, err = newEmbeddedDB(ctx) if err != nil { log.Printf("error with embedded postgres database: %v", err) return 1 @@ -31,7 +31,7 @@ func runTests(m *testing.M) int { return m.Run() } -func newEmbeededDB(ctx context.Context) (pool database.PoolTest, stop func(), err error) { +func newEmbeddedDB(ctx context.Context) (pool database.PoolTest, stop func(), err error) { connector, stop, err := embedded.StartEmbedded() if err != nil { return nil, nil, fmt.Errorf("unable to start embedded postgres: %w", err) diff --git a/internal/query/projection/instance_relational.go b/internal/query/projection/instance_relational.go index d85c7a1db3..9101fd749b 100644 --- a/internal/query/projection/instance_relational.go +++ b/internal/query/projection/instance_relational.go @@ -4,7 +4,6 @@ import ( "context" "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/zerrors" @@ -22,25 +21,6 @@ func (*instanceRelationalProjection) Name() string { return InstanceRelationalProjectionTable } -func (*instanceRelationalProjection) Init() *old_handler.Check { - return handler.NewTableCheck( - handler.NewTable([]*handler.InitColumn{ - handler.NewColumn(InstanceColumnID, handler.ColumnTypeText), - handler.NewColumn(InstanceColumnName, handler.ColumnTypeText, handler.Default("")), - handler.NewColumn(InstanceColumnDefaultOrgID, handler.ColumnTypeText, handler.Default("")), - handler.NewColumn(InstanceColumnProjectID, handler.ColumnTypeText, handler.Default("")), - handler.NewColumn(InstanceColumnConsoleID, handler.ColumnTypeText, handler.Default("")), - handler.NewColumn(InstanceColumnConsoleAppID, handler.ColumnTypeText, handler.Default("")), - handler.NewColumn(InstanceColumnDefaultLanguage, handler.ColumnTypeText, handler.Default("")), - handler.NewColumn(CreatedAt, handler.ColumnTypeTimestamp), - handler.NewColumn(UpdatedAt, handler.ColumnTypeTimestamp), - handler.NewColumn(DeletedAt, handler.ColumnTypeTimestamp), - }, - handler.NewPrimaryKey(InstanceColumnID), - ), - ) -} - func (p *instanceRelationalProjection) Reducers() []handler.AggregateReducer { return []handler.AggregateReducer{ {