package liquibase.database.core;

import liquibase.database.DatabaseConnection;
import liquibase.exception.DatabaseException;


/**
 * Encapsulates MySQL database support.
 */
public class MariaDBDatabase extends MySQLDatabase {
    private static final String PRODUCT_NAME = "MariaDB";

    @Override
    public String getShortName() {
        return "mariadb";
    }

    @Override
    protected String getDefaultDatabaseProductName() {
        return MariaDBDatabase.PRODUCT_NAME;
    }

    @Override
    public String getDefaultDriver(String url) {
        if (url.startsWith("jdbc:mariadb")) {
            return "org.mariadb.jdbc.Driver";
        }
        return null;
    }

    @Override
    public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException {
        // Presumbably for compatiblity reasons, a MariaDB instance might identify with getDatabaseProductName()=MySQL.
        // To be certain, We search for "mariadb" in the version string.
        if (PRODUCT_NAME.equalsIgnoreCase(conn.getDatabaseProductName())) {
            return true; // Identified as MariaDB product
        } else {
            return (("MYSQL".equalsIgnoreCase(conn.getDatabaseProductName())) && conn.getDatabaseProductVersion()
            .toLowerCase().contains("mariadb"));
        }
    }
}

@@ -119,16 +119,122 @@
 eption;%0A
+import liquibase.logging.LogService;%0Aimport liquibase.logging.LogType;%0Aimport liquibase.util.StringUtils;%0A
 %0A%0A/**%0A *
@@ -775,32 +775,967 @@
 rn null;%0A    %7D%0A%0A
+    @Override%0A    public int getMaxFractionalDigitsForTimestamp() %7B%0A%0A        int major = 0;%0A        int minor = 0;%0A        int patch = 0;%0A%0A        try %7B%0A            major = getDatabaseMajorVersion();%0A            minor = getDatabaseMinorVersion();%0A            patch = getDatabasePatchVersion();%0A        %7D catch (DatabaseException x) %7B%0A            LogService.getLog(getClass()).warning(%0A                    LogType.LOG, %22Unable to determine exact database server version%22%0A                            + %22 - specified TIMESTAMP precision%22%0A                            + %22 will not be set: %22, x);%0A            return 0;%0A        %7D%0A%0A        // MariaDB 5.3 introduced fractional support...%0A        // https://mariadb.com/kb/en/library/microseconds-in-mariadb/%0A        String minimumVersion = %225.3.0%22;%0A%0A        if (StringUtils.isMinimumVersion(minimumVersion, major, minor, patch))%0A            return 6;%0A        else%0A            return 0;%0A    %7D%0A%0A
     @Override%0A  

add MariaDB precision for TIME, DATETIME, and TIMESTAMP types for old releases (MariaDB 5.3-)