45 lines
1.9 KiB
PL/PgSQL
45 lines
1.9 KiB
PL/PgSQL
begin;
|
|
|
|
-- One remote host identity per company. Project hosts are views of this source;
|
|
-- an imported credential never chooses the local company or project.
|
|
create table device_b2_hosts (
|
|
id uuid primary key,
|
|
owner_scope_id uuid not null references device_owner_scopes(id),
|
|
remote_host_id text not null,
|
|
endpoint text not null,
|
|
fingerprint text not null check (fingerprint ~ '^[a-f0-9]{64}$'),
|
|
integration_id text not null check (integration_id ~ '^[a-f0-9]{32}$'),
|
|
authority text not null check (authority in ('host','contours')),
|
|
secret_ref text not null,
|
|
revision bigint not null default 1,
|
|
created_at timestamptz not null default now(),
|
|
updated_at timestamptz not null default now(),
|
|
unique(owner_scope_id, remote_host_id),
|
|
unique(id, owner_scope_id)
|
|
);
|
|
create table device_b2_host_views (
|
|
host_id uuid not null,
|
|
project_id uuid not null,
|
|
owner_scope_id uuid not null,
|
|
source_id uuid not null,
|
|
primary key(host_id),
|
|
foreign key(host_id, project_id, owner_scope_id)
|
|
references device_infrastructure_hosts(id, project_id, owner_scope_id),
|
|
foreign key(source_id, owner_scope_id) references device_b2_hosts(id, owner_scope_id)
|
|
);
|
|
create table device_b2_contour_links (
|
|
source_id uuid not null,
|
|
contour_id text not null check (contour_id ~ '^[a-f0-9]{32}$'),
|
|
project_id uuid not null,
|
|
owner_scope_id uuid not null,
|
|
created_by_ref text not null,
|
|
created_at timestamptz not null default now(),
|
|
primary key(source_id, contour_id),
|
|
foreign key(source_id, owner_scope_id) references device_b2_hosts(id, owner_scope_id),
|
|
foreign key(project_id, owner_scope_id) references device_projects(id, owner_scope_id)
|
|
);
|
|
comment on table device_b2_hosts is 'nodedc.device-b2-foundation/v1';
|
|
comment on table device_b2_host_views is 'nodedc.device-b2-foundation/v1';
|
|
comment on table device_b2_contour_links is 'nodedc.device-b2-foundation/v1';
|
|
commit;
|