From 81cf65f70cad39c06001440d9c3117d867c01187 Mon Sep 17 00:00:00 2001 From: Ilia Koliaskin Date: Tue, 18 Jun 2024 12:02:09 +0200 Subject: [PATCH] feat: add missing indexes to the oracle ddl script --- .../com/github/kagkarlsson/scheduler/DbUtils.java | 14 +++++++++++++- .../compatibility/Oracle11gCompatibilityTest.java | 2 +- db-scheduler/src/test/resources/oracle_tables.sql | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/DbUtils.java b/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/DbUtils.java index 5b2fd86c..74e17ed5 100644 --- a/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/DbUtils.java +++ b/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/DbUtils.java @@ -23,13 +23,25 @@ public static void clearTables(DataSource dataSource) { } public static Consumer runSqlResource(String resource) { + return runSqlResource(resource, false); + } + + public static Consumer 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); } diff --git a/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/compatibility/Oracle11gCompatibilityTest.java b/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/compatibility/Oracle11gCompatibilityTest.java index 403e20a1..668b5669 100644 --- a/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/compatibility/Oracle11gCompatibilityTest.java +++ b/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/compatibility/Oracle11gCompatibilityTest.java @@ -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 diff --git a/db-scheduler/src/test/resources/oracle_tables.sql b/db-scheduler/src/test/resources/oracle_tables.sql index 58113d03..96d89742 100644 --- a/db-scheduler/src/test/resources/oracle_tables.sql +++ b/db-scheduler/src/test/resources/oracle_tables.sql @@ -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);