|
|
@ -89,52 +89,17 @@ public abstract class UpgradeDao { |
|
|
|
public abstract DbType getDbType(); |
|
|
|
public abstract DbType getDbType(); |
|
|
|
|
|
|
|
|
|
|
|
public void initSchema() { |
|
|
|
public void initSchema() { |
|
|
|
// Execute the dolphinscheduler DDL, it cannot be rolled back
|
|
|
|
// Execute the dolphinscheduler full sql
|
|
|
|
runInitDDL(); |
|
|
|
runInitSql(getDbType()); |
|
|
|
|
|
|
|
|
|
|
|
// Execute the dolphinscheduler DML, it can be rolled back
|
|
|
|
|
|
|
|
runInitDML(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void runInitDML() { |
|
|
|
/** |
|
|
|
Resource mysqlSQLFilePath = new ClassPathResource("sql/" + initSqlPath() + "/dolphinscheduler_dml.sql"); |
|
|
|
* run init sql to init db schema |
|
|
|
Connection conn = null; |
|
|
|
* @param dbType db type |
|
|
|
try { |
|
|
|
*/ |
|
|
|
conn = dataSource.getConnection(); |
|
|
|
private void runInitSql(DbType dbType) { |
|
|
|
conn.setAutoCommit(false); |
|
|
|
String sqlFile = String.format("dolphinscheduler_%s.sql",dbType.getDescp()); |
|
|
|
|
|
|
|
Resource mysqlSQLFilePath = new ClassPathResource("sql/" + sqlFile); |
|
|
|
// Execute the dolphinscheduler_dml.sql script to import related data of dolphinscheduler
|
|
|
|
|
|
|
|
ScriptRunner initScriptRunner = new ScriptRunner(conn, false, true); |
|
|
|
|
|
|
|
Reader initSqlReader = new InputStreamReader(mysqlSQLFilePath.getInputStream()); |
|
|
|
|
|
|
|
initScriptRunner.runScript(initSqlReader); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
conn.commit(); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
conn.rollback(); |
|
|
|
|
|
|
|
} catch (SQLException e1) { |
|
|
|
|
|
|
|
logger.error(e1.getMessage(), e1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
logger.error(e.getMessage(), e); |
|
|
|
|
|
|
|
throw new RuntimeException(e.getMessage(), e); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (null != conn) { |
|
|
|
|
|
|
|
conn.rollback(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (SQLException e1) { |
|
|
|
|
|
|
|
logger.error(e1.getMessage(), e1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
logger.error(e.getMessage(), e); |
|
|
|
|
|
|
|
throw new RuntimeException(e.getMessage(), e); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
ConnectionUtils.releaseResource(conn); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void runInitDDL() { |
|
|
|
|
|
|
|
Resource mysqlSQLFilePath = new ClassPathResource("sql/" + initSqlPath() + "/dolphinscheduler_ddl.sql"); |
|
|
|
|
|
|
|
try (Connection conn = dataSource.getConnection()) { |
|
|
|
try (Connection conn = dataSource.getConnection()) { |
|
|
|
// Execute the dolphinscheduler_ddl.sql script to create the table structure of dolphinscheduler
|
|
|
|
// Execute the dolphinscheduler_ddl.sql script to create the table structure of dolphinscheduler
|
|
|
|
ScriptRunner initScriptRunner = new ScriptRunner(conn, true, true); |
|
|
|
ScriptRunner initScriptRunner = new ScriptRunner(conn, true, true); |
|
|
|