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
48 lines
1.6 KiB
PL/PgSQL
48 lines
1.6 KiB
PL/PgSQL
begin;
|
|
|
|
create table target_credential_library (
|
|
target_id wt_public_id not null
|
|
constraint target_fkey
|
|
references target (public_id)
|
|
on delete cascade
|
|
on update cascade,
|
|
credential_library_id wt_public_id not null
|
|
constraint credential_library_fkey
|
|
references credential_library (public_id)
|
|
on delete cascade
|
|
on update cascade,
|
|
credential_purpose text not null
|
|
constraint credential_purpose_enm_fkey
|
|
references credential_purpose_enm (name)
|
|
on delete restrict
|
|
on update cascade,
|
|
create_time wt_timestamp,
|
|
primary key(target_id, credential_library_id, credential_purpose)
|
|
);
|
|
comment on table target_credential_library is
|
|
'target_credential_library is a join table between the target and credential_library tables. '
|
|
'It also contains the credential purpose the relationship represents.';
|
|
|
|
create trigger default_create_time_column before insert on target_credential_library
|
|
for each row execute procedure default_create_time();
|
|
|
|
create trigger immutable_columns before update on target_credential_library
|
|
for each row execute procedure immutable_columns('target_id', 'credential_library_id', 'credential_purpose', 'create_time');
|
|
|
|
-- target_library provides the store id along with the other data stored in
|
|
-- target_credential_library
|
|
create view target_library
|
|
as
|
|
select
|
|
tcl.target_id,
|
|
tcl.credential_library_id,
|
|
tcl.credential_purpose,
|
|
cl.store_id
|
|
from
|
|
target_credential_library tcl,
|
|
credential_library cl
|
|
where
|
|
cl.public_id = tcl.credential_library_id;
|
|
|
|
commit;
|