Files
zitadel/backend/v3/domain/organization_metadata.go
T
SilvanandGitHub 6686c3b16b feat(relational): org metadata (#10761)
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
2025-10-14 10:15:16 +01:00

46 lines
1.8 KiB
Go

package domain
import (
"context"
"github.com/zitadel/zitadel/backend/v3/storage/database"
)
type OrganizationMetadata struct {
Metadata
OrganizationID string `json:"orgId,omitempty" db:"organization_id"`
}
type organizationMetadataColumns interface {
MetadataColumns
// OrganizationIDColumn returns the column for the org id field.
OrganizationIDColumn() database.Column
}
type organizationMetadataConditions interface {
MetadataConditions
// PrimaryKeyCondition returns the condition for the primary key fields.
PrimaryKeyCondition(instanceID, orgID, key string) database.Condition
// OrganizationIDCondition returns a filter on the org id field.
OrganizationIDCondition(orgID string) database.Condition
}
type OrganizationMetadataRepository interface {
organizationMetadataColumns
organizationMetadataConditions
// Get returns one metadata based on the criteria.
// If none is found, it returns an error of type [database.ErrNotFound].
// If multiple were found, it returns an error of type [database.ErrMultipleRows].
Get(ctx context.Context, client database.QueryExecutor, opts ...database.QueryOption) (*OrganizationMetadata, error)
// List returns a list of metadata based on the criteria.
// If none are found, it returns an empty slice.
List(ctx context.Context, client database.QueryExecutor, opts ...database.QueryOption) ([]*OrganizationMetadata, error)
// Set sets the given metadata for the organization.
// If a metadata with the same key already exists, it will be overwritten, otherwise created.
Set(ctx context.Context, client database.QueryExecutor, metadata ...*OrganizationMetadata) error
// Remove removes a metadata from the organization.
Remove(ctx context.Context, client database.QueryExecutor, condition database.Condition) (int64, error)
}