feat(platform): add managed data product history plane

This commit is contained in:
Codex
2026-07-18 14:38:06 +03:00
parent 02816c4352
commit 3c5d8f6cef
34 changed files with 2091 additions and 163 deletions
+64 -3
View File
@@ -55,7 +55,7 @@ export async function migrate(pool) {
payload_ref text,
payload_bytes integer,
received_at timestamptz not null,
expires_at timestamptz not null,
expires_at timestamptz,
check (payload is not null or payload_ref is not null)
)
`);
@@ -72,7 +72,7 @@ export async function migrate(pool) {
connection_id text not null,
provider_id text not null,
allowed_data_product_ids jsonb not null,
expires_at timestamptz not null,
expires_at timestamptz,
active boolean not null default true,
created_at timestamptz not null default now(),
rotated_at timestamptz,
@@ -89,6 +89,7 @@ export async function migrate(pool) {
await pool.query("alter table external_data_plane_writer_bindings add column if not exists binding_key text");
await pool.query("alter table external_data_plane_writer_bindings add column if not exists request_hash text");
await pool.query("alter table external_data_plane_writer_bindings add column if not exists generation integer not null default 1");
await pool.query("alter table external_data_plane_writer_bindings alter column expires_at drop not null");
await pool.query(`
do $$
begin
@@ -113,6 +114,18 @@ export async function migrate(pool) {
or (binding_key is not null and request_hash ~ '^[a-f0-9]{64}$')
);
end if;
if not exists (
select 1 from pg_constraint
where conrelid = 'external_data_plane_writer_bindings'::regclass
and conname = 'external_data_plane_writer_bindings_lifecycle_ck'
) then
alter table external_data_plane_writer_bindings
add constraint external_data_plane_writer_bindings_lifecycle_ck
check (
(binding_key is null and expires_at is not null)
or (binding_key is not null and expires_at is null)
) not valid;
end if;
end
$$
`);
@@ -123,15 +136,19 @@ export async function migrate(pool) {
create table if not exists external_data_plane_reader_bindings (
id uuid primary key,
token_hash text not null unique,
binding_key text,
request_hash text,
generation integer not null default 1,
tenant_id text not null,
connection_id text not null,
provider_id text not null,
allowed_data_product_ids jsonb not null,
expires_at timestamptz not null,
expires_at timestamptz,
active boolean not null default true,
created_at timestamptz not null default now(),
rotated_at timestamptz,
revoked_at timestamptz,
check (generation > 0),
check (
case when jsonb_typeof(allowed_data_product_ids) = 'array'
then jsonb_array_length(allowed_data_product_ids) > 0
@@ -140,6 +157,50 @@ export async function migrate(pool) {
)
)
`);
await pool.query("alter table external_data_plane_reader_bindings add column if not exists binding_key text");
await pool.query("alter table external_data_plane_reader_bindings add column if not exists request_hash text");
await pool.query("alter table external_data_plane_reader_bindings add column if not exists generation integer not null default 1");
await pool.query("alter table external_data_plane_reader_bindings alter column expires_at drop not null");
await pool.query(`
do $$
begin
if not exists (
select 1 from pg_constraint
where conrelid = 'external_data_plane_reader_bindings'::regclass
and conname = 'external_data_plane_reader_bindings_generation_positive_ck'
) then
alter table external_data_plane_reader_bindings
add constraint external_data_plane_reader_bindings_generation_positive_ck
check (generation > 0);
end if;
if not exists (
select 1 from pg_constraint
where conrelid = 'external_data_plane_reader_bindings'::regclass
and conname = 'external_data_plane_reader_bindings_managed_metadata_ck'
) then
alter table external_data_plane_reader_bindings
add constraint external_data_plane_reader_bindings_managed_metadata_ck
check (
(binding_key is null and request_hash is null)
or (binding_key is not null and request_hash ~ '^[a-f0-9]{64}$')
);
end if;
if not exists (
select 1 from pg_constraint
where conrelid = 'external_data_plane_reader_bindings'::regclass
and conname = 'external_data_plane_reader_bindings_lifecycle_ck'
) then
alter table external_data_plane_reader_bindings
add constraint external_data_plane_reader_bindings_lifecycle_ck
check (
(binding_key is null and expires_at is not null)
or (binding_key is not null and expires_at is null)
);
end if;
end
$$
`);
await pool.query("create unique index if not exists external_data_plane_reader_bindings_managed_key_idx on external_data_plane_reader_bindings (binding_key, generation) where binding_key is not null");
await pool.query("create index if not exists external_data_plane_reader_bindings_active_idx on external_data_plane_reader_bindings (active, expires_at)");
await pool.query(`