feat(database): support for postgres (#3998)

* beginning with postgres statements

* try pgx

* use pgx

* database

* init works for postgres

* arrays working

* init for cockroach

* init

* start tests

* tests

* TESTS

* ch

* ch

* chore: use go 1.18

* read stmts

* fix typo

* tests

* connection string

* add missing error handler

* cleanup

* start all apis

* go mod tidy

* old update

* switch back to minute

* on conflict

* replace string slice with `database.StringArray` in db models

* fix tests and start

* update go version in dockerfile

* setup go

* clean up

* remove notification migration

* update

* docs: add deploy guide for postgres

* fix: revert sonyflake

* use `database.StringArray` for daos

* use `database.StringArray` every where

* new tables

* index naming,
metadata primary key,
project grant role key type

* docs(postgres): change to beta

* chore: correct compose

* fix(defaults): add empty postgres config

* refactor: remove unused code

* docs: add postgres to self hosted

* fix broken link

* so?

* change title

* add mdx to link

* fix stmt

* update goreleaser in test-code

* docs: improve postgres example

* update more projections

* fix: add beta log for postgres

* revert index name change

* prerelease

* fix: add sequence to v1 "reduce paniced"

* log if nil

* add logging

* fix: log output

* fix(import): check if org exists and user

* refactor: imports

* fix(user): ignore malformed events

* refactor: method naming

* fix: test

* refactor: correct errors.Is call

* ci: don't build dev binaries on main

* fix(go releaser): update version to 1.11.0

* fix(user): projection should not break

* fix(user): handle error properly

* docs: correct config example

* Update .releaserc.js

* Update .releaserc.js

Co-authored-by: Livio Amstutz <[email protected]>
Co-authored-by: Elio Bischof <[email protected]>
This commit is contained in:
Silvan
2022-08-31 07:52:43 +00:00
committed by GitHub
co-authored by Livio Amstutz Elio Bischof
parent d6c9815945
commit 77b4fc5487
189 changed files with 3401 additions and 2956 deletions
+34 -36
View File
@@ -9,8 +9,7 @@ import (
"testing"
"time"
"github.com/lib/pq"
"github.com/zitadel/zitadel/internal/database"
"github.com/zitadel/zitadel/internal/domain"
errs "github.com/zitadel/zitadel/internal/errors"
)
@@ -51,14 +50,14 @@ func Test_LoginPolicyPrepares(t *testing.T) {
` projections.login_policies.mfa_init_skip_lifetime,`+
` projections.login_policies.second_factor_check_lifetime,`+
` projections.login_policies.multi_factor_check_lifetime,`+
` projections.idp_login_policy_links.idp_id,`+
` projections.idps.name,`+
` projections.idps.type`+
` projections.idp_login_policy_links2.idp_id,`+
` projections.idps2.name,`+
` projections.idps2.type`+
` FROM projections.login_policies`+
` LEFT JOIN projections.idp_login_policy_links ON `+
` projections.login_policies.aggregate_id = projections.idp_login_policy_links.aggregate_id`+
` LEFT JOIN projections.idps ON`+
` projections.idp_login_policy_links.idp_id = projections.idps.id`),
` LEFT JOIN projections.idp_login_policy_links2 ON `+
` projections.login_policies.aggregate_id = projections.idp_login_policy_links2.aggregate_id`+
` LEFT JOIN projections.idps2 ON`+
` projections.idp_login_policy_links2.idp_id = projections.idps2.id`),
nil,
nil,
),
@@ -96,14 +95,14 @@ func Test_LoginPolicyPrepares(t *testing.T) {
` projections.login_policies.mfa_init_skip_lifetime,`+
` projections.login_policies.second_factor_check_lifetime,`+
` projections.login_policies.multi_factor_check_lifetime,`+
` projections.idp_login_policy_links.idp_id,`+
` projections.idps.name,`+
` projections.idps.type`+
` projections.idp_login_policy_links2.idp_id,`+
` projections.idps2.name,`+
` projections.idps2.type`+
` FROM projections.login_policies`+
` LEFT JOIN projections.idp_login_policy_links ON `+
` projections.login_policies.aggregate_id = projections.idp_login_policy_links.aggregate_id`+
` LEFT JOIN projections.idps ON`+
` projections.idp_login_policy_links.idp_id = projections.idps.id`),
` LEFT JOIN projections.idp_login_policy_links2 ON `+
` projections.login_policies.aggregate_id = projections.idp_login_policy_links2.aggregate_id`+
` LEFT JOIN projections.idps2 ON`+
` projections.idp_login_policy_links2.idp_id = projections.idps2.id`),
[]string{
"aggregate_id",
"creation_date",
@@ -138,8 +137,8 @@ func Test_LoginPolicyPrepares(t *testing.T) {
true,
true,
true,
pq.Int32Array{int32(domain.SecondFactorTypeOTP)},
pq.Int32Array{int32(domain.MultiFactorTypeU2FWithPIN)},
database.EnumArray[domain.SecondFactorType]{domain.SecondFactorTypeOTP},
database.EnumArray[domain.MultiFactorType]{domain.MultiFactorTypeU2FWithPIN},
domain.PasswordlessTypeAllowed,
true,
true,
@@ -165,8 +164,8 @@ func Test_LoginPolicyPrepares(t *testing.T) {
AllowUsernamePassword: true,
AllowExternalIDPs: true,
ForceMFA: true,
SecondFactors: []domain.SecondFactorType{domain.SecondFactorTypeOTP},
MultiFactors: []domain.MultiFactorType{domain.MultiFactorTypeU2FWithPIN},
SecondFactors: database.EnumArray[domain.SecondFactorType]{domain.SecondFactorTypeOTP},
MultiFactors: database.EnumArray[domain.MultiFactorType]{domain.MultiFactorTypeU2FWithPIN},
PasswordlessType: domain.PasswordlessTypeAllowed,
IsDefault: true,
HidePasswordReset: true,
@@ -211,14 +210,14 @@ func Test_LoginPolicyPrepares(t *testing.T) {
` projections.login_policies.mfa_init_skip_lifetime,`+
` projections.login_policies.second_factor_check_lifetime,`+
` projections.login_policies.multi_factor_check_lifetime,`+
` projections.idp_login_policy_links.idp_id,`+
` projections.idps.name,`+
` projections.idps.type`+
` projections.idp_login_policy_links2.idp_id,`+
` projections.idps2.name,`+
` projections.idps2.type`+
` FROM projections.login_policies`+
` LEFT JOIN projections.idp_login_policy_links ON `+
` projections.login_policies.aggregate_id = projections.idp_login_policy_links.aggregate_id`+
` LEFT JOIN projections.idps ON`+
` projections.idp_login_policy_links.idp_id = projections.idps.id`),
` LEFT JOIN projections.idp_login_policy_links2 ON `+
` projections.login_policies.aggregate_id = projections.idp_login_policy_links2.aggregate_id`+
` LEFT JOIN projections.idps2 ON`+
` projections.idp_login_policy_links2.idp_id = projections.idps2.id`),
sql.ErrConnDone,
),
err: func(err error) (error, bool) {
@@ -262,7 +261,7 @@ func Test_LoginPolicyPrepares(t *testing.T) {
"second_factors",
},
[]driver.Value{
pq.Int32Array{int32(domain.SecondFactorTypeOTP)},
database.EnumArray[domain.SecondFactorType]{domain.SecondFactorTypeOTP},
},
),
},
@@ -270,7 +269,7 @@ func Test_LoginPolicyPrepares(t *testing.T) {
SearchResponse: SearchResponse{
Count: 1,
},
Factors: []domain.SecondFactorType{domain.SecondFactorTypeOTP},
Factors: database.EnumArray[domain.SecondFactorType]{domain.SecondFactorTypeOTP},
},
},
{
@@ -284,11 +283,11 @@ func Test_LoginPolicyPrepares(t *testing.T) {
"second_factors",
},
[]driver.Value{
pq.Int32Array{},
database.EnumArray[domain.SecondFactorType]{},
},
),
},
object: &SecondFactors{Factors: []domain.SecondFactorType{}},
object: &SecondFactors{Factors: database.EnumArray[domain.SecondFactorType]{}},
},
{
name: "prepareLoginPolicy2FAsQuery sql err",
@@ -308,7 +307,6 @@ func Test_LoginPolicyPrepares(t *testing.T) {
},
object: nil,
},
{
name: "prepareLoginPolicyMFAsQuery no result",
prepare: prepareLoginPolicyMFAsQuery,
@@ -341,7 +339,7 @@ func Test_LoginPolicyPrepares(t *testing.T) {
"multi_factors",
},
[]driver.Value{
pq.Int32Array{int32(domain.MultiFactorTypeU2FWithPIN)},
database.EnumArray[domain.MultiFactorType]{domain.MultiFactorTypeU2FWithPIN},
},
),
},
@@ -349,7 +347,7 @@ func Test_LoginPolicyPrepares(t *testing.T) {
SearchResponse: SearchResponse{
Count: 1,
},
Factors: []domain.MultiFactorType{domain.MultiFactorTypeU2FWithPIN},
Factors: database.EnumArray[domain.MultiFactorType]{domain.MultiFactorTypeU2FWithPIN},
},
},
{
@@ -363,11 +361,11 @@ func Test_LoginPolicyPrepares(t *testing.T) {
"multi_factors",
},
[]driver.Value{
pq.Int32Array{},
database.EnumArray[domain.MultiFactorType]{},
},
),
},
object: &MultiFactors{Factors: []domain.MultiFactorType{}},
object: &MultiFactors{Factors: database.EnumArray[domain.MultiFactorType]{}},
},
{
name: "prepareLoginPolicyMFAsQuery sql err",