-
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.
Implement a simple sql template to support Postgre
Signed-off-by: Paolo Di Tommaso <[email protected]>
- Loading branch information
1 parent
c131b38
commit 008f534
Showing
6 changed files
with
85 additions
and
5 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
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
22 changes: 22 additions & 0 deletions
22
src/main/java/io/seqera/migtool/builder/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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.seqera.migtool.builder; | ||
|
||
/** | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
public class DefaultSqlTemplate extends SqlTemplate { | ||
@Override | ||
public String selectMaxRank(String table) { | ||
return "select max(`rank`) from " + table; | ||
} | ||
|
||
@Override | ||
public String insetMigration(String table) { | ||
return "insert into "+table+" (`rank`,`script`,`checksum`,`created_on`,`execution_time`) values (?,?,?,?,?)"; | ||
} | ||
|
||
@Override | ||
public String selectMigration(String table) { | ||
return "select `id`, `checksum`, `script` from "+table+ " where `rank` = ? and `script` = ?"; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/io/seqera/migtool/builder/PostgresSqlTemplate.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.seqera.migtool.builder; | ||
|
||
/** | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
class PostgresSqlTemplate extends SqlTemplate { | ||
|
||
@Override | ||
public String selectMaxRank(String table) { | ||
return "select max(rank) from " + table; | ||
} | ||
|
||
@Override | ||
public String insetMigration(String table) { | ||
return "insert into "+table+" (rank,script,checksum,created_on,execution_time) values (?,?,?,?,?)"; | ||
} | ||
|
||
@Override | ||
public String selectMigration(String table) { | ||
return "select id, checksum, script from "+table+ " where rank = ? and script = ?"; | ||
} | ||
|
||
} |
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,22 @@ | ||
package io.seqera.migtool.builder; | ||
|
||
/** | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
public abstract class SqlTemplate { | ||
|
||
abstract public String selectMaxRank(String table); | ||
|
||
abstract public String insetMigration(String table); | ||
|
||
abstract public String selectMigration(String table); | ||
|
||
static public SqlTemplate from(String dialect) { | ||
if( "postgresql".equals(dialect) ) | ||
return new PostgresSqlTemplate(); | ||
else | ||
return new DefaultSqlTemplate(); | ||
} | ||
|
||
} |