-
Notifications
You must be signed in to change notification settings - Fork 3
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
Implement a foreign key for subjects #98
Conversation
migrations/000002_add_subject_parent_id.down.sql is supposed to be empty? otherwise looks good to me. |
No, that should revert the changes added in the corresponding |
0743b6d
to
1e51850
Compare
@@ -218,3 +282,39 @@ func TestMigration(t *testing.T) { // nolint:paralleltest // database tests shou | |||
assert.Equal(t, false, dirty, "Database state mismatch: want %t but got %t", false, dirty) | |||
assert.Equal(t, err, nil, "Error downgrading the database: %s", err) | |||
} | |||
|
|||
func TestSubjectMigration(t *testing.T) { // nolint:paralleltest // database tests should run serially |
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.
We could also consider adding a test that ensures the FK does what it should by:
- Create a parent subject
- Create a child subject with
parent_id
pointing to the parent subject - Delete the parent subject and ensure both are removed
Although - I'm not sure how likely this scenario is.
1e51850
to
e91b614
Compare
I added a valid downgrade and test coverage exercising the downgrade. |
02961d5
to
7a01c4e
Compare
7a01c4e
to
c75194a
Compare
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.
I think it all looks good, wondering if we need to test the case where parent subject is removed after being referenced?
Yeah - I'll add a test for that today. Thanks for the review! |
c75194a
to
8912cd8
Compare
8912cd8
to
f3d595f
Compare
We want to be able to nest subjects and build a hierarchical relationship between them. This commit does that by adding a database migration that adds a new column for parent_id and adds a FK relationship to it. This approach was discussed in #84
f3d595f
to
2d401ae
Compare
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.
/lgtm
Thanks for adding the test
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: rhmdnd, Vincent056 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
We want to be able to nest subjects and build a hierarchical
relationship between them. This commit does that by adding a database
migration that adds a new column for parent_id and adds a FK
relationship to it.
This approach was discussed in #84