-- FundingSchemes
ALTER TABLE contracttypes ADD COLUMN description character varying(255);
ALTER TABLE contracttypes RENAME COLUMN contracttypeid TO fundingschemeid;
ALTER TABLE contracttypes RENAME TO fundingschemes;
ALTER INDEX contracttypes_pkey RENAME TO fundingschemes_pkey;

-- FrameworkPrograms
ALTER TABLE fundingprogrammes RENAME COLUMN fundingprogrammeid TO frameworkprogramid;
ALTER TABLE fundingprogrammes RENAME TO frameworkprograms;
ALTER INDEX fundingprogrammes_pkey RENAME TO frameworkprograms_pkey;

-- SpecificPrograms
ALTER TABLE specificprogrammes RENAME COLUMN specificprogrammeid TO specificprogramid;
ALTER TABLE specificprogrammes RENAME COLUMN hasfundingprogramme TO hasframeworkprogram;
ALTER TABLE specificprogrammes ADD COLUMN description text;
ALTER TABLE specificprogrammes ADD COLUMN description text;
ALTER INDEX specificprogrammes_pkey RENAME TO specificprograms_pkey;
ALTER INDEX specificprogrammes_hasfundingprogramme_idx RENAME TO specificprograms_hasframeworkprogram_idx;

-- Programs
ALTER TABLE subdivisions RENAME COLUMN subdivisionid TO programid;
ALTER TABLE subdivisions RENAME COLUMN hasspecificprogramme TO hasspecificprogram;
ALTER TABLE subdivisions RENAME TO programs;
ALTER INDEX subdivisions_pkey RENAME TO programs_pkey;
ALTER INDEX subdivisions_hasspecificprogramme_idx RENAME TO programs_hasSpecificProgram_idx;

-- Persons
ALTER TABLE persons ADD COLUMN projectid character varying(255);
ALTER TABLE persons ADD COLUMN participantorder character varying(255);
ALTER TABLE persons ADD COLUMN projectRole character varying(255);
ALTER TABLE persons ADD COLUMN email character varying(255);
ALTER TABLE persons ADD COLUMN fax character varying(255);
ALTER TABLE persons ADD COLUMN phone character varying(255);
ALTER TABLE persons ADD COLUMN function character varying(255);
	
-- Webresources
ALTER TABLE webresource RENAME TO webresources;
ALTER INDEX webresource_pkey RENAME TO webresources_pkey;

-- Organizations
ALTER TABLE organizations DROP COLUMN legal_status;
ALTER TABLE organizations ADD COLUMN legal_body boolean;
ALTER TABLE organizations ADD COLUMN legal_person boolean;
ALTER TABLE organizations ADD COLUMN non_profit boolean;
ALTER TABLE organizations ADD COLUMN research_organization boolean;
ALTER TABLE organizations ADD COLUMN higher_education boolean;
ALTER TABLE organizations ADD COLUMN international_organization_with_eur_interests boolean;
ALTER TABLE organizations ADD COLUMN international_organization boolean;
ALTER TABLE organizations ADD COLUMN enterprise boolean;
ALTER TABLE organizations ADD COLUMN sme_validated boolean;

-- Datasources
ALTER TABLE datasources ALTER COLUMN openairecompliant SET DEFAULT false;

-- Participants
ALTER TABLE participants DROP COLUMN beneficiary_number;
ALTER TABLE participants ADD COLUMN participant_number integer not null;ALTER TABLE datasources 
ALTER TABLE participants ALTER COLUMN coordinator SET DEFAULT false;
ALTER TABLE participants RENAME COLUMN person TO coordinating_person;
ALTER TABLE participants RENAME COLUMN organization TO resp_organization;

-- Projects
ALTER TABLE projects DROP COLUMN ec_project_website;
ALTER TABLE projects ADD COLUMN fundedhow character varying(255) 
ALTER TABLE projects ADD CONSTRAINT fkc123456a12345b12 FOREIGN KEY (fundedhow) REFERENCES fundingschemes(fundingschemeid);


-- projects_contracttypes
DROP TABLE projects_contracttypes;

-- Results
ALTER TABLE results ADD COLUMN original_identifier character varying(255);