Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revision and RevisionChanges tables are not updating #9

Closed
sivailango opened this issue Feb 6, 2017 · 1 comment
Closed

Revision and RevisionChanges tables are not updating #9

sivailango opened this issue Feb 6, 2017 · 1 comment
Assignees
Labels

Comments

@sivailango
Copy link

index.js

"use strict";

var fs = require('fs');
var path = require('path');
var Sequelize = require('sequelize');
var env = process.env.NODE_ENV || 'development';
var config = require(path.join(__dirname, '../config/config.json'))[env];
var sequelize = new Sequelize(config.database, config.username, config.password, config);

var db = {}; 

var opts = {
	underscored: true,
	underscoredAttributes: true,
	enableCompression: false,
	enableMigration: true,
	debug: true
};

// Load Paper Trail
var PaperTrail = require('sequelize-paper-trail')(sequelize, opts);
// Setup Revision and RevisionChange models
//PaperTrail.defineModels(db);
PaperTrail.defineModels({});
  

fs.readdirSync(__dirname)
	.filter(function(file) {
		return (file.indexOf('.') !== 0) && (file !== 'index.js');
	}).forEach(function(file) {
		var model = sequelize["import"](path.join(__dirname, file));
		db[model.name] = model;
	});

Object.keys(db).forEach(function(modelName) {
	if ('associate' in db[modelName]) {
		db[modelName].associate(db);
	}
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;

User.js:

"use strict";

module.exports = function(sequelize, DataTypes) {

    var User = sequelize.define('user', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        firstName: {
            type: DataTypes.STRING
        },
        lastName: {
            type: DataTypes.STRING
        },
        dateOfJoin: {
            type: DataTypes.DATE
        },
        mobileNumber: {
            type: DataTypes.DOUBLE
        },
        address1: {
            type: DataTypes.STRING
        },
        address2: {
            type: DataTypes.STRING
        },
        city: {
            type: DataTypes.STRING
        },
        state: {
            type: DataTypes.STRING
        },
        pin: {
            type: DataTypes.STRING
        },
        emergencyContact: {
            type: DataTypes.DOUBLE
        },
        emergencyContactRelationship: {
            type: DataTypes.STRING
        },
        dateOfBirth: {
            type: DataTypes.DATE
        },
        gender: {
            type: DataTypes.ENUM('Male', 'Female')
        },
        maritalStatus: {
            type: DataTypes.BOOLEAN
        },
        email: {
            type: DataTypes.STRING,
            unique: true,
            validate: {
                isEmail: true
            }
        },
        password: {
            type: DataTypes.STRING
        },
        lastLoggedIn: {
            type: DataTypes.DATE
        },
        passwordExpiredOn: {
            type: DataTypes.DATE
        },
        accountStatus: {
            type: DataTypes.ENUM,
            values: ['CREATED', 'VERIFIED', 'ACTIVATED'],
            defaultValue: 'CREATED'
        },
        roles: {
            type: DataTypes.ARRAY(DataTypes.STRING)
        },
        preferences: {
            type: DataTypes.JSONB
        },
        reportingUserId: {
            type: DataTypes.STRING
        },
        revision: {
            type: DataTypes.INTEGER,
            defaultValue: 0
        } 
    }, {
        classMethods: {
            associate: function(models) {
                User.belongsTo(models.designation, { foreignKey: 'designationId' });
                User.belongsTo(models.department, { foreignKey: 'departmentId' });
                User.belongsTo(models.grade, { foreignKey: 'gradeId' });
                User.belongsTo(models.user_status, { foreignKey: 'statusId' });
            }
        }
    });
    
    User.hasPaperTrail();

    return User;

};

I could see Revision and RevisionChanges tables are created, but when I have updated the value on User model, I could not any see records on these tables, revision column of user model has created with value 1 and after that it never get increased. I could not find whats the problem, Am I missing anything? Also just I looked the index.js at node_modules folder of my local machine, it shows the code of release/0.4.0 branch, not from master branch

@nielsgl
Copy link
Owner

nielsgl commented Feb 6, 2017

Hmm, sorry about that, I thought that it was resolved :( I'm going to create a demo app so I can see where it is going wrong to resolve the issue.

@nielsgl nielsgl self-assigned this Feb 6, 2017
@nielsgl nielsgl added the bug label Feb 6, 2017
@nielsgl nielsgl closed this as completed Oct 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants