@kipicore/dbcore 1.1.178 → 1.1.179
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const up = async (queryInterface, Sequelize) => {
|
|
3
|
+
// Remove old index if exists
|
|
4
|
+
const oldIndexes = await queryInterface.showIndex('user_project_assessment_options');
|
|
5
|
+
const hasOldIndex = oldIndexes.some(idx => idx.name === 'user_project_assessments_unique_key');
|
|
6
|
+
if (hasOldIndex) {
|
|
7
|
+
await queryInterface.removeIndex('user_project_assessment_options', 'user_project_assessments_unique_key');
|
|
8
|
+
}
|
|
9
|
+
// Add new index if not exists
|
|
10
|
+
const newIndexName = 'user_project_assessments_unique_key';
|
|
11
|
+
const newIndexes = await queryInterface.showIndex('user_project_assessment_options');
|
|
12
|
+
const hasNewIndex = newIndexes.some(idx => idx.name === newIndexName);
|
|
13
|
+
if (!hasNewIndex) {
|
|
14
|
+
await queryInterface.addIndex('user_project_assessment_options', ['user_id', 'assessment_project_id', 'academic_calendar_id'], {
|
|
15
|
+
name: newIndexName,
|
|
16
|
+
unique: true,
|
|
17
|
+
where: { deleted_at: null },
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const down = async (queryInterface, Sequelize) => {
|
|
22
|
+
const newIndexName = 'user_project_assessments_unique_key';
|
|
23
|
+
const indexes = await queryInterface.showIndex('user_project_assessment_options');
|
|
24
|
+
const hasNewIndex = indexes.some(idx => idx.name === newIndexName);
|
|
25
|
+
if (hasNewIndex) {
|
|
26
|
+
await queryInterface.removeIndex('user_project_assessment_options', newIndexName);
|
|
27
|
+
}
|
|
28
|
+
const hasOldIndex = indexes.some(idx => idx.name === 'user_project_assessments_unique_key');
|
|
29
|
+
if (!hasOldIndex) {
|
|
30
|
+
await queryInterface.addIndex('user_project_assessment_options', ['user_id', 'assessment_project_id'], {
|
|
31
|
+
name: 'user_project_assessments_unique_key',
|
|
32
|
+
unique: true,
|
|
33
|
+
where: { deleted_at: null },
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
module.exports = {
|
|
38
|
+
up,
|
|
39
|
+
down,
|
|
40
|
+
};
|
|
@@ -96,7 +96,7 @@ UserProjectAssessmentOptionModel.init({
|
|
|
96
96
|
{
|
|
97
97
|
name: 'user_project_assessments_unique_key',
|
|
98
98
|
unique: true,
|
|
99
|
-
fields: ['user_id', 'assessment_project_id'],
|
|
99
|
+
fields: ['user_id', 'assessment_project_id', 'academic_calendar_id'],
|
|
100
100
|
where: { deleted_at: null },
|
|
101
101
|
},
|
|
102
102
|
],
|
package/package.json
CHANGED