Skip to content

Commit

Permalink
feat: add missing indexes to the oracle ddl script (#503)
Browse files Browse the repository at this point in the history
## Add missing indexes to the oracle ddl script

Every example for other databases (Postgres, Mssql, Mysql) contains
indexes on `execution_time` and `last_heartbeat` while for Oracle DB
they are missing.

I also expanded `DbUtiils` method to allow splitting sql statements from
an sql file. `jdbcRunner.execute(statement, NOOP)` can run only one
statement at a time for Oracle Db.

PS: two tests for oracle db are failing on master, is that expected?

## Reminders
- [x] Added/ran automated tests
- [x] Update README and/or examples
    - no need
- [x] Ran `mvn spotless:apply`

---
cc @kagkarlsson
  • Loading branch information
iluwa committed Jul 2, 2024
1 parent 16f6908 commit 309c355
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,25 @@ public static void clearTables(DataSource dataSource) {
}

public static Consumer<DataSource> runSqlResource(String resource) {
return runSqlResource(resource, false);
}

public static Consumer<DataSource> runSqlResource(String resource, boolean splitStatements) {
return dataSource -> {
final JdbcRunner jdbcRunner = new JdbcRunner(dataSource);
try {
final String statements =
CharStreams.toString(
new InputStreamReader(DbUtils.class.getResourceAsStream(resource)));
jdbcRunner.execute(statements, NOOP);
if (splitStatements) {
for (String statement : statements.split(";")) {
if (!statement.trim().isEmpty()) {
jdbcRunner.execute(statement, NOOP);
}
}
} else {
jdbcRunner.execute(statements, NOOP);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void initSchema() {
pooledDatasource = new HikariDataSource(hikariConfig);

// init schema
DbUtils.runSqlResource("/oracle_tables.sql").accept(pooledDatasource);
DbUtils.runSqlResource("/oracle_tables.sql", true).accept(pooledDatasource);
}

@BeforeEach
Expand Down
4 changes: 3 additions & 1 deletion db-scheduler/src/test/resources/oracle_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ create table scheduled_tasks
last_heartbeat TIMESTAMP(6) WITH TIME ZONE,
version NUMBER(19, 0),
PRIMARY KEY (task_name, task_instance)
)
);

CREATE INDEX scheduled_tasks__execution_time__idx on scheduled_tasks(execution_time);
CREATE INDEX scheduled_tasks__last_heartbeat__idx on scheduled_tasks(last_heartbeat);

0 comments on commit 309c355

Please sign in to comment.