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

com.liquibase.ext.changelog.FormattedMongoshChangelogRewriter Maven / Gradle / Ivy

The newest version!
package com.liquibase.ext.changelog;

import com.datical.liquibase.ext.changelog.AbstractFormattedChangelogRewriter;
import liquibase.GlobalConfiguration;
import liquibase.Scope;
import liquibase.util.StreamUtil;

import java.io.IOException;
import java.io.InputStream;

public class FormattedMongoshChangelogRewriter extends AbstractFormattedChangelogRewriter {

    @Override
    protected String getSingleLineCommentOneCharacter() {
        return "/";
    }

    @Override
    protected String getSingleLineCommentSequence() {
        return "//";
    }

    @Override
    protected String getFirstLine() {
        return "liquibase formatted mongo";
    }

    @Override
    protected String getSequenceName() {
        return "Mongosh";
    }

    @Override
    public boolean supports(String path) {
        try (InputStream is = Scope.getCurrentScope().getResourceAccessor().getExisting(path).openInputStream()) {
            String encoding = GlobalConfiguration.OUTPUT_FILE_ENCODING.getCurrentValue();
            String changelogString = StreamUtil.readStreamAsString(is, encoding);
            return changelogString.toLowerCase().contains(getFirstLine());
        } catch (IOException ioe) {
            return false;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy