|
30 | 30 | import org.jooq.Record; |
31 | 31 | import org.jooq.exception.DataAccessException; |
32 | 32 | import org.jooq.impl.DSL; |
| 33 | +import org.slf4j.Logger; |
33 | 34 | import org.slf4j.LoggerFactory; |
34 | 35 |
|
35 | 36 | import javax.sql.DataSource; |
|
54 | 55 | import static java.util.Optional.ofNullable; |
55 | 56 | import static java.util.stream.Collectors.toList; |
56 | 57 | import static java.util.stream.Collectors.toSet; |
57 | | -import static org.icij.datashare.Entity.LOGGER; |
58 | 58 | import static org.icij.datashare.UserEvent.Type.fromId; |
59 | 59 | import static org.icij.datashare.db.Tables.USER_HISTORY_PROJECT; |
60 | 60 | import static org.icij.datashare.db.tables.Document.DOCUMENT; |
|
79 | 79 | public class JooqRepository implements Repository { |
80 | 80 | private final DataSource connectionProvider; |
81 | 81 | private final SQLDialect dialect; |
| 82 | + private static Logger logger = LoggerFactory.getLogger(JooqRepository.class); |
82 | 83 |
|
83 | 84 | JooqRepository(final DataSource connectionProvider, final SQLDialect dialect) { |
84 | 85 | this.connectionProvider = connectionProvider; |
@@ -106,7 +107,7 @@ public void create(List<NamedEntity> neList) { |
106 | 107 | ne.getCategory().getAbbreviation(), ne.getDocumentId(), ne.getRootDocument(), |
107 | 108 | ne.getExtractorLanguage().iso6391Code(), ne.isHidden()); |
108 | 109 | } catch (JsonProcessingException e) { |
109 | | - LOGGER.error("cannot serialize offsets {}", ne.getOffsets()); |
| 110 | + logger.error("cannot serialize offsets {}", ne.getOffsets()); |
110 | 111 | } |
111 | 112 | }); |
112 | 113 | insertQuery.execute(); |
@@ -568,24 +569,29 @@ public User getUser(String uid) { |
568 | 569 |
|
569 | 570 | @Override |
570 | 571 | 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 | | - }); |
| 572 | + try { |
| 573 | + using(connectionProvider, dialect).transaction(configuration -> { |
| 574 | + DSLContext inner = using(configuration); |
| 575 | + Field<String> id = field("id", String.class); |
| 576 | + Result<? extends Record1<String>> records = inner.select(id).from("databasechangelog").where("filename=?", "liquibase/changelog/changes/043-adds-user-policy-table.yml").fetch(); |
| 577 | + if (records.isNotEmpty()) { |
| 578 | + inner.queries( |
| 579 | + inner.query("UPDATE databasechangelog set id='64' where filename='liquibase/changelog/changes/036-create_task.yml'"), |
| 580 | + inner.query("UPDATE databasechangelog set id='65' where filename='liquibase/changelog/changes/037-adds-task-result-and-error.yml'"), |
| 581 | + inner.query("UPDATE databasechangelog set id='66' where filename='liquibase/changelog/changes/038-adds-uri-column-batch-search.yml'"), |
| 582 | + inner.query("UPDATE databasechangelog set id='67' where filename='liquibase/changelog/changes/039-adds-column-nb-queries-without-results-batch-search.yml'"), |
| 583 | + inner.query("UPDATE databasechangelog set id='68' where filename='liquibase/changelog/changes/040-sqlite-pragma-journal-wal.yml'"), |
| 584 | + inner.query("UPDATE databasechangelog set id='69' where filename='liquibase/changelog/changes/041-adds-column-blur-sensitive-to-note.yml'"), |
| 585 | + inner.query("UPDATE databasechangelog set id='70' where id='42' and filename='liquibase/changelog/changes/042-task-result-batch-search-migration.yml'"), |
| 586 | + inner.query("UPDATE databasechangelog set id='71' where id='43' and filename='liquibase/changelog/changes/042-task-result-batch-search-migration.yml'"), |
| 587 | + inner.query("DELETE FROM databasechangelog where filename='liquibase/changelog/changes/043-adds-user-policy-table.yml'") |
| 588 | + ).executeBatch(); |
| 589 | + } |
| 590 | + }); |
| 591 | + } catch (DataAccessException tableDoesNotExist) { |
| 592 | + logger.debug("SQL error during liquibase migration table fixing, presumably because databasechangelog " + |
| 593 | + "table doesn't exist (when starting from scratch). Ignoring.", tableDoesNotExist); |
| 594 | + } |
589 | 595 | } |
590 | 596 |
|
591 | 597 | @Override |
|
0 commit comments