Skip to content

Commit

Permalink
Merge pull request #369 from internxt/bugfix/modify-folder-plainname-…
Browse files Browse the repository at this point in the history
…index

[_]: feat/modified-folders-table-plain_name-index
  • Loading branch information
CandelR authored Jan 19, 2023
2 parents 1743f91 + 8587f50 commit a736408
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
18 changes: 18 additions & 0 deletions migrations/20230105113000-modify-index-folder-plain-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.removeIndex('folders', 'folders_plainname_parentid_key');
await queryInterface.addIndex('folders', {
fields: ['plain_name', 'parent_id'],
name: 'folders_plainname_parentid_key',
unique: true,
where: { deleted: { [Sequelize.Op.eq]: false } },
});
},

down: async (queryInterface) => {
await queryInterface.removeIndex('folders', 'folders_plainname_parentid_key');
},
};
16 changes: 9 additions & 7 deletions src/app/services/folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,18 +451,20 @@ module.exports = (Model, App) => {
if (metadata.itemName) {
const cryptoFolderName = App.services.Crypt.encryptName(metadata.itemName, folder.parentId);

Model.folder.findOne({
where: {
parentId: { [Op.eq]: folder.parentId },
name: { [Op.eq]: cryptoFolderName },
deleted: { [Op.eq]: false },
},
})
Model.folder
.findOne({
where: {
parentId: { [Op.eq]: folder.parentId },
name: { [Op.eq]: cryptoFolderName },
deleted: { [Op.eq]: false },
},
})
.then((isDuplicated) => {
if (isDuplicated) {
return next(Error('Folder with this name exists'));
}
newMeta.name = cryptoFolderName;
newMeta.plain_name = metadata.itemName;
try {
AesUtil.decrypt(cryptoFolderName, folder.parentId);
newMeta.encrypt_version = '03-aes';
Expand Down
1 change: 1 addition & 0 deletions src/config/environments/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = {
database: process.env.RDS_DBNAME,
username: process.env.RDS_USERNAME,
password: process.env.RDS_PASSWORD,
port: process.env.RDS_PORT,
dialect: 'postgres',
dialectOptions: {
ssl: {
Expand Down

0 comments on commit a736408

Please sign in to comment.