mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 15:49:35 +00:00
sql
This commit is contained in:
@@ -2,6 +2,7 @@ package domain
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
||||
)
|
||||
@@ -23,6 +24,13 @@ type AddInstanceDomain struct {
|
||||
IsVerified bool `json:"isVerified,omitempty" db:"is_verified"`
|
||||
IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"`
|
||||
VerificationType DomainVerificationType `json:"verificationType,omitempty" db:"verification_type"`
|
||||
|
||||
// CreatedAt is the time when the domain was added.
|
||||
// It is set by the repository and should not be set by the caller.
|
||||
CreatedAt time.Time `json:"createdAt,omitzero" db:"created_at"`
|
||||
// UpdatedAt is the time when the domain was last updated.
|
||||
// It is set by the repository and should not be set by the caller.
|
||||
UpdatedAt time.Time `json:"updatedAt,omitzero" db:"updated_at"`
|
||||
}
|
||||
|
||||
type instanceDomainColumns interface {
|
||||
@@ -47,7 +55,7 @@ type InstanceDomainRepository interface {
|
||||
// Add adds a new domain to the instance.
|
||||
Add(ctx context.Context, domain *AddInstanceDomain) error
|
||||
// Update updates an existing domain in the instance.
|
||||
Update(ctx context.Context, condition database.Condition, changes ...database.Change) error
|
||||
Update(ctx context.Context, condition database.Condition, changes ...database.Change) (int64, error)
|
||||
// Remove removes a domain from the instance.
|
||||
Remove(ctx context.Context, condition database.Condition) error
|
||||
Remove(ctx context.Context, condition database.Condition) (int64, error)
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package domain
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
||||
)
|
||||
@@ -25,6 +26,13 @@ type AddOrganizationDomain struct {
|
||||
IsVerified bool `json:"isVerified,omitempty" db:"is_verified"`
|
||||
IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"`
|
||||
VerificationType DomainVerificationType `json:"verificationType,omitempty" db:"verification_type"`
|
||||
|
||||
// CreatedAt is the time when the domain was added.
|
||||
// It is set by the repository and should not be set by the caller.
|
||||
CreatedAt time.Time `json:"createdAt,omitzero" db:"created_at"`
|
||||
// UpdatedAt is the time when the domain was added.
|
||||
// It is set by the repository and should not be set by the caller.
|
||||
UpdatedAt time.Time `json:"updatedAt,omitzero" db:"updated_at"`
|
||||
}
|
||||
|
||||
type organizationDomainColumns interface {
|
||||
@@ -51,7 +59,7 @@ type OrganizationDomainRepository interface {
|
||||
// Add adds a new domain to the organization.
|
||||
Add(ctx context.Context, domain *AddOrganizationDomain) error
|
||||
// Update updates an existing domain in the organization.
|
||||
Update(ctx context.Context, condition database.Condition, changes ...database.Change) error
|
||||
Update(ctx context.Context, condition database.Condition, changes ...database.Change) (int64, error)
|
||||
// Remove removes a domain from the organization.
|
||||
Remove(ctx context.Context, condition database.Condition) error
|
||||
Remove(ctx context.Context, condition database.Condition) (int64, error)
|
||||
}
|
||||
|
@@ -20,18 +20,38 @@ type instanceDomain struct {
|
||||
|
||||
// Add implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) Add(ctx context.Context, domain *domain.AddInstanceDomain) error {
|
||||
panic("unimplemented")
|
||||
var builder database.StatementBuilder
|
||||
|
||||
builder.WriteString(`INSERT INTO zitadel.instance_domains (instance_id, domain, is_verified, is_primary, verification_type) ` +
|
||||
`VALUES ($1, $2, $3, $4, $5)` +
|
||||
` RETURNING created_at, updated_at`)
|
||||
|
||||
builder.AppendArgs(domain.InstanceID, domain.Domain, domain.IsVerified, domain.IsPrimary, domain.VerificationType)
|
||||
|
||||
return i.client.QueryRow(ctx, builder.String(), builder.Args()...).Scan(&domain.CreatedAt, &domain.UpdatedAt)
|
||||
}
|
||||
|
||||
// Remove implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) Remove(ctx context.Context, condition database.Condition) error {
|
||||
panic("unimplemented")
|
||||
func (i *instanceDomain) Remove(ctx context.Context, condition database.Condition) (int64, error) {
|
||||
var builder database.StatementBuilder
|
||||
|
||||
builder.WriteString(`DELETE FROM zitadel.instance_domains WHERE `)
|
||||
writeCondition(&builder, condition)
|
||||
|
||||
return i.client.Exec(ctx, builder.String(), builder.Args()...)
|
||||
}
|
||||
|
||||
// Update implements [domain.InstanceDomainRepository].
|
||||
// Subtle: this method shadows the method (instance).Update of instanceDomain.instance.
|
||||
func (i *instanceDomain) Update(ctx context.Context, condition database.Condition, changes ...database.Change) error {
|
||||
panic("unimplemented")
|
||||
func (i *instanceDomain) Update(ctx context.Context, condition database.Condition, changes ...database.Change) (int64, error) {
|
||||
var builder database.StatementBuilder
|
||||
|
||||
builder.WriteString(`UPDATE zitadel.instance_domains SET `)
|
||||
database.Changes(changes).Write(&builder)
|
||||
|
||||
writeCondition(&builder, condition)
|
||||
|
||||
return i.client.Exec(ctx, builder.String(), builder.Args()...)
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
@@ -39,18 +59,18 @@ func (i *instanceDomain) Update(ctx context.Context, condition database.Conditio
|
||||
// -------------------------------------------------------------
|
||||
|
||||
// SetVerificationType implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) SetVerificationType(verificationType domain.DomainVerificationType) database.Change {
|
||||
panic("unimplemented")
|
||||
func (i instanceDomain) SetVerificationType(verificationType domain.DomainVerificationType) database.Change {
|
||||
return database.NewChange(i.VerificationTypeColumn(), verificationType)
|
||||
}
|
||||
|
||||
// SetPrimary implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) SetPrimary() database.Change {
|
||||
panic("unimplemented")
|
||||
func (i instanceDomain) SetPrimary() database.Change {
|
||||
return database.NewChange(i.IsPrimaryColumn(), true)
|
||||
}
|
||||
|
||||
// SetVerified implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) SetVerified() database.Change {
|
||||
panic("unimplemented")
|
||||
func (i instanceDomain) SetVerified() database.Change {
|
||||
return database.NewChange(i.IsVerifiedColumn(), true)
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
@@ -58,23 +78,23 @@ func (i *instanceDomain) SetVerified() database.Change {
|
||||
// -------------------------------------------------------------
|
||||
|
||||
// DomainCondition implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) DomainCondition(op database.TextOperation, domain string) database.Condition {
|
||||
panic("unimplemented")
|
||||
func (i instanceDomain) DomainCondition(op database.TextOperation, domain string) database.Condition {
|
||||
return database.NewTextCondition(i.DomainColumn(), op, domain)
|
||||
}
|
||||
|
||||
// InstanceIDCondition implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) InstanceIDCondition(instanceID string) database.Condition {
|
||||
panic("unimplemented")
|
||||
func (i instanceDomain) InstanceIDCondition(instanceID string) database.Condition {
|
||||
return database.NewTextCondition(i.InstanceIDColumn(), database.TextOperationEqual, instanceID)
|
||||
}
|
||||
|
||||
// IsPrimaryCondition implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) IsPrimaryCondition(isPrimary bool) database.Condition {
|
||||
panic("unimplemented")
|
||||
func (i instanceDomain) IsPrimaryCondition(isPrimary bool) database.Condition {
|
||||
return database.NewBooleanCondition(i.IsPrimaryColumn(), isPrimary)
|
||||
}
|
||||
|
||||
// IsVerifiedCondition implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) IsVerifiedCondition(isVerified bool) database.Condition {
|
||||
panic("unimplemented")
|
||||
func (i instanceDomain) IsVerifiedCondition(isVerified bool) database.Condition {
|
||||
return database.NewBooleanCondition(i.IsVerifiedColumn(), isVerified)
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
@@ -83,43 +103,43 @@ func (i *instanceDomain) IsVerifiedCondition(isVerified bool) database.Condition
|
||||
|
||||
// CreatedAtColumn implements [domain.InstanceDomainRepository].
|
||||
// Subtle: this method shadows the method (instance).CreatedAtColumn of instanceDomain.instance.
|
||||
func (i *instanceDomain) CreatedAtColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (instanceDomain) CreatedAtColumn() database.Column {
|
||||
return database.NewColumn("created_at")
|
||||
}
|
||||
|
||||
// DomainColumn implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) DomainColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (instanceDomain) DomainColumn() database.Column {
|
||||
return database.NewColumn("domain")
|
||||
}
|
||||
|
||||
// InstanceIDColumn implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) InstanceIDColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (instanceDomain) InstanceIDColumn() database.Column {
|
||||
return database.NewColumn("instance_id")
|
||||
}
|
||||
|
||||
// IsPrimaryColumn implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) IsPrimaryColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (instanceDomain) IsPrimaryColumn() database.Column {
|
||||
return database.NewColumn("is_primary")
|
||||
}
|
||||
|
||||
// IsVerifiedColumn implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) IsVerifiedColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (instanceDomain) IsVerifiedColumn() database.Column {
|
||||
return database.NewColumn("is_verified")
|
||||
}
|
||||
|
||||
// UpdatedAtColumn implements [domain.InstanceDomainRepository].
|
||||
// Subtle: this method shadows the method (instance).UpdatedAtColumn of instanceDomain.instance.
|
||||
func (i *instanceDomain) UpdatedAtColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (instanceDomain) UpdatedAtColumn() database.Column {
|
||||
return database.NewColumn("updated_at")
|
||||
}
|
||||
|
||||
// VerificationTypeColumn implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) VerificationTypeColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (instanceDomain) VerificationTypeColumn() database.Column {
|
||||
return database.NewColumn("verification_type")
|
||||
}
|
||||
|
||||
// IsGeneratedColumn implements [domain.InstanceDomainRepository].
|
||||
func (i *instanceDomain) IsGeneratedColumn() database.Column {
|
||||
func (instanceDomain) IsGeneratedColumn() database.Column {
|
||||
return database.NewColumn("is_generated")
|
||||
}
|
||||
|
||||
|
@@ -113,7 +113,7 @@ func checkCreateOrgErr(err error) error {
|
||||
}
|
||||
|
||||
// Update implements [domain.OrganizationRepository].
|
||||
func (o org) Update(ctx context.Context, id domain.OrgIdentifierCondition, instanceID string, changes ...database.Change) (int64, error) {
|
||||
func (o *org) Update(ctx context.Context, id domain.OrgIdentifierCondition, instanceID string, changes ...database.Change) (int64, error) {
|
||||
if changes == nil {
|
||||
return 0, errors.New("Update must contain a condition") // (otherwise ALL organizations will be updated)
|
||||
}
|
||||
@@ -133,7 +133,7 @@ func (o org) Update(ctx context.Context, id domain.OrgIdentifierCondition, insta
|
||||
}
|
||||
|
||||
// Delete implements [domain.OrganizationRepository].
|
||||
func (o org) Delete(ctx context.Context, id domain.OrgIdentifierCondition, instanceID string) (int64, error) {
|
||||
func (o *org) Delete(ctx context.Context, id domain.OrgIdentifierCondition, instanceID string) (int64, error) {
|
||||
builder := database.StatementBuilder{}
|
||||
|
||||
builder.WriteString(`DELETE FROM zitadel.organizations`)
|
||||
@@ -230,9 +230,6 @@ func scanOrganization(ctx context.Context, querier database.Querier, builder *da
|
||||
|
||||
organization := &domain.Organization{}
|
||||
if err := rows.(database.CollectableRows).CollectExactlyOneRow(organization); err != nil {
|
||||
if err.Error() == "no rows in result set" {
|
||||
return nil, ErrResourceDoesNotExist
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@@ -20,18 +20,38 @@ type orgDomain struct {
|
||||
|
||||
// Add implements [domain.OrganizationDomainRepository].
|
||||
func (o *orgDomain) Add(ctx context.Context, domain *domain.AddOrganizationDomain) error {
|
||||
panic("unimplemented")
|
||||
var builder database.StatementBuilder
|
||||
|
||||
builder.WriteString(`INSERT INTO zitadel.organization_domains (instance_id, org_id, domain, is_verified, is_primary, verification_type) ` +
|
||||
`VALUES ($1, $2, $3, $4, $5, $6)` +
|
||||
` RETURNING created_at, updated_at`)
|
||||
|
||||
builder.AppendArgs(domain.InstanceID, domain.OrgID, domain.Domain, domain.IsVerified, domain.IsPrimary, domain.VerificationType)
|
||||
|
||||
return o.client.QueryRow(ctx, builder.String(), builder.Args()...).Scan(&domain.CreatedAt, &domain.UpdatedAt)
|
||||
}
|
||||
|
||||
// Update implements [domain.OrganizationDomainRepository].
|
||||
// Subtle: this method shadows the method (*org).Update of orgDomain.org.
|
||||
func (o *orgDomain) Update(ctx context.Context, condition database.Condition, changes ...database.Change) error {
|
||||
panic("unimplemented")
|
||||
func (o *orgDomain) Update(ctx context.Context, condition database.Condition, changes ...database.Change) (int64, error) {
|
||||
var builder database.StatementBuilder
|
||||
|
||||
builder.WriteString(`UPDATE zitadel.organization_domains SET `)
|
||||
database.Changes(changes).Write(&builder)
|
||||
|
||||
writeCondition(&builder, condition)
|
||||
|
||||
return o.client.Exec(ctx, builder.String(), builder.Args()...)
|
||||
}
|
||||
|
||||
// Remove implements [domain.OrganizationDomainRepository].
|
||||
func (o *orgDomain) Remove(ctx context.Context, condition database.Condition) error {
|
||||
panic("unimplemented")
|
||||
func (o *orgDomain) Remove(ctx context.Context, condition database.Condition) (int64, error) {
|
||||
var builder database.StatementBuilder
|
||||
|
||||
builder.WriteString(`DELETE FROM zitadel.organization_domains `)
|
||||
writeCondition(&builder, condition)
|
||||
|
||||
return o.client.Exec(ctx, builder.String(), builder.Args()...)
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
@@ -39,18 +59,18 @@ func (o *orgDomain) Remove(ctx context.Context, condition database.Condition) er
|
||||
// -------------------------------------------------------------
|
||||
|
||||
// SetPrimary implements [domain.OrganizationDomainRepository].
|
||||
func (o *orgDomain) SetPrimary() database.Change {
|
||||
panic("unimplemented")
|
||||
func (o orgDomain) SetPrimary() database.Change {
|
||||
return database.NewChange(o.IsPrimaryColumn(), true)
|
||||
}
|
||||
|
||||
// SetVerificationType implements [domain.OrganizationDomainRepository].
|
||||
func (o *orgDomain) SetVerificationType(verificationType domain.DomainVerificationType) database.Change {
|
||||
panic("unimplemented")
|
||||
func (o orgDomain) SetVerificationType(verificationType domain.DomainVerificationType) database.Change {
|
||||
return database.NewChange(o.VerificationTypeColumn(), verificationType)
|
||||
}
|
||||
|
||||
// SetVerified implements [domain.OrganizationDomainRepository].
|
||||
func (o *orgDomain) SetVerified() database.Change {
|
||||
panic("unimplemented")
|
||||
func (o orgDomain) SetVerified() database.Change {
|
||||
return database.NewChange(o.IsVerifiedColumn(), true)
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
@@ -58,29 +78,29 @@ func (o *orgDomain) SetVerified() database.Change {
|
||||
// -------------------------------------------------------------
|
||||
|
||||
// DomainCondition implements [domain.OrganizationDomainRepository].
|
||||
func (o *orgDomain) DomainCondition(op database.TextOperation, domain string) database.Condition {
|
||||
panic("unimplemented")
|
||||
func (o orgDomain) DomainCondition(op database.TextOperation, domain string) database.Condition {
|
||||
return database.NewTextCondition(o.DomainColumn(), op, domain)
|
||||
}
|
||||
|
||||
// InstanceIDCondition implements [domain.OrganizationDomainRepository].
|
||||
// Subtle: this method shadows the method (*org).InstanceIDCondition of orgDomain.org.
|
||||
func (o *orgDomain) InstanceIDCondition(instanceID string) database.Condition {
|
||||
panic("unimplemented")
|
||||
func (o orgDomain) InstanceIDCondition(instanceID string) database.Condition {
|
||||
return database.NewTextCondition(o.InstanceIDColumn(), database.TextOperationEqual, instanceID)
|
||||
}
|
||||
|
||||
// IsPrimaryCondition implements [domain.OrganizationDomainRepository].
|
||||
func (o *orgDomain) IsPrimaryCondition(isPrimary bool) database.Condition {
|
||||
panic("unimplemented")
|
||||
func (o orgDomain) IsPrimaryCondition(isPrimary bool) database.Condition {
|
||||
return database.NewBooleanCondition(o.IsPrimaryColumn(), isPrimary)
|
||||
}
|
||||
|
||||
// IsVerifiedCondition implements [domain.OrganizationDomainRepository].
|
||||
func (o *orgDomain) IsVerifiedCondition(isVerified bool) database.Condition {
|
||||
panic("unimplemented")
|
||||
func (o orgDomain) IsVerifiedCondition(isVerified bool) database.Condition {
|
||||
return database.NewBooleanCondition(o.IsVerifiedColumn(), isVerified)
|
||||
}
|
||||
|
||||
// OrgIDCondition implements [domain.OrganizationDomainRepository].
|
||||
func (o *orgDomain) OrgIDCondition(orgID string) database.Condition {
|
||||
panic("unimplemented")
|
||||
func (o orgDomain) OrgIDCondition(orgID string) database.Condition {
|
||||
return database.NewTextCondition(o.OrgIDColumn(), database.TextOperationEqual, orgID)
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
@@ -89,45 +109,45 @@ func (o *orgDomain) OrgIDCondition(orgID string) database.Condition {
|
||||
|
||||
// CreatedAtColumn implements [domain.OrganizationDomainRepository].
|
||||
// Subtle: this method shadows the method (*org).CreatedAtColumn of orgDomain.org.
|
||||
func (o *orgDomain) CreatedAtColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (orgDomain) CreatedAtColumn() database.Column {
|
||||
return database.NewColumn("created_at")
|
||||
}
|
||||
|
||||
// DomainColumn implements [domain.OrganizationDomainRepository].
|
||||
func (o *orgDomain) DomainColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (orgDomain) DomainColumn() database.Column {
|
||||
return database.NewColumn("domain")
|
||||
}
|
||||
|
||||
// InstanceIDColumn implements [domain.OrganizationDomainRepository].
|
||||
// Subtle: this method shadows the method (*org).InstanceIDColumn of orgDomain.org.
|
||||
func (o *orgDomain) InstanceIDColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (orgDomain) InstanceIDColumn() database.Column {
|
||||
return database.NewColumn("instance_id")
|
||||
}
|
||||
|
||||
// IsPrimaryColumn implements [domain.OrganizationDomainRepository].
|
||||
func (o *orgDomain) IsPrimaryColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (orgDomain) IsPrimaryColumn() database.Column {
|
||||
return database.NewColumn("is_primary")
|
||||
}
|
||||
|
||||
// IsVerifiedColumn implements [domain.OrganizationDomainRepository].
|
||||
func (o *orgDomain) IsVerifiedColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (orgDomain) IsVerifiedColumn() database.Column {
|
||||
return database.NewColumn("is_verified")
|
||||
}
|
||||
|
||||
// OrgIDColumn implements [domain.OrganizationDomainRepository].
|
||||
func (o *orgDomain) OrgIDColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (orgDomain) OrgIDColumn() database.Column {
|
||||
return database.NewColumn("org_id")
|
||||
}
|
||||
|
||||
// UpdatedAtColumn implements [domain.OrganizationDomainRepository].
|
||||
// Subtle: this method shadows the method (*org).UpdatedAtColumn of orgDomain.org.
|
||||
func (o *orgDomain) UpdatedAtColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (orgDomain) UpdatedAtColumn() database.Column {
|
||||
return database.NewColumn("updated_at")
|
||||
}
|
||||
|
||||
// VerificationTypeColumn implements [domain.OrganizationDomainRepository].
|
||||
func (o *orgDomain) VerificationTypeColumn() database.Column {
|
||||
panic("unimplemented")
|
||||
func (orgDomain) VerificationTypeColumn() database.Column {
|
||||
return database.NewColumn("verification_type")
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user