ALTER TABLE expedition ADD COLUMN gallery_id int;
ALTER TABLE expedition ADD FOREIGN KEY (gallery_id) REFERENCES gallery(id) ON DELETE SET NULL ON UPDATE CASCADE;

ALTER TABLE expedition ADD COLUMN map_big_image int;
ALTER TABLE expedition ADD FOREIGN KEY (map_big_image) REFERENCES file(id) ON DELETE SET NULL ON UPDATE CASCADE;

ALTER TABLE static_text DROP CONSTRAINT "static_text_FK_1";
ALTER TABLE static_text ADD FOREIGN KEY (static_text_group_id) REFERENCES static_text_group(id) ON UPDATE CASCADE ON DELETE CASCADE;

DROP TRIGGER remove_static_expedition_texts;
CREATE OR REPLACE FUNCTION remove_expedition() RETURNS trigger AS '
		BEGIN
			DELETE FROM static_text_group WHERE id IN (OLD.col_left_group_id, OLD.col_right_group_id);
		RETURN old;
			END
			' LANGUAGE plpgsql;

CREATE TRIGGER remove_static_expedition_texts BEFORE DELETE ON expedition
  FOR EACH ROW EXECUTE PROCEDURE remove_expedition();
  
ALTER TABLE expedition DROP CONSTRAINT "expedition_FK_2";
ALTER TABLE expedition DROP CONSTRAINT "expedition_FK_3";

DROP TRIGGER remove_static_reports_texts;
CREATE OR REPLACE FUNCTION remove_reports() RETURNS trigger AS '
		BEGIN
			DELETE FROM static_text_group WHERE id IN (OLD.report_group_id);
		RETURN old;
			END
' LANGUAGE plpgsql;

CREATE TRIGGER remove_static_reports_texts BEFORE DELETE ON expedition_reports
  FOR EACH ROW EXECUTE PROCEDURE remove_reports();
  
ALTER TABLE expedition_reports DROP CONSTRAINT "expedition_reports_FK_1";
ALTER TABLE expedition_reports ADD FOREIGN KEY (report_group_id) REFERENCES static_text_group(id) ON DELETE SET NULL;

ALTER TABLE expedition ADD COLUMN thumb_info VARCHAR(255);

ALTER TABLE expedition_reports ADD COLUMN show_button BOOLEAN DEFAULT FALSE;