mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-29 07:28:52 +00:00
refactor(rt): add primary key columns to repo interfaces (#10843)
# Which Problems Are Solved Relational table's primary keys are part of the SQL table definition. However, by abstraction through the repository interfaces callers (service layer) have no clear understanding of the primary key definion. This might lead to confusion during implementation: - The repository makes a sanity check on required conditions before query execution and returns an error if the condition was not met. - When a Get method is executed, an error is returned if not exactly one row is found. Get replaces the legacy GetXxxByID methods we have on projections. However, a list of flexible conditions can be passed. - Operations like UPDATE and DELETE should often only affect a single row, identified by the primary key. If the primary key conditions are missing an error is returned. Because there is no "type safety" enforced here, the errors are returned during runtime. When all possible combinations of API arguments are not properly tested such errors are actually bugs in the experience of the end-user. (The API should do it's own input validation, but a programmer's error is easily made). # How the Problems Are Solved Add `PrimaryKeyColumns` and `PrimaryKeyCondition` to existing repository intefaces. # Additional Changes - Where reducers already used repositories, the PrimaryKeyConditions are used where possible. # Additional Context - Part of https://github.com/zitadel/zitadel/wiki/Decision-Log#expose-primary-key-definition-in-repository-interfaces --------- Co-authored-by: Marco A. <[email protected]>
This commit is contained in:
@@ -27,6 +27,8 @@ type userColumns interface {
|
||||
|
||||
// userConditions define all the conditions for the user table.
|
||||
type userConditions interface {
|
||||
// PrimaryKeyCondition returns a filter on the primary key fields.
|
||||
PrimaryKeyCondition(instanceID, userID string) database.Condition
|
||||
// InstanceIDCondition returns an equal filter on the instance id field.
|
||||
InstanceIDCondition(instanceID string) database.Condition
|
||||
// OrgIDCondition returns an equal filter on the org id field.
|
||||
@@ -53,6 +55,8 @@ type userChanges interface {
|
||||
|
||||
// UserRepository is the interface for the user repository.
|
||||
type UserRepository interface {
|
||||
Repository
|
||||
|
||||
userColumns
|
||||
userConditions
|
||||
userChanges
|
||||
|
||||
Reference in New Issue
Block a user