From 44971b3559c146e13f1a1cd31e454ab87b5a3f0a Mon Sep 17 00:00:00 2001 From: Johan Brandhorst-Satzkorn Date: Thu, 21 Dec 2023 20:43:04 -0800 Subject: [PATCH] internal/db: migrations for accounts pagination --- .../80/14_account_table_updates.up.sql | 30 +++++++++++++++++++ .../db/sqltest/tests/pagination/account.sql | 18 +++++++++++ 2 files changed, 48 insertions(+) create mode 100644 internal/db/schema/migrations/oss/postgres/80/14_account_table_updates.up.sql create mode 100644 internal/db/sqltest/tests/pagination/account.sql diff --git a/internal/db/schema/migrations/oss/postgres/80/14_account_table_updates.up.sql b/internal/db/schema/migrations/oss/postgres/80/14_account_table_updates.up.sql new file mode 100644 index 000000000..b9046454e --- /dev/null +++ b/internal/db/schema/migrations/oss/postgres/80/14_account_table_updates.up.sql @@ -0,0 +1,30 @@ +-- Copyright (c) HashiCorp, Inc. +-- SPDX-License-Identifier: BUSL-1.1 + +begin; + + -- Add new indexes for the create time and update time queries. + create index auth_ldap_account_create_time_public_id_idx + on auth_ldap_account (create_time desc, public_id desc); + create index auth_ldap_account_update_time_public_id_idx + on auth_ldap_account (update_time desc, public_id desc); + + analyze auth_ldap_account; + + -- Add new indexes for the create time and update time queries. + create index auth_oidc_account_create_time_public_id_idx + on auth_oidc_account (create_time desc, public_id desc); + create index auth_oidc_account_update_time_public_id_idx + on auth_oidc_account (update_time desc, public_id desc); + + analyze auth_oidc_account; + + -- Add new indexes for the create time and update time queries. + create index auth_password_account_create_time_public_id_idx + on auth_password_account (create_time desc, public_id desc); + create index auth_password_account_update_time_public_id_idx + on auth_password_account (update_time desc, public_id desc); + + analyze auth_password_account; + +commit; \ No newline at end of file diff --git a/internal/db/sqltest/tests/pagination/account.sql b/internal/db/sqltest/tests/pagination/account.sql new file mode 100644 index 000000000..aec41efd2 --- /dev/null +++ b/internal/db/sqltest/tests/pagination/account.sql @@ -0,0 +1,18 @@ +-- Copyright (c) HashiCorp, Inc. +-- SPDX-License-Identifier: BUSL-1.1 + +begin; + select plan(6); + + select has_index('auth_ldap_account', 'auth_ldap_account_create_time_public_id_idx', array['create_time', 'public_id']); + select has_index('auth_ldap_account', 'auth_ldap_account_update_time_public_id_idx', array['update_time', 'public_id']); + + select has_index('auth_oidc_account', 'auth_oidc_account_create_time_public_id_idx', array['create_time', 'public_id']); + select has_index('auth_oidc_account', 'auth_oidc_account_update_time_public_id_idx', array['update_time', 'public_id']); + + select has_index('auth_password_account', 'auth_password_account_create_time_public_id_idx', array['create_time', 'public_id']); + select has_index('auth_password_account', 'auth_password_account_update_time_public_id_idx', array['update_time', 'public_id']); + + select * from finish(); + +rollback; \ No newline at end of file