-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SCRUM-3693: roll down MaTI DB between environments
- Loading branch information
Showing
10 changed files
with
158 additions
and
89 deletions.
There are no files selected for viewing
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
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
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
1 change: 1 addition & 0 deletions
1
src/main/java/org/alliancegenome/mati/repository/SubdomainSequenceRepository.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
68 changes: 68 additions & 0 deletions
68
src/main/java/org/alliancegenome/mati/rolldownrepository/DBRoller.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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.alliancegenome.mati.rolldownrepository; | ||
|
||
import io.quarkus.hibernate.orm.PersistenceUnit; | ||
import jakarta.enterprise.context.RequestScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.Query; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Rolls-down the MaTI database from one environment to other | ||
* prod -> beta | ||
* beta -> alpha | ||
*/ | ||
@RequestScoped | ||
public class DBRoller { | ||
|
||
@PersistenceUnit("rolldown") | ||
@Inject | ||
EntityManager entityManager; | ||
|
||
/** | ||
* Creates the SQL sentences for setting the PostgreSQL sequences values | ||
* @param subdomains the list of subdomains | ||
* @param counters a dictionary mapping subdomains to values (e.g. subdomain_person -> 120 ) | ||
* @return a list of SQL statements. For example: | ||
* [ SETVAL('subdomain_name1_seq',10) ... SETVAL('subdomain_nameN_seq',N) ] | ||
*/ | ||
private List<String> prepareSETVALStatements(List<String> subdomains, Map<String,Long> counters) { | ||
List<String> setVALStatements = new ArrayList<>(); | ||
for (String subdomain : subdomains) { | ||
if (counters.containsKey(subdomain)) { | ||
Long counter = counters.get(subdomain); | ||
if (counter > 0) { | ||
setVALStatements.add("SETVAL('subdomain_" + subdomain + "_seq'," + counter + ")"); | ||
} | ||
} | ||
} | ||
return setVALStatements; | ||
} | ||
|
||
/** | ||
* Rolls down the values from one environment to other | ||
* @param subdomains the list of subdomains | ||
* @param counters a dictionary mapping subdomains to values (e.g. subdomain_reference -> 20 ) | ||
* @return a success/failure value | ||
*/ | ||
public boolean setSubdomainCounters(List<String> subdomains, Map<String,Long> counters) { | ||
List<String> setStatements = prepareSETVALStatements(subdomains, counters); | ||
if (!setStatements.isEmpty()) { | ||
String body = String.join(",", setStatements); | ||
String sql = "SELECT " + body; | ||
Query query = entityManager.createNativeQuery(sql); | ||
try { | ||
int num_queries = query.getResultList().size(); | ||
if (num_queries == setStatements.size()) { | ||
return true; | ||
} | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
junit.jupiter.testclass.order.default = \ | ||
org.junit.jupiter.api.ClassOrderer$OrderAnnotation |