ALTER TABLE `individual_consumers` RENAME TO `consumers_individual`;
ALTER TABLE `legal_consumers` RENAME TO `consumers_legal`;

ALTER TABLE `consumers_individual`
  RENAME INDEX `individual_consumers_mobile_number_consumer_id_key` TO `consumers_individual_mobile_number_consumer_id_key`;
ALTER TABLE `consumers_individual`
  RENAME INDEX `individual_consumers_partner_id_national_code_key` TO `consumers_individual_partner_id_national_code_key`;
ALTER TABLE `consumers_legal`
  RENAME INDEX `legal_consumers_partner_id_registration_code_key` TO `consumers_legal_partner_id_registration_code_key`;

ALTER TABLE `consumers_individual` DROP FOREIGN KEY `individual_consumers_partner_id_fkey`;
ALTER TABLE `consumers_individual` DROP FOREIGN KEY `individual_consumers_consumer_id_fkey`;
ALTER TABLE `consumers_legal` DROP FOREIGN KEY `legal_consumers_partner_id_fkey`;
ALTER TABLE `consumers_legal` DROP FOREIGN KEY `legal_consumers_consumer_id_fkey`;

ALTER TABLE `consumers_individual`
  ADD CONSTRAINT `consumers_individual_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  ADD CONSTRAINT `consumers_individual_consumer_id_fkey` FOREIGN KEY (`consumer_id`) REFERENCES `consumers`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `consumers_legal`
  ADD CONSTRAINT `consumers_legal_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  ADD CONSTRAINT `consumers_legal_consumer_id_fkey` FOREIGN KEY (`consumer_id`) REFERENCES `consumers`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
