Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/alias/target/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
`
)
4 changes: 2 additions & 2 deletions internal/auth/ldap/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
`
)
4 changes: 2 additions & 2 deletions internal/auth/oidc/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
`
)
2 changes: 1 addition & 1 deletion internal/auth/password/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
`
)
2 changes: 1 addition & 1 deletion internal/auth/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/authtoken/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
`
)
2 changes: 1 addition & 1 deletion internal/credential/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion internal/credential/static/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/credential/vault/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions internal/db/schema/migrations/oss/postgres_46_01_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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",
Expand Down
30 changes: 18 additions & 12 deletions internal/db/schema/migrations/oss/postgres_97_03_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 (
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions internal/host/plugin/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down Expand Up @@ -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 = `
Expand Down
2 changes: 1 addition & 1 deletion internal/host/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions internal/host/static/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down Expand Up @@ -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)
`
)
8 changes: 4 additions & 4 deletions internal/iam/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down
2 changes: 1 addition & 1 deletion internal/session/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down
2 changes: 1 addition & 1 deletion internal/target/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down
7 changes: 7 additions & 0 deletions testing/dbtest/docker/Dockerfile.17-alpine
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion testing/dbtest/docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading