-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Paolo Di Tommaso <[email protected]>
- Loading branch information
1 parent
008f534
commit c79052f
Showing
7 changed files
with
88 additions
and
24 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
5 changes: 3 additions & 2 deletions
5
...a/migtool/builder/DefaultSqlTemplate.java → .../migtool/template/DefaultSqlTemplate.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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package io.seqera.migtool.builder; | ||
package io.seqera.migtool.template; | ||
|
||
/** | ||
* Default SQL template for migtool SQL statements | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
public class DefaultSqlTemplate extends SqlTemplate { | ||
class DefaultSqlTemplate extends SqlTemplate { | ||
@Override | ||
public String selectMaxRank(String table) { | ||
return "select max(`rank`) from " + table; | ||
|
5 changes: 3 additions & 2 deletions
5
.../migtool/builder/PostgresSqlTemplate.java → .../migtool/template/PostgreSqlTemplate.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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package io.seqera.migtool.builder; | ||
package io.seqera.migtool.template; | ||
|
||
/** | ||
* PostreSQL dialect implementation | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
class PostgresSqlTemplate extends SqlTemplate { | ||
class PostgreSqlTemplate extends SqlTemplate { | ||
|
||
@Override | ||
public String selectMaxRank(String table) { | ||
|
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package io.seqera.migtool.builder; | ||
package io.seqera.migtool.template; | ||
|
||
/** | ||
* Implements a simple template pattern to provide specialised | ||
* version of required SQL statements depending on the specified SQL "dialect" | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
|
@@ -14,9 +16,13 @@ public abstract class SqlTemplate { | |
|
||
static public SqlTemplate from(String dialect) { | ||
if( "postgresql".equals(dialect) ) | ||
return new PostgresSqlTemplate(); | ||
return new PostgreSqlTemplate(); | ||
else | ||
return new DefaultSqlTemplate(); | ||
} | ||
|
||
public static SqlTemplate defaultTemplate() { | ||
return new DefaultSqlTemplate(); | ||
} | ||
|
||
} |
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
30 changes: 30 additions & 0 deletions
30
src/test/groovy/io/seqera/migtool/template/SqlTemplateTest.groovy
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,30 @@ | ||
package io.seqera.migtool.template | ||
|
||
import spock.lang.Specification | ||
|
||
/** | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
class SqlTemplateTest extends Specification{ | ||
|
||
def 'should validate default template' () { | ||
given: | ||
def t = SqlTemplate.from('anything') | ||
|
||
expect: | ||
t.selectMaxRank('FOO') == 'select max(`rank`) from FOO' | ||
t.insetMigration('FOO') == 'insert into FOO (`rank`,`script`,`checksum`,`created_on`,`execution_time`) values (?,?,?,?,?)' | ||
t.selectMigration('FOO') == 'select `id`, `checksum`, `script` from FOO where `rank` = ? and `script` = ?' | ||
} | ||
|
||
def 'should validate postgre template' () { | ||
given: | ||
def t = SqlTemplate.from('postgresql') | ||
|
||
expect: | ||
t.selectMaxRank('FOO') == 'select max(rank) from FOO' | ||
t.insetMigration('FOO') == 'insert into FOO (rank,script,checksum,created_on,execution_time) values (?,?,?,?,?)' | ||
t.selectMigration('FOO') == 'select id, checksum, script from FOO where rank = ? and script = ?' | ||
} | ||
} |