<commit_before>package ru.yandex.mysqlDiff.diff

import scala.collection.mutable.ArrayBuffer

import model._
import script._

import util.CollectionUtils._

// XXX: drop
import vendor.mysql._

// XXX: drop
import vendor.mysql._

import Implicits._

/**
 * Tool that compares two database models.
 */
case class DiffMaker(val context: Context) {
    import context._

    
    /**
     * Are the values equivalent from DB point of view. For example, 1 and '1' are equivalent.
     */
    def defaultValuesEquivalent(a: SqlExpr, b: SqlExpr) = {
        def e1(a: SqlExpr, b: SqlExpr) = (a, b) match {
            case (NumberValue(x), StringValue(y)) if x.toString == y => true
            // XXX: should only for date and time types
            case (StringValue("0000-00-00 00:00:00"), StringValue("0000-00-00")) => true
            case _ => false
        }

        a == b || e1(a, b) || e1(b, a)
    }
    
    def dataTypesEquivalent(a: DataType, b: DataType) =
        dataTypes.equivalent(a, b)
    
    def columnPropertiesEquivalent(a: ColumnProperty, b: ColumnProperty) = {
        require(a.propertyType == b.propertyType)
        val propertyType = a.propertyType
        (a, b) match {
            case (DataTypeProperty(adt), DataTypeProperty(bdt)) => dataTypesEquivalent(adt, bdt)
            case (DefaultValue(adv), DefaultValue(bdv)) => defaultValuesEquivalent(adv, bdv)
            case _ => a == b<commit_msg>make 0000-00-00 00:00:00 and 0 equivalent (this is temp hack)<commit_after>package ru.yandex.mysqlDiff.diff

import scala.collection.mutable.ArrayBuffer

import model._
import script._

import util.CollectionUtils._

// XXX: drop
import vendor.mysql._

// XXX: drop
import vendor.mysql._

import Implicits._

/**
 * Tool that compares two database models.
 */
case class DiffMaker(val context: Context) {
    import context._

    
    /**
     * Are the values equivalent from DB point of view. For example, 1 and '1' are equivalent.
     */
    def defaultValuesEquivalent(a: SqlExpr, b: SqlExpr) = {
        def e1(a: SqlExpr, b: SqlExpr) = (a, b) match {
            case (NumberValue(x), StringValue(y)) if x.toString == y => true
            // XXX: should only for date and time types
            case (StringValue("0000-00-00 00:00:00"), StringValue("0000-00-00")) => true
            case (StringValue("0000-00-00 00:00:00"), NumberValue(0)) => true
            case _ => false
        }

        a == b || e1(a, b) || e1(b, a)
    }
    
    def dataTypesEquivalent(a: DataType, b: DataType) =
        dataTypes.equivalent(a, b)
    
    def columnPropertiesEquivalent(a: ColumnProperty, b: ColumnProperty) = {
        require(a.propertyType == b.propertyType)
        val propertyType = a.propertyType
        (a, b) match {
            case (DataTypeProperty(adt), DataTypeProperty(bdt)) => dataTypesEquivalent(adt, bdt)
            case (DefaultValue(adv), DefaultValue(bdv)) => defaultValuesEquivalent(adv, bdv)
            case _ => a == b
{'fraction_non_alphanumeric': 0.12173038229376258, 'fraction_numerical': 0.028169014084507043, 'mean_word_length': 2.6289537712895377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1885834', 'n_tokens_mistral': 965, 'n_tokens_neox': 913, 'n_words': 259}