Files
threshold/internal/db/schema/migrations/oss/postgres/3/01_auth.up.sql
T
429247f407 [COMPLIANCE] Update Copyright Headers (#6282)
* [COMPLIANCE] Update Copyright and License Headers

* chore: make gen to generate files with copyright headers

* chore: update missed copyright headers

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Justin Nguyen <justin.nguyen@hashicorp.com>
2026-01-28 11:05:07 -06:00

34 lines
950 B
PL/PgSQL

-- Copyright IBM Corp. 2020, 2025
-- SPDX-License-Identifier: BUSL-1.1
begin;
-- this constraint is intended to ensure that a user cannot have more than one
-- account per auth_method.
--
-- If this constraint causes the migrations to fail the operartor can run the
-- following query to get a list of user ids which have more that one account
-- within the same auth method. At that point, the operator will need to pick
-- which account to keep.
----------------------------------------------------------------------------
-- with too_many_accounts(iam_user_id, acct_count) as (
-- select
-- iam_user_id,
-- count(*) as acct_count
-- from
-- auth_account
-- group by auth_method_id, iam_user_id
-- )
-- select
-- *
-- from
-- too_many_accounts
-- where
-- acct_count > 1;
alter table auth_account
add constraint auth_account_auth_method_id_public_id_uq
unique(auth_method_id, iam_user_id);
commit;