
ALTER TABLE `etp_patient_refus_etp` ADD `pre_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE etp_patient_refus_etp SET pre_code = @counter := @counter + 1 ORDER BY pre_code;
ALTER TABLE `ran`.`etp_patient_refus_etp` DROP PRIMARY KEY, ADD UNIQUE `uniq_pre_mre` (`per_code`, `mre_code`) USING BTREE;
ALTER TABLE `etp_patient_refus_etp` ADD PRIMARY KEY(`pre_code`);
ALTER TABLE `etp_patient_refus_etp` CHANGE `pre_code` `pre_code` INT(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `etp_cs_recueil_item` ADD `cri_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE etp_cs_recueil_item SET cri_code = @counter := @counter + 1 ORDER BY cri_code;
ALTER TABLE `ran`.`etp_cs_recueil_item` DROP PRIMARY KEY, ADD UNIQUE `uniq_cse_ite` (`ite_code`, `cse_code`) USING BTREE;
ALTER TABLE `etp_cs_recueil_item` ADD PRIMARY KEY(`cri_code`);
ALTER TABLE `etp_cs_recueil_item` CHANGE `cri_code` `cri_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `etp_cs_synthese` ADD `cssy_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE etp_cs_synthese SET cssy_code = @counter := @counter + 1 ORDER BY cssy_code;
ALTER TABLE `ran`.`etp_cs_synthese` DROP PRIMARY KEY, ADD UNIQUE `uniq_cse_ite` (`cse_code`, `ite_code`) USING BTREE;
ALTER TABLE `etp_cs_synthese` ADD PRIMARY KEY(`cssy_code`);
ALTER TABLE `etp_cs_synthese` CHANGE `cssy_code` `cssy_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `etp_prof_cs_item_etp` ADD `pcie_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE etp_prof_cs_item_etp SET pcie_code = @counter := @counter + 1 ORDER BY pcie_code;
ALTER TABLE `ran`.`etp_prof_cs_item_etp` DROP PRIMARY KEY, ADD UNIQUE `uniq_ite_pce` (`ite_code`, `pce_code`) USING BTREE;
ALTER TABLE `etp_prof_cs_item_etp` ADD PRIMARY KEY(`pcie_code`);
ALTER TABLE `etp_prof_cs_item_etp` CHANGE `pcie_code` `pcie_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `etp_item_ss_item` ADD `isi_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE etp_item_ss_item SET isi_code = @counter := @counter + 1 ORDER BY isi_code;
ALTER TABLE `ran`.`etp_item_ss_item` DROP PRIMARY KEY, ADD UNIQUE `uniq_pere_fils` (`etp_ite_code_pere`, `etp_ite_code_fils`) USING BTREE;
ALTER TABLE `etp_item_ss_item` ADD PRIMARY KEY(`isi_code`);
ALTER TABLE `etp_item_ss_item` CHANGE `isi_code` `isi_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `etp_intervenant` ADD `itvt_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE etp_intervenant SET itvt_code = @counter := @counter + 1 ORDER BY itvt_code;
ALTER TABLE `ran`.`etp_intervenant` DROP PRIMARY KEY, ADD UNIQUE `uniq_personne` (`per_code`) USING BTREE;
ALTER TABLE `etp_intervenant` ADD PRIMARY KEY(`itvt_code`);
ALTER TABLE `etp_intervenant` CHANGE `itvt_code` `itvt_code` INT(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `etp_intervention` ADD `itvt_code` INT NULL AFTER `lit_code`;
ALTER TABLE `etp_intervention` ADD INDEX(`itvt_code`);
ALTER TABLE `etp_intervention` ADD  FOREIGN KEY (`itvt_code`) REFERENCES `etp_intervenant`(`itvt_code`) ON DELETE RESTRICT ON UPDATE RESTRICT;
update `etp_intervention` itv set itvt_code=(select itvt_code from etp_intervenant itvt where itvt.per_code=itv.per_code);

ALTER TABLE `etp_cs_evaluation` ADD `csev_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE etp_cs_evaluation SET csev_code = @counter := @counter + 1 ORDER BY csev_code;
ALTER TABLE `ran`.`etp_cs_evaluation` DROP PRIMARY KEY, ADD UNIQUE (`cse_code`) USING BTREE;
ALTER TABLE `etp_cs_evaluation` ADD PRIMARY KEY(`csev_code`);
ALTER TABLE `etp_cs_evaluation` CHANGE `csev_code` `csev_code` INT(11) NOT NULL AUTO_INCREMENT;


/*
ALTER TABLE `etp_cs_recueil_donnees` ADD `crd_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE etp_cs_recueil_donnees SET crd_code = @counter := @counter + 1 ORDER BY crd_code;
ALTER TABLE `ran`.`etp_cs_recueil_donnees` DROP PRIMARY KEY, ADD UNIQUE (`cse_code`) USING BTREE;
ALTER TABLE `etp_cs_recueil_donnees` ADD PRIMARY KEY(`crd_code`);
ALTER TABLE `etp_cs_recueil_donnees` CHANGE `crd_code` `crd_code` INT(11) NOT NULL AUTO_INCREMENT;
*/



ALTER TABLE `etp_cs_prog_interv` ADD `cspi_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE etp_cs_prog_interv SET cspi_code = @counter := @counter + 1 ORDER BY cspi_code;
ALTER TABLE `ran`.`etp_cs_prog_interv` DROP PRIMARY KEY, ADD UNIQUE `uniq_cse_itv` (`cse_code`, `itv_code`) USING BTREE;
ALTER TABLE `etp_cs_prog_interv` ADD PRIMARY KEY(`cspi_code`);
ALTER TABLE `etp_cs_prog_interv` CHANGE `cspi_code` `cspi_code` INT(11) NOT NULL AUTO_INCREMENT;



ALTER TABLE `etp_cs_suivi` ADD `cssu_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE etp_cs_suivi SET cssu_code = @counter := @counter + 1 ORDER BY cssu_code;
ALTER TABLE `ran`.`etp_cs_suivi` DROP PRIMARY KEY, ADD UNIQUE `uniq_cse` (`cse_code`) USING BTREE;
ALTER TABLE `etp_cs_suivi` ADD PRIMARY KEY(`cssu_code`);
ALTER TABLE `etp_cs_suivi` CHANGE `cssu_code` `cssu_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `etp_eval_competence` ADD `evco_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE etp_eval_competence SET evco_code = @counter := @counter + 1 ORDER BY evco_code;
ALTER TABLE `ran`.`etp_eval_competence` DROP PRIMARY KEY, ADD UNIQUE `uniq_ite_cse` (`ite_code`, `cse_code`);
ALTER TABLE `etp_eval_competence` ADD PRIMARY KEY(`evco_code`);
ALTER TABLE `etp_eval_competence` CHANGE `evco_code` `evco_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `etp_eval_init_competence` ADD `eic_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE etp_eval_init_competence SET eic_code = @counter := @counter + 1 ORDER BY eic_code;
ALTER TABLE `ran`.`etp_eval_init_competence` DROP PRIMARY KEY, ADD UNIQUE `uniq_ite_cse` (`ite_code`, `cse_code`) USING BTREE;
ALTER TABLE `etp_eval_init_competence` ADD PRIMARY KEY(`eic_code`);
ALTER TABLE `etp_eval_init_competence` CHANGE `eic_code` `eic_code` INT(11) NOT NULL AUTO_INCREMENT;



ALTER TABLE `consult_param_bio` ADD `cspbi_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE consult_param_bio SET cspbi_code = @counter := @counter + 1 ORDER BY cspbi_code;
ALTER TABLE `ran`.`consult_param_bio` DROP PRIMARY KEY, ADD UNIQUE `uniq_csl_pbi` (`csl_code`, `pbi_code`) USING BTREE;
ALTER TABLE `consult_param_bio` ADD PRIMARY KEY(`cspbi_code`);
ALTER TABLE `consult_param_bio` CHANGE `cspbi_code` `cspbi_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `donneur_param_bio` ADD `dpbi_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE donneur_param_bio SET dpbi_code = @counter := @counter + 1 ORDER BY dpbi_code;
ALTER TABLE `ran`.`donneur_param_bio` DROP PRIMARY KEY, ADD UNIQUE `uniq_gre_pbi` (`gre_code`, `pbi_code`) USING BTREE;
ALTER TABLE `donneur_param_bio` ADD PRIMARY KEY(`dpbi_code`);
ALTER TABLE `donneur_param_bio` CHANGE `dpbi_code` `dpbi_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `profil_cs_param_bio` ADD `prcpbi_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE profil_cs_param_bio SET pcspbi_code = @counter := @counter + 1 ORDER BY pcspbi_code;
ALTER TABLE `ran`.`profil_cs_param_bio` DROP PRIMARY KEY, ADD UNIQUE `uniq_pbi_prc` (`pbi_code`, `prc_code`) USING BTREE;
ALTER TABLE `profil_cs_param_bio` ADD PRIMARY KEY(`prcpbi_code`);
ALTER TABLE `profil_cs_param_bio` CHANGE `prcpbi_code` `prcpbi_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `hla_rein_droit` ADD `hrd_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE hla_rein_droit SET hrd_code = @counter := @counter + 1 ORDER BY hrd_code;
ALTER TABLE `ran`.`hla_rein_droit` DROP PRIMARY KEY, ADD UNIQUE `uniq_gre_pbi` (`gre_code`, `pbi_code`) USING BTREE;
ALTER TABLE `hla_rein_droit` ADD PRIMARY KEY(`hrd_code`);
ALTER TABLE `hla_rein_droit` CHANGE `hrd_code` `hrd_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `hla_rein_gauche` ADD `hrg_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE hla_rein_gauche SET hrg_code = @counter := @counter + 1 ORDER BY hrg_code;
ALTER TABLE `ran`.`hla_rein_gauche` DROP PRIMARY KEY, ADD UNIQUE `uniq_gre_pbi` (`gre_code`, `pbi_code`) USING BTREE;
ALTER TABLE `hla_rein_gauche` ADD PRIMARY KEY(`hrg_code`);
ALTER TABLE `hla_rein_gauche` CHANGE `hrg_code` `hrg_code` INT(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `personne_telephone` ADD `pertel_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE personne_telephone SET pertel_code = @counter := @counter + 1 ORDER BY pertel_code;
ALTER TABLE `ran`.`personne_telephone` DROP PRIMARY KEY, ADD UNIQUE `uniq_per_tel` (`per_code`, `tel_code`) USING BTREE;
ALTER TABLE `personne_telephone` ADD PRIMARY KEY(`pertel_code`);
ALTER TABLE `personne_telephone` CHANGE `pertel_code` `pertel_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `patients_consultes` ADD `perpat_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE patients_consultes SET perpat_code = @counter := @counter + 1 ORDER BY perpat_code;
ALTER TABLE `ran`.`patients_consultes` DROP PRIMARY KEY, ADD UNIQUE `uniq_per_pat` (`per_code_uti`, `per_code_pat`) USING BTREE;
ALTER TABLE `patients_consultes` ADD PRIMARY KEY(`perpat_code`);
ALTER TABLE `patients_consultes` CHANGE `perpat_code` `perpat_code` INT(11) NOT NULL AUTO_INCREMENT;




ALTER TABLE `prescription` ADD `pre_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE prescription SET pre_code = @counter := @counter + 1 ORDER BY pre_code;
ALTER TABLE `ran`.`prescription` DROP PRIMARY KEY, ADD UNIQUE `uniq_pre_code` (`ord_code`, `medi_code`) USING BTREE;
ALTER TABLE `prescription` ADD PRIMARY KEY(`pre_code`);
ALTER TABLE `prescription` CHANGE `pre_code` `pre_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `patient_medecin_trait` ADD `pmt_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE patient_medecin_trait SET pmt_code = @counter := @counter + 1 ORDER BY pmt_code;
ALTER TABLE `ran`.`patient_medecin_trait` DROP PRIMARY KEY, ADD UNIQUE `uniq_pmt_code` (`per_code_med`, `per_code_pat`) USING BTREE;
ALTER TABLE `patient_medecin_trait` ADD PRIMARY KEY(`pmt_code`);
ALTER TABLE `patient_medecin_trait` CHANGE `pmt_code` `pmt_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE utilisateur_pwd_reset DROP PRIMARY KEY;
ALTER TABLE `utilisateur_pwd_reset` ADD `upr_code` INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`upr_code`);
ALTER TABLE `utilisateur_pwd_reset` ADD UNIQUE(`upr_token`);
SET @counter = 0;
UPDATE utilisateur_pwd_reset SET upr_code = @counter := @counter + 1 ORDER BY upr_code;



ALTER TABLE `courrier_edite` ADD `cou_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE courrier_edite SET cou_code = @counter := @counter + 1 ORDER BY cou_code;
ALTER TABLE `ran`.`courrier_edite` DROP PRIMARY KEY, ADD UNIQUE `uniq_csl_per` (`csl_code`, `per_code`) USING BTREE;
ALTER TABLE `courrier_edite` ADD PRIMARY KEY(`cou_code`);
ALTER TABLE `courrier_edite` CHANGE `cou_code` `cou_code` INT(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `donneur` ADD `don_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE donneur SET don_code = @counter := @counter + 1 ORDER BY don_code;
ALTER TABLE `donneur` DROP PRIMARY KEY, ADD UNIQUE (`gre_code`) USING BTREE;
ALTER TABLE `donneur` ADD PRIMARY KEY(`don_code`);
ALTER TABLE `donneur` CHANGE `don_code` `don_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `donneur_decede` ADD `dod_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE donneur_decede SET dod_code = @counter := @counter + 1 ORDER BY dod_code;
ALTER TABLE `donneur_decede` DROP PRIMARY KEY, ADD UNIQUE (`gre_code`) USING BTREE;
ALTER TABLE `donneur_decede` ADD PRIMARY KEY(`dod_code`);
ALTER TABLE `donneur_decede` CHANGE `dod_code` `dod_code` INT(11) NOT NULL AUTO_INCREMENT;



ALTER TABLE `donneur_vivant` ADD `dov_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE donneur_vivant SET dov_code = @counter := @counter + 1 ORDER BY dov_code;
ALTER TABLE `donneur_vivant` DROP PRIMARY KEY, ADD UNIQUE (`gre_code`) USING BTREE;
ALTER TABLE `donneur_vivant` ADD PRIMARY KEY(`dov_code`);
ALTER TABLE `donneur_vivant` CHANGE `dov_code` `dov_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `greffe_incompatibilite_hla` ADD `gih_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE `greffe_incompatibilite_hla` SET gih_code = @counter := @counter + 1 ORDER BY gih_code;
ALTER TABLE `greffe_incompatibilite_hla` DROP PRIMARY KEY, ADD UNIQUE `uniq_gre_hla_vih` (`hla_code`, `gre_code`,`vih_code`) USING BTREE;
ALTER TABLE `greffe_incompatibilite_hla` ADD PRIMARY KEY(`gih_code`);
ALTER TABLE `greffe_incompatibilite_hla` CHANGE `gih_code` `gih_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `valeur_statut_viro` ADD `vsr_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE `valeur_statut_viro` SET vsr_code = @counter := @counter + 1 ORDER BY vsr_code;
ALTER TABLE `valeur_statut_viro` DROP PRIMARY KEY, ADD UNIQUE `uniq_gre_hla_vih` (`gre_code`, `svi_code`,`vir_code`) USING BTREE;
ALTER TABLE `valeur_statut_viro` ADD PRIMARY KEY(`vsr_code`);
ALTER TABLE `valeur_statut_viro` CHANGE `vsr_code` `vsr_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `donneur_serologie` ADD `dse_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE `donneur_serologie` SET dse_code = @counter := @counter + 1 ORDER BY dse_code;
ALTER TABLE `donneur_serologie` DROP PRIMARY KEY, ADD UNIQUE `uniq_gre_ser_sts` (`gre_code`, `ser_code`,`sts_code`) USING BTREE;
ALTER TABLE `donneur_serologie` ADD PRIMARY KEY(`dse_code`);
ALTER TABLE `donneur_serologie` CHANGE `dse_code` `dse_code` INT(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `greffe_cond_immuno_supp` ADD `gci_code` INT NOT NULL FIRST;
SET @counter = 0;
UPDATE `greffe_cond_immuno_supp` SET gci_code = @counter := @counter + 1 ORDER BY gci_code;
ALTER TABLE `greffe_cond_immuno_supp` DROP PRIMARY KEY, ADD UNIQUE `uniq_gre_cis` (`gre_code`, `cis_code`) USING BTREE;
ALTER TABLE `greffe_cond_immuno_supp` ADD PRIMARY KEY(`gci_code`);
ALTER TABLE `greffe_cond_immuno_supp` CHANGE `gci_code` `gci_code` INT(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `etp_courrier_edite` CHANGE `coe_code` `coe_code` INT(6) NOT NULL AUTO_INCREMENT;
ALTER TABLE `medicament` CHANGE `medi_code` `medi_code` INT(6) NOT NULL AUTO_INCREMENT;
ALTER TABLE `patient_comment` CHANGE `pat_com` `pat_com` INT(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `etp_cs` CHANGE `cse_code` `cse_code` bigint(20) NOT NULL AUTO_INCREMENT;
ALTER TABLE `etp_intervention` CHANGE `itv_code` `itv_code` INT(6) NOT NULL AUTO_INCREMENT;
ALTER TABLE `etp_specialite` CHANGE `spe_code` `spe_code` smallint(6) NOT NULL AUTO_INCREMENT;
ALTER TABLE `etp_lieu_intervention` CHANGE `lit_code` `lit_code` int(3) NOT NULL AUTO_INCREMENT;
ALTER TABLE `etp_signet_courrier` CHANGE `stc_code` `stc_code` int(2) NOT NULL AUTO_INCREMENT;

