create table if not exists public.seedream_layer_compositions ( job_id text primary key references public.generation_jobs(id) on delete cascade, owner_id text not null, base_asset_id text not null, base_visible boolean not null default true, layers jsonb not null default '[]'::jsonb, version bigint not null default 1 check (version > 0), created_at timestamptz not null default now(), updated_at timestamptz not null default now(), constraint seedream_layer_compositions_layers_array_check check (jsonb_typeof(layers) = 'array') ); create index if not exists seedream_layer_compositions_owner_updated_idx on public.seedream_layer_compositions(owner_id, updated_at desc);