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:
Livio Amstutz
2022-03-23 09:02:39 +01:00
committed by GitHub
parent 9e13b70a3d
commit 56b916a2b0
400 changed files with 6508 additions and 8890 deletions

View File

@@ -4,13 +4,14 @@ import (
"testing"
"time"
"github.com/lib/pq"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/eventstore/handler"
"github.com/caos/zitadel/internal/eventstore/repository"
"github.com/caos/zitadel/internal/repository/project"
"github.com/lib/pq"
)
func TestAppProjection_reduces(t *testing.T) {
@@ -44,7 +45,7 @@ func TestAppProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "INSERT INTO zitadel.projections.apps (id, name, project_id, creation_date, change_date, resource_owner, state, sequence) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
expectedStmt: "INSERT INTO projections.apps (id, name, project_id, creation_date, change_date, resource_owner, instance_id, state, sequence) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
expectedArgs: []interface{}{
"app-id",
"my-app",
@@ -52,6 +53,7 @@ func TestAppProjection_reduces(t *testing.T) {
anyArg{},
anyArg{},
"ro-id",
"instance-id",
domain.AppStateActive,
uint64(15),
},
@@ -81,7 +83,7 @@ func TestAppProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE zitadel.projections.apps SET (name, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
expectedStmt: "UPDATE projections.apps SET (name, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
expectedArgs: []interface{}{
"my-app",
anyArg{},
@@ -113,7 +115,7 @@ func TestAppProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE zitadel.projections.apps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
expectedStmt: "UPDATE projections.apps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
expectedArgs: []interface{}{
domain.AppStateInactive,
anyArg{},
@@ -145,7 +147,7 @@ func TestAppProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE zitadel.projections.apps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
expectedStmt: "UPDATE projections.apps SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4)",
expectedArgs: []interface{}{
domain.AppStateActive,
anyArg{},
@@ -177,7 +179,7 @@ func TestAppProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM zitadel.projections.apps WHERE (id = $1)",
expectedStmt: "DELETE FROM projections.apps WHERE (id = $1)",
expectedArgs: []interface{}{
"app-id",
},
@@ -204,7 +206,7 @@ func TestAppProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM zitadel.projections.apps WHERE (project_id = $1)",
expectedStmt: "DELETE FROM projections.apps WHERE (project_id = $1)",
expectedArgs: []interface{}{
"agg-id",
},
@@ -236,7 +238,7 @@ func TestAppProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "INSERT INTO zitadel.projections.apps_api_configs (app_id, client_id, client_secret, auth_method) VALUES ($1, $2, $3, $4)",
expectedStmt: "INSERT INTO projections.apps_api_configs (app_id, client_id, client_secret, auth_method) VALUES ($1, $2, $3, $4)",
expectedArgs: []interface{}{
"app-id",
"client-id",
@@ -245,7 +247,7 @@ func TestAppProjection_reduces(t *testing.T) {
},
},
{
expectedStmt: "UPDATE zitadel.projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
expectedStmt: "UPDATE projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -279,7 +281,7 @@ func TestAppProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE zitadel.projections.apps_api_configs SET (client_secret, auth_method) = ($1, $2) WHERE (app_id = $3)",
expectedStmt: "UPDATE projections.apps_api_configs SET (client_secret, auth_method) = ($1, $2) WHERE (app_id = $3)",
expectedArgs: []interface{}{
anyArg{},
domain.APIAuthMethodTypePrivateKeyJWT,
@@ -287,7 +289,7 @@ func TestAppProjection_reduces(t *testing.T) {
},
},
{
expectedStmt: "UPDATE zitadel.projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
expectedStmt: "UPDATE projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -341,14 +343,14 @@ func TestAppProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE zitadel.projections.apps_api_configs SET (client_secret) = ($1) WHERE (app_id = $2)",
expectedStmt: "UPDATE projections.apps_api_configs SET (client_secret) = ($1) WHERE (app_id = $2)",
expectedArgs: []interface{}{
anyArg{},
"app-id",
},
},
{
expectedStmt: "UPDATE zitadel.projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
expectedStmt: "UPDATE projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -395,7 +397,7 @@ func TestAppProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "INSERT INTO zitadel.projections.apps_oidc_configs (app_id, version, client_id, client_secret, redirect_uris, response_types, grant_types, application_type, auth_method_type, post_logout_redirect_uris, is_dev_mode, access_token_type, access_token_role_assertion, id_token_role_assertion, id_token_userinfo_assertion, clock_skew, additional_origins) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)",
expectedStmt: "INSERT INTO projections.apps_oidc_configs (app_id, version, client_id, client_secret, redirect_uris, response_types, grant_types, application_type, auth_method_type, post_logout_redirect_uris, is_dev_mode, access_token_type, access_token_role_assertion, id_token_role_assertion, id_token_userinfo_assertion, clock_skew, additional_origins) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)",
expectedArgs: []interface{}{
"app-id",
domain.OIDCVersionV1,
@@ -417,7 +419,7 @@ func TestAppProjection_reduces(t *testing.T) {
},
},
{
expectedStmt: "UPDATE zitadel.projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
expectedStmt: "UPDATE projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -462,7 +464,7 @@ func TestAppProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE zitadel.projections.apps_oidc_configs SET (version, redirect_uris, response_types, grant_types, application_type, auth_method_type, post_logout_redirect_uris, is_dev_mode, access_token_type, access_token_role_assertion, id_token_role_assertion, id_token_userinfo_assertion, clock_skew, additional_origins) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) WHERE (app_id = $15)",
expectedStmt: "UPDATE projections.apps_oidc_configs SET (version, redirect_uris, response_types, grant_types, application_type, auth_method_type, post_logout_redirect_uris, is_dev_mode, access_token_type, access_token_role_assertion, id_token_role_assertion, id_token_userinfo_assertion, clock_skew, additional_origins) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) WHERE (app_id = $15)",
expectedArgs: []interface{}{
domain.OIDCVersionV1,
pq.StringArray{"redirect.one.ch", "redirect.two.ch"},
@@ -482,7 +484,7 @@ func TestAppProjection_reduces(t *testing.T) {
},
},
{
expectedStmt: "UPDATE zitadel.projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
expectedStmt: "UPDATE projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -536,14 +538,14 @@ func TestAppProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE zitadel.projections.apps_oidc_configs SET (client_secret) = ($1) WHERE (app_id = $2)",
expectedStmt: "UPDATE projections.apps_oidc_configs SET (client_secret) = ($1) WHERE (app_id = $2)",
expectedArgs: []interface{}{
anyArg{},
"app-id",
},
},
{
expectedStmt: "UPDATE zitadel.projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
expectedStmt: "UPDATE projections.apps SET (change_date, sequence) = ($1, $2) WHERE (id = $3)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),