<commit_before>module.exports = function(){
    var compareDBDescriptor = function(before, after){
        var ret = {
            need: false,
            addModel: [], // modelname
            rmModel: [], // modelnames
            changeModelDb: {}, // modelname - {defore: , after: }
            addAttr:{},// modelname - [attributes]
            rmAttr: {}, // modelname - [attributes]
            addOneA: {}, // modelname - [ass-names]
            rmOneA: {}, // modelname - [ass-names]
            addManyA: {}, // modelname - [ass-names]
            rmManyA: {}, // modelname - [ass-names]
            ddlSyncExt: {}, //modelname-descriptor
            ddlSyncRm: {}, // modelname-descriptor 
            changes: {}, // modelname - string
            err:[]
        }; 
        var beforeD = JSON.parse(JSON.stringify(before));
        var afterD = JSON.parse(JSON.stringify(after));
        ret.ddlSyncExt = beforeD;
        // ret.ddlSyncRm = afterD;
        for (var mdl in afterD) {
            var appMD = afterD[mdl]; // model descriptor
            var sncModel = beforeD[mdl];
            if (sncModel) {// compare models
                //attributes
                for (var atr in appMD.attributes) {
                    if (!sncModel.attributes[atr]) { // find new model attributes
                        ret.need = true;
                        sncModel.attributes[atr] = appMD.attributes[atr];
                        if (!ret.addAttr[mdl]) ret.addAttr[mdl] = [];
                        ret.addAttr[mdl].push(atr);
                        ret.ddlSyncExt[mdl] = sncModel;
                    } else {
                        if (!_.isEqual(sncModel.attributes[atr], appMD.attributes[atr])) {//model attribute was changed - error
                            if(!ret.changes[mdl]) ret.changes[mdl] = [];
                            ret.changes[mdl].push(" Attribute: " + atr);
                            ret.err.push("Model: " + mdl + " Attribute: " + atr + ' was changed. Migration cannot be complete.');
                        }
                    }
                }
                for (var atr in sncModel.attributes) {// find model attrs to remove
                    if (!appMD.attributes[atr]) {// remove attr
                        ret.need = true;
                        if (!ret.rmAttr[mdl]) ret.rmAttr[mdl] = [];
                        ret.rmAttr[mdl].push(atr);
                        ret.ddlSyncRm[mdl] = appMD; 
                    }
                }
                //has one   впринципе это никому не нужно, т.к. в аттрибутах уже учтено
                _.each(appMD.hasOne, function(obj,key){
                    if(!sncModel.hasOne[key]){ //new hasOne association
                        ret.need = true;
                        if(!ret.addOneA[mdl])ret.addOneA[mdl] = [];
                        ret.addOneA[mdl].push(key);
                    } else {
                        if (!_.isEqual(sncModel.hasOne[key], appMD.hasOne[key])) {//model association was changed - error
                            if(!ret.changes[mdl]) ret.changes[mdl] = [];
                            ret.changes[mdl].push(" Has One association: " + key);
                            ret.err.push("Model: " + mdl + " HasOne association: " + key + ' was changed. Migration cannot be complete.');
                        }
                    }
                });
                _.each(sncModel.hasOne, function(obj, key){
                    if(!appMD.hasOne[key]){
                        ret.need = true;
                        if(!ret.rmOneA[mdl]) ret.rmOneA[mdl] = [];
                        ret.rmOneA[mdl].push(key);
                    }
                });
                
                //has many таблицы исчезнувших ассоциации останутся в базе ели модель не будет удалена полностью
                _.each(appMD.hasMany, function(obj,key){
                    if(!sncModel.hasMany[key]){ //new hasMany association
                        ret.need = true;
                        if(!ret.addManyA[mdl])ret.addManyA[mdl] = [];
                        ret.addManyA[mdl].push(key);
                    } else {
                        if (!_.isEqual(sncModel.hasMany[key], appMD.hasMany[key])) {//model association was changed - error
                            if(!ret.changes[mdl]) ret.changes[mdl] = [];
                            ret.changes[mdl].push(" HasMany association: " + key);
                            ret.err.push("Model: " + mdl + " HasMany association: " + key + ' was changed. Migration cannot be complete.');
                        }
                    }
                });
                _.each(sncModel.hasMany, function(obj, key){
                    if(!appMD.hasMany[key]){
                        ret.need = true;
                        if(!ret.rmManyA[mdl]) ret.rmManyA[mdl] = [];
                        ret.rmManyA[mdl].push(key);
                    }
                });
                
            } else { // find new model
                ret.need = true;
                ret.addModel.push(mdl);
                ret.ddlSyncExt[mdl] = appMD;
            }
        }
        for (var mdl in beforeD) {
            if (!afterD[mdl]){ // remove this model
                ret.rmModel.push(mdl);
                ret.need = true;<commit_msg>differenca correct adding new associations<commit_after>module.exports = function(){
    var compareDBDescriptor = function(before, after){
        var ret = {
            need: false,
            addModel: [], // modelname
            rmModel: [], // modelnames
            changeModelDb: {}, // modelname - {defore: , after: }
            addAttr:{},// modelname - [attributes]
            rmAttr: {}, // modelname - [attributes]
            addOneA: {}, // modelname - [ass-names]
            rmOneA: {}, // modelname - [ass-names]
            addManyA: {}, // modelname - [ass-names]
            rmManyA: {}, // modelname - [ass-names]
            ddlSyncExt: {}, //modelname-descriptor
            ddlSyncRm: {}, // modelname-descriptor 
            changes: {}, // modelname - string
            err:[]
        }; 
        var beforeD = JSON.parse(JSON.stringify(before));
        var afterD = JSON.parse(JSON.stringify(after));
        ret.ddlSyncExt = beforeD;
        // ret.ddlSyncRm = afterD;
        for (var mdl in afterD) {
            var appMD = afterD[mdl]; // model descriptor
            var sncModel = beforeD[mdl];
            if (sncModel) {// compare models
                //attributes
                for (var atr in appMD.attributes) {
                    if (!sncModel.attributes[atr]) { // find new model attributes
                        ret.need = true;
                        sncModel.attributes[atr] = appMD.attributes[atr];
                        if (!ret.addAttr[mdl]) ret.addAttr[mdl] = [];
                        ret.addAttr[mdl].push(atr);
                        ret.ddlSyncExt[mdl] = sncModel;
                    } else {
                        if (!_.isEqual(sncModel.attributes[atr], appMD.attributes[atr])) {//model attribute was changed - error
                            if(!ret.changes[mdl]) ret.changes[mdl] = [];
                            ret.changes[mdl].push(" Attribute: " + atr);
                            ret.err.push("Model: " + mdl + " Attribute: " + atr + ' was changed. Migration cannot be complete.');
                        }
                    }
                }
                for (var atr in sncModel.attributes) {// find model attrs to remove
                    if (!appMD.attributes[atr]) {// remove attr
                        ret.need = true;
                        if (!ret.rmAttr[mdl]) ret.rmAttr[mdl] = [];
                        ret.rmAttr[mdl].push(atr);
                        ret.ddlSyncRm[mdl] = appMD; 
                    }
                }
                //has one   впринципе это никому не нужно, т.к. в аттрибутах уже учтено
                _.each(appMD.hasOne, function(obj,key){
                    if(!sncModel.hasOne[key]){ //new hasOne association
                        ret.need = true;
                        sncModel.hasOne[key] = appMD.hasOne[key];
                        if(!ret.addOneA[mdl])ret.addOneA[mdl] = [];
                        ret.addOneA[mdl].push(key);
                    } else {
                        if (!_.isEqual(sncModel.hasOne[key], appMD.hasOne[key])) {//model association was changed - error
                            if(!ret.changes[mdl]) ret.changes[mdl] = [];
                            ret.changes[mdl].push(" Has One association: " + key);
                            ret.err.push("Model: " + mdl + " HasOne association: " + key + ' was changed. Migration cannot be complete.');
                        }
                    }
                });
                _.each(sncModel.hasOne, function(obj, key){
                    if(!appMD.hasOne[key]){
                        ret.need = true;
                        if(!ret.rmOneA[mdl]) ret.rmOneA[mdl] = [];
                        ret.rmOneA[mdl].push(key);
                    }
                });
                
                //has many таблицы исчезнувших ассоциации останутся в базе ели модель не будет удалена полностью
                _.each(appMD.hasMany, function(obj,key){
                    if(!sncModel.hasMany[key]){ //new hasMany association
                        ret.need = true;
                        sncModel.hasMany[key] = appMD.hasMany[key];
                        if(!ret.addManyA[mdl])ret.addManyA[mdl] = [];
                        ret.addManyA[mdl].push(key);
                    } else {
                        if (!_.isEqual(sncModel.hasMany[key], appMD.hasMany[key])) {//model association was changed - error
                            if(!ret.changes[mdl]) ret.changes[mdl] = [];
                            ret.changes[mdl].push(" HasMany association: " + key);
                            ret.err.push("Model: " + mdl + " HasMany association: " + key + ' was changed. Migration cannot be complete.');
                        }
                    }
                });
                _.each(sncModel.hasMany, function(obj, key){
                    if(!appMD.hasMany[key]){
                        ret.need = true;
                        if(!ret.rmManyA[mdl]) ret.rmManyA[mdl] = [];
                        ret.rmManyA[mdl].push(key);
                    }
                });
                
            } else { // find new model
                ret.need = true;
                ret.addModel.push(mdl);
                ret.ddlSyncExt[mdl] = appMD;
            }
        }
        for (var mdl in beforeD) {
            if (!afterD[mdl]){ // remove this model
                ret.rmModel.push(mdl);
                ret.need = true;
{'fraction_non_alphanumeric': 0.12589227774172615, 'fraction_numerical': 0.0, 'mean_word_length': 1.1597597597597598, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2258263', 'n_tokens_mistral': 3002, 'n_tokens_neox': 2928, 'n_words': 569}