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

skill & skillsProvider removal #126

Open
wants to merge 5 commits into
base: feature/removing_skill_model
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix #127
  • Loading branch information
xxcxy committed Oct 8, 2021
commit 68089aae588786cc1d3eaaf342c1ebe61e7e9a24
3 changes: 0 additions & 3 deletions scripts/db/migrations/06_create-organizationSkillsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ module.exports = {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
skillProviderId: {
type: DataTypes.UUID
},
createdBy: {
type: DataTypes.STRING
},
Expand Down
38 changes: 38 additions & 0 deletions scripts/db/migrations/08_create-skill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { DataTypes } = require('sequelize')

module.exports = {
up: async (query) => {
await query.createTable('Skills', {
id: {
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
createdBy: {
type: DataTypes.STRING
},
updatedBy: {
type: DataTypes.STRING
},
name: {
type: DataTypes.STRING
},
externalId: {
type: DataTypes.STRING
},
uri: {
type: DataTypes.STRING
},
created: {
type: DataTypes.DATE,
allowNull: false
},
updated: {
type: DataTypes.DATE
}
})
},
down: async (query) => {
await query.dropTable('Skills')
}
}
32 changes: 32 additions & 0 deletions scripts/db/migrations/09_create-skillsProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { DataTypes } = require('sequelize')

module.exports = {
up: async (query) => {
await query.createTable('SkillsProviders', {
id: {
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
createdBy: {
type: DataTypes.STRING
},
updatedBy: {
type: DataTypes.STRING
},
name: {
type: DataTypes.STRING
},
created: {
type: DataTypes.DATE,
allowNull: false
},
updated: {
type: DataTypes.DATE
}
})
},
down: async (query) => {
await query.dropTable('SkillsProviders')
}
}
3 changes: 0 additions & 3 deletions scripts/db/migrations/13_create-usersSkill.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ module.exports = {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
skillId: {
type: DataTypes.UUID
},
createdBy: {
type: DataTypes.STRING
},
Expand Down
27 changes: 27 additions & 0 deletions scripts/db/migrations/14_add-relationship.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ const { DataTypes } = require('sequelize')

module.exports = {
up: async (query) => {
await query.addColumn('Skills', 'skillProviderId', {
type: DataTypes.UUID,
references: {
model: 'SkillsProviders',
key: 'id'
},
onUpdate: 'CASCADE'
})
await query.addColumn('OrganizationSkillsProviders', 'skillProviderId', {
type: DataTypes.UUID,
references: {
model: 'SkillsProviders',
key: 'id'
},
onUpdate: 'CASCADE'
})
await query.addColumn('UsersSkills', 'userId', {
type: DataTypes.UUID,
references: {
Expand Down Expand Up @@ -72,6 +88,14 @@ module.exports = {
onUpdate: 'CASCADE',
onDelete: 'CASCADE'
})
await query.addColumn('UsersSkills', 'skillId', {
type: DataTypes.UUID,
references: {
model: 'Skills',
key: 'id'
},
onUpdate: 'CASCADE'
})
await query.addColumn('UsersRoles', 'roleId', {
type: DataTypes.UUID,
references: {
Expand Down Expand Up @@ -106,6 +130,8 @@ module.exports = {
})
},
down: async (query) => {
await query.removeColumn('Skills', 'skillProviderId')
await query.removeColumn('OrganizationSkillsProviders', 'skillProviderId')
await query.removeColumn('UsersSkills', 'userId')
await query.removeColumn('Achievements', 'userId')
await query.removeColumn('UserAttributes', 'userId')
Expand All @@ -114,6 +140,7 @@ module.exports = {
await query.removeColumn('ExternalProfiles', 'organizationId')
await query.removeColumn('AttributeGroups', 'organizationId')
await query.removeColumn('OrganizationSkillsProviders', 'organizationId')
await query.removeColumn('UsersSkills', 'skillId')
await query.removeColumn('UsersRoles', 'roleId')
await query.removeColumn('Achievements', 'achievementsProviderId')
await query.removeColumn('UserAttributes', 'attributeId')
Expand Down
96 changes: 96 additions & 0 deletions scripts/db/migrations/15_remove-skills-skillsProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const { DataTypes } = require('sequelize')

module.exports = {
up: async (query) => {
await query.removeColumn('UsersSkills', 'skillId')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sande3p this would cause all the existing data to be lost, I guess. How can we handle that?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxceem do you have idea how can handle this without loosing data?

Copy link

@maxceem maxceem Oct 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @vikasrohit. I don't think these columns should be removed as we this script adds them back after removing which looks like doesn't make sense. I guess these columns should be left as it is without any changes. The only thing which has to be changed - references from other tables to these columns have to be removed and that's it.

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xxcxy @Sande3p any of you verified the migration script for preventing data loss on your local? I want to make sure before I run it on dev.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will drop table Skills and SkillsProviders.
If you mean preventing other table's data loss, then yes, i tried.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean preventing other table's data loss, then yes, i tried.

Yes, that is what I was worried about. If the data is not lost in any tables excepts the two we want to get rid of.

await query.removeColumn('OrganizationSkillsProviders', 'skillProviderId')
await query.addColumn('OrganizationSkillsProviders', 'skillProviderId', {
type: DataTypes.UUID
})
await query.addColumn('UsersSkills', 'skillId', {
type: DataTypes.UUID
})
await query.dropTable('SkillsProviders')
await query.dropTable('Skills')
},
down: async (query) => {
await query.createTable('Skills', {
id: {
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
createdBy: {
type: DataTypes.STRING
},
updatedBy: {
type: DataTypes.STRING
},
name: {
type: DataTypes.STRING
},
externalId: {
type: DataTypes.STRING
},
uri: {
type: DataTypes.STRING
},
created: {
type: DataTypes.DATE,
allowNull: false
},
updated: {
type: DataTypes.DATE
}
})
await query.createTable('SkillsProviders', {
id: {
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
createdBy: {
type: DataTypes.STRING
},
updatedBy: {
type: DataTypes.STRING
},
name: {
type: DataTypes.STRING
},
created: {
type: DataTypes.DATE,
allowNull: false
},
updated: {
type: DataTypes.DATE
}
})
await query.removeColumn('UsersSkills', 'skillId')
await query.removeColumn('OrganizationSkillsProviders', 'skillProviderId')
await query.addColumn('Skills', 'skillProviderId', {
type: DataTypes.UUID,
references: {
model: 'SkillsProviders',
key: 'id'
},
onUpdate: 'CASCADE'
})
await query.addColumn('OrganizationSkillsProviders', 'skillProviderId', {
type: DataTypes.UUID,
references: {
model: 'SkillsProviders',
key: 'id'
},
onUpdate: 'CASCADE'
})
await query.addColumn('UsersSkills', 'skillId', {
type: DataTypes.UUID,
references: {
model: 'Skills',
key: 'id'
},
onUpdate: 'CASCADE'
})
}
}