-- astiumcdr
ALTER TABLE astiumcdr ADD CONSTRAINT astiumcdr_src_company_constraint FOREIGN KEY (src_company) REFERENCES company (id);
ALTER TABLE astiumcdr ADD CONSTRAINT astiumcdr_src_department_constraint FOREIGN KEY (src_department) REFERENCES department (id);
ALTER TABLE astiumcdr ADD CONSTRAINT astiumcdr_src_contact_constraint FOREIGN KEY (src_contact) REFERENCES contact (id);
ALTER TABLE astiumcdr ADD CONSTRAINT astiumcdr_dial_company_constraint FOREIGN KEY (dial_company) REFERENCES company (id);
ALTER TABLE astiumcdr ADD CONSTRAINT astiumcdr_dial_department_constraint FOREIGN KEY (dial_department) REFERENCES department (id);
ALTER TABLE astiumcdr ADD CONSTRAINT astiumcdr_dial_contact_constraint FOREIGN KEY (dial_contact) REFERENCES contact (id);
ALTER TABLE astiumcdr ADD CONSTRAINT astiumcdr_ans_company_constraint FOREIGN KEY (ans_company) REFERENCES company (id);
ALTER TABLE astiumcdr ADD CONSTRAINT astiumcdr_ans_department_constraint FOREIGN KEY (ans_department) REFERENCES department (id);
ALTER TABLE astiumcdr ADD CONSTRAINT astiumcdr_ans_contact_constraint FOREIGN KEY (ans_contact) REFERENCES contact (id);
ALTER TABLE astiumcdr ADD CONSTRAINT astiumcdr_chrg_company_constraint FOREIGN KEY (chrg_company) REFERENCES company (id);
ALTER TABLE astiumcdr ADD CONSTRAINT astiumcdr_chrg_department_constraint FOREIGN KEY (chrg_department) REFERENCES department (id);
ALTER TABLE astiumcdr ADD CONSTRAINT astiumcdr_chrg_contact_constraint FOREIGN KEY (chrg_contact) REFERENCES contact (id);

-- astium
ALTER TABLE astium ADD CONSTRAINT astium_src_subnet_constraint FOREIGN KEY (subnet) REFERENCES subnet (id);

-- cmc
ALTER TABLE cmc ADD CONSTRAINT cmc_company_constraint FOREIGN KEY (company) REFERENCES company (id);

-- company
ALTER TABLE company ADD CONSTRAINT zonetab_timezone_constraint FOREIGN KEY (timezone) REFERENCES zonetab(timezone);

-- contacthist
ALTER TABLE contacthist ADD CONSTRAINT contacthist_contact_constraint FOREIGN KEY (contact) REFERENCES company (id);

-- contact_number
ALTER TABLE contact_number ADD CONSTRAINT contact_number_company_constraint FOREIGN KEY (company) REFERENCES company (id);

-- contact_pickupgroup
ALTER TABLE contact_pickupgroup ADD CONSTRAINT contact_pickupgroup_contact_constraint FOREIGN KEY (contact) REFERENCES company (id);
ALTER TABLE contact_pickupgroup ADD CONSTRAINT contact_pickupgroup_pickupgroup_constraint FOREIGN KEY (pickupgroup) REFERENCES pickupgroup (id);

-- contact
ALTER TABLE contact ADD CONSTRAINT contact_company_constraint FOREIGN KEY (company) REFERENCES company (id);
ALTER TABLE contact ADD CONSTRAINT contact_parkinglot_constraint FOREIGN KEY (parkinglot) REFERENCES parkinglot (id);

-- department
ALTER TABLE department ADD CONSTRAINT department_receptionist_constraint FOREIGN KEY (receptionist) REFERENCES phoneline (id);

-- extrafield
ALTER TABLE extrafield ADD CONSTRAINT extrafield_company_constraint FOREIGN KEY (company) REFERENCES company (id);

-- inbound
ALTER TABLE inbound ADD CONSTRAINT inbound_greeting_constraint  FOREIGN KEY (greeting) REFERENCES soundfile(id);

-- ivr
ALTER TABLE ivr ADD CONSTRAINT ivr_phoneline_constraint FOREIGN KEY (phoneline) REFERENCES phoneline (id);

-- lease
ALTER TABLE lease ADD CONSTRAINT lease_subnet_constraint FOREIGN KEY (subnet) REFERENCES subnet (id);

-- local_network
ALTER TABLE local_network ADD CONSTRAINT local_network_astium_constraint FOREIGN KEY (astium) REFERENCES astium (id);

-- messaging_input
ALTER TABLE messaging_input ADD CONSTRAINT messaging_input_messaging_constraint FOREIGN KEY (messaging) REFERENCES messaging (id);
ALTER TABLE messaging_input ADD CONSTRAINT messaging_input_switch_constraint FOREIGN KEY (switch) REFERENCES switch (id);

-- messaging_output
ALTER TABLE messaging_output ADD CONSTRAINT messaging_output_messaging_constraint FOREIGN KEY (messaging) REFERENCES messaging (id);
ALTER TABLE messaging_output ADD CONSTRAINT messaging_output_switch_constraint FOREIGN KEY (switch) REFERENCES switch (id);

-- messaging
ALTER TABLE messaging ADD CONSTRAINT messaging_phoneline_constraint FOREIGN KEY (phoneline) REFERENCES phoneline (id);

-- permissions
ALTER TABLE permissions ADD CONSTRAINT permissions_company_constraint FOREIGN KEY (company) REFERENCES company (id);
ALTER TABLE permissions ADD CONSTRAINT permissions_contacttype_constraint FOREIGN KEY (contacttype) REFERENCES contacttype (id);

-- phoneline_forwarding
ALTER TABLE phoneline_forwarding ADD CONSTRAINT phoneline_forwarding_contacttype_constraint FOREIGN KEY (contacttype) REFERENCES contacttype (id);

-- phoneline_schedule
ALTER TABLE phoneline_schedule ADD CONSTRAINT phoneline_schedule_phoneline_constraint FOREIGN KEY (phoneline) REFERENCES phoneline (id);
ALTER TABLE phoneline_schedule ADD CONSTRAINT phoneline_schedule_schedule_constraint FOREIGN KEY (schedule) REFERENCES schedule (id);

-- phoneline
ALTER TABLE phoneline ADD CONSTRAINT phoneline_contact_constraint FOREIGN KEY (contact) REFERENCES contact (id);

--phone
ALTER TABLE phone ADD CONSTRAINT phone_astium_constraint FOREIGN KEY (astium) REFERENCES astium (id);
ALTER TABLE phone ADD CONSTRAINT phone_phoneline_constraint FOREIGN KEY (phoneline) REFERENCES phoneline (id);
ALTER TABLE phone ADD CONSTRAINT phone_pairedwith_constraint FOREIGN KEY (pairedwith) REFERENCES phone (id);

-- pickupgroup
ALTER TABLE pickupgroup ADD CONSTRAINT pickupgroup_company_constraint FOREIGN KEY (company) REFERENCES company (id);

-- presence
ALTER TABLE presence ADD CONSTRAINT presence_company_constraint FOREIGN KEY (company) REFERENCES company (id);
ALTER TABLE presence ADD CONSTRAINT presence_department_constraint FOREIGN KEY (department) REFERENCES department (id);
ALTER TABLE presence ADD CONSTRAINT presence_contact_constraint FOREIGN KEY (contact) REFERENCES contact (id);

-- profile
ALTER TABLE profile ADD CONSTRAINT profile_phoneline_constraint FOREIGN KEY (phoneline) REFERENCES phoneline (id);

-- qprc
ALTER TABLE qprc ADD CONSTRAINT qprc_company_constraint FOREIGN KEY (company) REFERENCES company (id);

-- queuelog
ALTER TABLE queuelog ADD CONSTRAINT queuelog_queue_constraint FOREIGN KEY (queue) REFERENCES queue (id);

-- queue
ALTER TABLE queue ADD CONSTRAINT queue_department_constraint FOREIGN KEY (department) REFERENCES department (id);

-- ringgroup
ALTER TABLE ringgroup ADD CONSTRAINT ringgroup_department_constraint FOREIGN KEY (department) REFERENCES department (id);

-- soundfile
ALTER TABLE soundfile ADD CONSTRAINT soundfile_phoneline_constraint FOREIGN KEY (phoneline) REFERENCES phoneline (id);

-- switch
ALTER TABLE switch ADD CONSTRAINT switch_company_constraint FOREIGN KEY (company) REFERENCES company (id);
ALTER TABLE switch ADD CONSTRAINT switch_phoneline_constraint FOREIGN KEY (phoneline) REFERENCES phoneline (id);

-- wakeup
ALTER TABLE wakeup ADD CONSTRAINT wakeup_contact_constraint FOREIGN KEY (contact) REFERENCES contact (id);



