[jOOQ/jOOQ#9506] More work on Migrations API:
- Add SnapshotMojo to create snapshots of database versions - Don't include path in Version::id anymore
This commit is contained in:
parent
d0a5e9635c
commit
b988c5b5cb
@ -65,6 +65,7 @@ public abstract class AbstractMigrateMojo extends AbstractMigrationsMojo {
|
||||
Migrations migrations = configuration.dsl().migrations();
|
||||
Commits commits = migrations.commits();
|
||||
commits.load(file(directory));
|
||||
cp = (CommitProvider) () -> commits;
|
||||
}
|
||||
|
||||
Migration migration = configuration
|
||||
@ -85,8 +86,8 @@ public abstract class AbstractMigrateMojo extends AbstractMigrationsMojo {
|
||||
abstract void execute1(Migration migration) throws Exception;
|
||||
|
||||
// [#9506] TODO: Move this utility into the library
|
||||
private File file(String file) {
|
||||
getLog().info("Reading migrations directory: " + file);
|
||||
final File file(String file) {
|
||||
getLog().debug("Reading migrations directory: " + file);
|
||||
File f = new File(file);
|
||||
|
||||
if (!f.isAbsolute())
|
||||
|
||||
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* Apache-2.0 license and offer limited warranties, support, maintenance, and
|
||||
* commercial database integrations.
|
||||
*
|
||||
* For more information, please visit: https://www.jooq.org/legal/licensing
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.migrations.maven;
|
||||
|
||||
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
|
||||
import static org.apache.maven.plugins.annotations.ResolutionScope.TEST;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import org.jooq.History;
|
||||
import org.jooq.HistoryVersion;
|
||||
import org.jooq.Migration;
|
||||
import org.jooq.Queries;
|
||||
import org.jooq.exception.DataMigrationVerificationException;
|
||||
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
|
||||
/**
|
||||
* Create a snapshot of the current version.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
@Mojo(
|
||||
name = "snapshot",
|
||||
defaultPhase = GENERATE_SOURCES,
|
||||
requiresDependencyResolution = TEST,
|
||||
threadSafe = true
|
||||
)
|
||||
public class SnapshotMojo extends AbstractMigrateMojo {
|
||||
|
||||
@Override
|
||||
final void execute1(Migration migration) throws Exception {
|
||||
History history = migration.dsl().migrations().history();
|
||||
Queries queries = migration.queries();
|
||||
|
||||
if (queries.queries().length > 0) {
|
||||
Queries queries2 = migration.queries();
|
||||
getLog().warn("There are outstanding changes that have not been migrated yet, which are not in the snapshot:\n"
|
||||
+ queries2);
|
||||
}
|
||||
|
||||
HistoryVersion current = history.current();
|
||||
File file = new File(file(directory), current.version().id() + "/snapshots/snapshot.sql");
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
try (FileWriter f = new FileWriter(file);
|
||||
PrintWriter w = new PrintWriter(f)
|
||||
) {
|
||||
getLog().info("Writing snapshot to: " + file + "\n" + current.version().meta());
|
||||
w.println(current.version().meta().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -61,6 +61,7 @@ public interface Commit extends Node<Commit> {
|
||||
* Set the new {@link #valid()} flag for this commit, returning a copy of
|
||||
* the commit itself.
|
||||
*/
|
||||
@NotNull
|
||||
Commit valid(boolean valid);
|
||||
|
||||
/**
|
||||
|
||||
@ -441,12 +441,15 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
|
||||
for (int j = 0; j < list.size(); j++) {
|
||||
File file = list.get(j);
|
||||
String commitId = newId + "-" + file.path();
|
||||
|
||||
// [#9506] TODO: This historic Version::id generation used to be necessary to create unique
|
||||
// Version IDs per file path. It doesn't seem to be necessary anymore.
|
||||
// String commitId = newId + "-" + file.path();
|
||||
|
||||
if (file.type() == SCHEMA)
|
||||
to = to.commit(commitId, sources(apply(files, file, true).values()).toArray(EMPTY_SOURCE));
|
||||
to = to.commit(newId, sources(apply(files, file, true).values()).toArray(EMPTY_SOURCE));
|
||||
else
|
||||
to = to.apply(commitId, file.content());
|
||||
to = to.apply(newId, file.content());
|
||||
}
|
||||
|
||||
return to;
|
||||
|
||||
@ -1407,8 +1407,10 @@ final class Interpreter {
|
||||
return "Sequence";
|
||||
else if (named instanceof Domain)
|
||||
return "Domain";
|
||||
else if (named instanceof Synonym)
|
||||
return "Synonym";
|
||||
|
||||
|
||||
|
||||
|
||||
else
|
||||
return named.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user