-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow users to use their own implementation of FileMigrationLoader. R… #107
Merged
harawata
merged 1 commit into
mybatis:master
from
harawata:custom-file-migration-loader
Dec 15, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 23 additions & 0 deletions
23
src/main/java/org/apache/ibatis/migration/FileMigrationLoaderFactory.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,23 @@ | ||
/** | ||
* Copyright 2010-2017 the original author or authors. | ||
* | ||
* 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.apache.ibatis.migration; | ||
|
||
import java.io.File; | ||
import java.util.Properties; | ||
|
||
public interface FileMigrationLoaderFactory { | ||
MigrationLoader create(File scriptsDir, String charset, Properties variables); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea. How about taking it one step higher to
MigrationLoaderFactory
so that it's no longer file based? Basically, you can abstract theMigration
and get an iterator of them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I agree, we have a MigrationLoader so a MigrationLoader factory makes a lot of sense. The FileMigrationLoader is just an implementation.
It might be more useful to just give it the
path()
,environment()
for flexibility.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you guys for the quick feedback!
I thought about that.
The return type of
FileMigrationLoaderFactory#create()
isMigrationLoader
, so by design, it is possible to return a customMigrationLoader
that loads migrations from some other source (i.e. it does not have to be a subclass ofFileMigrationLoader
).But this is
BaseCommand
which is the base class for the command line API and the current command line workflow cannot be separated from files completely (e.g.migrate new
).That is why I named it
FileMigrationLoaderFactory
.It was my first implementation and I'm still not that sure which is better, so if you think that is better, I'll change. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea it's tied to Files atm but we also have for example
JavaMigrationLoader
that is useful for runtime migrations.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw that. But
JavaMigrationLoader
has a methodgetMigrations()
which returns aList<Change>
(counter conventional, btw).When you look at
Change
you seeNotice the part where it says
fileName
? It's still anchored to the file system.Side question: Why is the id
BigDecimal
? Do you expect a version like3.1415926
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean @chb0github, both have getMigrations which returns a list of changes.
That is true. I was just thinking about it from a Factory standpoint. The factory author can create the loader any way they like so I just assumed they would have the proper classLoader/packageNames to create the JavaMigrationLoader
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harawata if you have no more changes let's pull this in. Don't worry about the Factory idea for now. We can deal with it when we have to like you said
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@h3adache ,
Okay!
Regarding the arguments of
create()
, I re-checkedSelectedPaths
andEnvironment
and couldn't think of a good use case for other properties.Let's merge this as it is and see what users say.
I'll add documentation and tests as soon as possible.
Thank you both for insightful comments!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use it to create a JarFileMigrationLoader. :)
ATM our FileMigrationLoader doesn't read jar bundled migrations properly.
I create a JarFileMigrationLoader to handle that for me but I read the properties from the bundled environment file in the jar as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@h3adache Done! b95e393