Skip to content

Commit a0e1d69

Browse files
bamthomasmvanzalu
andcommitted
fix: migrate ids from liquibase migration table
Migration ids were wrongly set and not unique so they've been changed on the following commit: 5a9fa8a The issue is that the automatic migration is crashing because ids have changed. We added an automated raw SQL migration step (on the liquibase table) in datashare that is fixing liquibase migrations. So this commit could be reverted after the next stable release (i.e. when all intalled users have been run once datashare with this commit). Co-authored-by: Maxime Vanza Lutonda <mvanzalu@users.noreply.github.com>
1 parent 2e3f4a5 commit a0e1d69

3 files changed

Lines changed: 35 additions & 22 deletions

File tree

datashare-api/src/main/java/org/icij/datashare/Repository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public interface Repository {
6666

6767
boolean save(User user);
6868
User getUser(String userId);
69+
// TODO: from version 21.0.3
70+
// remove this after version 22.0.0 (or in a few stable releases)
71+
void temporaryFixLiquibaseIds();
6972

7073
class AggregateList<T> {
7174
public final List<Aggregate<T>> aggregates;

datashare-app/src/main/java/org/icij/datashare/mode/CommonMode.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,10 @@ public Routes addExtensionsConfiguration(Routes routes) {
328328

329329
void configurePersistence() {
330330
RepositoryFactoryImpl repositoryFactory = new RepositoryFactoryImpl(propertiesProvider);
331-
bind(Repository.class).toInstance(repositoryFactory.createRepository());
331+
Repository repository = repositoryFactory.createRepository();
332+
// TODO: remove this in few stable releases (cf git commit comment)
333+
repository.temporaryFixLiquibaseIds();
334+
bind(Repository.class).toInstance(repository);
332335
bind(ApiKeyRepository.class).toInstance(repositoryFactory.createApiKeyRepository());
333336
bind(BatchSearchRepository.class).toInstance(repositoryFactory.createBatchSearchRepository());
334337
bind(CasbinRuleAdapter.class).toInstance(repositoryFactory.createCasbinRuleRepository());

datashare-db/src/main/java/org/icij/datashare/db/JooqRepository.java

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,8 @@
2626
import org.icij.datashare.text.Tag;
2727
import org.icij.datashare.text.nlp.Pipeline;
2828
import org.icij.datashare.user.User;
29-
import org.jooq.DSLContext;
30-
import org.jooq.Field;
31-
import org.jooq.InsertOnDuplicateSetMoreStep;
32-
import org.jooq.InsertValuesStep2;
33-
import org.jooq.InsertValuesStep3;
34-
import org.jooq.InsertValuesStep4;
35-
import org.jooq.InsertValuesStep5;
36-
import org.jooq.InsertValuesStep6;
37-
import org.jooq.InsertValuesStep9;
29+
import org.jooq.*;
3830
import org.jooq.Record;
39-
import org.jooq.Record1;
40-
import org.jooq.SQLDialect;
41-
import org.jooq.SelectConditionStep;
42-
import org.jooq.SelectJoinStep;
43-
import org.jooq.SelectOnConditionStep;
44-
import org.jooq.SelectSelectStep;
45-
import org.jooq.SortField;
46-
import org.jooq.UpdateConditionStep;
47-
import org.jooq.UpdateSetMoreStep;
4831
import org.jooq.exception.DataAccessException;
4932
import org.jooq.impl.DSL;
5033
import org.slf4j.LoggerFactory;
@@ -89,6 +72,7 @@
8972
import static org.jooq.impl.DSL.condition;
9073
import static org.jooq.impl.DSL.count;
9174
import static org.jooq.impl.DSL.countDistinct;
75+
import static org.jooq.impl.DSL.field;
9276
import static org.jooq.impl.DSL.using;
9377
import static org.jooq.impl.DSL.value;
9478

@@ -534,8 +518,8 @@ public boolean save(Note note) {
534518

535519
@Override
536520
public boolean save(Project project) {
537-
LocalDateTime projectCreationDate = project.creationDate == null ? null : LocalDateTime.ofInstant(project.creationDate.toInstant(),ZoneOffset.UTC);
538-
LocalDateTime projectUpdateDate = project.updateDate == null ? null : LocalDateTime.ofInstant(project.updateDate.toInstant(),ZoneOffset.UTC);
521+
LocalDateTime projectCreationDate = project.creationDate == null ? null : LocalDateTime.ofInstant(project.creationDate.toInstant(), ZoneOffset.UTC);
522+
LocalDateTime projectUpdateDate = project.updateDate == null ? null : LocalDateTime.ofInstant(project.updateDate.toInstant(), ZoneOffset.UTC);
539523
InsertOnDuplicateSetMoreStep<ProjectRecord> innerSet = using(connectionProvider, dialect).insertInto(
540524
PROJECT, PROJECT.ID, PROJECT.LABEL, PROJECT.DESCRIPTION, PROJECT.PATH, PROJECT.SOURCE_URL,
541525
PROJECT.MAINTAINER_NAME, PROJECT.PUBLISHER_NAME, PROJECT.LOGO_URL,
@@ -582,6 +566,28 @@ public User getUser(String uid) {
582566
return createUserFrom(ctx.selectFrom(USER_INVENTORY).where(USER_INVENTORY.ID.eq(uid)).fetchOne());
583567
}
584568

569+
@Override
570+
public void temporaryFixLiquibaseIds() {
571+
using(connectionProvider, dialect).transaction(configuration -> {
572+
DSLContext inner = using(configuration);
573+
Field<String> id = field("id", String.class);
574+
Result<? extends Record1<String>> records = inner.select(id).from("databasechangelog").where("filename=?", "liquibase/changelog/changes/043-adds-user-policy-table.yml").fetch();
575+
if (records.isNotEmpty()) {
576+
inner.queries(
577+
inner.query("UPDATE databasechangelog set id='64' where filename='liquibase/changelog/changes/036-create_task.yml'"),
578+
inner.query("UPDATE databasechangelog set id='65' where filename='liquibase/changelog/changes/037-adds-task-result-and-error.yml'"),
579+
inner.query("UPDATE databasechangelog set id='66' where filename='liquibase/changelog/changes/038-adds-uri-column-batch-search.yml'"),
580+
inner.query("UPDATE databasechangelog set id='67' where filename='liquibase/changelog/changes/039-adds-column-nb-queries-without-results-batch-search.yml'"),
581+
inner.query("UPDATE databasechangelog set id='68' where filename='liquibase/changelog/changes/040-sqlite-pragma-journal-wal.yml'"),
582+
inner.query("UPDATE databasechangelog set id='69' where filename='liquibase/changelog/changes/041-adds-column-blur-sensitive-to-note.yml'"),
583+
inner.query("UPDATE databasechangelog set id='70' where id='42' and filename='liquibase/changelog/changes/042-task-result-batch-search-migration.yml'"),
584+
inner.query("UPDATE databasechangelog set id='71' where id='43' and filename='liquibase/changelog/changes/042-task-result-batch-search-migration.yml'"),
585+
inner.query("DELETE FROM databasechangelog where filename='liquibase/changelog/changes/043-adds-user-policy-table.yml'")
586+
).executeBatch();
587+
}
588+
});
589+
}
590+
585591
@Override
586592
public boolean getHealth() {
587593
DSLContext ctx = DSL.using(connectionProvider, dialect);
@@ -701,7 +707,8 @@ private Document createDocumentFrom(Record result) {
701707
DocumentRecord documentRecord = result.into(DOCUMENT);
702708
Map<String, Object> metadata;
703709
try {
704-
metadata = JsonObjectMapper.readValue(documentRecord.getMetadata(), new TypeReference<>() {});
710+
metadata = JsonObjectMapper.readValue(documentRecord.getMetadata(), new TypeReference<>() {
711+
});
705712
} catch (IOException e) {
706713
throw new RuntimeException(e);
707714
}

0 commit comments

Comments
 (0)