feat: test event reduction to relational tables (#11718)

# Which Problems Are Solved

This PR provides an example for testing DB reduction to relational
tables without exploiting integration tests.

# How the Problems Are Solved

- Set up a disposable embedded Postgres DB used to store the results of
the calls to the reducers and verify such results
- Add utility method to return transactions from the existing DB pool.
These transactions can be used by the single test cases to insert and
read data from DB
- Add a test to verify that the handler contains the expected reducers
(checking also that they are on the right aggregate type)
- Add tests to verify the single reduce functions. A parent test creates
the required objects to satisfy the foreign key constraints.

# Additional Changes

  - Typo fixed in `postgres.DecodeConfig()`
  - Discard unneeded `projectionName` parameter for `Executor` function
 
# Additional Context

- Closes #11430
This commit is contained in:
Marco A.
2026-03-02 16:44:51 +00:00
committed by GitHub
parent d3434dd46c
commit 3ebeb61b80
7 changed files with 338 additions and 318 deletions
@@ -81,9 +81,7 @@ func DecodeConfig(input any) (database.Connector, error) {
if err = decoder.Decode(c); err != nil {
return nil, err
}
return &Config{
Config: &pgxpool.Config{},
}, nil
return connector, nil
}
return nil, errors.New("invalid configuration")
}
@@ -2,8 +2,10 @@ package postgres
import (
"context"
"database/sql"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/jackc/pgx/v5/stdlib"
"github.com/zitadel/zitadel/backend/v3/storage/database"
"github.com/zitadel/zitadel/backend/v3/storage/database/dialect/postgres/migration"
@@ -13,7 +15,13 @@ type pgxPool struct {
*pgxpool.Pool
}
// RawDB implements [database.PoolTest].
func (p *pgxPool) RawDB() *sql.DB {
return stdlib.OpenDBFromPool(p.Pool)
}
var _ database.Pool = (*pgxPool)(nil)
var _ database.PoolTest = (*pgxPool)(nil)
func PGxPool(pool *pgxpool.Pool) *pgxPool {
return &pgxPool{