Files
threshold/internal/db/schema/migrations/oss/postgres/7/02_plugin.up.sql
T
Timothy Messier 8caaf3e076 refactor(schema): Add support for migration editions
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
2021-10-08 06:50:26 -04:00

41 lines
1.1 KiB
PL/PgSQL

begin;
create domain wt_plugin_id as text
not null
check(
length(trim(value)) > 10 or value = 'pi_system'
);
comment on domain wt_plugin_id is
'"pi_system", or random ID generated with github.com/hashicorp/go-secure-stdlib/base62';
create table plugin (
public_id wt_plugin_id primary key
);
comment on table plugin is
'plugin is a table where each row represents a unique plugin registered with Boundary.';
insert into plugin (public_id)
values
('pi_system');
create trigger immutable_columns before update on plugin
for each row execute procedure immutable_columns('public_id');
create or replace function
disallow_system_plugin_deletion()
returns trigger
as $$
begin
if old.public_id = 'pi_system' then
raise exception 'deletion of system plugin not allowed';
end if;
return old;
end;
$$ language plpgsql;
create trigger plugin_disallow_system_deletion before delete on plugin
for each row execute procedure disallow_system_plugin_deletion();
commit;