2022-11-15 10:26:26 -08:00
|
|
|
-- Copyright (c) HashiCorp, Inc.
|
2023-02-02 17:15:17 -08:00
|
|
|
-- SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2021-05-06 14:54:10 -07:00
|
|
|
begin;
|
|
|
|
|
|
2022-08-08 18:17:57 -04:00
|
|
|
create domain wt_plugin_id as text not null
|
2022-11-15 10:26:26 -08:00
|
|
|
check(
|
|
|
|
|
length(trim(value)) > 10 or value = 'pi_system'
|
|
|
|
|
);
|
2021-05-06 14:54:10 -07:00
|
|
|
comment on domain wt_plugin_id is
|
2022-11-15 10:26:26 -08:00
|
|
|
'"pi_system", or random ID generated with github.com/hashicorp/go-secure-stdlib/base62';
|
2021-05-06 14:54:10 -07:00
|
|
|
|
|
|
|
|
create table plugin (
|
2022-11-15 10:26:26 -08:00
|
|
|
public_id wt_plugin_id primary key
|
2021-05-06 14:54:10 -07:00
|
|
|
);
|
|
|
|
|
comment on table plugin is
|
2022-11-15 10:26:26 -08:00
|
|
|
'plugin is a table where each row represents a unique plugin registered with Boundary.';
|
2021-05-06 14:54:10 -07:00
|
|
|
|
|
|
|
|
insert into plugin (public_id)
|
2022-11-15 10:26:26 -08:00
|
|
|
values
|
|
|
|
|
('pi_system');
|
2021-05-06 14:54:10 -07:00
|
|
|
|
|
|
|
|
create trigger immutable_columns before update on plugin
|
2022-11-15 10:26:26 -08:00
|
|
|
for each row execute procedure immutable_columns('public_id');
|
2021-05-06 14:54:10 -07:00
|
|
|
|
2022-08-08 18:17:57 -04:00
|
|
|
create or replace function disallow_system_plugin_deletion() returns trigger
|
2021-05-06 14:54:10 -07:00
|
|
|
as $$
|
|
|
|
|
begin
|
2022-11-15 10:26:26 -08:00
|
|
|
if old.public_id = 'pi_system' then
|
|
|
|
|
raise exception 'deletion of system plugin not allowed';
|
|
|
|
|
end if;
|
|
|
|
|
return old;
|
2021-05-06 14:54:10 -07:00
|
|
|
end;
|
|
|
|
|
$$ language plpgsql;
|
|
|
|
|
|
|
|
|
|
create trigger plugin_disallow_system_deletion before delete on plugin
|
2022-11-15 10:26:26 -08:00
|
|
|
for each row execute procedure disallow_system_plugin_deletion();
|
2021-05-06 14:54:10 -07:00
|
|
|
|
|
|
|
|
commit;
|