create table if not exists model_sample_sets (
    id varchar(64) primary key,
    model_group_id varchar(64) not null references model_groups(id),
    name varchar(256) not null,
    version varchar(32) not null,
    purpose varchar(64) not null,
    sample_ids jsonb not null,
    locked boolean not null default true,
    created_by varchar(128) not null,
    created_at timestamptz not null default now(),
    unique(model_group_id, name, version)
);

insert into model_sample_sets(id, model_group_id, name, version, purpose, sample_ids, locked, created_by)
select 'regression-' || replace(model_group_id, 'group-', ''), model_group_id,
       '标准回归集', 'v1.0', 'regression', jsonb_agg(id order by id), true, '算法数据管理员'
from model_samples
group by model_group_id
on conflict (id) do nothing;
