alter table rental_bookings
  add column if not exists relation_group_key text;

update rental_bookings
set relation_group_key = concat(
  coalesce(project_number, 'BOOK'),
  '::',
  coalesce(project_name, ''),
  '::',
  start_date::text,
  '::',
  end_date::text,
  '::',
  coalesce(to_char(start_time, 'HH24:MI'), ''),
  '::',
  coalesce(to_char(end_time, 'HH24:MI'), '')
)
where relation_group_key is null;

alter table rental_bookings
  alter column relation_group_key set not null;

create index if not exists rental_bookings_relation_group_key_idx
  on rental_bookings (relation_group_key);
