mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 05:52:51 +00:00
This pull request introduces a new feature that allows adding, updating, and querying metadata for organizations. The changes are primarily in the backend and include new database tables, repositories, and domain logic to support organization metadata. ## Changes * New `org_metadata` table: A new table `zitadel.org_metadata` is introduced to store metadata for organizations. It includes columns for `instance_id`, `org_id`, `key`, and `value`. The `value` is stored as a `BYTEA` type to allow for flexible data storage. * New `OrganizationMetadataRepository`: A new repository `OrganizationMetadataRepository` is created to handle all database operations for organization metadata. It provides methods to `Get`, `List`, `Set`, and `Remove` metadata. * New `org_metadata_relational_projection`: A new projection `org_metadata_relational_projection` is added to update the `zitadel.org_metadata` table based on events. It handles `MetadataSet`, `MetadataRemoved`, and `MetadataRemovedAll` events. * Updated `OrganizationRepository`: The `OrganizationRepository` is updated to support loading organization metadata. A new method `LoadMetadata` is added to enable joining the `org_metadata` table when querying for organizations. * Updated Organization domain: The Organization domain model is updated to include a new field `Metadata` of type `[]*OrganizationMetadata`. ## Additional Info * Extensible Design: The new metadata feature is designed to be extensible, allowing for future enhancements such as indexing on specific JSON fields within the `value` column. * closes https://github.com/zitadel/zitadel/issues/10206 * closes https://github.com/zitadel/zitadel/issues/10214
43 lines
1.5 KiB
Go
43 lines
1.5 KiB
Go
package domain
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
|
)
|
|
|
|
type Metadata struct {
|
|
InstanceID string `json:"instanceId,omitempty" db:"instance_id"`
|
|
Key string `json:"key,omitempty" db:"key"`
|
|
// Value is a byte slice that might be json encoded.
|
|
// the API does not require json encoding so we keep it as a byte slice here.
|
|
Value []byte `json:"value,omitempty" db:"value"`
|
|
|
|
CreatedAt time.Time `json:"createdAt,omitzero" db:"created_at"`
|
|
UpdatedAt time.Time `json:"updatedAt,omitzero" db:"updated_at"`
|
|
}
|
|
|
|
type MetadataColumns interface {
|
|
// PrimaryKeyColumns returns the columns for the primary key.
|
|
PrimaryKeyColumns() []database.Column
|
|
// InstanceIDColumn returns the column for the instance id field.
|
|
InstanceIDColumn() database.Column
|
|
// KeyColumn returns the column for the key field.
|
|
KeyColumn() database.Column
|
|
// ValueColumn returns the column for the value field.
|
|
ValueColumn() database.Column
|
|
// CreatedAtColumn returns the column for the created at field.
|
|
CreatedAtColumn() database.Column
|
|
// UpdatedAtColumn returns the column for the updated at field.
|
|
UpdatedAtColumn() database.Column
|
|
}
|
|
|
|
type MetadataConditions interface {
|
|
// InstanceIDCondition returns a filter on the instance id field.
|
|
InstanceIDCondition(instanceID string) database.Condition
|
|
// KeyCondition returns a filter on the key field.
|
|
KeyCondition(op database.TextOperation, key string) database.Condition
|
|
// ValueCondition returns a filter on the value field.
|
|
ValueCondition(op database.BytesOperation, value []byte) database.Condition
|
|
}
|