feat: add embedded testing server for postgres (#9955)

# Which Problems Are Solved

1. there was no embedded database to run tests against
2. there were no tests for postgres/migrate
3. there was no test setup for repository which starts a client for the
embedded database

# How the Problems Are Solved

1. postgres/embedded package was added
2. tests were added
3. TestMain was added incl. an example test

# Additional Changes

none

# Additional Context

closes #9934

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Silvan
2025-05-26 09:31:45 +02:00
committed by GitHub
parent 362420f62b
commit 01180d2a63
11 changed files with 274 additions and 19 deletions

View File

@@ -9,11 +9,12 @@ import (
"github.com/zitadel/zitadel/backend/v3/storage/database/dialect/postgres/migration"
)
type pgxConn struct{ *pgxpool.Conn }
type pgxConn struct {
*pgxpool.Conn
}
var (
_ database.Client = (*pgxConn)(nil)
_ database.Migrator = (*pgxConn)(nil)
_ database.Client = (*pgxConn)(nil)
)
// Release implements [database.Client].
@@ -53,5 +54,10 @@ func (c *pgxConn) Exec(ctx context.Context, sql string, args ...any) error {
// Migrate implements [database.Migrator].
func (c *pgxConn) Migrate(ctx context.Context) error {
return migration.Migrate(ctx, c.Conn.Conn())
if isMigrated {
return nil
}
err := migration.Migrate(ctx, c.Conn.Conn())
isMigrated = err == nil
return err
}