<commit_before>
var orm = require('orm');
var async = require('async');
var dbConfig = require('../config/database');

module.exports.run = function(done) {
    orm.connect(dbConfig, function(err, db) {
        var cinema = require('../models/cinema')(db);
        var movie  = require('../models/movie')(db);

        async.series([
            // Truncate tables
            cinema.clear,
            movie.clear,

            // Seed data
            async.apply(cinema.create, require('./cinemas').cinemas),
            async.apply(movie.create, require('./movies').movies),

        ], function(err) {
            if (err) console.error(err);
            db.close(done);
        });
    });
};<commit_msg>Truncate tables when there are foreign key constraints<commit_after>
var orm = require('orm');
var async = require('async');
var dbConfig = require('../config/database');

var truncate = function(db, table, done) {
    async.series([
        async.apply(db.driver.db.query.bind(db.driver.db), 'SET FOREIGN_KEY_CHECKS = 0'),
        async.apply(db.driver.db.query.bind(db.driver.db), 'TRUNCATE TABLE ' + db.driver.query.escape(table)),
        async.apply(db.driver.db.query.bind(db.driver.db), 'SET FOREIGN_KEY_CHECKS = 1'),
    ], done);
};

module.exports.run = function(done) {
    orm.connect(dbConfig, function(err, db) {
        var cinema = require('../models/cinema')(db);
        var movie  = require('../models/movie')(db);

        async.series([
            // Truncate tables
            async.apply(truncate, db, 'cinemas'),
            async.apply(truncate, db, 'movies'),

            // Seed data
            async.apply(cinema.create, require('./cinemas').cinemas),
            async.apply(movie.create, require('./movies').movies),

        ], function(err) {
            if (err) console.error(err);
            db.close(done);
        });
    });
};
{'fraction_non_alphanumeric': 0.1723404255319149, 'fraction_numerical': 0.0010638297872340426, 'mean_word_length': 2.3292035398230087, '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': '302157', 'n_tokens_mistral': 591, 'n_tokens_neox': 567, 'n_words': 104}