-
Notifications
You must be signed in to change notification settings - Fork 55
Add proper relationships to Comments #838
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6ea2809
Add specific foreign keys for comment targets
Slendy 0809586
Remove inheritdoc tags from migration
Slendy bce3467
Merge branch 'main' into comment-relationship
Slendy 0935ac7
Fix punctuation of deleted comment message and add mod deletion message
Slendy 84963d3
Merge branch 'main' into comment-relationship
Slendy cb91824
Merge branch 'main' into comment-relationship
Slendy a3ee9cd
Fix broken merge
Slendy 1e06997
Cleanup comment queries
Slendy f5b2c49
Merge branch 'main' into comment-relationship
Slendy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
ProjectLighthouse/Migrations/20230714212153_AddUserIdAndSlotIdToComment.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| using LBPUnion.ProjectLighthouse.Database; | ||
| using Microsoft.EntityFrameworkCore.Infrastructure; | ||
| using Microsoft.EntityFrameworkCore.Migrations; | ||
|
|
||
| #nullable disable | ||
|
|
||
| namespace ProjectLighthouse.Migrations | ||
| { | ||
| [DbContext(typeof(DatabaseContext))] | ||
| [Migration("20230714212153_AddUserIdAndSlotIdToComment")] | ||
| public partial class AddUserIdAndSlotIdToComment : Migration | ||
| { | ||
| protected override void Up(MigrationBuilder migrationBuilder) | ||
| { | ||
| migrationBuilder.AddColumn<int>( | ||
| name: "TargetSlotId", | ||
| table: "Comments", | ||
| type: "int", | ||
| nullable: true); | ||
|
|
||
| migrationBuilder.AddColumn<int>( | ||
| name: "TargetUserId", | ||
| table: "Comments", | ||
| type: "int", | ||
| nullable: true); | ||
|
|
||
| // Set SlotId and UserId to null if there isn't an existing slot or user | ||
| migrationBuilder.Sql("UPDATE Comments AS c INNER JOIN Users AS u ON c.TargetId = u.UserId AND c.Type = 0 SET c.TargetUserId = u.UserId"); | ||
| migrationBuilder.Sql("UPDATE Comments AS c INNER JOIN Slots AS s ON c.TargetId = s.SlotId AND c.Type = 1 SET c.TargetSlotId = s.SlotId"); | ||
|
|
||
| // Delete rows that have null SlotIds or UserIds | ||
| migrationBuilder.Sql("DELETE FROM Comments WHERE TargetUserId IS NULL AND TargetSlotId IS NULL"); | ||
| } | ||
|
|
||
| protected override void Down(MigrationBuilder migrationBuilder) | ||
| { | ||
| migrationBuilder.DropColumn( | ||
| name: "TargetSlotId", | ||
| table: "Comments"); | ||
|
|
||
| migrationBuilder.DropColumn( | ||
| name: "TargetUserId", | ||
| table: "Comments"); | ||
| } | ||
| } | ||
| } | ||
72 changes: 72 additions & 0 deletions
72
ProjectLighthouse/Migrations/20230714212234_AddForeignKeyConstraintToComment.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| using LBPUnion.ProjectLighthouse.Database; | ||
| using Microsoft.EntityFrameworkCore.Infrastructure; | ||
| using Microsoft.EntityFrameworkCore.Migrations; | ||
|
|
||
| #nullable disable | ||
|
|
||
| namespace ProjectLighthouse.Migrations | ||
| { | ||
| [DbContext(typeof(DatabaseContext))] | ||
| [Migration("20230714212234_AddForeignKeyConstraintToComment")] | ||
| public partial class AddForeignKeyConstraintToComment : Migration | ||
| { | ||
| protected override void Up(MigrationBuilder migrationBuilder) | ||
| { | ||
| migrationBuilder.DropColumn( | ||
| name: "TargetId", | ||
| table: "Comments"); | ||
|
|
||
| migrationBuilder.CreateIndex( | ||
| name: "IX_Comments_TargetSlotId", | ||
| table: "Comments", | ||
| column: "TargetSlotId"); | ||
|
|
||
| migrationBuilder.CreateIndex( | ||
| name: "IX_Comments_TargetUserId", | ||
| table: "Comments", | ||
| column: "TargetUserId"); | ||
|
|
||
| migrationBuilder.AddForeignKey( | ||
| name: "FK_Comments_Slots_TargetSlotId", | ||
| table: "Comments", | ||
| column: "TargetSlotId", | ||
| principalTable: "Slots", | ||
| principalColumn: "SlotId", | ||
| onDelete: ReferentialAction.Cascade); | ||
|
|
||
| migrationBuilder.AddForeignKey( | ||
| name: "FK_Comments_Users_TargetUserId", | ||
| table: "Comments", | ||
| column: "TargetUserId", | ||
| principalTable: "Users", | ||
| principalColumn: "UserId", | ||
| onDelete: ReferentialAction.Cascade); | ||
| } | ||
|
|
||
| protected override void Down(MigrationBuilder migrationBuilder) | ||
| { | ||
| migrationBuilder.DropForeignKey( | ||
| name: "FK_Comments_Slots_TargetSlotId", | ||
| table: "Comments"); | ||
|
|
||
| migrationBuilder.DropForeignKey( | ||
| name: "FK_Comments_Users_TargetUserId", | ||
| table: "Comments"); | ||
|
|
||
| migrationBuilder.DropIndex( | ||
| name: "IX_Comments_TargetSlotId", | ||
| table: "Comments"); | ||
|
|
||
| migrationBuilder.DropIndex( | ||
| name: "IX_Comments_TargetUserId", | ||
| table: "Comments"); | ||
|
|
||
| migrationBuilder.AddColumn<int>( | ||
| name: "TargetId", | ||
| table: "Comments", | ||
| type: "int", | ||
| nullable: false, | ||
| defaultValue: 0); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.