All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.flywaydb.core.api.output.MigrateHtmlRenderer Maven / Gradle / Ivy

There is a newer version: 10.15.2
Show newest version
/*
 * Copyright (C) Red Gate Software Ltd 2010-2024
 *
 * 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.api.output;

import org.flywaydb.core.api.configuration.Configuration;
import org.flywaydb.core.extensibility.HtmlRenderer;
import org.flywaydb.core.extensibility.HtmlReportSummary;
import org.flywaydb.core.internal.util.FileUtils;
import org.flywaydb.core.internal.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

import static org.flywaydb.core.internal.util.TimeFormat.*;

public class MigrateHtmlRenderer implements HtmlRenderer {
    @Override
    public String render(MigrateResult result, Configuration config) {

        return getBody(result);
    }

    private String getBody(MigrateResult result) {
        StringBuilder html = new StringBuilder("
"); if (result.warnings != null && result.warnings.size() > 0) { html.append("

Warnings

\n"); for (String warning : result.warnings) { html.append("
").append(warning).append("
\n"); } html.append("
\n"); } if (result.migrations != null && result.migrations.size() > 0) { HtmlTableRenderer tableRenderer = new HtmlTableRenderer(); tableRenderer.addHeadings("Version", "Description", "Category", "Type", "Filepath", "ExecutionTime"); result.migrations.forEach(output -> tableRenderer.addRow(output.version, output.description, output.category, output.type, FileUtils.getFilename(output.filepath), format(output.executionTime))); html.append(tableRenderer.render()); } else { html.append("

No migrations found

\n"); } html.append("
\n"); return html.toString(); } @Override public String tabTitle(MigrateResult result, Configuration config) { return config.getDryRunOutput() == null ? "Migration report" : "DryRun report"; } @Override public Class getType() { return MigrateResult.class; } @Override public List getHtmlSummary(MigrateResult result) { List htmlResult = new ArrayList<>(); int migratedCount = result.migrationsExecuted; String databaseVersion = result.targetSchemaVersion == null ? result.migrations.stream().min((a, b) -> b.version.compareTo(a.version)).map(m -> m.version).orElse("0") : result.targetSchemaVersion; htmlResult.add(new HtmlReportSummary(result.targetSchemaVersion != null? "scGood" : "scError", "infoOutlined", "Database version: " + databaseVersion)); htmlResult.add(new HtmlReportSummary(migratedCount > 0 ? "scGood" : "scWarn", "checkFilled", migratedCount + " script" + StringUtils.pluralizeSuffix(migratedCount) + " migrated")); if (StringUtils.hasText(result.schemaName)) { htmlResult.add(new HtmlReportSummary("scNote", "database", "Database Schema: " + result.schemaName)); } htmlResult.add(new HtmlReportSummary("scNote", "clockOutlined", "Execution Time: " + format(result.migrations.stream().mapToInt(i -> i.executionTime).sum()))); return htmlResult; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy