-
Notifications
You must be signed in to change notification settings - Fork 1
HEEDLS-712 - Modify the PK on CompetencyAssessmentQuestionRoleRequire… #852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HEEDLS-712 - Modify the PK on CompetencyAssessmentQuestionRoleRequire… #852
Conversation
…ments to be a compound key
…h a unique constraint instead
| using FluentMigrator; | ||
|
|
||
| [Migration(202201111021)] | ||
| public class ChangeCompetencyAssessmentQuestionRoleRequirementsPrimaryKey: Migration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the original migration made when we wanted to replace the ID column with a compound PK on the two necessary columns. As it was pushed into an MR, and thus run on Jenkins, prior to the decision to just use a unique constraint instead, this migration has been left, and the other migration tackles it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, missed this comment!
| Alter.Table("CompetencyAssessmentQuestionRoleRequirements").AddColumn("ID").AsInt32().NotNullable().Identity(); | ||
| Create.PrimaryKey("PK_CompetencyAssessmentQuestionRoleRequirements") | ||
| .OnTable("CompetencyAssessmentQuestionRoleRequirements").Column("ID"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might notice that this is not identical to the Down() method in the other migration. I only noticed when creating this migration that adding a column with .PrimaryKey() when altering a table (rather than creating) doesn't actually make the column a primary key. This seems to be due to a subtlety in FluentMigrator that should probably be more obvious but isn't, see here for details: fluentmigrator/fluentmigrator#96
| Delete.PrimaryKey("PK_CompetencyAssessmentQuestionRoleRequirements") | ||
| .FromTable("CompetencyAssessmentQuestionRoleRequirements"); | ||
| Alter.Table("CompetencyAssessmentQuestionRoleRequirements").AddColumn("ID").AsInt32().NotNullable() | ||
| .PrimaryKey().Identity(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given your comment on the next migration, should this Down() have Create.PrimaryKey...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. When I made the other migration, I thought it would be good to leave this one as is for some reason. But now I think it would break anytime someone wanted to migrate down beyond this. I've updated it to include the correct primary key addition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
…ments to be a compound key
JIRA link
https://softwiretech.atlassian.net/browse/HEEDLS-712
Description
The CompetencyAssessmentQuestionRoleRequirements table should only have one record for each SelfAssessmentID/CompetencyID combination, but the table did not actually enforce this. As advised by Kevin, I have removed the previous PK on the ID column, and the column itself, and replaced it with a compound PK on SelfAssessmentID and CompetencyID.
I have also made code changes where the ID was used and confirmed the method in question functions appropriately.
Screenshots
N/A
Developer checks
(Leave tasks unticked if they haven't been appropriate for your ticket.)
I have: