Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: e820c75d by Tony CHEMIT at 2018-05-10T10:53:14Z Fix migration - - - - - 2 changed files: - persistence/src/main/java/fr/ird/observe/persistence/migration/DataSourceMigrationForVersion_6_0.java - − persistence/src/main/java/fr/ird/observe/persistence/migration/DataSourceMigrationForVersion_7_0_RC_4.java Changes: ===================================== persistence/src/main/java/fr/ird/observe/persistence/migration/DataSourceMigrationForVersion_6_0.java ===================================== --- a/persistence/src/main/java/fr/ird/observe/persistence/migration/DataSourceMigrationForVersion_6_0.java +++ b/persistence/src/main/java/fr/ird/observe/persistence/migration/DataSourceMigrationForVersion_6_0.java @@ -28,8 +28,8 @@ import com.google.common.collect.ImmutableMap; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.nuiton.topia.persistence.support.TopiaSqlQuery; -import org.nuiton.topia.service.migration.resources.MigrationVersionResourceExecutor; import org.nuiton.topia.service.migration.resources.MigrationVersionResource; +import org.nuiton.topia.service.migration.resources.MigrationVersionResourceExecutor; import org.nuiton.version.Versions; import java.sql.Connection; @@ -315,75 +315,6 @@ public class DataSourceMigrationForVersion_6_0 extends MigrationVersionResource executor.writeSql(String.format("UPDATE observe_longline.weightMeasure SET weightMeasureType2 = '%s' WHERE weightMeasureType = '%s';", newId, oldId)); } } - - @Override - protected void prepareMigrationScript(TopiaSqlSupport topiaSqlSupport, List<String> queries, boolean showSql, boolean showProgression) { - Boolean withTriggers = topiaSqlSupport.findSingleResult(new TopiaSqlQuery<Boolean>() { - @Override - public PreparedStatement prepareQuery(Connection connection) throws SQLException { - return connection.prepareStatement("select exists(select * from pg_proc where proname = 'sync_activity_the_geom');"); - } - - @Override - public Boolean prepareResult(ResultSet resultSet) throws SQLException { - return resultSet.getBoolean(1); - } - }); - - if (withTriggers) { - queries.add("CREATE OR REPLACE function sync_activity_the_geom () returns trigger as '\n" + - "BEGIN\n" + - " IF (TG_OP = ''DELETE'') THEN\n" + - " RETURN OLD;\n" + - " END IF;\n" + - " IF (NEW.latitude IS NULL OR NEW.longitude IS NULL) THEN\n" + - " -- on ne calcule pas le point postgis si au moins une des -- coordonnees n est pas renseignee\n" + - " RAISE NOTICE ''No latitude or longitude, can not compute postgis field for id % '', NEW.topiaId;\n" + - " NEW.the_geom := NULL;\n" + - " return NEW;\n" + - " END IF;\n" + - " IF (TG_OP = ''UPDATE'' AND NEW.latitude = OLD.latitude AND NEW.longitude = OLD.longitude)\n" + - " THEN\n" + - " -- on ne calcule pas le point postgis si les coordonnées n''ont pas changées\n" + - " return NEW;\n" + - " END IF;\n" + - " RAISE NOTICE ''Will compute the_geom for activite % - latitude % and longitude %'', NEW.topiaId, NEW.latitude, NEW.longitude;\n" + - " -- affectation du point\n" + - " NEW.the_geom := ST_SetSRID(ST_MakePoint(NEW.longitude,NEW.latitude), 4326);\n" + - " RAISE NOTICE ''Computed for activity % latitude % and longitude %, the_geom %'', NEW.topiaId, NEW.latitude, NEW.longitude, NEW.the_geom;\n" + - "\n" + - " RETURN NEW;\n" + - "END\n" + - "'\n" + - "LANGUAGE 'plpgsql';\n"); - queries.add("CREATE OR REPLACE function sync_harbour_the_geom () returns trigger as '\n" + - "BEGIN\n" + - " IF (TG_OP = ''DELETE'') THEN\n" + - " RETURN OLD;\n" + - " END IF;\n" + - " IF (NEW.latitude IS NULL OR NEW.longitude IS NULL) THEN\n" + - " -- on ne calcule pas le point postgis si au moins une des -- coordonnees n est pas renseignee\n" + - " RAISE NOTICE ''No latitude or longitude, can not compute postgis field for id % '', NEW.topiaId;\n" + - " NEW.the_geom := NULL;\n" + - " return NEW;\n" + - " END IF;\n" + - " IF (TG_OP = ''UPDATE'' AND NEW.latitude = OLD.latitude AND NEW.longitude = OLD.longitude)\n" + - " THEN\n" + - " -- on ne calcule pas le point postgis si les coordonnées n''ont pas changées\n" + - " return NEW;\n" + - " END IF;\n" + - " RAISE NOTICE ''Will compute the_geom for harbour % - latitude % and longitude %'', NEW.topiaId, NEW.latitude, NEW.longitude;\n" + - " -- affectation du point\n" + - " NEW.the_geom := ST_SetSRID(ST_MakePoint(NEW.longitude,NEW.latitude), 4326);\n" + - " RAISE NOTICE ''Computed for harbour % latitude % and longitude %, the_geom %'', NEW.topiaId, NEW.latitude, NEW.longitude, NEW.the_geom;\n" + - " RETURN NEW;\n" + - "END\n" + - "'\n" + - "LANGUAGE 'plpgsql';"); - addScript("00", "fix_trigger", queries); - } - super.prepareMigrationScript(topiaSqlSupport, queries, showSql, showProgression); - } } } ===================================== persistence/src/main/java/fr/ird/observe/persistence/migration/DataSourceMigrationForVersion_7_0_RC_4.java deleted ===================================== --- a/persistence/src/main/java/fr/ird/observe/persistence/migration/DataSourceMigrationForVersion_7_0_RC_4.java +++ /dev/null @@ -1,90 +0,0 @@ -package fr.ird.observe.persistence.migration; - -/*- - * #%L - * ObServe :: Persistence - * %% - * Copyright (C) 2008 - 2018 IRD, Code Lutin, Ultreia.io - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.nuiton.topia.persistence.support.TopiaSqlSupport; - -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - -/** - * Created on 27/10/16. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 6.0 - */ -@MigrationVersion(version = "6.1") -public class DataSourceMigrationForVersion_7_0_RC_4 extends AbstractObserveMigrationCallBack { - - DataSourceMigrationForVersion_7_0_RC_4(AbstractDataSourceMigration callBack, String scriptSuffix) { - super(DataSourceMigrationForVersion_7_0_RC_4.class, callBack, scriptSuffix); - } - - @Override - protected void prepareMigrationScript(TopiaSqlSupport topiaSqlSupport, List<String> queries, boolean showSql, boolean showProgression) { - - addScript("01", "add_object_operation", queries); - addScript("02", "add_object_material", queries); - addScript("03", "add_floating_object_part", queries); - addScript("04", "remove_dcp_fields", queries); - - Map<String, String> speciesGroupIdMapping = new TreeMap<>(); - speciesGroupIdMapping.put("fr.ird.observe.entities.referentiel.SpeciesGroup#1445863056144#0.9820877553253712", "INSERT INTO OBSERVE_COMMON.SPECIESGROUP (TOPIAID, TOPIAVERSION, TOPIACREATEDATE, LASTUPDATEDATE, CODE, URI, NEEDCOMMENT, STATUS, LABEL1, LABEL2, LABEL3, LABEL4, LABEL5, LABEL6, LABEL7, LABEL8) VALUES ('fr.ird.observe.entities.referentiel.SpeciesGroup#1445863056144#0.9820877553253712', 1, '2015-10-26 16:37:36.144000000', '2016-12-06 15:54:27.727005000', '11', null, false, 1, 'Rays', 'Raies', 'Rayas', null, null, null, null, null);"); - speciesGroupIdMapping.put("fr.ird.observe.entities.referentiel.SpeciesGroup#1239832683690#0.24333033683679461", "INSERT INTO OBSERVE_COMMON.SPECIESGROUP (TOPIAID, TOPIAVERSION, TOPIACREATEDATE, LASTUPDATEDATE, CODE, URI, NEEDCOMMENT, STATUS, LABEL1, LABEL2, LABEL3, LABEL4, LABEL5, LABEL6, LABEL7, LABEL8) VALUES ('fr.ird.observe.entities.referentiel.SpeciesGroup#1239832683690#0.24333033683679461', 14, '2009-04-15 00:00:00.003000000', '2016-12-06 15:54:27.727005000', '4', null, false, 1, 'Turtles', 'Tortues', 'Tortugas', null, null, null, null, null);"); - speciesGroupIdMapping.put("fr.ird.observe.entities.referentiel.SpeciesGroup#1446014286433#0.6480183366605247", "INSERT INTO OBSERVE_COMMON.SPECIESGROUP (TOPIAID, TOPIAVERSION, TOPIACREATEDATE, LASTUPDATEDATE, CODE, URI, NEEDCOMMENT, STATUS, LABEL1, LABEL2, LABEL3, LABEL4, LABEL5, LABEL6, LABEL7, LABEL8) VALUES ('fr.ird.observe.entities.referentiel.SpeciesGroup#1446014286433#0.6480183366605247', 1, '2015-10-28 10:38:06.432000000', '2016-12-06 15:54:27.727005000', '12', null, false, 1, 'Whale shark', 'Requin-baleine', 'Tiburón ballena', null, null, null, null, null);"); - speciesGroupIdMapping.put("fr.ird.observe.entities.referentiel.SpeciesGroup#1239832683689#0.7120116158620075", "INSERT INTO OBSERVE_COMMON.SPECIESGROUP (TOPIAID, TOPIAVERSION, TOPIACREATEDATE, LASTUPDATEDATE, CODE, URI, NEEDCOMMENT, STATUS, LABEL1, LABEL2, LABEL3, LABEL4, LABEL5, LABEL6, LABEL7, LABEL8) VALUES ('fr.ird.observe.entities.referentiel.SpeciesGroup#1239832683689#0.7120116158620075', 17, '2009-04-15 00:00:00.001000000', '2017-02-28 15:04:55.370000000', '2', null, false, 1, 'Sharks', 'Requins', 'Tiburones', null, null, null, null, null);"); - - Set<String> existingSpeciesGroupIds = getTopiaIds(topiaSqlSupport, "OBSERVE_COMMON.SPECIESGROUP"); - for (Map.Entry<String, String> entry : speciesGroupIdMapping.entrySet()) { - if (!existingSpeciesGroupIds.contains(entry.getKey())) { - queries.add(entry.getValue()); - } - } - addScript("05", "add_species_group_release_mode", queries); - addScript("06", "add_non_target_catch_release", queries); - addScript("07", "drop_table_sizemeasuretype", queries); - addScript("08", "add_floating_object_fields", queries); - addScript("09", "fill_object_material", queries); - - } - - public static class H2DataSourceMigrationForVersion extends DataSourceMigrationForVersion_7_0_RC_4 { - - public H2DataSourceMigrationForVersion(AbstractDataSourceMigration callBack) { - super(callBack, H2DataSourceMigration.TYPE); - } - - } - - public static class PGDataSourceMigrationForVersion extends DataSourceMigrationForVersion_7_0_RC_4 { - - public PGDataSourceMigrationForVersion(AbstractDataSourceMigration callBack) { - super(callBack, PGDataSourceMigration.TYPE); - } - - } - -} - View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/e820c75d813ec854d539cacff1c7... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/e820c75d813ec854d539cacff1c7... You're receiving this email because of your account on gitlab.com.