mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 13:19:21 +00:00
feat(db): Adding identity_providers table for relational database
This commit is contained in:
@@ -84,7 +84,7 @@ type InstanceRepository interface {
|
|||||||
// Member() MemberRepository
|
// Member() MemberRepository
|
||||||
|
|
||||||
Get(ctx context.Context, id string) (*Instance, error)
|
Get(ctx context.Context, id string) (*Instance, error)
|
||||||
List(ctx context.Context, opts ...database.Condition) ([]*Instance, error)
|
List(ctx context.Context, conditions ...database.Condition) ([]*Instance, error)
|
||||||
|
|
||||||
Create(ctx context.Context, instance *Instance) error
|
Create(ctx context.Context, instance *Instance) error
|
||||||
Update(ctx context.Context, id string, changes ...database.Change) (int64, error)
|
Update(ctx context.Context, id string, changes ...database.Change) (int64, error)
|
||||||
|
@@ -37,7 +37,7 @@ type organizationColumns interface {
|
|||||||
IDColumn() database.Column
|
IDColumn() database.Column
|
||||||
// NameColumn returns the column for the name field.
|
// NameColumn returns the column for the name field.
|
||||||
NameColumn() database.Column
|
NameColumn() database.Column
|
||||||
// InstanceIDColumn returns the column for the default org id field
|
// InstanceIDColumn returns the column for the instance id field
|
||||||
InstanceIDColumn() database.Column
|
InstanceIDColumn() database.Column
|
||||||
// StateColumn returns the column for the name field.
|
// StateColumn returns the column for the name field.
|
||||||
StateColumn() database.Column
|
StateColumn() database.Column
|
||||||
|
@@ -30,7 +30,6 @@ CREATE TABLE identity_providers (
|
|||||||
|
|
||||||
, created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
, created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
, updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
, updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
, deleted_at TIMESTAMPTZ
|
|
||||||
|
|
||||||
, PRIMARY KEY (instance_id, id)
|
, PRIMARY KEY (instance_id, id)
|
||||||
, CONSTRAINT identity_providers_unique UNIQUE NULLS NOT DISTINCT (instance_id, org_id, id)
|
, CONSTRAINT identity_providers_unique UNIQUE NULLS NOT DISTINCT (instance_id, org_id, id)
|
||||||
|
@@ -172,28 +172,19 @@ func (instance) UpdatedAtColumn() database.Column {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func scanInstance(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (*domain.Instance, error) {
|
func scanInstance(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (*domain.Instance, error) {
|
||||||
rows, err := querier.Query(ctx, builder.String(), builder.Args()...)
|
instance := &domain.Instance{}
|
||||||
|
err := scan(ctx, querier, builder, instance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
instance := new(domain.Instance)
|
|
||||||
if err := rows.(database.CollectableRows).CollectExactlyOneRow(instance); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance, nil
|
return instance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func scanInstances(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (instances []*domain.Instance, err error) {
|
func scanInstances(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) ([]*domain.Instance, error) {
|
||||||
rows, err := querier.Query(ctx, builder.String(), builder.Args()...)
|
instances := []*domain.Instance{}
|
||||||
|
err := scanMultiple(ctx, querier, builder, &instances)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := rows.(database.CollectableRows).Collect(&instances); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return instances, nil
|
return instances, nil
|
||||||
}
|
}
|
||||||
|
@@ -217,27 +217,18 @@ func (org) UpdatedAtColumn() database.Column {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func scanOrganization(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (*domain.Organization, error) {
|
func scanOrganization(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (*domain.Organization, error) {
|
||||||
rows, err := querier.Query(ctx, builder.String(), builder.Args()...)
|
organization := &domain.Organization{}
|
||||||
|
err := scan(ctx, querier, builder, organization)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
organization := &domain.Organization{}
|
|
||||||
if err := rows.(database.CollectableRows).CollectExactlyOneRow(organization); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return organization, nil
|
return organization, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func scanOrganizations(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) ([]*domain.Organization, error) {
|
func scanOrganizations(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) ([]*domain.Organization, error) {
|
||||||
rows, err := querier.Query(ctx, builder.String(), builder.Args()...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
organizations := []*domain.Organization{}
|
organizations := []*domain.Organization{}
|
||||||
if err := rows.(database.CollectableRows).Collect(&organizations); err != nil {
|
err := scanMultiple(ctx, querier, builder, &organizations)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return organizations, nil
|
return organizations, nil
|
||||||
|
@@ -1,6 +1,9 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,3 +21,36 @@ func writeCondition(
|
|||||||
builder.WriteString(" WHERE ")
|
builder.WriteString(" WHERE ")
|
||||||
condition.Write(builder)
|
condition.Write(builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func scan(ctx context.Context, querier database.Querier, builder *database.StatementBuilder, res any) error {
|
||||||
|
rows, err := querier.Query(ctx, builder.String(), builder.Args()...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rows.(database.CollectableRows).CollectExactlyOneRow(res); err != nil {
|
||||||
|
if err.Error() == "no rows in result set" {
|
||||||
|
return ErrResourceDoesNotExist
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func scanMultiple(ctx context.Context, querier database.Querier, builder *database.StatementBuilder, res any) error {
|
||||||
|
rows, err := querier.Query(ctx, builder.String(), builder.Args()...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rows.(database.CollectableRows).Collect(res); err != nil {
|
||||||
|
// if no results returned, this is not a error
|
||||||
|
// it just means the organization was not found
|
||||||
|
// the caller should check if the returned organization is nil
|
||||||
|
if err.Error() == "no rows in result set" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user