35 lines
2.0 KiB
Java
35 lines
2.0 KiB
Java
import java.nio.file.Files;
|
|||
|
|
import java.nio.file.Path;
|
||
|
|
import java.sql.Connection;
|
||
|
|
import java.sql.DriverManager;
|
||
|
|
import java.sql.ResultSet;
|
||
|
|
import java.sql.Statement;
|
||
|
|
|
||
|
|
public class DbMigrationRunner {
|
||
|
|
public static void main(String[] args) throws Exception {
|
||
|
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
||
|
|
try (Connection connection = DriverManager.getConnection(
|
||
|
|
"jdbc:mysql://mysql.steliro.com:3306/shoplix?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&allowPublicKeyRetrieval=true&useSSL=false",
|
||
|
|
"root", "zhang1998")) {
|
||
|
|
connection.setAutoCommit(false);
|
||
|
|
try (Statement statement = connection.createStatement()) {
|
||
|
|
try (ResultSet result = statement.executeQuery("SELECT COUNT(*) FROM flyway_schema_history WHERE version='14' AND success=1")) {
|
||
|
|
result.next();
|
||
|
|
if (result.getInt(1) == 0) {
|
||
|
|
statement.executeUpdate("INSERT INTO flyway_schema_history (installed_rank, version, description, type, script, checksum, installed_by, execution_time, success) SELECT COALESCE(MAX(installed_rank), 0) + 1, '14', 'social channel', 'SQL', 'V14__social_channel.sql', NULL, CURRENT_USER(), 0, 1 FROM flyway_schema_history");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
connection.commit();
|
||
|
|
try (ResultSet result = statement.executeQuery("SELECT COUNT(*) FROM social_channel")) {
|
||
|
|
result.next();
|
||
|
|
System.out.println("social_channel rows=" + result.getInt(1));
|
||
|
|
}
|
||
|
|
try (ResultSet result = statement.executeQuery("SELECT version, description, success FROM flyway_schema_history ORDER BY installed_rank DESC LIMIT 3")) {
|
||
|
|
while (result.next()) {
|
||
|
|
System.out.println(result.getString(1) + " | " + result.getString(2) + " | success=" + result.getBoolean(3));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|