diff --git a/jOOQ-migrations-maven/src/main/java/org/jooq/migrations/maven/AbstractMigrateMojo.java b/jOOQ-migrations-maven/src/main/java/org/jooq/migrations/maven/AbstractMigrateMojo.java index 5be5352eb8..ac43b0636b 100644 --- a/jOOQ-migrations-maven/src/main/java/org/jooq/migrations/maven/AbstractMigrateMojo.java +++ b/jOOQ-migrations-maven/src/main/java/org/jooq/migrations/maven/AbstractMigrateMojo.java @@ -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()) diff --git a/jOOQ-migrations-maven/src/main/java/org/jooq/migrations/maven/SnapshotMojo.java b/jOOQ-migrations-maven/src/main/java/org/jooq/migrations/maven/SnapshotMojo.java new file mode 100644 index 0000000000..5b1143d836 --- /dev/null +++ b/jOOQ-migrations-maven/src/main/java/org/jooq/migrations/maven/SnapshotMojo.java @@ -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()); + } + } +} diff --git a/jOOQ/src/main/java/org/jooq/Commit.java b/jOOQ/src/main/java/org/jooq/Commit.java index 26a3c45b0e..78e8f90be2 100644 --- a/jOOQ/src/main/java/org/jooq/Commit.java +++ b/jOOQ/src/main/java/org/jooq/Commit.java @@ -61,6 +61,7 @@ public interface Commit extends Node { * Set the new {@link #valid()} flag for this commit, returning a copy of * the commit itself. */ + @NotNull Commit valid(boolean valid); /** diff --git a/jOOQ/src/main/java/org/jooq/impl/CommitImpl.java b/jOOQ/src/main/java/org/jooq/impl/CommitImpl.java index e7bbfe7a43..ba21764050 100644 --- a/jOOQ/src/main/java/org/jooq/impl/CommitImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/CommitImpl.java @@ -441,12 +441,15 @@ final class CommitImpl extends AbstractNode 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; diff --git a/jOOQ/src/main/java/org/jooq/impl/Interpreter.java b/jOOQ/src/main/java/org/jooq/impl/Interpreter.java index bd097868d7..7f8a4c5f6d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Interpreter.java +++ b/jOOQ/src/main/java/org/jooq/impl/Interpreter.java @@ -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(); }