tududi/backend/migrations/20250810090200-create-permissions.js
antanst b8611d9338 chore(lint): remove unnecessary try/catch and tighten error handling
- Projects: remove superfluous try/catch around toast; keep explicit error path
- AdminUsers/Sidebar/ShareService: keep minimal catch blocks only to ignore non-JSON parse failures, without swallowing errors
- Lint/format pass remains green
2025-09-22 15:20:46 +03:00

68 lines
2.3 KiB
JavaScript

'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('permissions', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: Sequelize.INTEGER,
allowNull: false,
references: { model: 'users', key: 'id' },
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
resource_type: { type: Sequelize.STRING, allowNull: false },
resource_uid: { type: Sequelize.STRING, allowNull: false },
access_level: { type: Sequelize.STRING, allowNull: false },
propagation: {
type: Sequelize.STRING,
allowNull: false,
defaultValue: 'direct',
},
granted_by_user_id: {
type: Sequelize.INTEGER,
allowNull: false,
references: { model: 'users', key: 'id' },
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
source_action_id: {
type: Sequelize.INTEGER,
allowNull: true,
references: { model: 'actions', key: 'id' },
onUpdate: 'CASCADE',
onDelete: 'SET NULL',
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updated_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
});
await queryInterface.addConstraint('permissions', {
fields: ['user_id', 'resource_type', 'resource_uid'],
type: 'unique',
name: 'uniq_permissions_user_resource',
});
await queryInterface.addIndex('permissions', [
'resource_type',
'resource_uid',
]);
await queryInterface.addIndex('permissions', ['user_id']);
await queryInterface.addIndex('permissions', ['access_level']);
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('permissions');
},
};