Skip to content

fix: no-op redundant AddExternalLoginsUserForeignKey migration#938

Merged
Chris0Jeky merged 1 commit intomainfrom
fix/932-redundant-migration
Apr 23, 2026
Merged

fix: no-op redundant AddExternalLoginsUserForeignKey migration#938
Chris0Jeky merged 1 commit intomainfrom
fix/932-redundant-migration

Conversation

@Chris0Jeky
Copy link
Copy Markdown
Owner

Summary

  • No-ops the 20260422183834_AddExternalLoginsUserForeignKey migration whose Up/Down bodies redundantly re-added FK_ExternalLogins_Users_UserId, which was already added in 20260402230822_AddTokenInvalidatedAt
  • The migration file is retained (not deleted) because it may already be recorded in __EFMigrationsHistory on existing databases
  • Empty method bodies with explanatory comments replace the redundant AddForeignKey/DropForeignKey calls

Closes #932

Test plan

  • dotnet build backend/Taskdeck.sln -c Release -- 0 errors
  • dotnet test backend/Taskdeck.sln -c Release -m:1 -- all test suites pass (5 pre-existing env-specific failures in CORS/HSTS/MCP telemetry tests are unrelated)
  • Verified only the .cs migration file changed; Designer file and model snapshot are untouched
  • Confirmed the FK is present in the earlier migration 20260402230822_AddTokenInvalidatedAt.cs (lines 20-26)

@Chris0Jeky
Copy link
Copy Markdown
Owner Author

Adversarial Self-Review

1. Is the no-op approach safe for databases that already ran this migration?

Yes. Databases that already ran AddExternalLoginsUserForeignKey have the FK in place (added by AddTokenInvalidatedAt and then redundantly re-added). The migration is already recorded in __EFMigrationsHistory, so EF Core will never re-run it. The no-op change only affects future executions, of which there will be none for these databases.

2. Is the no-op approach safe for fresh databases that haven't run it yet?

Yes. Fresh databases will run all migrations in order:

  1. 20260402230822_AddTokenInvalidatedAt adds both the TokenInvalidatedAt column and FK_ExternalLogins_Users_UserId.
  2. 20260422183834_AddExternalLoginsUserForeignKey (now a no-op) does nothing.
  3. The model snapshot still declares the ExternalLogin -> User FK relationship (verified at line 1956-1963 of TaskdeckDbContextModelSnapshot.cs), so EF Core's model validation will not flag any drift.

3. Did I accidentally modify the model snapshot?

No. git diff --name-only HEAD~1 shows only one file changed: 20260422183834_AddExternalLoginsUserForeignKey.cs. The .Designer.cs file and TaskdeckDbContextModelSnapshot.cs are untouched.

4. Is the comment accurate about which earlier migration added the FK?

Yes. Verified that 20260402230822_AddTokenInvalidatedAt.cs lines 20-26 contain an identical AddForeignKey call for FK_ExternalLogins_Users_UserId on the ExternalLogins table.

5. Could this break EF Core's migration state tracking?

No. EF Core tracks migrations by their ID (the [Migration("20260422183834_AddExternalLoginsUserForeignKey")] attribute in the Designer file), not by inspecting the Up/Down method bodies. The Designer file is untouched, so migration ordering and identity are preserved. EF Core will still recognize this migration as applied and skip it.

Verdict

No issues found. The change is safe for all database states (fresh, existing, and rollback scenarios).

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the AddExternalLoginsUserForeignKey migration to be a no-op, as the foreign key was already established in a previous migration. This ensures database consistency without causing errors during migration execution. I have no feedback to provide.

@Chris0Jeky
Copy link
Copy Markdown
Owner Author

Independent Adversarial Review

Verdict: APPROVED -- no issues found.

Migration Redundancy Verification

I independently confirmed the FK duplication:

  • 20260402230822_AddTokenInvalidatedAt.Up() (lines 20-26) adds FK_ExternalLogins_Users_UserId on ExternalLogins -> Users.Id with Cascade delete.
  • 20260422183834_AddExternalLoginsUserForeignKey.Up() (original) adds an identical FK: same name, table, column, principal table, principal column, and delete behavior.

The second migration was entirely redundant.

Diff Correctness

  • Only one file changed: 20260422183834_AddExternalLoginsUserForeignKey.cs -- confirmed via git diff --name-only.
  • Designer.cs: Untouched (zero diff). Migration ID attribute preserved, so EF Core identity/ordering is intact.
  • Model snapshot: Untouched (zero diff). The ExternalLogin -> User FK relationship is still declared (lines 1890-1897 of snapshot), so EF Core model validation will not detect drift.
  • Comments in no-op methods: Accurate -- correctly reference the earlier migration by its full timestamp ID.

Scenario Analysis

Scenario Safe? Reasoning
Existing DB (migration already recorded) Yes EF Core tracks by migration ID in __EFMigrationsHistory; it will never re-run this. No-op body is irrelevant.
Fresh DB (all migrations run in order) Yes AddTokenInvalidatedAt creates the FK. This migration runs as a no-op. Model snapshot is correct.
Rollback of this migration Yes No-op Down means nothing happens, which is correct since the FK belongs to the earlier migration.
Rollback of AddTokenInvalidatedAt Yes Its Down() drops the FK and column. This later migration's no-op Down won't interfere.

CI Status

  • Migration Validation: PASSED
  • Backend Unit (ubuntu + windows): PASSED
  • Frontend Unit (ubuntu + windows): PASSED
  • Backend Architecture: PASSED
  • CodeQL / Security analysis: PASSED
  • Container Images: PASSED
  • Docs Governance: PASSED
  • API Integration (ubuntu + windows): FAILED -- pre-existing on main. Failures are in CorsApiTests and SecurityHeadersApiTests due to a missing Connectors:EncryptionKey environment variable. The same two jobs fail on the latest main run (run ID 24809498549). Unrelated to this PR.

Bot Findings

No bot review comments or inline findings to address. One COMMENTED review with no feedback.

Conclusion

The change is minimal, correct, and safe for all database states. No fixes needed.

FK_ExternalLogins_Users_UserId was already added in migration
20260402230822_AddTokenInvalidatedAt. The later migration
20260422183834_AddExternalLoginsUserForeignKey redundantly re-added the
same FK, causing unnecessary table rebuilds on SQLite and potential
failures on stricter providers.

Replace the Up/Down bodies with empty no-ops so existing databases
that already recorded this migration in __EFMigrationsHistory remain
valid, while fresh databases simply skip the duplicate operation.
@Chris0Jeky Chris0Jeky force-pushed the fix/932-redundant-migration branch from 35b0af9 to aa7ef08 Compare April 23, 2026 09:41
@Chris0Jeky
Copy link
Copy Markdown
Owner Author

Adversarial Review (post-rebase)

Reviewer: Rebased onto current main (which includes CI fixes from PR #942). Clean rebase, no conflicts. Force-pushed with lease.

Diff Verification

  • Single file changed: 20260422183834_AddExternalLoginsUserForeignKey.cs (7 insertions, 10 deletions)
  • Designer.cs: Zero diff -- migration identity ([Migration("20260422183834_AddExternalLoginsUserForeignKey")]) preserved
  • Model snapshot: Zero diff -- ExternalLogin -> User FK relationship still declared (lines 1890-1897)

FK Duplication Confirmed

Independently verified the redundancy:

  • 20260402230822_AddTokenInvalidatedAt.Up() lines 20-26: AddForeignKey("FK_ExternalLogins_Users_UserId", table: "ExternalLogins", column: "UserId", principalTable: "Users", principalColumn: "Id", onDelete: Cascade)
  • The later migration had an identical call. Making it a no-op is correct.

Up() Safety

Empty body with explanatory comment. No residual code that could execute. Correct.

Down() Safety

Empty body -- this is the critical check. The original Down() called DropForeignKey("FK_ExternalLogins_Users_UserId"), which would have dropped the FK that legitimately belongs to AddTokenInvalidatedAt. The no-op Down() is actually safer than the original, because rolling back this migration alone would no longer orphan the ExternalLogins table's FK constraint.

Scenario Matrix

Scenario Result
Existing DB, migration recorded Safe -- EF Core skips recorded migrations
Fresh DB, all migrations in sequence Safe -- FK created by AddTokenInvalidatedAt, this is a no-op
Rollback of this migration only Safe -- no-op Down means the FK from AddTokenInvalidatedAt remains intact
Rollback of AddTokenInvalidatedAt Safe -- its Down() drops the FK and column; this migration's no-op Down does not interfere

Bot Comments

Gemini: "no feedback to provide" -- nothing to address.

CI

All checks re-triggered after rebase onto main. Pending. Pre-existing API Integration failures (CORS/HSTS tests due to missing Connectors:EncryptionKey) are unrelated to this PR.

Verdict

APPROVED. The change is minimal, correct, and safe for all database states. The no-op Down() is actually an improvement over the original, which would have erroneously dropped a FK owned by an earlier migration.

@Chris0Jeky Chris0Jeky merged commit 89f61dc into main Apr 23, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from Pending to Done in Taskdeck Execution Apr 23, 2026
@Chris0Jeky Chris0Jeky deleted the fix/932-redundant-migration branch April 23, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix: redundant AddExternalLoginsUserForeignKey migration (tech debt)

1 participant