Added a new Endpoint struct at the top level host package level to capture host, set, and address chosen. Temporarily add a host_plugin_host table to capture the hosts returned by the plugins. This ensures the datawarehouse is able to query the table to decide what host was chosen. The view used to update the datawarehouse dimension table provides rows with host set ids and hosts which are not in that host set. This is ok since the function which updates the dimension table provides the host set and host id chosen so that relationship doesn't need to be captured in the view itself. Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
224 lines
9.5 KiB
PL/PgSQL
224 lines
9.5 KiB
PL/PgSQL
begin;
|
|
|
|
/*
|
|
┌──────────────────┐
|
|
│ plugin_host │
|
|
├──────────────────┤
|
|
│public_id (pk) │
|
|
│... │
|
|
└──────────────────┘
|
|
┼
|
|
┼
|
|
○
|
|
╱│╲
|
|
┌─────────────────────┐
|
|
│ host_plugin_catalog │
|
|
├─────────────────────┤ ┌───────────────────────────┐
|
|
┌────────────────┐ │public_id (pk) │ │host_plugin_catalog_secret │
|
|
│host_catalog │ │plugin_id (fk) │ ├───────────────────────────┤
|
|
├────────────────┤ │scope_id (fk) │ │host_catalog_id (pk, fk) │
|
|
│public_id │┼┼──○┼│name │┼┼──○┼│secret │
|
|
│scope_id │ │description │ │key_id (fk) │
|
|
└────────────────┘ │attributes │ └───────────────────────────┘
|
|
┼ └─────────────────────┘
|
|
┼ ┼
|
|
│ ┼
|
|
│ ○
|
|
○ ╱│╲
|
|
╱│╲ ┌────────────────────┐
|
|
┌────────────────┐ │ host_plugin_set │
|
|
│ host_set │ ├────────────────────┤
|
|
├────────────────┤ │public_id (pk) │
|
|
│public_id │ │host_catalog_id (fk)│
|
|
│host_catalog_id │┼┼──○┼│name │
|
|
└────────────────┘ │description │
|
|
│attributes │
|
|
└────────────────────┘
|
|
|
|
*/
|
|
|
|
create table host_plugin_catalog (
|
|
public_id wt_public_id primary key,
|
|
scope_id wt_scope_id not null
|
|
constraint iam_scope_fkey
|
|
references iam_scope (public_id)
|
|
on delete cascade
|
|
on update cascade,
|
|
plugin_id wt_plugin_id not null
|
|
constraint plugin_host_fkey
|
|
references plugin_host (public_id)
|
|
on delete cascade
|
|
on update cascade,
|
|
name wt_name,
|
|
description text,
|
|
create_time wt_timestamp,
|
|
update_time wt_timestamp,
|
|
version wt_version,
|
|
attributes bytea not null,
|
|
constraint host_catalog_fkey
|
|
foreign key (scope_id, public_id)
|
|
references host_catalog (scope_id, public_id)
|
|
on delete cascade
|
|
on update cascade,
|
|
constraint host_plugin_catalog_scope_id_name_uq
|
|
unique(scope_id, name)
|
|
);
|
|
|
|
create trigger update_version_column after update on host_plugin_catalog
|
|
for each row execute procedure update_version_column();
|
|
|
|
create trigger update_time_column before update on host_plugin_catalog
|
|
for each row execute procedure update_time_column();
|
|
|
|
create trigger default_create_time_column before insert on host_plugin_catalog
|
|
for each row execute procedure default_create_time();
|
|
|
|
create trigger immutable_columns before update on host_plugin_catalog
|
|
for each row execute procedure immutable_columns('public_id', 'scope_id', 'plugin_id', 'create_time');
|
|
|
|
create trigger insert_host_catalog_subtype before insert on host_plugin_catalog
|
|
for each row execute procedure insert_host_catalog_subtype();
|
|
|
|
create trigger update_host_catalog_subtype before update on host_plugin_catalog
|
|
for each row execute procedure update_host_catalog_subtype();
|
|
|
|
create trigger delete_host_catalog_subtype after delete on host_plugin_catalog
|
|
for each row execute procedure delete_host_catalog_subtype();
|
|
|
|
create table host_plugin_catalog_secret (
|
|
catalog_id wt_public_id primary key
|
|
constraint host_plugin_catalog_fkey
|
|
references host_plugin_catalog (public_id)
|
|
on delete cascade
|
|
on update cascade,
|
|
create_time wt_timestamp,
|
|
update_time wt_timestamp,
|
|
secret bytea not null -- encrypted value
|
|
constraint secret_must_not_be_empty
|
|
check(length(secret) > 0),
|
|
key_id wt_private_id not null
|
|
constraint kms_database_key_version_fkey
|
|
references kms_database_key_version (private_id)
|
|
on delete restrict
|
|
on update cascade
|
|
);
|
|
|
|
create trigger update_time_column before update on host_plugin_catalog_secret
|
|
for each row execute procedure update_time_column();
|
|
|
|
create trigger default_create_time_column before insert on host_plugin_catalog_secret
|
|
for each row execute procedure default_create_time();
|
|
|
|
create trigger immutable_columns before update on host_plugin_catalog_secret
|
|
for each row execute procedure immutable_columns('catalog_id', 'create_time');
|
|
|
|
create table host_plugin_set (
|
|
public_id wt_public_id primary key,
|
|
catalog_id wt_public_id not null
|
|
constraint host_plugin_catalog_fkey
|
|
references host_plugin_catalog (public_id)
|
|
on delete cascade
|
|
on update cascade,
|
|
name wt_name,
|
|
description text,
|
|
create_time wt_timestamp,
|
|
update_time wt_timestamp,
|
|
version wt_version,
|
|
attributes bytea not null,
|
|
constraint host_plugin_set_catalog_id_name_uq
|
|
unique(catalog_id, name),
|
|
constraint host_set_fkey
|
|
foreign key (catalog_id, public_id)
|
|
references host_set (catalog_id, public_id)
|
|
on delete cascade
|
|
on update cascade,
|
|
constraint host_plugin_set_catalog_id_public_id_uq
|
|
unique(catalog_id, public_id)
|
|
);
|
|
|
|
create trigger update_version_column after update on host_plugin_set
|
|
for each row execute procedure update_version_column();
|
|
|
|
create trigger update_time_column before update on host_plugin_set
|
|
for each row execute procedure update_time_column();
|
|
|
|
create trigger default_create_time_column before insert on host_plugin_set
|
|
for each row execute procedure default_create_time();
|
|
|
|
create trigger immutable_columns before update on host_plugin_set
|
|
for each row execute procedure immutable_columns('public_id', 'catalog_id','create_time');
|
|
|
|
create trigger insert_host_set_subtype before insert on host_plugin_set
|
|
for each row execute procedure insert_host_set_subtype();
|
|
|
|
create trigger delete_host_set_subtype after delete on host_plugin_set
|
|
for each row execute procedure delete_host_set_subtype();
|
|
|
|
|
|
-- TODO: Rebuild this table to appropriately cache or sync data from the
|
|
-- plugin'ed service.
|
|
-- host_plugin_host captures plugin based host data. This is only written to
|
|
-- from the controller and is not mutable directly by actions from the end
|
|
-- user.
|
|
create table host_plugin_host (
|
|
public_id wt_public_id primary key,
|
|
catalog_id wt_public_id not null
|
|
constraint host_plugin_catalog_fkey
|
|
references host_plugin_catalog (public_id)
|
|
on delete cascade
|
|
on update cascade,
|
|
name wt_name,
|
|
description text,
|
|
create_time wt_timestamp,
|
|
update_time wt_timestamp,
|
|
version wt_version,
|
|
|
|
-- TODO: Break out the address to match the domain model where a host
|
|
-- can have multiple addresses and relies on the set to select the
|
|
-- prefered one.
|
|
address text not null
|
|
constraint address_must_be_more_than_2_characters
|
|
check(length(trim(address)) > 2)
|
|
constraint address_must_be_less_than_256_characters
|
|
check(length(trim(address)) < 256),
|
|
|
|
constraint host_fkey
|
|
foreign key (catalog_id, public_id)
|
|
references host (catalog_id, public_id)
|
|
on delete cascade
|
|
on update cascade,
|
|
|
|
constraint host_plugin_host_catalog_id_name_uq
|
|
unique(catalog_id, name),
|
|
|
|
constraint host_plugin_host_catalog_id_public_id_uq
|
|
unique(catalog_id, public_id)
|
|
);
|
|
|
|
create trigger update_version_column after update on host_plugin_host
|
|
for each row execute procedure update_version_column();
|
|
|
|
create trigger update_time_column before update on host_plugin_host
|
|
for each row execute procedure update_time_column();
|
|
|
|
create trigger default_create_time_column before insert on host_plugin_host
|
|
for each row execute procedure default_create_time();
|
|
|
|
create trigger immutable_columns before update on host_plugin_host
|
|
for each row execute procedure immutable_columns('public_id', 'catalog_id','create_time');
|
|
|
|
create trigger insert_host_subtype before insert on host_plugin_host
|
|
for each row execute procedure insert_host_subtype();
|
|
|
|
create trigger delete_host_subtype after delete on host_plugin_host
|
|
for each row execute procedure delete_host_subtype();
|
|
|
|
|
|
insert into oplog_ticket (name, version)
|
|
values
|
|
('host_plugin_catalog', 1),
|
|
('host_plugin_catalog_secret', 1),
|
|
('host_plugin_set', 1);
|
|
|
|
commit;
|