DO $$
BEGIN

    IF NOT EXISTS (
        SELECT 1 
        FROM information_schema.columns 
        WHERE table_name = 't_mo_date_type' 
        AND column_name = 'v006medicalterms'
    ) THEN
        ALTER TABLE ies.t_mo_date_type 
        ADD COLUMN v006medicalterms INT;

        ALTER TABLE ies.t_mo_date_type 
        ADD CONSTRAINT fk_t_v006_medical_terms_t_mo_date_type_v006medicalterms
        FOREIGN KEY (v006medicalterms) 
        REFERENCES ies.t_v006_medical_terms (idump);
    END IF;
END $$;