mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 03:27:32 +00:00

# Which Problems Are Solved As an outcome of [this issue](https://github.com/zitadel/zitadel/issues/9599) we want to implement relational tables in Zitadel. For that we use new tables as a successor of the current tables used by Zitadel in `projections`, `auth` and `admin` schemas. The new logic is based on [this proposal](https://github.com/zitadel/zitadel/pull/9870). This issue does not contain the switch from CQRS to the new tables. This is change will be implemented in a later stage. We focus on the most critical tables which is user authentication. We need a table to manage organizations. ### organization fields The following fields must be managed in this table: - `id` - `instance_id` - `name` - `state` enum (active, inactive) - `created_at` - `updated_at` - `deleted_at` DISCUSS: should we add a `primary_domain` to this table so that we do not have to join on domains to return a simple org? We must ensure the unique constraints for this table matches the current commands. ### organization repository The repository must provide the following functions: Manipulations: - create - `instance_id` - `name` - update - `name` - delete Queries: - get returns single organization matching the criteria and pagination, should return error if multiple were found - list returns list of organizations matching the criteria, pagination Criteria are the following: - by id - by name pagination: - by created_at - by updated_at - by name ### organization events The following events must be applied on the table using a projection (`internal/query/projection`) - `org.added` results in create - `org.changed` sets the `name` field - `org.deactivated` sets the `state` field - `org.reactivated` sets the `state` field - `org.removed` sets the `deleted_at` field - if answer is yes to discussion: `org.domain.primary.set` sets the `primary_domain` field - `instance.removed` sets the the `deleted_at` field if not already set ### acceptance criteria - [x] migration is implemented and gets executed - [x] domain interfaces are implemented and documented for service layer - [x] repository is implemented and implements domain interface - [x] testing - [x] the repository methods - [x] events get reduced correctly - [x] unique constraints # Additional Context Replace this example with links to related issues, discussions, discord threads, or other sources with more context. Use the Closing #issue syntax for issues that are resolved with this PR. - Closes #https://github.com/zitadel/zitadel/issues/9936 --------- Co-authored-by: adlerhurst <27845747+adlerhurst@users.noreply.github.com>
84 lines
2.0 KiB
Go
84 lines
2.0 KiB
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// Pool is a connection pool. e.g. pgxpool
|
|
type Pool interface {
|
|
Beginner
|
|
QueryExecutor
|
|
Migrator
|
|
|
|
Acquire(ctx context.Context) (Client, error)
|
|
Close(ctx context.Context) error
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
// Client is a single database connection which can be released back to the pool.
|
|
type Client interface {
|
|
Beginner
|
|
QueryExecutor
|
|
Migrator
|
|
|
|
Release(ctx context.Context) error
|
|
}
|
|
|
|
// Querier is a database client that can execute queries and return rows.
|
|
type Querier interface {
|
|
Query(ctx context.Context, stmt string, args ...any) (Rows, error)
|
|
QueryRow(ctx context.Context, stmt string, args ...any) Row
|
|
}
|
|
|
|
// Executor is a database client that can execute statements.
|
|
// It returns the number of rows affected or an error
|
|
type Executor interface {
|
|
Exec(ctx context.Context, stmt string, args ...any) (int64, error)
|
|
}
|
|
|
|
// QueryExecutor is a database client that can execute queries and statements.
|
|
type QueryExecutor interface {
|
|
Querier
|
|
Executor
|
|
}
|
|
|
|
// Scanner scans a single row of data into the destination.
|
|
type Scanner interface {
|
|
Scan(dest ...any) error
|
|
}
|
|
|
|
// Row is an abstraction of sql.Row.
|
|
type Row interface {
|
|
Scanner
|
|
}
|
|
|
|
// Rows is an abstraction of sql.Rows.
|
|
type Rows interface {
|
|
Scanner
|
|
Next() bool
|
|
Close() error
|
|
Err() error
|
|
}
|
|
|
|
type CollectableRows interface {
|
|
// Collect collects all rows and scans them into dest.
|
|
// dest must be a pointer to a slice of pointer to structs
|
|
// e.g. *[]*MyStruct
|
|
// Rows are closed after this call.
|
|
Collect(dest any) error
|
|
// CollectFirst collects the first row and scans it into dest.
|
|
// dest must be a pointer to a struct
|
|
// e.g. *MyStruct{}
|
|
// Rows are closed after this call.
|
|
CollectFirst(dest any) error
|
|
// CollectExactlyOneRow collects exactly one row and scans it into dest.
|
|
// e.g. *MyStruct{}
|
|
// Rows are closed after this call.
|
|
CollectExactlyOneRow(dest any) error
|
|
}
|