-
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.
- Loading branch information
Showing
18 changed files
with
650 additions
and
40 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
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,60 @@ | ||
package io.seqera.migtool; | ||
|
||
import java.util.List; | ||
|
||
public enum Dialect { | ||
MYSQL(List.of("mysql")), | ||
H2(List.of("h2")), | ||
MARIADB(List.of("mariadb")), | ||
SQLITE(List.of("sqlite")), | ||
POSTGRES(List.of("postgres", "postgresql")), | ||
TCPOSTGRES(List.of("tc")); | ||
|
||
private final List<String> names; | ||
|
||
Dialect(List<String> names) { | ||
this.names = names; | ||
} | ||
|
||
public static Dialect from(String dialect) { | ||
for (Dialect d : Dialect.values()) { | ||
if (d.names.contains(dialect.toLowerCase())) { | ||
return d; | ||
} | ||
} | ||
throw new IllegalStateException("Unknown dialect: " + dialect); | ||
} | ||
|
||
boolean isPostgres() { | ||
return this == POSTGRES; | ||
} | ||
|
||
boolean isMySQL() { | ||
return this == MYSQL; | ||
} | ||
|
||
boolean isH2() { | ||
return this == H2; | ||
} | ||
|
||
boolean isSQLite() { | ||
return this == SQLITE; | ||
} | ||
|
||
boolean isMariaDB() { | ||
return this == MARIADB; | ||
} | ||
|
||
boolean isTestContainersPostgres() { | ||
return this == TCPOSTGRES; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (this == TCPOSTGRES) { | ||
// the dialect is actually POSTGRES | ||
return "postgres"; | ||
} | ||
return names.get(0); | ||
} | ||
} |
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,29 @@ | ||
package io.seqera.migtool; | ||
|
||
public enum Driver { | ||
MYSQL("com.mysql.cj.jdbc.Driver"), | ||
H2("org.h2.Driver"), | ||
SQLITE("org.sqlite.JDBC"), | ||
POSTGRES("org.postgresql.Driver"), | ||
TCPOSTGRES("org.testcontainers.jdbc.ContainerDatabaseDriver"); | ||
|
||
private final String driver; | ||
|
||
Driver(String driver) { | ||
this.driver = driver; | ||
} | ||
|
||
static Driver from(String driver) { | ||
for (Driver d : Driver.values()) { | ||
if (d.driver.equals(driver)) { | ||
return d; | ||
} | ||
} | ||
throw new IllegalStateException("Unknown driver: " + driver); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return driver; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
class MigRecord implements Comparable<MigRecord> { | ||
public class MigRecord implements Comparable<MigRecord> { | ||
|
||
enum Language { | ||
SQL, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
create table if not exists MIGTOOL_HISTORY | ||
( | ||
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, | ||
rank INTEGER NOT NULL, | ||
script VARCHAR(250) NOT NULL, | ||
checksum VARCHAR(64) NOT NULL, | ||
created_on timestamp NOT NULL, | ||
execution_time INTEGER | ||
); |
20 changes: 20 additions & 0 deletions
20
src/nativeCliTest/groovy/io/seqera/migtool/HelperTest.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,20 @@ | ||
package io.seqera.migtool | ||
|
||
import spock.lang.Specification | ||
|
||
class HelperTest extends Specification { | ||
|
||
def 'should load resources' () { | ||
expect: | ||
Helper.getResourceFiles('/db/mysql') == ['/db/mysql/file1.sql'].toSet() | ||
Helper.getResourceFiles('/db/mariadb') == ['/db/mariadb/V01__maria1.sql', '/db/mariadb/V02__maria2.sql', '/db/mariadb/v01-foo.txt'].toSet() | ||
Helper.getResourceFiles('/db/postgres') == ['/db/postgres/V01__postgres.sql'].toSet() | ||
} | ||
|
||
def 'should read resource file' () { | ||
expect: | ||
Helper.getResourceAsString('db/mysql/file1.sql').trim() == 'select * from my-table;' | ||
Helper.getResourceAsString('db/mariadb/V01__maria1.sql') == 'create table XXX ( col1 varchar(1) );\n' | ||
Helper.getResourceAsString('db/postgres/V01__postgres.sql').trim() == 'select * from my-table;' | ||
} | ||
} |
Oops, something went wrong.