<commit_before>'use strict';

const _ = require('lodash');
const joi = require('joi');

const internals = {};

internals.schema = {
    modelName: joi.string().default('TableLog'),
    tableName: joi.string().default('table_log')
};

internals.createModel = function (sequelize, opts) {
    var DataTypes = sequelize.Sequelize;

    return sequelize.define(opts.modelName, {
        id: { type: DataTypes.STRING, primaryKey: true },
        updatedAt: DataTypes.DATE
    }, { tableName: opts.tableName, timestamps: false })
};

internals.createLogFn = function (sequelize, logTable, modelTable) {
    return sequelize.query(`CREATE OR REPLACE FUNCTION ${modelTable}_update_log() RETURNS TRIGGER AS $$ BEGIN INSERT INTO ${logTable} (id, "updatedAt") VALUES ('${modelTable}', NOW()) ON CONFLICT (id) DO UPDATE SET "updatedAt" = NOW(); RETURN NEW; END; $$ language plpgsql;`)
};

internals.dropTrigger = function (sequelize, modelTable) {
    return sequelize.query(`DROP TRIGGER IF EXISTS log_update ON ${modelTable}`);
};

internals.createTrigger = function (sequelize, modelTable) {
    return sequelize.query(`CREATE TRIGGER log_update AFTER INSERT OR UPDATE OR DELETE ON ${modelTable} FOR EACH ROW EXECUTE PROCEDURE ${modelTable}_update_log()`);
};

module.exports = function (opts = {}) {
    opts = joi.attempt(opts, internals.schema);

    return function (model) {
        const sequelize = model.sequelize;
        const tableName = model.options.tableName;<commit_msg>quote the table name to prevent errors on reserved words like "user"<commit_after>'use strict';

const _ = require('lodash');
const joi = require('joi');

const internals = {};

internals.schema = {
    modelName: joi.string().default('TableLog'),
    tableName: joi.string().default('table_log')
};

internals.createModel = function (sequelize, opts) {
    var DataTypes = sequelize.Sequelize;

    return sequelize.define(opts.modelName, {
        id: { type: DataTypes.STRING, primaryKey: true },
        updatedAt: DataTypes.DATE
    }, { tableName: opts.tableName, timestamps: false })
};

internals.createLogFn = function (sequelize, logTable, modelTable) {
    return sequelize.query(`CREATE OR REPLACE FUNCTION ${modelTable}_update_log() RETURNS TRIGGER AS $$ BEGIN INSERT INTO ${logTable} (id, "updatedAt") VALUES ('${modelTable}', NOW()) ON CONFLICT (id) DO UPDATE SET "updatedAt" = NOW(); RETURN NEW; END; $$ language plpgsql;`)
};

internals.dropTrigger = function (sequelize, modelTable) {
    return sequelize.query(`DROP TRIGGER IF EXISTS log_update ON "${modelTable}"`);
};

internals.createTrigger = function (sequelize, modelTable) {
    return sequelize.query(`CREATE TRIGGER log_update AFTER INSERT OR UPDATE OR DELETE ON "${modelTable}" FOR EACH ROW EXECUTE PROCEDURE ${modelTable}_update_log()`);
};

module.exports = function (opts = {}) {
    opts = joi.attempt(opts, internals.schema);

    return function (model) {
        const sequelize = model.sequelize;
        const tableName = model.options.tableName;
{'fraction_non_alphanumeric': 0.1328462304882099, 'fraction_numerical': 0.0, 'mean_word_length': 4.619402985074627, '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': '4517939', 'n_tokens_mistral': 966, 'n_tokens_neox': 920, 'n_words': 248}