diff --git a/internal/alias/target/query.go b/internal/alias/target/query.go index 43e613b3f58..f872d2b2f27 100644 --- a/internal/alias/target/query.go +++ b/internal/alias/target/query.go @@ -5,6 +5,6 @@ package target const ( estimateCount = ` -select sum(reltuples::bigint) as estimate from pg_class where oid in ('alias'::regclass) +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('alias'::regclass) ` ) diff --git a/internal/auth/ldap/query.go b/internal/auth/ldap/query.go index 16488c457eb..3ae88cb244b 100644 --- a/internal/auth/ldap/query.go +++ b/internal/auth/ldap/query.go @@ -5,9 +5,9 @@ package ldap const ( estimateCountAccounts = ` -select sum(reltuples::bigint) as estimate from pg_class where oid in ('auth_ldap_account'::regclass) +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('auth_ldap_account'::regclass) ` estimateCountManagedGroups = ` -select sum(reltuples::bigint) as estimate from pg_class where oid in ('auth_ldap_managed_group'::regclass) +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('auth_ldap_managed_group'::regclass) ` ) diff --git a/internal/auth/oidc/query.go b/internal/auth/oidc/query.go index 1540da0a1f5..2282b84a12f 100644 --- a/internal/auth/oidc/query.go +++ b/internal/auth/oidc/query.go @@ -17,9 +17,9 @@ const ( ` estimateCountAccounts = ` - select sum(reltuples::bigint) as estimate from pg_class where oid in ('auth_oidc_account'::regclass) + select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('auth_oidc_account'::regclass) ` estimateCountManagedGroups = ` - select sum(reltuples::bigint) as estimate from pg_class where oid in ('auth_oidc_managed_group'::regclass) + select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('auth_oidc_managed_group'::regclass) ` ) diff --git a/internal/auth/password/query.go b/internal/auth/password/query.go index 3036d3e506c..49ada63413b 100644 --- a/internal/auth/password/query.go +++ b/internal/auth/password/query.go @@ -45,6 +45,6 @@ select * ); ` estimateCountAccounts = ` -select sum(reltuples::bigint) as estimate from pg_class where oid in ('auth_password_account'::regclass) +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('auth_password_account'::regclass) ` ) diff --git a/internal/auth/query.go b/internal/auth/query.go index 668d93535de..27b01eabbc4 100644 --- a/internal/auth/query.go +++ b/internal/auth/query.go @@ -5,7 +5,7 @@ package auth const ( estimateCountAuthMethodsQuery = ` -select sum(reltuples::bigint) as estimate from pg_class where oid in ( +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ( 'auth_password_method'::regclass, 'auth_ldap_method'::regclass, 'auth_oidc_method'::regclass diff --git a/internal/authtoken/query.go b/internal/authtoken/query.go index 12b92fe3eb8..f71142338f2 100644 --- a/internal/authtoken/query.go +++ b/internal/authtoken/query.go @@ -5,6 +5,6 @@ package authtoken const ( estimateCountAuthTokens = ` -select reltuples::bigint as estimate from pg_class where oid in ('auth_token'::regclass) +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('auth_token'::regclass) ` ) diff --git a/internal/credential/query.go b/internal/credential/query.go index 99ff0eda7b9..de1ac7ed005 100644 --- a/internal/credential/query.go +++ b/internal/credential/query.go @@ -5,7 +5,7 @@ package credential const ( estimateCountStoresQuery = ` -select sum(reltuples::bigint) as estimate from pg_class where oid in ( +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ( 'credential_vault_store'::regclass, 'credential_static_store'::regclass ) diff --git a/internal/credential/static/query.go b/internal/credential/static/query.go index 4390bfa8e15..d1918f442ec 100644 --- a/internal/credential/static/query.go +++ b/internal/credential/static/query.go @@ -60,7 +60,7 @@ select distinct json.public_id, ` estimateCountCredentials = ` -select sum(reltuples::bigint) as estimate +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ( 'credential_static_json_credential'::regclass, diff --git a/internal/credential/vault/query.go b/internal/credential/vault/query.go index 62d55665863..da82289812a 100644 --- a/internal/credential/vault/query.go +++ b/internal/credential/vault/query.go @@ -191,7 +191,7 @@ delete from credential_vault_credential ` estimateCountCredentialLibraries = ` -select sum(reltuples::bigint) as estimate +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ( 'credential_vault_generic_library'::regclass, diff --git a/internal/daemon/controller/handlers/roles/role_service_test.go b/internal/daemon/controller/handlers/roles/role_service_test.go index 2149b3b39a0..c464dc89930 100644 --- a/internal/daemon/controller/handlers/roles/role_service_test.go +++ b/internal/daemon/controller/handlers/roles/role_service_test.go @@ -2125,6 +2125,9 @@ func checkEqualGrants(t *testing.T, expected []string, got *pb.Role) { sort.Slice(got.GrantStrings, func(i, j int) bool { return got.GrantStrings[i] < got.GrantStrings[j] }) + sort.Slice(got.Grants, func(i, j int) bool { + return got.Grants[i].GetRaw() < got.Grants[j].GetRaw() + }) for i, v := range expected { parsed, err := perms.Parse(context.Background(), perms.GrantTuple{RoleScopeId: "o_abc123", GrantScopeId: "o_abc123", Grant: v}) require.NoError(err) diff --git a/internal/db/schema/migrations/oss/postgres_46_01_test.go b/internal/db/schema/migrations/oss/postgres_46_01_test.go index beb2491f8a9..34435ba76e8 100644 --- a/internal/db/schema/migrations/oss/postgres_46_01_test.go +++ b/internal/db/schema/migrations/oss/postgres_46_01_test.go @@ -347,17 +347,17 @@ func validateRepairFunc(t *testing.T, rw *db.Db, repairReport migration.Repairs) from target_credential_library as tcl where tcl.target_id = 'ttcp_PRJA___65001' ), - resources (target_id, resource_id) as ( - select target_id, host_set_id as resource_id + resources (ord, target_id, resource_id) as ( + select 1 as ord, target_id, host_set_id as resource_id from ths - union - select target_id, credential_static_id as resource_id + union all + select 2 as ord, target_id, credential_static_id as resource_id from tsc - union - select target_id, credential_library_id as resource_id + union all + select 3 as ord, target_id, credential_library_id as resource_id from tcl ) - select * from resources;` + select target_id, resource_id from resources order by ord;` rows, err = rw.Query(ctx, query, nil) require.NoError(err) associations := []targetAssociation{} @@ -372,7 +372,7 @@ func validateRepairFunc(t *testing.T, rw *db.Db, repairReport migration.Repairs) }) } require.NoError(rows.Err()) - require.Equal([]targetAssociation{ + require.ElementsMatch([]targetAssociation{ { targetId: "ttcp_PRJA___65001", resourceId: "clvlt_PRJA___65001", diff --git a/internal/db/schema/migrations/oss/postgres_97_03_test.go b/internal/db/schema/migrations/oss/postgres_97_03_test.go index 2ca6f5729d1..a4bc3b7e563 100644 --- a/internal/db/schema/migrations/oss/postgres_97_03_test.go +++ b/internal/db/schema/migrations/oss/postgres_97_03_test.go @@ -34,7 +34,8 @@ const ( version, grant_this_role_scope, grant_scope - from iam_role_global; + from iam_role_global + order by version, public_id; ` selectOrgRoleQuery = ` select @@ -45,7 +46,8 @@ const ( version, grant_this_role_scope, grant_scope - from iam_role_org; + from iam_role_org + order by version, public_id; ` selectProjectRoleQuery = ` select @@ -55,28 +57,32 @@ const ( description, version, grant_this_role_scope - from iam_role_project; + from iam_role_project + order by version, public_id; ` selectGlobalIndividualOrgGrantScopeQuery = ` select role_id, scope_id, grant_scope - from iam_role_global_individual_org_grant_scope; + from iam_role_global_individual_org_grant_scope + order by role_id, scope_id; ` selectGlobalIndividualProjectGrantScopeQuery = ` select role_id, scope_id, grant_scope - from iam_role_global_individual_project_grant_scope; + from iam_role_global_individual_project_grant_scope + order by role_id, scope_id; ` selectOrgIndividualGrantScopeQuery = ` select role_id, scope_id, grant_scope - from iam_role_org_individual_grant_scope; + from iam_role_org_individual_grant_scope + order by role_id, scope_id; ` selectCountSubTableRolesQuery = ` select ( @@ -286,7 +292,7 @@ func Test_IamRoleAndGrantScopeMigration(t *testing.T) { require.NoError(rows.Err()) require.NoError(rows.Close()) require.Len(globalRoles, 10) - require.Equal([]testRole{ + require.ElementsMatch([]testRole{ { role_id: "r_go____name", scope_id: "global", @@ -400,7 +406,7 @@ func Test_IamRoleAndGrantScopeMigration(t *testing.T) { require.NoError(rows.Err()) require.NoError(rows.Close()) require.Len(orgRoles, 6) - require.Equal([]testRole{ + require.ElementsMatch([]testRole{ { role_id: "r_op_bc__art", scope_id: "o_____colors", @@ -477,7 +483,7 @@ func Test_IamRoleAndGrantScopeMigration(t *testing.T) { require.NoError(rows.Err()) require.NoError(rows.Close()) require.Len(projRoles, 5) - require.Equal([]testRole{ + require.ElementsMatch([]testRole{ { role_id: "r_prjaa____test", scope_id: "p_pA____test", @@ -537,7 +543,7 @@ func Test_IamRoleAndGrantScopeMigration(t *testing.T) { require.NoError(rows.Err()) require.NoError(rows.Close()) require.Len(individualOrgRoles, 1) - require.Equal([]testRole{ + require.ElementsMatch([]testRole{ { role_id: "r_go____name", scope_id: "o_____colors", @@ -562,7 +568,7 @@ func Test_IamRoleAndGrantScopeMigration(t *testing.T) { require.NoError(rows.Err()) require.NoError(rows.Close()) require.Len(individualProjRoles, 2) - require.Equal([]testRole{ + require.ElementsMatch([]testRole{ { role_id: "r_gp____spec", scope_id: "p____bcolors", @@ -592,7 +598,7 @@ func Test_IamRoleAndGrantScopeMigration(t *testing.T) { require.NoError(rows.Err()) require.NoError(rows.Close()) require.Len(individualOrgRoles, 2) - require.Equal([]testRole{ + require.ElementsMatch([]testRole{ { role_id: "r_op_rc__art", scope_id: "p____rcolors", diff --git a/internal/host/plugin/query.go b/internal/host/plugin/query.go index 6eb8e4a663e..9ddb556bb7e 100644 --- a/internal/host/plugin/query.go +++ b/internal/host/plugin/query.go @@ -56,7 +56,7 @@ where public_id = ? ` estimateCountHosts = ` -select sum(reltuples::bigint) as estimate from pg_class where oid in ('host_plugin_host'::regclass) +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('host_plugin_host'::regclass) ` listHostsTemplate = ` @@ -344,7 +344,7 @@ order by update_time desc, public_id desc; ` estimateCountHostSets = ` -select sum(reltuples::bigint) as estimate from pg_class where oid in ('host_plugin_set'::regclass) +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('host_plugin_set'::regclass) ` listSetsTemplate = ` diff --git a/internal/host/query.go b/internal/host/query.go index 6f5a7660256..b294c048528 100644 --- a/internal/host/query.go +++ b/internal/host/query.go @@ -5,7 +5,7 @@ package host const ( estimateCountCatalogsQuery = ` -select sum(reltuples::bigint) as estimate from pg_class where oid in ( +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ( 'static_host_catalog'::regclass, 'host_plugin_catalog'::regclass ) diff --git a/internal/host/static/query.go b/internal/host/static/query.go index d0ab0059603..785bb3c0339 100644 --- a/internal/host/static/query.go +++ b/internal/host/static/query.go @@ -48,7 +48,7 @@ order by action, host_id; ` estimateCountHosts = ` -select sum(reltuples::bigint) as estimate from pg_class where oid in ('static_host'::regclass) +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('static_host'::regclass) ` listHostsTemplate = ` @@ -215,6 +215,6 @@ order by update_time desc, public_id desc; ` estimateCountHostSets = ` -select sum(reltuples::bigint) as estimate from pg_class where oid in ('static_host_set'::regclass) +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('static_host_set'::regclass) ` ) diff --git a/internal/iam/query.go b/internal/iam/query.go index a15d5d30a89..7e153b0a1e9 100644 --- a/internal/iam/query.go +++ b/internal/iam/query.go @@ -565,19 +565,19 @@ const ( ` estimateCountRoles = ` - select reltuples::bigint as estimate from pg_class where oid in ('iam_role'::regclass) + select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('iam_role'::regclass) ` estimateCountUsers = ` - select reltuples::bigint as estimate from pg_class where oid in ('iam_user'::regclass) + select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('iam_user'::regclass) ` estimateCountGroups = ` - select reltuples::bigint as estimate from pg_class where oid in ('iam_group'::regclass) + select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('iam_group'::regclass) ` estimateCountScopes = ` - select reltuples::bigint as estimate from pg_class where oid in ('iam_scope'::regclass) + select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('iam_scope'::regclass) ` scopeIdFromRoleIdQuery = ` diff --git a/internal/session/query.go b/internal/session/query.go index 0b46628fcbc..9cecb832254 100644 --- a/internal/session/query.go +++ b/internal/session/query.go @@ -420,7 +420,7 @@ with session_ids as ( order by update_time desc, public_id desc; ` estimateCountSessions = ` - select reltuples::bigint as estimate from pg_class where oid in ('session'::regclass) + select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('session'::regclass) ` selectStates = ` diff --git a/internal/target/query.go b/internal/target/query.go index 838de8f129b..915a2c46261 100644 --- a/internal/target/query.go +++ b/internal/target/query.go @@ -60,7 +60,7 @@ select public_id, project_id from target ` estimateCountTargets = ` -select sum(reltuples::bigint) as estimate from pg_class where oid in ('target_tcp'::regclass, 'target_ssh'::regclass, 'target_rdp'::regclass) +select greatest(0, coalesce(sum(reltuples::bigint), 0)) as estimate from pg_class where oid in ('target_tcp'::regclass, 'target_ssh'::regclass, 'target_rdp'::regclass) ` listTargetsTemplate = ` diff --git a/testing/dbtest/docker/Dockerfile.17-alpine b/testing/dbtest/docker/Dockerfile.17-alpine new file mode 100644 index 00000000000..e949cd2884b --- /dev/null +++ b/testing/dbtest/docker/Dockerfile.17-alpine @@ -0,0 +1,7 @@ +FROM postgres:17-alpine + +ADD init-db.sh /docker-entrypoint-initdb.d/00-init-db.sh +ADD restore-benchmark-dumps.sh /docker-entrypoint-initdb.d/01-restore-benchmark-dumps.sh +ADD postgresql.conf /etc/postgresql/postgresql.conf + +CMD ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"] diff --git a/testing/dbtest/docker/Makefile b/testing/dbtest/docker/Makefile index 88f0ae72b3e..8dbcc22280e 100644 --- a/testing/dbtest/docker/Makefile +++ b/testing/dbtest/docker/Makefile @@ -6,7 +6,7 @@ DOCKER_ARGS ?= -d DOCKER_MIRROR?=docker.io REGISTRY_NAME?=hashicorpboundary TEST_IMAGE_NAME=postgres -TEST_IMAGE_TAG ?= $(DOCKER_MIRROR)/$(REGISTRY_NAME)/$(TEST_IMAGE_NAME):12-alpine +TEST_IMAGE_TAG ?= $(DOCKER_MIRROR)/$(REGISTRY_NAME)/$(TEST_IMAGE_NAME):17-alpine PG_OPTS ?= TEST_DB_PORT ?= 5432 TEST_CONTAINER_NAME ?= boundary-sql-tests