Search in sources :

Example 6 with FileSystemResource

use of org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource in project flyway by flyway.

the class SqlMigrationResolverSmallTest method extractScriptNameFileSystemPrefix.

@Test
public void extractScriptNameFileSystemPrefix() {
    SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, new Location("filesystem:/some/dir"), PlaceholderReplacer.NO_PLACEHOLDERS, FlywayConfigurationForTests.create());
    assertEquals("V3.171__patch.sql", sqlMigrationResolver.extractScriptName(new FileSystemResource("/some/dir/V3.171__patch.sql")));
}
Also used : FileSystemResource(org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource) Location(org.flywaydb.core.internal.util.Location) Test(org.junit.Test)

Example 7 with FileSystemResource

use of org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource in project killbill by killbill.

the class DbMigrateWithDryRun method applyMigration.

private void applyMigration(final int installedRnk, final MigrationInfoImpl migration) {
    final MigrationVersion version = migration.getVersion();
    final String migrationText;
    if (version != null) {
        migrationText = "schema " + schema + " to version " + version + " - " + migration.getDescription();
    } else {
        migrationText = "schema " + schema + " with repeatable migration " + migration.getDescription();
    }
    LOG.info("Migrating " + migrationText);
    // PIERRE: override the executor to capture the SQL
    final FileSystemResource sqlScriptResource = new FileSystemResource(migration.getResolvedMigration().getPhysicalLocation());
    final MigrationExecutor migrationExecutor = new CapturingSqlMigrationExecutor(sqlStatements, dbSupport, sqlScriptResource, placeholderReplacer, encoding);
    try {
        doMigrate(migration, migrationExecutor, migrationText);
    } catch (final SQLException e) {
        throw new FlywayException("Unable to apply migration", e);
    }
    final AppliedMigration appliedMigration = new AppliedMigration(installedRnk, version, migration.getDescription(), migration.getType(), migration.getScript(), migration.getResolvedMigration().getChecksum(), null, null, -1, true);
    metaDataTableForDryRun.addAppliedMigration(appliedMigration);
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) MigrationVersion(org.flywaydb.core.api.MigrationVersion) SQLException(java.sql.SQLException) AppliedMigration(org.flywaydb.core.internal.metadatatable.AppliedMigration) MigrationExecutor(org.flywaydb.core.api.resolver.MigrationExecutor) FileSystemResource(org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource)

Aggregations

FileSystemResource (org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource)7 Location (org.flywaydb.core.internal.util.Location)6 Test (org.testng.annotations.Test)5 Resource (org.flywaydb.core.internal.util.scanner.Resource)3 SQLException (java.sql.SQLException)1 FlywayException (org.flywaydb.core.api.FlywayException)1 MigrationVersion (org.flywaydb.core.api.MigrationVersion)1 MigrationExecutor (org.flywaydb.core.api.resolver.MigrationExecutor)1 AppliedMigration (org.flywaydb.core.internal.metadatatable.AppliedMigration)1 Test (org.junit.Test)1