iachat/app/models
Gabriel Jablonski 079d4b4996
fix(conversations): enforce NOT NULL on contact_id + cleanup orphans (#273)
* fix(conversations): enforce NOT NULL + FK on contact_id

Conversations had contact_id nullable with no FK to contacts. Combined
with dependent: :destroy_async on Contact#conversations, deleting a
contact could leave conversations pointing to a missing contact,
breaking the conversations#index API with
"undefined method 'additional_attributes' for nil" from the contact
partial.

Changes:
- Migration cleans up existing orphans, sets contact_id NOT NULL and
  adds a FK with ON DELETE CASCADE so the invariant is enforced at the
  DB level (complements the existing Rails presence validation).
- ContactMergeAction uses update_all for conversations/messages/notes/
  contact_inboxes so a failing callback cannot silently leave records
  pointing to the mergee contact before it is destroyed.
- Drop the now-redundant orphan filter in Conversations::ResolutionJob
  and its spec; the invariant is enforced at the schema level.

* fix: address review feedback

- Drop the ON DELETE CASCADE FK on conversations.contact_id. Several
  conversation-owned tables (messages, mentions, conversation_participants,
  reporting_events, csat_survey_responses, calls, applied_slas, sla_events,
  and polymorphic notifications) still have plain conversation_id references
  without FK cascades. The DB-level cascade would skip Conversation's
  dependent: cleanup and replace the NULL-contact bug with orphan children,
  and would also conflict with the existing non-cascade FKs on
  scheduled_messages/recurring_scheduled_messages. Keep the invariant at the
  Rails layer (NOT NULL + presence validation + dependent: :destroy_async).
- Clean up orphan conversations in the migration via Rails destroy so
  dependent associations are propagated correctly, instead of a raw
  DELETE FROM conversations that would orphan all child rows.
- Revert ContactMergeAction.merge_* methods back to per-record update! so
  Conversation#after_update_commit still fires (notify_status_change /
  CONVERSATION_CONTACT_CHANGED) for contact_id changes. The bang form
  still removes the silent-failure risk of the original .update call.
2026-04-22 13:57:40 -03:00
..
channel feat(whatsapp): convert inbox between WhatsApp providers (#268) 2026-04-18 20:57:27 -03:00
concerns Merge branch 'main' into chore/merge-4.13.0 2026-04-17 16:23:47 -03:00
integrations Revert "chore: Upgrade Rails to 7.2.2 and update Gemfile dependencies (#11037)" 2026-02-03 21:09:42 -08:00
internal_chat feat(internal-chat): implement internal chat system for agents (#247) 2026-04-11 13:50:15 -03:00
access_token.rb Feature: Access tokens for API access (#604) 2020-03-11 00:02:15 +05:30
account_user.rb feat(internal-chat): implement internal chat system for agents (#247) 2026-04-11 13:50:15 -03:00
account.rb Merge branch 'main' into chore/merge-4.13.0 2026-04-17 16:23:47 -03:00
agent_bot_inbox.rb Feature: Access tokens for API access (#604) 2020-03-11 00:02:15 +05:30
agent_bot.rb feat: sign webhooks for API channel and agentbots (#13892) 2026-04-06 15:28:25 +05:30
application_record.rb feat(mailer): add i18n support for transactional emails with pt-BR (#255) 2026-04-03 15:48:52 -03:00
article.rb Merge branch 'main' into chore/merge-4.13.0 2026-04-17 16:23:47 -03:00
assignment_policy.rb chore(annotations): sync model annotations with current schema (#12245) 2025-08-20 20:23:42 +02:00
attachment.rb Merge branch 'main' into chore/merge-4.13.0 2026-04-17 16:23:47 -03:00
automation_rule.rb Merge branch 'main' into chore/merge-4.13.0 2026-04-17 16:23:47 -03:00
campaign.rb Merge branch 'main' into chatwoot/develop 2025-07-16 09:37:08 -03:00
canned_response.rb chore: Apply fixes for items in rubocop_todo [CW-1806] (#8864) 2024-02-07 13:36:04 +04:00
category.rb feat: Add draft status for help center locales (#13768) 2026-03-17 12:45:54 +04:00
contact_inbox.rb Chore/merge upstream 4.8.0 (#150) 2025-11-19 16:25:58 -03:00
contact.rb feat: group conversations (#228) 2026-03-19 21:56:58 -03:00
conversation_participant.rb chore: Add controllers for conversation participants (#6462) 2023-02-15 16:33:31 -08:00
conversation.rb fix(conversations): enforce NOT NULL on contact_id + cleanup orphans (#273) 2026-04-22 13:57:40 -03:00
csat_survey_response.rb fix: Annotaterb model annotation incomplete migration (#13132) 2026-03-25 17:51:06 -07:00
custom_attribute_definition.rb feat: harden filter service 2026-03-09 21:19:20 +05:30
custom_filter.rb chore: Increase custom filter limit from 50 to 1000 per user (#12603) 2025-10-06 10:41:26 -07:00
dashboard_app.rb feat: dashboard apps on sidebar (#146) 2025-11-19 14:44:18 -03:00
data_import.rb chore: Add delay before running dataimport job (#8039) 2023-10-03 22:18:57 -07:00
email_template.rb chore: upgrade ruby version to 3.4.4 (#11524) 2025-05-21 19:40:07 +05:30
folder.rb feat: Portal endpoint (#4633) 2022-05-16 13:59:59 +05:30
group_member.rb feat: group conversations (#228) 2026-03-19 21:56:58 -03:00
inbox_assignment_policy.rb feat: Add assignment policies controllers with jbuilder views (#12199) 2025-08-18 19:15:21 -07:00
inbox_member.rb feat: auditlog for team and inbox member updates (#7516) 2023-08-15 19:55:19 -07:00
inbox_signature.rb feat: add per-inbox signature management (#226) 2026-02-26 19:53:03 -03:00
inbox.rb feat: schedule messages recurrence (#240) 2026-03-19 22:51:14 -03:00
installation_config.rb fix(installation_config): restore coder that accepts both jsonb hash and YAML string 2026-04-17 23:48:46 -03:00
integrations.rb Feature: Slack integration (#783) 2020-06-12 23:12:47 +05:30
jsonb_attributes_length_validator.rb Fix: added validation for custom and additional attribute (#4260) 2022-03-24 15:38:28 +05:30
kbase.rb Feature: Knowledge Base APIs (#1002) 2020-09-26 02:32:34 +05:30
label.rb feat: multiple UX improvements to labels (#7358) 2023-06-25 18:49:49 +05:30
macro.rb fix: add explicit remove assignment actions to macros and automations (#12172) 2026-04-16 15:57:41 +05:30
mention.rb fix: Notification page breakages (#5236) 2022-08-10 13:46:46 +02:00
message.rb Merge branch 'main' into chore/merge-4.13.0 2026-04-17 16:23:47 -03:00
note.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
notification_setting.rb fix: Specify external db with non-standard port (#2711) 2021-07-28 19:36:51 +05:30
notification_subscription.rb fix: Change the column identifier from string to text to avoid overflow (#9073) 2024-03-07 11:13:01 +05:30
notification.rb fix: pass serialized data in notification.deleted event to avoid Deserialisation (#13061) 2026-01-12 13:15:40 +05:30
platform_app_permissible.rb fix: SuperAdmin Improvements (#3733) 2022-01-11 19:00:00 -08:00
platform_app.rb Chore: Replaced dependent destroy with dependent destroy_async in all models (#3249) 2021-11-18 10:32:29 +05:30
portal.rb Merge branch 'chatwoot/develop' into chore/merge-upstream-4.12.0 2026-03-20 00:27:45 -03:00
recurring_scheduled_message.rb feat: schedule messages recurrence (#240) 2026-03-19 22:51:14 -03:00
related_category.rb feat: CRUD operation for associated articles to current article (#4912) 2022-07-04 20:29:44 +05:30
reporting_event.rb fix: Annotaterb model annotation incomplete migration (#13132) 2026-03-25 17:51:06 -07:00
reporting_events_rollup.rb feat(internal-chat): implement internal chat system for agents (#247) 2026-04-11 13:50:15 -03:00
scheduled_message.rb feat: schedule messages recurrence (#240) 2026-03-19 22:51:14 -03:00
super_admin.rb feat(internal-chat): implement internal chat system for agents (#247) 2026-04-11 13:50:15 -03:00
team_member.rb feat(internal-chat): implement internal chat system for agents (#247) 2026-04-11 13:50:15 -03:00
team.rb chore: apply Rails/SaveBang cop (#15) 2025-04-03 23:29:24 -03:00
user.rb fix(mailer): fall back to user account for devise email locale (#267) 2026-04-17 21:58:08 -03:00
webhook.rb Merge branch 'main' into chore/merge-4.13.0 2026-04-17 16:23:47 -03:00
working_hour.rb chore: Replace deprecated functions (#5611) 2022-10-12 14:55:59 -07:00