Skip to content

Conversation

@dkhalife
Copy link
Owner

@dkhalife dkhalife commented Mar 17, 2025

It should be possible to delete a user and have all their data deleted through cascades.

Copilot AI review requested due to automatic review settings March 17, 2025 01:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR aims to fix the foreign key relationship in the NotificationSettings table by removing the direct foreign key reference and instead linking NotificationSettings through the associated User. Key changes include:

  • Removing the direct NotificationSettings foreign key from the Notification model.
  • Adding cascade deletion constraints to the Task and User relations.
  • Updating queries and notification sending logic to reference NotificationSettings via the User association.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/models/notification.go Removed NotificationSettings relationship and added cascade constraints for Task and User
internal/services/notifications/notifications.go Updated notification provider lookups to reference NotificationSettings via User
internal/repos/notifier/notifier.go Modified Preload to load NotificationSettings nested under User
Comments suppressed due to low confidence (3)

internal/models/notification.go:15

  • The direct foreign key relationship for NotificationSettings is removed; ensure that all related logic is updated to use the User association for accessing NotificationSettings.
-	NotificationSettings NotificationSettings `json:"-" gorm:"foreignKey:UserID;references:UserID"`

internal/services/notifications/notifications.go:16

  • [nitpick] The nested use of 'Provider.Provider' may be confusing; consider renaming the inner field to clearly differentiate between the provider's type and its configuration.
switch notification.User.NotificationSettings.Provider.Provider {

internal/repos/notifier/notifier.go:86

  • Ensure that preloading 'User.NotificationSettings' fully covers the required associations after the foreign key change; verify that no unintended gaps exist in the data loading.
if err := r.db.Where("is_sent = 0 AND scheduled_for < ?", cutoff).Preload("User.NotificationSettings").Find(&notifications).Error; err != nil {

@dkhalife dkhalife enabled auto-merge (squash) March 17, 2025 01:06
@dkhalife dkhalife merged commit 175fc5b into main Mar 17, 2025
4 checks passed
@dkhalife dkhalife deleted the fk-notifications-user branch March 17, 2025 01:07
dkhalife added a commit that referenced this pull request Oct 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants