use of org.flywaydb.core.internal.dbsupport.SqlScript in project flyway by flyway.
the class PostgreSQLSqlScriptSmallTest method parseSqlStatementsDo.
@Test
public void parseSqlStatementsDo() throws Exception {
String source = new ClassPathResource("migration/dbsupport/postgresql/sql/dollar/V2__Even_more_dollars.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
SqlScript sqlScript = new SqlScript(source, new PostgreSQLDbSupport(null));
List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
assertEquals(3, sqlStatements.size());
assertEquals(17, sqlStatements.get(0).getLineNumber());
assertEquals(23, sqlStatements.get(1).getLineNumber());
assertEquals(28, sqlStatements.get(2).getLineNumber());
}
use of org.flywaydb.core.internal.dbsupport.SqlScript in project flyway by flyway.
the class OracleSqlScriptSmallTest method parseProcedure.
@Test
public void parseProcedure() throws Exception {
String source = "CREATE OR REPLACE PROCEDURE set_right_value_for_sequence(seq_name in VARCHAR2, table_name in VARCHAR2, column_id in VARCHAR2)\n" + "IS\n" + " seq_val NUMBER(6);\n" + " row_count NUMBER(6);\n" + "BEGIN\n" + " EXECUTE IMMEDIATE\n" + " 'select ' || seq_name || '.nextval from dual' INTO seq_val;\n" + "\n" + " EXECUTE IMMEDIATE\n" + " 'alter sequence ' || seq_name || ' increment by -' || seq_val || ' minvalue 0';\n" + "\n" + " EXECUTE IMMEDIATE\n" + " 'select ' || seq_name || '.nextval from dual' INTO seq_val;\n" + "\n" + " EXECUTE IMMEDIATE\n" + " 'select case when max(' || column_id || ') is null then 1 else max(' || column_id || ') end from ' || table_name INTO row_count;\n" + "\n" + " EXECUTE IMMEDIATE\n" + " 'alter sequence ' || seq_name || ' increment by ' || row_count || ' minvalue 0';\n" + "\n" + " EXECUTE IMMEDIATE\n" + " 'select ' || seq_name || '.nextval from dual' INTO seq_val;\n" + "\n" + " EXECUTE IMMEDIATE\n" + " 'alter sequence ' || seq_name || ' increment by 1 minvalue 1';\n" + "END;\n" + "/\n" + "\n" + "EXECUTE set_right_value_for_sequence('SEQ_ATR', 'TOTCATTRIB', 'ATTRIB_ID');";
SqlScript sqlScript = new SqlScript(source, new OracleDbSupport(null));
List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
assertEquals(2, sqlStatements.size());
}
use of org.flywaydb.core.internal.dbsupport.SqlScript in project flyway by flyway.
the class OracleSqlScriptSmallTest method parseMergeInsert.
@Test
public void parseMergeInsert() throws Exception {
String source = "INSERT INTO ss.CODETBL(FIELDNAME,FIELDVALUE,IDS)\n" + "SELECT FIELDNAME,FIELDVALUE,IDS FROM\n" + "(\n" + "SELECT 'ACCT_TYPE_CD' FIELDNAME, '$' FIELDVALUE,'SAMP' IDS FROM DUAL UNION ALL\n" + "SELECT 'ACCT_TYPE_CD', 'L','SAMP' FROM DUAL UNION ALL\n" + "SELECT 'ACCT_TYPE_CD', 'C','SAMP' FROM DUAL \n" + ")\n" + "D\n" + "WHERE NOT EXISTS\n" + "(\n" + "SELECT 1 FROM SS.CODETBL \n" + "WHERE D.FIELDNAME = FIELDNAME \n" + "AND D.FIELDVALUE = FIELDVALUE\n" + "AND D.IDS = IDS\n" + ");";
SqlScript sqlScript = new SqlScript(source, new OracleDbSupport(null));
List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
assertEquals(1, sqlStatements.size());
}
use of org.flywaydb.core.internal.dbsupport.SqlScript in project flyway by flyway.
the class OracleSqlScriptSmallTest method parsePackages.
@Test
public void parsePackages() throws Exception {
String source = new ClassPathResource("migration/dbsupport/oracle/sql/package/V1__Package.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
SqlScript sqlScript = new SqlScript(source, new OracleDbSupport(null));
List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
assertEquals(2, sqlStatements.size());
assertEquals(17, sqlStatements.get(0).getLineNumber());
assertEquals(33, sqlStatements.get(1).getLineNumber());
}
use of org.flywaydb.core.internal.dbsupport.SqlScript in project flyway by flyway.
the class MetaDataTableImpl method createIfNotExists.
/**
* Creates the metatable if it doesn't exist, upgrades it if it does.
*/
private void createIfNotExists() {
int retries = 0;
while (!table.exists()) {
if (retries == 0) {
LOG.info("Creating Metadata table: " + table);
}
try {
String resourceName = "org/flywaydb/core/internal/dbsupport/" + dbSupport.getDbName() + "/createMetaDataTable.sql";
String source = new ClassPathResource(resourceName, getClass().getClassLoader()).loadAsString("UTF-8");
Map<String, String> placeholders = new HashMap<String, String>();
placeholders.put("schema", table.getSchema().getName());
placeholders.put("table", table.getName());
String sourceNoPlaceholders = new PlaceholderReplacer(placeholders, "${", "}").replacePlaceholders(source);
final SqlScript sqlScript = new SqlScript(sourceNoPlaceholders, dbSupport);
sqlScript.execute(jdbcTemplate);
LOG.debug("Metadata table " + table + " created.");
} catch (FlywayException e) {
if (++retries >= 10) {
throw e;
}
try {
LOG.debug("Metadata table creation failed. Retrying in 1 sec ...");
Thread.sleep(1000);
} catch (InterruptedException e1) {
// Ignore
}
}
}
}
Aggregations