Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe

Commits:

2 changed files:

Changes:

  • persistence/src/main/java/fr/ird/observe/persistence/migration/DataSourceMigrationForVersion_7_0_RC_9.java
    ... ... @@ -22,7 +22,10 @@ package fr.ird.observe.persistence.migration;
    22 22
      * #L%
    
    23 23
      */
    
    24 24
     
    
    25
    +import java.sql.PreparedStatement;
    
    26
    +import java.sql.ResultSet;
    
    25 27
     import java.util.List;
    
    28
    +import org.apache.commons.lang3.mutable.MutableBoolean;
    
    26 29
     import org.nuiton.topia.persistence.support.TopiaSqlSupport;
    
    27 30
     
    
    28 31
     /**
    
    ... ... @@ -37,17 +40,23 @@ public abstract class DataSourceMigrationForVersion_7_0_RC_9 extends AbstractObs
    37 40
             super(DataSourceMigrationForVersion_7_0_RC_9.class, callBack, scriptSuffix);
    
    38 41
         }
    
    39 42
     
    
    40
    -    protected abstract void removeForeignKeys(TopiaSqlSupport topiaSqlSupport, List<String> queries);
    
    43
    +    protected abstract boolean removeForeignKeys(TopiaSqlSupport topiaSqlSupport, List<String> queries);
    
    41 44
     
    
    42 45
         @Override
    
    43 46
         protected void prepareMigrationScript(TopiaSqlSupport topiaSqlSupport, List<String> queries, boolean showSql, boolean showProgression) {
    
    44 47
     
    
    45
    -        removeForeignKeys(topiaSqlSupport, queries);
    
    46
    -
    
    48
    +        boolean withTrigger = removeForeignKeys(topiaSqlSupport, queries);
    
    49
    +        if (withTrigger) {
    
    50
    +            queries.add("DROP TRIGGER IF EXISTS tr_sync_seine_activity_the_geom ON observe_seine.activity");
    
    51
    +            queries.add("DROP TRIGGER IF EXISTS tr_sync_longline_activity_the_geom ON observe_longline.activity");
    
    52
    +        }
    
    47 53
             addScript("01", "rename_longline_obs", queries);
    
    48 54
             addScript("02", "move_wind_referential", queries);
    
    49 55
             addScript("03", "wind_i18n", queries);
    
    50 56
     
    
    57
    +        if (withTrigger) {
    
    58
    +
    
    59
    +        }
    
    51 60
         }
    
    52 61
     
    
    53 62
         public static class H2DataSourceMigrationForVersion extends DataSourceMigrationForVersion_7_0_RC_9 {
    
    ... ... @@ -57,7 +66,7 @@ public abstract class DataSourceMigrationForVersion_7_0_RC_9 extends AbstractObs
    57 66
             }
    
    58 67
     
    
    59 68
             @Override
    
    60
    -        protected void removeForeignKeys(TopiaSqlSupport topiaSqlSupport, List<String> queries) {
    
    69
    +        protected boolean removeForeignKeys(TopiaSqlSupport topiaSqlSupport, List<String> queries) {
    
    61 70
                 H2DataSourceMigration.removeFK(topiaSqlSupport, "observe_longline", "Encounter", "activity", queries);
    
    62 71
                 H2DataSourceMigration.removeFK(topiaSqlSupport, "observe_longline", "SensorUsed", "activity", queries);
    
    63 72
                 H2DataSourceMigration.removeFK(topiaSqlSupport, "observe_longline", "Activity", "set", queries);
    
    ... ... @@ -71,6 +80,7 @@ public abstract class DataSourceMigrationForVersion_7_0_RC_9 extends AbstractObs
    71 80
                 H2DataSourceMigration.removeFK(topiaSqlSupport, "observe_longline", "Section", "set", queries);
    
    72 81
                 H2DataSourceMigration.removeFK(topiaSqlSupport, "observe_longline", "Tdr", "set", queries);
    
    73 82
                 H2DataSourceMigration.removeFK(topiaSqlSupport, "observe_seine", "Activity", "wind", queries);
    
    83
    +            return false;
    
    74 84
             }
    
    75 85
         }
    
    76 86
     
    
    ... ... @@ -81,7 +91,7 @@ public abstract class DataSourceMigrationForVersion_7_0_RC_9 extends AbstractObs
    81 91
             }
    
    82 92
     
    
    83 93
             @Override
    
    84
    -        protected void removeForeignKeys(TopiaSqlSupport topiaSqlSupport, List<String> queries) {
    
    94
    +        protected boolean removeForeignKeys(TopiaSqlSupport topiaSqlSupport, List<String> queries) {
    
    85 95
                 PGDataSourceMigration.removeFK(topiaSqlSupport, "observe_longline", "encounter", "activity", queries);
    
    86 96
                 PGDataSourceMigration.removeFK(topiaSqlSupport, "observe_longline", "sensorUsed", "activity", queries);
    
    87 97
                 PGDataSourceMigration.removeFK(topiaSqlSupport, "observe_longline", "Activity", "set", queries);
    
    ... ... @@ -95,6 +105,16 @@ public abstract class DataSourceMigrationForVersion_7_0_RC_9 extends AbstractObs
    95 105
                 PGDataSourceMigration.removeFK(topiaSqlSupport, "observe_longline", "Section", "set", queries);
    
    96 106
                 PGDataSourceMigration.removeFK(topiaSqlSupport, "observe_longline", "Tdr", "set", queries);
    
    97 107
                 PGDataSourceMigration.removeFK(topiaSqlSupport, "observe_seine", "Activity", "wind", queries);
    
    108
    +
    
    109
    +            MutableBoolean result = new MutableBoolean(false);
    
    110
    +            topiaSqlSupport.doSqlWork(connection -> {
    
    111
    +                PreparedStatement preparedStatement = connection.prepareStatement(" SELECT tgname FROM pg_trigger WHERE  tgrelid = 'observe_seine.activity'::regclass AND tgname LIKE 'tr_sync%';");
    
    112
    +                ResultSet resultSet = preparedStatement.executeQuery();
    
    113
    +                if (resultSet.next()) {
    
    114
    +                    result.setTrue();
    
    115
    +                }
    
    116
    +            });
    
    117
    +            return result.booleanValue();
    
    98 118
             }
    
    99 119
         }
    
    100 120
     
    

  • persistence/src/main/resources/db/migration/6.904/04_add_triggers-PG.sql
    1
    +---
    
    2
    +-- #%L
    
    3
    +-- ObServe :: Persistence
    
    4
    +-- %%
    
    5
    +-- Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
    
    6
    +-- %%
    
    7
    +-- This program is free software: you can redistribute it and/or modify
    
    8
    +-- it under the terms of the GNU General Public License as
    
    9
    +-- published by the Free Software Foundation, either version 3 of the
    
    10
    +-- License, or (at your option) any later version.
    
    11
    +--
    
    12
    +-- This program is distributed in the hope that it will be useful,
    
    13
    +-- but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14
    +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15
    +-- GNU General Public License for more details.
    
    16
    +--
    
    17
    +-- You should have received a copy of the GNU General Public
    
    18
    +-- License along with this program.  If not, see
    
    19
    +-- <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    20
    +-- #L%
    
    21
    +---
    
    22
    +
    
    23
    +CREATE TRIGGER tr_sync_seine_activity_the_geom BEFORE insert or update ON observe_seine.activity FOR EACH ROW EXECUTE PROCEDURE sync_activity_the_geom();
    
    24
    +CREATE TRIGGER tr_sync_longline_activity_obs_the_geom BEFORE insert or update ON observe_longline.activityObs FOR EACH ROW EXECUTE PROCEDURE sync_activity_the_geom();
    \ No newline at end of file