-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backend/frontend] Fix simulation import (#1067)
- Loading branch information
1 parent
3a89f05
commit 6c12f36
Showing
16 changed files
with
712 additions
and
381 deletions.
There are no files selected for viewing
432 changes: 265 additions & 167 deletions
432
openbas-api/src/main/java/io/openbas/importer/V1_DataImporter.java
Large diffs are not rendered by default.
Oops, something went wrong.
43 changes: 28 additions & 15 deletions
43
openbas-api/src/main/java/io/openbas/migration/V3_16__Add_array_union_agg_method.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,45 @@ | ||
package io.openbas.migration; | ||
|
||
import lombok.extern.java.Log; | ||
import org.flywaydb.core.api.migration.BaseJavaMigration; | ||
import org.flywaydb.core.api.migration.Context; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.Statement; | ||
|
||
@Log | ||
@Component | ||
public class V3_16__Add_array_union_agg_method extends BaseJavaMigration { | ||
|
||
@Override | ||
public void migrate(Context context) throws Exception { | ||
Connection connection = context.getConnection(); | ||
Statement select = connection.createStatement(); | ||
select.execute("CREATE FUNCTION array_union(a ANYARRAY, b ANYARRAY)" | ||
+ " RETURNS ANYARRAY AS" | ||
+ " $$" | ||
+ "SELECT array_agg(DISTINCT x)" | ||
+ "FROM (" | ||
+ " SELECT unnest(a) x" | ||
+ " UNION ALL SELECT unnest(b)" | ||
+ " ) AS u" | ||
+ " $$ LANGUAGE SQL;" | ||
+ "CREATE AGGREGATE array_union_agg(ANYARRAY) (" | ||
+ " SFUNC = array_union," | ||
+ " STYPE = ANYARRAY," | ||
+ " INITCOND = '{}'" | ||
+ ");"); | ||
try (Statement statement = connection.createStatement()) { | ||
ResultSet rs = statement.executeQuery( | ||
"SELECT EXISTS (SELECT 1 FROM pg_proc WHERE proname = 'array_union');"); | ||
|
||
boolean functionExists = false; | ||
if (rs.next()) { | ||
functionExists = rs.getBoolean(1); | ||
} | ||
if (!functionExists) { | ||
statement.execute("CREATE FUNCTION array_union(a ANYARRAY, b ANYARRAY)" | ||
+ " RETURNS ANYARRAY AS" | ||
+ " $$" | ||
+ "SELECT array_agg(DISTINCT x)" | ||
+ "FROM (" | ||
+ " SELECT unnest(a) x" | ||
+ " UNION ALL SELECT unnest(b)" | ||
+ " ) AS u" | ||
+ " $$ LANGUAGE SQL;" | ||
+ "CREATE AGGREGATE array_union_agg(ANYARRAY) (" | ||
+ " SFUNC = array_union," | ||
+ " STYPE = ANYARRAY," | ||
+ " INITCOND = '{}'" | ||
+ ");"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.