-- Add the exportable preferences columns to the fields table and the required new tables (issue #388) -- ------ -- POSTGRESQL ALTER TABLE flexible_element ADD COLUMN exportable BOOLEAN NOT NULL DEFAULT TRUE; ALTER TABLE flexible_element ADD COLUMN globally_exportable BOOLEAN NOT NULL DEFAULT TRUE; -- Add tables and basic default settings for Global Export (issue #388) -- ------ -- tables in POSTGRESQL CREATE TABLE global_export ( id bigint NOT NULL, generated_date timestamp without time zone NOT NULL, organization_id integer NOT NULL ); CREATE TABLE global_export_content ( id bigint NOT NULL, csv_content text, project_model_name character varying(8192) NOT NULL, global_export_id bigint NOT NULL ); CREATE TABLE global_export_settings ( id bigint NOT NULL, auto_delete_frequency integer, auto_export_frequency integer, default_organization_export_format character varying(255), export_format character varying(255), last_export_date timestamp without time zone, locale_string character varying(4) NOT NULL, organization_id integer NOT NULL ); ALTER TABLE ONLY global_export_content ADD CONSTRAINT global_export_content_pkey PRIMARY KEY (id); ALTER TABLE ONLY global_export ADD CONSTRAINT global_export_pkey PRIMARY KEY (id); ALTER TABLE ONLY global_export_settings ADD CONSTRAINT global_export_settings_pkey PRIMARY KEY (id); ALTER TABLE ONLY global_export_settings ADD CONSTRAINT fk2fb477b2f85c2c3c FOREIGN KEY (organization_id) REFERENCES organization(id_organization); ALTER TABLE ONLY global_export ADD CONSTRAINT fk9e763fd0f85c2c3c FOREIGN KEY (organization_id) REFERENCES organization(id_organization); ALTER TABLE ONLY global_export_content ADD CONSTRAINT fkdca84b0af33647b9 FOREIGN KEY (global_export_id) REFERENCES global_export(id); -- POSTGRESQL INSERT INTO global_export_settings(id, auto_delete_frequency, auto_export_frequency, default_organization_export_format, export_format, last_export_date, locale_string, organization_id) SELECT nextval('hibernate_sequence'), NULL, NULL, 'XLS', 'XLS', NULL, 'fr', id_organization FROM organization; -- Changes the date type columns to timestamp to avoid time difference (issue #463) -- ------ -- POSTGRESQL ALTER TABLE userdatabase ALTER COLUMN startdate TYPE TIMESTAMP; ALTER TABLE project ALTER COLUMN end_date TYPE TIMESTAMP; ALTER TABLE project ALTER COLUMN close_date TYPE TIMESTAMP; ALTER TABLE personalevent ALTER COLUMN enddate TYPE TIMESTAMP WITH TIME ZONE; ALTER TABLE personalevent ALTER COLUMN startdate TYPE TIMESTAMP WITH TIME ZONE; -- Increases the indicator name length (issue #408). -- ------ ALTER TABLE indicator ALTER COLUMN name TYPE varchar(1024); -- Increases the indicator category length (issue #434). -- -----ALTER TABLE indicator ALTER COLUMN category TYPE varchar(1024); -- Merges 'risks' and 'hypothesis' columns of the log frame (issue #189). -- ------ -- POSTGRESQL ALTER TABLE log_frame_element ADD COLUMN risksAndAssumptions TEXT; -- MYSQL AND POSTGRESQL UPDATE log_frame_element SET risksAndAssumptions=( risks || '\n' || assumptions) WHERE char_length(assumptions)>0 and char_length(risks)>0; UPDATE log_frame_element SET risksAndAssumptions=risks WHERE (char_length(assumptions)=0 or assumptions is null) and char_length(risks)>0; UPDATE log_frame_element SET risksAndAssumptions=assumptions WHERE (char_length(risks)=0 or risks is null) and char_length(assumptions)>0; ALTER TABLE log_frame_element DROP risks; ALTER TABLE log_frame_element DROP assumptions; -- Add a date_deleted column to the table project_model and org_unit_model (issue #489) -- ------ -- POSTGRESQL ALTER TABLE org_unit_model ADD COLUMN date_deleted DATE; ALTER TABLE project_model ADD COLUMN date_deleted DATE; -- Increases the project code length (issue #504). -- ------ -- POSTGRESQL ALTER TABLE userdatabase ALTER COLUMN name TYPE varchar(50); -- Updates the countries ISO codes (issue #457) UPDATE Country SET ISO2 = 'BN' WHERE CountryId = 281; UPDATE Country SET ISO2 = 'CN' WHERE CountryId = 293; UPDATE Country SET ISO2 = 'GN' WHERE CountryId = 339; UPDATE Country SET ISO2 = 'HN' WHERE CountryId = 345; UPDATE Country SET ISO2 = 'IN' WHERE CountryId = 349; UPDATE Country SET ISO2 = 'MN' WHERE CountryId = 394; UPDATE Country SET ISO2 = 'AN' WHERE CountryId = 404; UPDATE Country SET ISO2 = 'PN' WHERE CountryId = 423; UPDATE Country SET ISO2 = 'KN' WHERE CountryId = 434; UPDATE Country SET ISO2 = 'SN' WHERE CountryId = 443; UPDATE Country SET ISO2 = 'TN' WHERE CountryId = 472; UPDATE Country SET ISO2 = 'VN' WHERE CountryId = 487; -- Fixes issue with old inconsistent data in the log_frame_model table (issue #189) UPDATE log_frame_model SET a_gp_max=1, a_max=1, a_per_er_max=1, a_per_gp_max=1, a_enable_groups=false, er_enable_groups=false, p_enable_groups=false, so_enable_groups=false, er_gp_max=1, er_max=1, er_per_gp_max=1, er_per_so_max=1, p_gp_max=1, p_max=1, p_per_gp_max=1, so_gp_max=1, so_max=1, so_per_gp_max=1 WHERE name LIKE 'Auto-created default model at%'; -- Removes temporarily ACTIVITY INFO permission (issue #591) DELETE FROM global_permission WHERE permission = 'VIEW_ACTIVITYINFO'; -- Deletes the projects links linked to a deleted project (issue #565) DELETE FROM project_funding AS pf USING userdatabase AS ud WHERE ud.databaseid = pf.id_project_funded AND ud.datedeleted is not null; DELETE FROM project_funding AS pf USING userdatabase AS ud WHERE ud.databaseid = pf.id_project_funding AND ud.datedeleted is not null;