mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 00:17:32 +00:00
feat: projections auto create their tables (#3324)
* begin init checks for projections * first projection checks * debug notification providers with query fixes * more projections and first index * more projections * more projections * finish projections * fix tests (remove db name) * create tables in setup * fix logging / error handling * add tenant to views * rename tenant to instance_id * add instance_id to all projections * add instance_id to all queries * correct instance_id on projections * add instance_id to failed_events * use separate context for instance * implement features projection * implement features projection * remove unique constraint from setup when migration failed * add error to failed setup event * add instance_id to primary keys * fix IAM projection * remove old migrations folder * fix keysFromYAML test
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
@@ -32,6 +34,10 @@ var (
|
||||
name: projection.OrgColumnResourceOwner,
|
||||
table: orgsTable,
|
||||
}
|
||||
OrgColumnInstanceID = Column{
|
||||
name: projection.OrgColumnInstanceID,
|
||||
table: orgsTable,
|
||||
}
|
||||
OrgColumnState = Column{
|
||||
name: projection.OrgColumnState,
|
||||
table: orgsTable,
|
||||
@@ -83,7 +89,8 @@ func (q *OrgSearchQueries) toQuery(query sq.SelectBuilder) sq.SelectBuilder {
|
||||
func (q *Queries) OrgByID(ctx context.Context, id string) (*Org, error) {
|
||||
stmt, scan := prepareOrgQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
OrgColumnID.identifier(): id,
|
||||
OrgColumnID.identifier(): id,
|
||||
OrgColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-AWx52", "Errors.Query.SQLStatement")
|
||||
@@ -96,7 +103,8 @@ func (q *Queries) OrgByID(ctx context.Context, id string) (*Org, error) {
|
||||
func (q *Queries) OrgByDomainGlobal(ctx context.Context, domain string) (*Org, error) {
|
||||
stmt, scan := prepareOrgQuery()
|
||||
query, args, err := stmt.Where(sq.Eq{
|
||||
OrgColumnDomain.identifier(): domain,
|
||||
OrgColumnDomain.identifier(): domain,
|
||||
OrgColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-TYUCE", "Errors.Query.SQLStatement")
|
||||
@@ -109,12 +117,17 @@ func (q *Queries) OrgByDomainGlobal(ctx context.Context, domain string) (*Org, e
|
||||
func (q *Queries) IsOrgUnique(ctx context.Context, name, domain string) (isUnique bool, err error) {
|
||||
query, scan := prepareOrgUniqueQuery()
|
||||
stmt, args, err := query.Where(
|
||||
sq.Or{
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
OrgColumnDomain.identifier(): domain,
|
||||
OrgColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
},
|
||||
sq.Eq{
|
||||
OrgColumnName.identifier(): name,
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
OrgColumnDomain.identifier(): domain,
|
||||
},
|
||||
sq.Eq{
|
||||
OrgColumnName.identifier(): name,
|
||||
},
|
||||
},
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
@@ -132,7 +145,10 @@ func (q *Queries) ExistsOrg(ctx context.Context, id string) (err error) {
|
||||
|
||||
func (q *Queries) SearchOrgs(ctx context.Context, queries *OrgSearchQueries) (orgs *Orgs, err error) {
|
||||
query, scan := prepareOrgsQuery()
|
||||
stmt, args, err := queries.toQuery(query).ToSql()
|
||||
stmt, args, err := queries.toQuery(query).
|
||||
Where(sq.Eq{
|
||||
OrgColumnInstanceID.identifier(): authz.GetInstance(ctx).ID,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "QUERY-wQ3by", "Errors.Query.InvalidRequest")
|
||||
}
|
||||
|
Reference in New Issue
Block a user