2025-04-29 06:03:47 +02:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
2025-05-08 07:42:53 +02:00
|
|
|
|
2025-05-08 15:30:06 +02:00
|
|
|
"github.com/zitadel/zitadel/backend/v3/storage/cache"
|
2025-05-08 07:42:53 +02:00
|
|
|
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
2025-04-29 06:03:47 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Instance struct {
|
2025-06-17 09:46:01 +02:00
|
|
|
ID string `json:"id,omitempty" db:"id"`
|
|
|
|
Name string `json:"name,omitempty" db:"name"`
|
|
|
|
DefaultOrgID string `json:"defaultOrgId,omitempty" db:"default_org_id"`
|
|
|
|
IAMProjectID string `json:"iamProjectId,omitempty" db:"iam_project_id"`
|
|
|
|
ConsoleClientID string `json:"consoleClientId,omitempty" db:"console_client_id"`
|
|
|
|
ConsoleAppID string `json:"consoleAppId,omitempty" db:"console_app_id"`
|
|
|
|
DefaultLanguage string `json:"defaultLanguage,omitempty" db:"default_language"`
|
|
|
|
CreatedAt time.Time `json:"createdAt" db:"created_at"`
|
|
|
|
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
|
|
|
|
DeletedAt *time.Time `json:"deletedAt" db:"deleted_at"`
|
2025-04-29 06:03:47 +02:00
|
|
|
}
|
|
|
|
|
2025-05-08 15:30:06 +02:00
|
|
|
type instanceCacheIndex uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
instanceCacheIndexUndefined instanceCacheIndex = iota
|
|
|
|
instanceCacheIndexID
|
|
|
|
)
|
|
|
|
|
2025-04-29 06:03:47 +02:00
|
|
|
// Keys implements the [cache.Entry].
|
2025-05-08 15:30:06 +02:00
|
|
|
func (i *Instance) Keys(index instanceCacheIndex) (key []string) {
|
|
|
|
if index == instanceCacheIndexID {
|
|
|
|
return []string{i.ID}
|
|
|
|
}
|
|
|
|
return nil
|
2025-04-29 06:03:47 +02:00
|
|
|
}
|
|
|
|
|
2025-05-08 15:30:06 +02:00
|
|
|
var _ cache.Entry[instanceCacheIndex, string] = (*Instance)(nil)
|
|
|
|
|
2025-05-08 19:01:55 +02:00
|
|
|
// instanceColumns define all the columns of the instance table.
|
2025-05-08 07:42:53 +02:00
|
|
|
type instanceColumns interface {
|
|
|
|
// IDColumn returns the column for the id field.
|
|
|
|
IDColumn() database.Column
|
|
|
|
// NameColumn returns the column for the name field.
|
|
|
|
NameColumn() database.Column
|
2025-06-17 09:46:01 +02:00
|
|
|
// DefaultOrgIDColumn returns the column for the default org id field
|
|
|
|
DefaultOrgIDColumn() database.Column
|
|
|
|
// IAMProjectIDColumn returns the column for the default IAM org id field
|
|
|
|
IAMProjectIDColumn() database.Column
|
|
|
|
// ConsoleClientIDColumn returns the column for the default IAM org id field
|
|
|
|
ConsoleClientIDColumn() database.Column
|
|
|
|
// ConsoleAppIDColumn returns the column for the console client id field
|
|
|
|
ConsoleAppIDColumn() database.Column
|
|
|
|
// DefaultLanguageColumn returns the column for the default language field
|
|
|
|
DefaultLanguageColumn() database.Column
|
2025-05-08 07:42:53 +02:00
|
|
|
// CreatedAtColumn returns the column for the created at field.
|
|
|
|
CreatedAtColumn() database.Column
|
|
|
|
// UpdatedAtColumn returns the column for the updated at field.
|
|
|
|
UpdatedAtColumn() database.Column
|
|
|
|
// DeletedAtColumn returns the column for the deleted at field.
|
|
|
|
DeletedAtColumn() database.Column
|
|
|
|
}
|
|
|
|
|
2025-05-08 19:01:55 +02:00
|
|
|
// instanceConditions define all the conditions for the instance table.
|
2025-05-08 07:42:53 +02:00
|
|
|
type instanceConditions interface {
|
|
|
|
// IDCondition returns an equal filter on the id field.
|
|
|
|
IDCondition(instanceID string) database.Condition
|
|
|
|
// NameCondition returns a filter on the name field.
|
|
|
|
NameCondition(op database.TextOperation, name string) database.Condition
|
|
|
|
}
|
|
|
|
|
2025-05-08 19:01:55 +02:00
|
|
|
// instanceChanges define all the changes for the instance table.
|
2025-05-08 07:42:53 +02:00
|
|
|
type instanceChanges interface {
|
|
|
|
// SetName sets the name column.
|
|
|
|
SetName(name string) database.Change
|
2025-04-29 06:03:47 +02:00
|
|
|
}
|
|
|
|
|
2025-05-08 19:01:55 +02:00
|
|
|
// InstanceRepository is the interface for the instance repository.
|
2025-05-08 07:42:53 +02:00
|
|
|
type InstanceRepository interface {
|
|
|
|
instanceColumns
|
|
|
|
instanceConditions
|
|
|
|
instanceChanges
|
|
|
|
|
2025-06-17 09:46:01 +02:00
|
|
|
// TODO
|
2025-05-08 19:01:55 +02:00
|
|
|
// Member returns the member repository which is a sub repository of the instance repository.
|
2025-06-17 09:46:01 +02:00
|
|
|
// Member() MemberRepository
|
2025-05-08 07:42:53 +02:00
|
|
|
|
2025-06-17 09:46:01 +02:00
|
|
|
Get(ctx context.Context, opts ...database.Condition) (*Instance, error)
|
|
|
|
List(ctx context.Context, opts ...database.Condition) ([]*Instance, error)
|
2025-05-08 07:42:53 +02:00
|
|
|
|
|
|
|
Create(ctx context.Context, instance *Instance) error
|
2025-06-17 09:46:01 +02:00
|
|
|
Update(ctx context.Context, condition database.Condition, changes ...database.Change) (int64, error)
|
2025-05-08 07:42:53 +02:00
|
|
|
Delete(ctx context.Context, condition database.Condition) error
|
2025-04-29 06:03:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type CreateInstance struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
}
|