This refactors the schema package and subpackages to support editions.
An Edition is a collection of sql migrations. A given boundary binary
can have multiple migration editions. The `schema.Manager` is updated to
apply the necessary migrations in the correct order, leveraging an
Edition's priority to determine the order in which the separate Editions
are applied.
The sql migration files are now nested under a directory for the
edition.
This also switches from the generated code to using embed, which
eliminates the need for the `make migrations` target and the generated
code. As such this commit removes the target and generated code.
See:
https://pkg.go.dev/embed
31 lines
878 B
PL/PgSQL
31 lines
878 B
PL/PgSQL
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; |