forked from flyway/flyway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed flyway#1062: API: Make it possible to use pre-instantiated Java…
…-based migrations
- Loading branch information
Axel Fontaine
committed
Dec 11, 2018
1 parent
03bbf67
commit 62f729b
Showing
11 changed files
with
200 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...re/src/main/java/org/flywaydb/core/internal/resolver/java/FixedJavaMigrationResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2010-2018 Boxfuse GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.flywaydb.core.internal.resolver.java; | ||
|
||
import org.flywaydb.core.api.migration.JavaMigration; | ||
import org.flywaydb.core.api.resolver.Context; | ||
import org.flywaydb.core.api.resolver.MigrationResolver; | ||
import org.flywaydb.core.api.resolver.ResolvedMigration; | ||
import org.flywaydb.core.internal.resolver.ResolvedMigrationComparator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Migration resolver for a fixed set of pre-instantiated Java-based migrations. | ||
*/ | ||
public class FixedJavaMigrationResolver implements MigrationResolver { | ||
/** | ||
* The JavaMigration instances to use. | ||
*/ | ||
private final JavaMigration[] javaMigrations; | ||
|
||
/** | ||
* Creates a new instance. | ||
* | ||
* @param javaMigrations The JavaMigration instances to use. | ||
*/ | ||
public FixedJavaMigrationResolver(JavaMigration... javaMigrations) { | ||
this.javaMigrations = javaMigrations; | ||
} | ||
|
||
@Override | ||
public List<ResolvedMigration> resolveMigrations(Context context) { | ||
List<ResolvedMigration> migrations = new ArrayList<>(); | ||
|
||
for (JavaMigration javaMigration : javaMigrations) { | ||
migrations.add(new ResolvedJavaMigration(javaMigration)); | ||
} | ||
|
||
Collections.sort(migrations, new ResolvedMigrationComparator()); | ||
return migrations; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...ay-core/src/main/java/org/flywaydb/core/internal/resolver/java/ResolvedJavaMigration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2010-2018 Boxfuse GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.flywaydb.core.internal.resolver.java; | ||
|
||
import org.flywaydb.core.api.MigrationType; | ||
import org.flywaydb.core.api.migration.JavaMigration; | ||
import org.flywaydb.core.internal.resolver.ResolvedMigrationImpl; | ||
import org.flywaydb.core.internal.util.ClassUtils; | ||
|
||
/** | ||
* A resolved Java migration. | ||
*/ | ||
public class ResolvedJavaMigration extends ResolvedMigrationImpl { | ||
/** | ||
* Creates a new ResolvedJavaMigration based on this JavaMigration. | ||
* | ||
* @param javaMigration The JavaMigration to use. | ||
*/ | ||
public ResolvedJavaMigration(JavaMigration javaMigration) { | ||
setVersion(javaMigration.getVersion()); | ||
setDescription(javaMigration.getDescription()); | ||
setScript(javaMigration.getClass().getName()); | ||
setChecksum(javaMigration.getChecksum()); | ||
setType( | ||
|
||
|
||
|
||
MigrationType.JDBC | ||
); | ||
setPhysicalLocation(ClassUtils.getLocationOnDisk(javaMigration.getClass())); | ||
setExecutor(new JavaMigrationExecutor(javaMigration)); | ||
} | ||
} |
Oops, something went wrong.