[jOOQ/jOOQ#9506] More work on Migrations API:
- Remove debug info - Add Commit.valid()
This commit is contained in:
parent
cebf801890
commit
d0a5e9635c
@ -170,8 +170,6 @@ abstract class AbstractMigrationsMojo extends AbstractMojo {
|
||||
// [#2886] Add the surrounding project's dependencies to the current classloader
|
||||
Thread.currentThread().setContextClassLoader(pluginClassLoader);
|
||||
|
||||
project.getRuntimeClasspathElements().forEach(System.out::println);
|
||||
|
||||
if (jdbc == null || jdbc.url == null)
|
||||
throw new MojoExecutionException("JDBC URL is required");
|
||||
|
||||
|
||||
@ -226,7 +226,8 @@ public final class GitCommitProvider implements CommitProvider {
|
||||
del(files, status.getMissing());
|
||||
del(files, status.getRemoved());
|
||||
|
||||
return commit.commit("uncommitted", "uncommitted", files);
|
||||
// [#9506] TODO: It should be possible to migrate to uncommitted changes in dev mode.
|
||||
return commit.commit("uncommitted", "uncommitted", files).valid(false);
|
||||
}
|
||||
|
||||
private void add(List<File> files, Set<String> paths) {
|
||||
|
||||
@ -52,6 +52,17 @@ import org.jetbrains.annotations.NotNull;
|
||||
@Experimental
|
||||
public interface Commit extends Node<Commit> {
|
||||
|
||||
/**
|
||||
* Whether this commit is a valid commit that can be migrated to.
|
||||
*/
|
||||
boolean valid();
|
||||
|
||||
/**
|
||||
* Set the new {@link #valid()} flag for this commit, returning a copy of
|
||||
* the commit itself.
|
||||
*/
|
||||
Commit valid(boolean valid);
|
||||
|
||||
/**
|
||||
* The files affected by this commit, in no particular order.
|
||||
*/
|
||||
|
||||
@ -82,6 +82,7 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
final List<Tag> tags;
|
||||
final Map<String, File> delta;
|
||||
final Map<String, File> files;
|
||||
final boolean valid;
|
||||
|
||||
CommitImpl(
|
||||
Configuration configuration,
|
||||
@ -90,7 +91,8 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
String author,
|
||||
Commit root,
|
||||
List<Commit> parents,
|
||||
Collection<? extends File> delta
|
||||
Collection<? extends File> delta,
|
||||
boolean valid
|
||||
) {
|
||||
super(configuration, id, message, author, root);
|
||||
|
||||
@ -102,9 +104,10 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
this.tags = new ArrayList<>();
|
||||
this.delta = map(delta, false);
|
||||
this.files = initFiles();
|
||||
this.valid = valid;
|
||||
}
|
||||
|
||||
private CommitImpl(CommitImpl copy) {
|
||||
private CommitImpl(CommitImpl copy, boolean newValid) {
|
||||
super(copy.configuration(), copy.id(), copy.message(), copy.author(), copy.root);
|
||||
|
||||
this.ctx = copy.ctx;
|
||||
@ -112,6 +115,7 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
this.tags = new ArrayList<>(copy.tags);
|
||||
this.delta = copy.delta;
|
||||
this.files = copy.files;
|
||||
this.valid = newValid;
|
||||
}
|
||||
|
||||
// TODO extract this Map<String, File> type to new type
|
||||
@ -144,6 +148,16 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
return apply(map(parent.files(), true), delta(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean valid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Commit valid(boolean newValid) {
|
||||
return new CommitImpl(this, newValid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Commit> parents() {
|
||||
return Collections.unmodifiableList(parents);
|
||||
@ -155,14 +169,14 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Commit tag(String id) {
|
||||
return tag(id, null);
|
||||
public final Commit tag(String tagId) {
|
||||
return tag(tagId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Commit tag(String id, String message) {
|
||||
CommitImpl result = new CommitImpl(this);
|
||||
result.tags.add(new TagImpl(id, message));
|
||||
public final Commit tag(String tagId, String tagMessage) {
|
||||
CommitImpl result = new CommitImpl(this, valid);
|
||||
result.tags.add(new TagImpl(tagId, tagMessage));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -212,7 +226,7 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
|
||||
@Override
|
||||
public final Commit commit(String newId, String newMessage, String newAuthor, Collection<? extends File> newFiles) {
|
||||
return new CommitImpl(configuration(), newId, newMessage, newAuthor, root, Arrays.asList(this), newFiles);
|
||||
return new CommitImpl(configuration(), newId, newMessage, newAuthor, root, Arrays.asList(this), newFiles, valid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -242,7 +256,7 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
|
||||
@Override
|
||||
public final Commit merge(String newId, String newMessage, String newAuthor, Commit with, Collection<? extends File> newFiles) {
|
||||
return new CommitImpl(configuration(), newId, newMessage, newAuthor, root, Arrays.asList(this, with), newFiles);
|
||||
return new CommitImpl(configuration(), newId, newMessage, newAuthor, root, Arrays.asList(this, with), newFiles, valid);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -174,6 +174,10 @@ final class MigrationImpl extends AbstractScope implements Migration {
|
||||
validateCommitProvider(ctx, from());
|
||||
validateCommitProvider(ctx, to());
|
||||
revertUntracked(ctx, null, currentRecord);
|
||||
|
||||
// [#9506] TODO: Better error handling helping the understand see their mistake
|
||||
if (!to().valid())
|
||||
throw new DataMigrationVerificationException("Commit is not a valid commit to migrate to: " + to());
|
||||
}
|
||||
|
||||
private final void validateCommitProvider(DefaultMigrationContext ctx, Commit commit) {
|
||||
|
||||
@ -76,7 +76,7 @@ final class MigrationsImpl extends AbstractScope implements Migrations {
|
||||
|
||||
@Override
|
||||
public final Commits commits() {
|
||||
return new CommitsImpl(configuration(), new CommitImpl(configuration(), ROOT, null, null, null, emptyList(), emptyList()));
|
||||
return new CommitsImpl(configuration(), new CommitImpl(configuration(), ROOT, null, null, null, emptyList(), emptyList(), true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user