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

@@ -28,17 +28,17 @@ func Test_UserAuthMethodPrepares(t *testing.T) {
prepare: prepareUserAuthMethodsQuery,
want: want{
sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT zitadel.projections.user_auth_methods.token_id,`+
` zitadel.projections.user_auth_methods.creation_date,`+
` zitadel.projections.user_auth_methods.change_date,`+
` zitadel.projections.user_auth_methods.resource_owner,`+
` zitadel.projections.user_auth_methods.user_id,`+
` zitadel.projections.user_auth_methods.sequence,`+
` zitadel.projections.user_auth_methods.name,`+
` zitadel.projections.user_auth_methods.state,`+
` zitadel.projections.user_auth_methods.method_type,`+
regexp.QuoteMeta(`SELECT projections.user_auth_methods.token_id,`+
` projections.user_auth_methods.creation_date,`+
` projections.user_auth_methods.change_date,`+
` projections.user_auth_methods.resource_owner,`+
` projections.user_auth_methods.user_id,`+
` projections.user_auth_methods.sequence,`+
` projections.user_auth_methods.name,`+
` projections.user_auth_methods.state,`+
` projections.user_auth_methods.method_type,`+
` COUNT(*) OVER ()`+
` FROM zitadel.projections.user_auth_methods`),
` FROM projections.user_auth_methods`),
nil,
nil,
),
@@ -50,17 +50,17 @@ func Test_UserAuthMethodPrepares(t *testing.T) {
prepare: prepareUserAuthMethodsQuery,
want: want{
sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT zitadel.projections.user_auth_methods.token_id,`+
` zitadel.projections.user_auth_methods.creation_date,`+
` zitadel.projections.user_auth_methods.change_date,`+
` zitadel.projections.user_auth_methods.resource_owner,`+
` zitadel.projections.user_auth_methods.user_id,`+
` zitadel.projections.user_auth_methods.sequence,`+
` zitadel.projections.user_auth_methods.name,`+
` zitadel.projections.user_auth_methods.state,`+
` zitadel.projections.user_auth_methods.method_type,`+
regexp.QuoteMeta(`SELECT projections.user_auth_methods.token_id,`+
` projections.user_auth_methods.creation_date,`+
` projections.user_auth_methods.change_date,`+
` projections.user_auth_methods.resource_owner,`+
` projections.user_auth_methods.user_id,`+
` projections.user_auth_methods.sequence,`+
` projections.user_auth_methods.name,`+
` projections.user_auth_methods.state,`+
` projections.user_auth_methods.method_type,`+
` COUNT(*) OVER ()`+
` FROM zitadel.projections.user_auth_methods`),
` FROM projections.user_auth_methods`),
[]string{
"token_id",
"creation_date",
@@ -112,17 +112,17 @@ func Test_UserAuthMethodPrepares(t *testing.T) {
prepare: prepareUserAuthMethodsQuery,
want: want{
sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT zitadel.projections.user_auth_methods.token_id,`+
` zitadel.projections.user_auth_methods.creation_date,`+
` zitadel.projections.user_auth_methods.change_date,`+
` zitadel.projections.user_auth_methods.resource_owner,`+
` zitadel.projections.user_auth_methods.user_id,`+
` zitadel.projections.user_auth_methods.sequence,`+
` zitadel.projections.user_auth_methods.name,`+
` zitadel.projections.user_auth_methods.state,`+
` zitadel.projections.user_auth_methods.method_type,`+
regexp.QuoteMeta(`SELECT projections.user_auth_methods.token_id,`+
` projections.user_auth_methods.creation_date,`+
` projections.user_auth_methods.change_date,`+
` projections.user_auth_methods.resource_owner,`+
` projections.user_auth_methods.user_id,`+
` projections.user_auth_methods.sequence,`+
` projections.user_auth_methods.name,`+
` projections.user_auth_methods.state,`+
` projections.user_auth_methods.method_type,`+
` COUNT(*) OVER ()`+
` FROM zitadel.projections.user_auth_methods`),
` FROM projections.user_auth_methods`),
[]string{
"token_id",
"creation_date",
@@ -196,17 +196,17 @@ func Test_UserAuthMethodPrepares(t *testing.T) {
prepare: prepareUserAuthMethodsQuery,
want: want{
sqlExpectations: mockQueryErr(
regexp.QuoteMeta(`SELECT zitadel.projections.user_auth_methods.token_id,`+
` zitadel.projections.user_auth_methods.creation_date,`+
` zitadel.projections.user_auth_methods.change_date,`+
` zitadel.projections.user_auth_methods.resource_owner,`+
` zitadel.projections.user_auth_methods.user_id,`+
` zitadel.projections.user_auth_methods.sequence,`+
` zitadel.projections.user_auth_methods.name,`+
` zitadel.projections.user_auth_methods.state,`+
` zitadel.projections.user_auth_methods.method_type,`+
regexp.QuoteMeta(`SELECT projections.user_auth_methods.token_id,`+
` projections.user_auth_methods.creation_date,`+
` projections.user_auth_methods.change_date,`+
` projections.user_auth_methods.resource_owner,`+
` projections.user_auth_methods.user_id,`+
` projections.user_auth_methods.sequence,`+
` projections.user_auth_methods.name,`+
` projections.user_auth_methods.state,`+
` projections.user_auth_methods.method_type,`+
` COUNT(*) OVER ()`+
` FROM zitadel.projections.user_auth_methods`),
` FROM projections.user_auth_methods`),
sql.ErrConnDone,
),
err: func(err error) (error, bool) {
@@ -223,16 +223,16 @@ func Test_UserAuthMethodPrepares(t *testing.T) {
prepare: prepareUserAuthMethodQuery,
want: want{
sqlExpectations: mockQueries(
`SELECT zitadel.projections.user_auth_methods.token_id,`+
` zitadel.projections.user_auth_methods.creation_date,`+
` zitadel.projections.user_auth_methods.change_date,`+
` zitadel.projections.user_auth_methods.resource_owner,`+
` zitadel.projections.user_auth_methods.user_id,`+
` zitadel.projections.user_auth_methods.sequence,`+
` zitadel.projections.user_auth_methods.name,`+
` zitadel.projections.user_auth_methods.state,`+
` zitadel.projections.user_auth_methods.method_type`+
` FROM zitadel.projections.user_auth_methods`,
`SELECT projections.user_auth_methods.token_id,`+
` projections.user_auth_methods.creation_date,`+
` projections.user_auth_methods.change_date,`+
` projections.user_auth_methods.resource_owner,`+
` projections.user_auth_methods.user_id,`+
` projections.user_auth_methods.sequence,`+
` projections.user_auth_methods.name,`+
` projections.user_auth_methods.state,`+
` projections.user_auth_methods.method_type`+
` FROM projections.user_auth_methods`,
nil,
nil,
),
@@ -250,16 +250,16 @@ func Test_UserAuthMethodPrepares(t *testing.T) {
prepare: prepareUserAuthMethodQuery,
want: want{
sqlExpectations: mockQuery(
regexp.QuoteMeta(`SELECT zitadel.projections.user_auth_methods.token_id,`+
` zitadel.projections.user_auth_methods.creation_date,`+
` zitadel.projections.user_auth_methods.change_date,`+
` zitadel.projections.user_auth_methods.resource_owner,`+
` zitadel.projections.user_auth_methods.user_id,`+
` zitadel.projections.user_auth_methods.sequence,`+
` zitadel.projections.user_auth_methods.name,`+
` zitadel.projections.user_auth_methods.state,`+
` zitadel.projections.user_auth_methods.method_type`+
` FROM zitadel.projections.user_auth_methods`),
regexp.QuoteMeta(`SELECT projections.user_auth_methods.token_id,`+
` projections.user_auth_methods.creation_date,`+
` projections.user_auth_methods.change_date,`+
` projections.user_auth_methods.resource_owner,`+
` projections.user_auth_methods.user_id,`+
` projections.user_auth_methods.sequence,`+
` projections.user_auth_methods.name,`+
` projections.user_auth_methods.state,`+
` projections.user_auth_methods.method_type`+
` FROM projections.user_auth_methods`),
[]string{
"token_id",
"creation_date",
@@ -301,16 +301,16 @@ func Test_UserAuthMethodPrepares(t *testing.T) {
prepare: prepareUserAuthMethodQuery,
want: want{
sqlExpectations: mockQueryErr(
regexp.QuoteMeta(`SELECT zitadel.projections.user_auth_methods.token_id,`+
` zitadel.projections.user_auth_methods.creation_date,`+
` zitadel.projections.user_auth_methods.change_date,`+
` zitadel.projections.user_auth_methods.resource_owner,`+
` zitadel.projections.user_auth_methods.user_id,`+
` zitadel.projections.user_auth_methods.sequence,`+
` zitadel.projections.user_auth_methods.name,`+
` zitadel.projections.user_auth_methods.state,`+
` zitadel.projections.user_auth_methods.method_type`+
` FROM zitadel.projections.user_auth_methods`),
regexp.QuoteMeta(`SELECT projections.user_auth_methods.token_id,`+
` projections.user_auth_methods.creation_date,`+
` projections.user_auth_methods.change_date,`+
` projections.user_auth_methods.resource_owner,`+
` projections.user_auth_methods.user_id,`+
` projections.user_auth_methods.sequence,`+
` projections.user_auth_methods.name,`+
` projections.user_auth_methods.state,`+
` projections.user_auth_methods.method_type`+
` FROM projections.user_auth_methods`),
sql.ErrConnDone,
),
err: func(err error) (error, bool) {