Files
vitfit-r2/V2/app/modules/audit/migrations/013-audit-logs.js
T
2026-06-13 08:03:45 -04:00

29 lines
1.1 KiB
JavaScript

'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('AuditLogs', {
id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
organizationId: { type: Sequelize.INTEGER },
userId: { type: Sequelize.INTEGER },
userRole: { type: Sequelize.STRING },
action: { type: Sequelize.STRING, allowNull: false },
entityType: { type: Sequelize.STRING },
entityId: { type: Sequelize.INTEGER },
details: { type: Sequelize.TEXT },
ipAddress: { type: Sequelize.STRING },
userAgent: { type: Sequelize.STRING },
createdAt: { type: Sequelize.DATE, allowNull: false },
});
await queryInterface.addIndex('AuditLogs', ['organizationId', 'createdAt']);
await queryInterface.addIndex('AuditLogs', ['userId']);
await queryInterface.addIndex('AuditLogs', ['action']);
await queryInterface.addIndex('AuditLogs', ['entityType', 'entityId']);
},
async down(queryInterface) {
await queryInterface.dropTable('AuditLogs');
},
};