mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-13 06:07:46 +00:00
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:
@@ -9,11 +9,12 @@ import (
|
||||
"github.com/zitadel/zitadel/backend/v3/storage/database/dialect/postgres/migration"
|
||||
)
|
||||
|
||||
type pgxPool struct{ *pgxpool.Pool }
|
||||
type pgxPool struct {
|
||||
*pgxpool.Pool
|
||||
}
|
||||
|
||||
var (
|
||||
_ database.Pool = (*pgxPool)(nil)
|
||||
_ database.Migrator = (*pgxPool)(nil)
|
||||
_ database.Pool = (*pgxPool)(nil)
|
||||
)
|
||||
|
||||
// Acquire implements [database.Pool].
|
||||
@@ -22,7 +23,7 @@ func (c *pgxPool) Acquire(ctx context.Context) (database.Client, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pgxConn{conn}, nil
|
||||
return &pgxConn{Conn: conn}, nil
|
||||
}
|
||||
|
||||
// Query implements [database.Pool].
|
||||
@@ -62,9 +63,16 @@ func (c *pgxPool) Close(_ context.Context) error {
|
||||
|
||||
// Migrate implements [database.Migrator].
|
||||
func (c *pgxPool) Migrate(ctx context.Context) error {
|
||||
if isMigrated {
|
||||
return nil
|
||||
}
|
||||
|
||||
client, err := c.Pool.Acquire(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return migration.Migrate(ctx, client.Conn())
|
||||
|
||||
err = migration.Migrate(ctx, client.Conn())
|
||||
isMigrated = err == nil
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user