Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit afd44af

Browse files
committed
fix onDelete action
1 parent 96e4e9b commit afd44af

File tree

2 files changed

+36
-43
lines changed

2 files changed

+36
-43
lines changed

scripts/db/migrations.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,33 @@ const path = require('path')
33
const Umzug = require('umzug')
44
const { createDb } = require('../../src/common/db-helper')
55

6-
const umzug = new Umzug({
7-
migrations: {
8-
// indicates the folder containing the migration .js files
9-
path: path.join(__dirname, './migrations'),
10-
// inject sequelize's QueryInterface in the migrations
11-
params: [
12-
sequelize.getQueryInterface()
13-
]
14-
},
15-
// indicates that the migration data should be store in the database
16-
// itself through sequelize. The default configuration creates a table
17-
// named `SequelizeMeta`.
18-
storage: 'sequelize',
19-
storageOptions: {
20-
sequelize: sequelize
21-
}
22-
});
6+
function getUmzug () {
7+
return new Umzug({
8+
migrations: {
9+
// indicates the folder containing the migration .js files
10+
path: path.join(__dirname, './migrations'),
11+
// inject sequelize's QueryInterface in the migrations
12+
params: [
13+
sequelize.getQueryInterface()
14+
]
15+
},
16+
// indicates that the migration data should be store in the database
17+
// itself through sequelize. The default configuration creates a table
18+
// named `SequelizeMeta`.
19+
storage: 'sequelize',
20+
storageOptions: {
21+
sequelize: sequelize
22+
}
23+
})
24+
}
2325

2426
(async () => {
2527
if (process.argv[2] === 'up') {
2628
createDb()
27-
await umzug.up()
29+
await getUmzug().up()
2830
console.log('All migrations performed successfully')
2931
} else if (process.argv[2] === 'down') {
30-
await umzug.down()
32+
await getUmzug().down()
3133
console.log('The last executed migration reverted successfully')
3234
} else {
3335
console.error('You should pass \'up\' or \'down\' as the parameter')

scripts/db/migrations/14_add-relationship.js

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ module.exports = {
88
model: 'SkillsProviders',
99
key: 'id'
1010
},
11-
onUpdate: 'CASCADE',
12-
onDelete: 'SET NULL'
11+
onUpdate: 'CASCADE'
1312
})
1413
await query.addColumn('OrganizationSkillsProviders', 'skillProviderId', {
1514
type: DataTypes.UUID,
1615
references: {
1716
model: 'SkillsProviders',
1817
key: 'id'
1918
},
20-
onUpdate: 'CASCADE',
21-
onDelete: 'SET NULL'
19+
onUpdate: 'CASCADE'
2220
})
2321
await query.addColumn('UsersSkills', 'userId', {
2422
type: DataTypes.UUID,
@@ -27,7 +25,7 @@ module.exports = {
2725
key: 'id'
2826
},
2927
onUpdate: 'CASCADE',
30-
onDelete: 'SET NULL'
28+
onDelete: 'CASCADE'
3129
})
3230
await query.addColumn('Achievements', 'userId', {
3331
type: DataTypes.UUID,
@@ -36,7 +34,7 @@ module.exports = {
3634
key: 'id'
3735
},
3836
onUpdate: 'CASCADE',
39-
onDelete: 'SET NULL'
37+
onDelete: 'CASCADE'
4038
})
4139
await query.addColumn('UserAttributes', 'userId', {
4240
type: DataTypes.UUID,
@@ -45,7 +43,7 @@ module.exports = {
4543
key: 'id'
4644
},
4745
onUpdate: 'CASCADE',
48-
onDelete: 'SET NULL'
46+
onDelete: 'CASCADE'
4947
})
5048
await query.addColumn('ExternalProfiles', 'userId', {
5149
type: DataTypes.UUID,
@@ -54,7 +52,7 @@ module.exports = {
5452
key: 'id'
5553
},
5654
onUpdate: 'CASCADE',
57-
onDelete: 'SET NULL'
55+
onDelete: 'CASCADE'
5856
})
5957
await query.addColumn('UsersRoles', 'userId', {
6058
type: DataTypes.UUID,
@@ -63,25 +61,23 @@ module.exports = {
6361
key: 'id'
6462
},
6563
onUpdate: 'CASCADE',
66-
onDelete: 'SET NULL'
64+
onDelete: 'CASCADE'
6765
})
6866
await query.addColumn('ExternalProfiles', 'organizationId', {
6967
type: DataTypes.UUID,
7068
references: {
7169
model: 'Organizations',
7270
key: 'id'
7371
},
74-
onUpdate: 'CASCADE',
75-
onDelete: 'SET NULL'
72+
onUpdate: 'CASCADE'
7673
})
7774
await query.addColumn('AttributeGroups', 'organizationId', {
7875
type: DataTypes.UUID,
7976
references: {
8077
model: 'Organizations',
8178
key: 'id'
8279
},
83-
onUpdate: 'CASCADE',
84-
onDelete: 'SET NULL'
80+
onUpdate: 'CASCADE'
8581
})
8682
await query.addColumn('OrganizationSkillsProviders', 'organizationId', {
8783
type: DataTypes.UUID,
@@ -90,52 +86,47 @@ module.exports = {
9086
key: 'id'
9187
},
9288
onUpdate: 'CASCADE',
93-
onDelete: 'SET NULL'
89+
onDelete: 'CASCADE'
9490
})
9591
await query.addColumn('UsersSkills', 'skillId', {
9692
type: DataTypes.UUID,
9793
references: {
9894
model: 'Skills',
9995
key: 'id'
10096
},
101-
onUpdate: 'CASCADE',
102-
onDelete: 'SET NULL'
97+
onUpdate: 'CASCADE'
10398
})
10499
await query.addColumn('UsersRoles', 'roleId', {
105100
type: DataTypes.UUID,
106101
references: {
107102
model: 'Roles',
108103
key: 'id'
109104
},
110-
onUpdate: 'CASCADE',
111-
onDelete: 'SET NULL'
105+
onUpdate: 'CASCADE'
112106
})
113107
await query.addColumn('Achievements', 'achievementsProviderId', {
114108
type: DataTypes.UUID,
115109
references: {
116110
model: 'AchievementsProviders',
117111
key: 'id'
118112
},
119-
onUpdate: 'CASCADE',
120-
onDelete: 'SET NULL'
113+
onUpdate: 'CASCADE'
121114
})
122115
await query.addColumn('UserAttributes', 'attributeId', {
123116
type: DataTypes.UUID,
124117
references: {
125118
model: 'Attributes',
126119
key: 'id'
127120
},
128-
onUpdate: 'CASCADE',
129-
onDelete: 'SET NULL'
121+
onUpdate: 'CASCADE'
130122
})
131123
await query.addColumn('Attributes', 'attributeGroupId', {
132124
type: DataTypes.UUID,
133125
references: {
134126
model: 'AttributeGroups',
135127
key: 'id'
136128
},
137-
onUpdate: 'CASCADE',
138-
onDelete: 'SET NULL'
129+
onUpdate: 'CASCADE'
139130
})
140131
},
141132
down: async (query) => {

0 commit comments

Comments
 (0)