Search in sources :

Example 1 with SqlStatement

use of org.flywaydb.core.internal.dbsupport.SqlStatement in project killbill by killbill.

the class Migrator method main.

/**
     * Main method.
     *
     * @param args The command-line arguments.
     */
public static void main(final String[] args) {
    final Level logLevel = getLogLevel(args);
    initLogging(logLevel);
    try {
        if (isPrintVersionAndExit(args)) {
            printVersion();
            System.exit(0);
        }
        final List<String> operations = determineOperations(args);
        if (operations.isEmpty()) {
            printUsage();
            return;
        }
        final Properties properties = new Properties();
        initializeDefaults(properties);
        loadConfiguration(properties, args);
        overrideConfiguration(properties, args);
        dumpConfiguration(properties);
        loadJdbcDrivers();
        loadJavaMigrationsFromJarDirs(properties);
        final List<SqlStatement> sqlStatements = new LinkedList<SqlStatement>();
        final FlywayWithDryRun flyway = new FlywayWithDryRun(sqlStatements);
        filterProperties(properties);
        flyway.configure(properties);
        for (final String operation : operations) {
            executeOperation(flyway, operation, sqlStatements);
        }
    } catch (final Exception e) {
        if (logLevel == Level.DEBUG) {
            LOG.error("Unexpected error", e);
        } else {
            if (e instanceof FlywayException) {
                LOG.error(e.getMessage());
            } else {
                LOG.error(e.toString());
            }
        }
        System.exit(1);
    }
}
Also used : SqlStatement(org.flywaydb.core.internal.dbsupport.SqlStatement) FlywayException(org.flywaydb.core.api.FlywayException) FlywayWithDryRun(org.flywaydb.core.FlywayWithDryRun) Level(org.flywaydb.core.internal.util.logging.console.ConsoleLog.Level) Properties(java.util.Properties) LinkedList(java.util.LinkedList) FlywayException(org.flywaydb.core.api.FlywayException) IOException(java.io.IOException)

Example 2 with SqlStatement

use of org.flywaydb.core.internal.dbsupport.SqlStatement in project flyway by flyway.

the class MySQLSqlScriptSmallTest method unquotedMultiLineCommentDirective.

@Test
public void unquotedMultiLineCommentDirective() throws Exception {
    String source = "INSERT INTO tablename VALUES ('a','b');\n" + "/*!50001 CREATE TABLE `viewname` (\n" + "`id` int(10) unsigned,\n" + "`name` varchar(10)\n" + ") ENGINE=MyISAM */;\n" + "INSERT INTO tablename VALUES ('a','b');";
    SqlScript sqlScript = new SqlScript(source, new MySQLDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(3, sqlStatements.size());
    assertEquals(1, sqlStatements.get(0).getLineNumber());
    assertEquals(2, sqlStatements.get(1).getLineNumber());
    assertEquals(6, sqlStatements.get(2).getLineNumber());
}
Also used : SqlStatement(org.flywaydb.core.internal.dbsupport.SqlStatement) SqlScript(org.flywaydb.core.internal.dbsupport.SqlScript) Test(org.junit.Test)

Example 3 with SqlStatement

use of org.flywaydb.core.internal.dbsupport.SqlStatement in project flyway by flyway.

the class EnterpriseDBSqlScriptSmallTest method parseSqlStatements.

@Test
public void parseSqlStatements() throws Exception {
    String source = new ClassPathResource("migration/dbsupport/enterprisedb/sql/placeholders/V1__Placeholders.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
    SqlScript sqlScript = new SqlScript(source, new EnterpriseDBDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(3, sqlStatements.size());
    assertEquals(18, sqlStatements.get(0).getLineNumber());
    assertEquals(27, sqlStatements.get(1).getLineNumber());
    assertEquals(32, sqlStatements.get(2).getLineNumber());
    assertEquals("COMMIT", sqlStatements.get(2).getSql());
}
Also used : SqlStatement(org.flywaydb.core.internal.dbsupport.SqlStatement) SqlScript(org.flywaydb.core.internal.dbsupport.SqlScript) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) Test(org.junit.Test)

Example 4 with SqlStatement

use of org.flywaydb.core.internal.dbsupport.SqlStatement in project flyway by flyway.

the class EnterpriseDBSqlScriptSmallTest method parseSqlStatementsWithInlineCommentsInsidePlSqlBlocks.

@Test
public void parseSqlStatementsWithInlineCommentsInsidePlSqlBlocks() throws Exception {
    String source = new ClassPathResource("migration/dbsupport/enterprisedb/sql/function/V2__FunctionWithConditionals.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
    SqlScript sqlScript = new SqlScript(source, new EnterpriseDBDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(1, sqlStatements.size());
    assertEquals(18, sqlStatements.get(0).getLineNumber());
    assertTrue(sqlStatements.get(0).getSql().contains("/* for the rich */"));
}
Also used : SqlStatement(org.flywaydb.core.internal.dbsupport.SqlStatement) SqlScript(org.flywaydb.core.internal.dbsupport.SqlScript) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) Test(org.junit.Test)

Example 5 with SqlStatement

use of org.flywaydb.core.internal.dbsupport.SqlStatement in project flyway by flyway.

the class EnterpriseDBSqlScriptSmallTest method parseFunctionsAndProcedures.

@Test
public void parseFunctionsAndProcedures() throws Exception {
    String source = new ClassPathResource("migration/dbsupport/enterprisedb/sql/function/V1__Function.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
    SqlScript sqlScript = new SqlScript(source, new EnterpriseDBDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(5, sqlStatements.size());
    assertEquals(18, sqlStatements.get(0).getLineNumber());
    assertEquals(33, sqlStatements.get(1).getLineNumber());
    assertEquals(41, sqlStatements.get(2).getLineNumber());
    assertEquals(43, sqlStatements.get(3).getLineNumber());
    assertEquals(51, sqlStatements.get(4).getLineNumber());
    assertEquals("COMMIT", sqlStatements.get(4).getSql());
}
Also used : SqlStatement(org.flywaydb.core.internal.dbsupport.SqlStatement) SqlScript(org.flywaydb.core.internal.dbsupport.SqlScript) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) Test(org.junit.Test)

Aggregations

SqlStatement (org.flywaydb.core.internal.dbsupport.SqlStatement)21 SqlScript (org.flywaydb.core.internal.dbsupport.SqlScript)19 Test (org.junit.Test)19 ClassPathResource (org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource)11 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 FlywayWithDryRun (org.flywaydb.core.FlywayWithDryRun)1 FlywayException (org.flywaydb.core.api.FlywayException)1 MigrationVersion (org.flywaydb.core.api.MigrationVersion)1 Level (org.flywaydb.core.internal.util.logging.console.ConsoleLog.Level)1