alter table contract_store
    add column contract_id bigint;
alter table contract_room
    add column contract_id bigint;

update contract_store join contract on contract_store.contract_number = contract.contract_number
set contract_store.contract_id = contract.id;

update contract_room join contract on contract_room.contract_number = contract.contract_number
set contract_room.contract_id = contract.id;

rename table contract_room to contract_room_type;

update contract_room_type
set store_id = store_info_id;

alter table contract_room_type
    drop column store_info_id;

alter table residence_room_type
    change store_info_id store_id bigint null;

