create table buckets( id bigserial primary key, group_id bigint not null references groups(id) on delete cascade, created_by bigint not null references users(id), name text not null, description text, icon_key text, budget_limit_dollars numeric(12,2), position integer not null default 0, created_at timestamptz not null default now() ); create index buckets_group_id_idx on buckets(group_id); create table bucket_tags( bucket_id bigint not null references buckets(id) on delete cascade, tag_id bigint not null references tags(id) on delete cascade, created_at timestamptz not null default now(), primary key (bucket_id, tag_id) ); create index bucket_tags_bucket_idx on bucket_tags(bucket_id); create index bucket_tags_tag_idx on bucket_tags(tag_id);