DELETE FROM `admsis_protik`.`crm_opportunity` WHERE (`id` = '204');
DELETE FROM `admsis_protik`.`crm_opportunity` WHERE (`id` = '203');
DELETE FROM `admsis_protik`.`crm_opportunity` WHERE (`id` = '202');
DELETE FROM `admsis_protik`.`crm_opportunity` WHERE (`id` = '201');

DELETE FROM `admsis_protik`.`crm_lead` WHERE (`id` = '1');

DELETE FROM `admsis_protik`.`crm_follow_up` WHERE (`id` = '103');


ALTER TABLE `admsis_protik`.`crm_opportunity` 
DROP FOREIGN KEY `fk_lead1`;
ALTER TABLE `admsis_protik`.`crm_opportunity` 
DROP COLUMN `crm_lead_id`,
DROP INDEX `fk_lead_idx` ;
;


DROP TABLE `admsis_protik`.`crm_lead`;

ALTER TABLE `admsis_protik`.`crm_prospection` 
RENAME TO  `admsis_protik`.`crm_lead` ;

ALTER TABLE `admsis_protik`.`crm_opportunity` 
DROP FOREIGN KEY `fk_prospection1`;
ALTER TABLE `admsis_protik`.`crm_opportunity` 
CHANGE COLUMN `crm_prospection_id` `crm_lead_id` INT(11) NULL DEFAULT NULL ,
DROP INDEX `fk_prospection_idx` ,
ADD INDEX `fk_crm_lead_idx` (`crm_lead_id` ASC);
;


ALTER TABLE `admsis_protik`.`crm_opportunity` 
ADD CONSTRAINT `fk_lead1`
  FOREIGN KEY (`crm_lead_id`)
  REFERENCES `admsis_protik`.`crm_lead` (`id`);


ALTER TABLE `admsis_protik`.`crm_lead` 
ADD COLUMN `crm_lead_category_id` INT(11) NULL AFTER `user_id`,
ADD COLUMN `crm_lead_status_id` INT(11) NULL AFTER `crm_lead_category_id`;


ALTER TABLE `admsis_protik`.`crm_lead` 
ADD INDEX `crm_lead_category_idfk_1_idx` (`crm_lead_category_id` ASC),
ADD INDEX `crm_lead_status_idfk_1_idx` (`crm_lead_status_id` ASC);
;

ALTER TABLE `admsis_protik`.`crm_lead` 
ADD CONSTRAINT `crm_lead_category_idfk_1`
  FOREIGN KEY (`crm_lead_category_id`)
  REFERENCES `admsis_protik`.`crm_lead_category` (`id`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION,
ADD CONSTRAINT `crm_lead_status_idfk_1`
  FOREIGN KEY (`crm_lead_status_id`)
  REFERENCES `admsis_protik`.`crm_lead_status` (`id`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION;


ALTER TABLE `admsis_protik`.`crm_follow_up` 
DROP FOREIGN KEY `fk_crm_prospection_id1`;
ALTER TABLE `admsis_protik`.`crm_follow_up` 
CHANGE COLUMN `crm_prospection_id` `crm_lead_id` INT(11) NULL DEFAULT NULL ,
DROP INDEX `fk_crm_prospection_id1_idx` ,
ADD INDEX `fk_crm_lead_id1_idx` (`crm_lead_id` ASC);
;

ALTER TABLE `admsis_protik`.`crm_follow_up` 
ADD CONSTRAINT `fk_crm_lead_id1`
  FOREIGN KEY (`crm_lead_id`)
  REFERENCES `admsis_protik`.`crm_lead` (`id`);


ALTER TABLE `admsis_protik`.`crm_contact` 
DROP FOREIGN KEY `fk_crm_prospection_id_2`;
ALTER TABLE `admsis_protik`.`crm_contact` 
CHANGE COLUMN `crm_prospection_id` `crm_lead_id` INT(11) NULL DEFAULT NULL ,
DROP INDEX `fk_crm_prospection_id1_idx` ,
ADD INDEX `fk_crm_lead_id1_idx` (`crm_lead_id` ASC);
;
ALTER TABLE `admsis_protik`.`crm_contact` 
ADD CONSTRAINT `fk_crm_lead_id_2`
  FOREIGN KEY (`crm_lead_id`)
  REFERENCES `admsis_protik`.`crm_lead` (`id`);


ALTER TABLE `admsis_protik`.`crm_lead` 
ADD COLUMN `crm_tag_id` INT(11) NULL AFTER `crm_lead_status_id`;

ALTER TABLE `admsis_protik`.`crm_lead` 
ADD INDEX `crm_lead_tag_idfk_1_idx` (`crm_tag_id` ASC);
;

ALTER TABLE `admsis_protik`.`crm_lead` 
ADD CONSTRAINT `crm_lead_tag_idfk_1`
  FOREIGN KEY (`crm_tag_id`)
  REFERENCES `admsis_protik`.`crm_tag` (`id`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION;
