package com.atlassian.stash.internal.hibernate.dialect;

import org.hibernate.dialect.MySQL5InnoDBDialect;

import java.sql.Types;

/**
 * Hibernate 4.1 adds registration for most column types in the {@code Dialect} constructor, which was not present
 * in 3.6 and prior, which maps {@code Types.BOOLEAN} to {@code "boolean"}. This dialect remaps it to {@code "bit"},
 * which is what the Liquibase mappings produce.
 * <p>
 * Additionally, because this dialect extends from {@code MySQL5InnoDBDialect} rather than {@code MySQLDialect},
 * which is what {@code StandardDialectResolver} returns for MySQL by default, this also applies MySQL 5 overrides
 * to certain settings and applies {@code InnoDB}-specific overrides on top of those.
 *
 * @since 2.0
 */
public class CustomMySqlDialect extends MySQL5InnoDBDialect {

    /**
     * Remaps {@code Types.BOOLEAN} as {@code "bit"} rather than {@code "boolean"}, the mapping applied in the top-
     * level {@code Dialect} constructor.
     * <p>
     * Note: {@code tinyint(1)} columns, which are what Liquibase uses for {@code Types.BOOLEAN} in MySQL, are
     * called {@code bit} columns by the MySQL JDBC driver. The type here needs to match that JDBC driver value.
     */
    public CustomMySqlDialect() {
        registerColumnType(Types.BOOLEAN, "bit");
    }
}
