chatwoot/db/migrate
Sandeep pandey 16b8693e1b
fix: standardize contact company field on company_name (#14099)
Standardizes the contact company import/filter/automation contract on
`company_name`.

Closes #14096
Revives #9907

## Why

Contact company is read across the current CRM/contact UI from
`additional_attributes['company_name']`, but CSV import and a few
backend filter/automation paths still used the older `company` key. That
meant imported company values could be saved in a place the dashboard,
sorting, filters, and automation conditions did not consistently read
from.

Based on the production data check, the legacy `company` automation
configuration is effectively dead: the affected account did not have
contacts populated with `additional_attributes['company']`. So this PR
intentionally avoids adding long-term fallback behavior and uses
`company_name` as the single key going forward.

## What changed

- Contact CSV import now writes only `company_name` into
`additional_attributes['company_name']`.
- The example contact import CSV now uses the `company_name` header.
- Contact company sorting/filter config now uses `company_name`.
- Automation condition config now uses `company_name`.
- Existing standard automation conditions with `attribute_key:
'company'` are migrated to `company_name`.
- Existing saved contact filters with standard `attribute_key:
'company'` are migrated to `company_name`.
- Custom attributes named `company` are preserved and are not rewritten
by the migration.

## How to test

- Import a contact CSV with a `company_name` column and confirm the
Contact Company field is populated.
- Sort contacts by Company and confirm imported contacts are ordered
correctly.
- Create/edit an automation with Company as a condition and confirm it
saves with `company_name`.
- Verify existing saved contact filters and automation rules using the
old standard `company` key are migrated to `company_name`.

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Sojan Jose <sojan@pepalo.com>
2026-04-27 18:43:26 +05:30
..
20230426130150_init_schema.rb chore: Squash migrations till 05/2023 (#8862) 2024-02-06 17:00:38 +04:00
20230503101201_create_sla_policies.rb feat: SLA CRUD APIs (EE) (#7027) 2023-05-11 22:42:56 +05:30
20230509101256_add_index_to_messages_created_at.rb feat(perf): add index to messages created at (#7044) 2023-05-10 11:34:49 +05:30
20230510060828_add_index_to_messages_for_reportings.rb feat: add index migration (#7050) 2023-05-10 17:55:14 +05:30
20230510113208_set_default_empty_string_for_contact_name.rb chore: Add migration to set the default empty string value for contact name (#7052) 2023-05-11 17:35:19 +05:30
20230515051424_update_article_image_keys.rb Revert "chore: Upgrade Rails to 7.2.2 and update Gemfile dependencies (#11037)" 2026-02-03 21:09:42 -08:00
20230523104139_add_partial_index_for_resolved_contacts.rb feat(perf): contacts query performance (#7175) 2023-05-23 17:22:47 +05:30
20230525085402_add_custom_sender_name_toggle.rb feat: Ability to customise the email sender name [CW-1629] (#7345) 2023-07-04 20:46:01 +05:30
20230608040738_add_processed_message_content_to_messages.rb fix: Automations condition based quoted text (#7272) 2023-06-09 17:00:05 +05:30
20230612103936_add_index_to_reporting_events.rb feat: add index to reporting events [CW-1960] (#7294) 2023-06-12 18:23:42 +05:30
20230614044633_add_sender_name_to_in.rb feat: Ability to customise the email sender name [CW-1629] (#7345) 2023-07-04 20:46:01 +05:30
20230620132319_add_sla_policy_to_conversations.rb chore: Add sla policy association to conversation (#7360) 2023-06-21 14:48:50 +05:30
20230620212340_add_waiting_since_to_conversations.rb feat: Add a sort option for conversations waiting for a reply from an agent (#7364) 2023-06-21 13:20:39 -07:00
20230706090122_sentiment_column_to_messages.rb feat: Sentiment Analysis (#7475) 2023-07-12 15:03:31 +05:30
20230714054138_add_api_key_sid_to_twilio_sms.rb feat: Add support for API key authentication in Twilio (#7523) 2023-07-14 19:20:54 -07:00
20230727065605_add_partial_index_contact_account_id.rb feat(perf): contact page loading speed (#7629) 2023-07-27 13:32:22 +05:30
20230801180936_update_default_status_in_hooks.rb fix: Update the default status of the hooks to enabled (#7652) 2023-08-01 12:14:47 -07:00
20230905060223_add_regex_to_custom_attribute_definition.rb feat: Support Regex validation for custom attributes (#7856) 2024-01-23 18:01:57 +04:00
20231011041615_ensure_message_private_not_null.rb chore: Ensure null validation for private attribute in messages (#8085) 2023-10-11 13:16:59 +05:30
20231013072802_add_icon_to_categories.rb feat: Adds the ability to set an emoji for help center category (#8111) 2023-10-20 13:52:30 +05:30
20231114111614_change_feature_flags_to_bigint_in_accounts.rb feat: convert feature_flag to bigint [CW-2767] (#8350) 2023-11-17 15:50:24 -08:00
20231129091149_add_snoozed_until_to_notifications.rb feat: Snooze notification API (#8439) 2023-12-04 12:32:35 +05:30
20231201014644_remove_notifications_with_message_primary_actor.rb chore: Change primary actor to Conversation for all the notification types. (#8435) 2023-12-06 10:43:09 +05:30
20231211010807_add_cached_labels_list.rb chore(migration): Re-run database migration job for caching. (#8581) 2023-12-18 17:29:02 -08:00
20231219000743_re_run_cache_label_job.rb chore(migration): Re-run database migration job for caching. (#8581) 2023-12-18 17:29:02 -08:00
20231219073832_add_last_activity_at_to_notifications.rb feat: Add last_activity_at field to Notification model (#8585) 2023-12-20 13:02:37 +05:30
20231223033019_refactor_sla_policy_columns.rb feat: sla 1 - refactor sla_policies model and add applied_sla model (#8602) 2024-01-23 23:48:02 +05:30
20231223040257_create_applied_slas.rb feat: sla 1 - refactor sla_policies model and add applied_sla model (#8602) 2024-01-23 23:48:02 +05:30
20240124054340_add_contact_type_to_contacts.rb feat: Add contact_type attribute to contact model (#8768) 2024-01-24 12:26:47 +05:30
20240124084032_add_middle_name_and_last_name_to_contacts.rb feat: Add middle_name and last_name to contact model (#8771) 2024-01-24 16:22:04 +05:30
20240129080827_add_location_and_country_code_to_contacts.rb feat: Add attributes location and country_code to Contact model (#8803) 2024-01-29 14:10:14 +05:30
20240131040316_remove_imap_inbox_syned_at_from_channel_email.rb chore: Remove unused attribute imap_inbox_synced_at (#8822) 2024-01-31 11:48:46 +04:00
20240207103014_change_applied_sla_sla_status_to_enum.rb feat: Add sidekiq jobs to monitor applied SLAs (#8828) 2024-02-07 21:44:56 +04:00
20240213131252_add_blocked_to_contacts.rb feat: Ability to block contacts permanently (#8922) 2024-02-21 14:18:42 -08:00
20240215065844_add_meta_to_notifications.rb feat: Add meta to notification model (#8941) 2024-02-16 14:38:02 +05:30
20240216055809_add_unique_index_to_applied_slas.rb feat: sla-7 ensure applied_sla uniqueness (#8938) 2024-02-20 21:59:49 +05:30
20240306201954_change_identifier_type_in_notifications_subscriptions.rb fix: Change the column identifier from string to text to avoid overflow (#9073) 2024-03-07 11:13:01 +05:30
20240319062553_create_sla_events.rb feat: add sla events table (#9126) 2024-03-20 11:59:37 +05:30
20240322071629_convert_cached_label_list_to_text.rb fix: Convert cached_label_list to text (#9143) 2024-03-25 18:47:08 -07:00
20240415210313_add_channel_web_widget_to_portals.rb feat: Add widget to help center config (#9235) 2024-04-15 16:46:48 -07:00
20240515201632_index_improvements_conversations_contacts.rb chore: Improved indexes for Conversations & Contacts [CW-3300] (#9475) 2024-05-15 16:10:39 -07:00
20240516003531_add_index_for_message_type_account_date.rb chore: Add indexes to improve reporting performance (#9478) 2024-05-15 21:21:15 -07:00
20240726220747_add_custom_roles.rb feat: Add APIs to manage custom roles in Chatwoot (#9995) 2024-08-23 17:18:28 +05:30
20240923215335_add_locale_to_article.rb fix: Include uncategorized articles in the all article section to allow edit/delete (#10153) 2024-09-23 23:39:03 -07:00
20241217041352_fix_old_audio_alert_data.rb fix: Update old data to fix login issues (#10594) 2024-12-17 17:17:11 +05:30
20250104200055_create_captain_tables.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
20250104210328_remove_robin_tables.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
20250105001414_add_status_to_captain_documents.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
20250105005821_remove_not_null_from_captain_documents.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
20250107030743_add_config_to_captain_assistant.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
20250108031358_create_captain_inbox.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
20250108211541_remove_index_from_captain_assistants.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
20250116000103_add_status_to_captain_assistant_responses.rb feat: Add a review step for FAQs generated from conversations before using it (#10693) 2025-01-16 09:54:34 +05:30
20250116061033_convert_document_to_polymorphic_association.rb fix(ce): Check the edition before running the data migration (#10728) 2025-01-21 10:00:37 +05:30
20250207040150_add_meta_to_attachment.rb feat: Show shared contact's name in Telegram channel (#10856) 2025-02-11 19:39:54 +05:30
20250228185548_add_internal_attributes_to_accounts.rb feat: Add support for account abuse detection (#11001) 2025-02-28 15:28:19 -08:00
20250315202035_add_index_to_articles.rb chore: Limit the number of articles retrieved by widget (#11095) 2025-03-15 14:10:12 -07:00
20250326034635_add_instagram_channel.rb feat: Added Instagram channel migration (#11181) 2025-03-26 11:12:32 +05:30
20250402233933_remove_portal_members.rb chore: Clean up report & knowledge base policies (#11234) 2025-04-03 16:00:32 -07:00
20250410061725_convert_csml_bots_to_webhook_bots.rb feat: Implement UI for Agent Bots in settings and remove CSML support (#11276) 2025-04-16 18:02:49 +05:30
20250416182131_flip_chatwoot_v4_default_feature_flag_installation_config.rb chore: Enable chatwoot_v4 feature flag by default for accounts (#11321) 2025-04-17 08:53:37 +05:30
20250421082927_add_settings_column_to_account.rb feat: Add support for minutes in auto resolve feature (#11269) 2025-05-07 00:36:15 -07:00
20250421085134_update_auto_resolve_to_mminutes.rb feat: Add support for minutes in auto resolve feature (#11269) 2025-05-07 00:36:15 -07:00
20250512231036_create_copilot_threads.rb feat: Add support for persistent copilot threads and messages (#11489) 2025-05-15 17:37:04 -07:00
20250512231037_create_copilot_messages.rb feat: Add support for persistent copilot threads and messages (#11489) 2025-05-15 17:37:04 -07:00
20250514045638_add_csat_config_to_inboxes.rb feat: Improve CSAT responses (#11485) 2025-05-16 14:18:52 +05:30
20250523024825_remove_uuid_from_copilot_threads.rb feat: Add support for realtime-events in copilot-threads and copilot-messages (#11557) 2025-05-22 22:25:05 -07:00
20250523024826_remove_user_id_from_copilot_messages.rb feat: Add support for realtime-events in copilot-threads and copilot-messages (#11557) 2025-05-22 22:25:05 -07:00
20250523031839_change_message_type_to_integer_in_copilot_messages.rb feat: Add support for realtime-events in copilot-threads and copilot-messages (#11557) 2025-05-22 22:25:05 -07:00
20250620120000_create_channel_voice.rb feat: Whatsapp embedded signup (#11612) 2025-07-14 21:37:06 -07:00
20250627195529_add_index_to_messages.rb fix: disable_ddl_transaction! on add_index action (#11833) 2025-06-27 16:58:50 -07:00
20250709102213_add_template_params_to_campaigns.rb chore(annotations): sync model annotations with current schema (#12245) 2025-08-20 20:23:42 +02:00
20250710145708_create_captain_scenarios.rb feat: add Captain::Scenario Model and API [CW-4597] (#11907) 2025-07-14 16:12:38 +05:30
20250714104358_add_response_guidelines_and_guardrails_to_captain_assistants.rb feat: add response guidelines and guardrails field (#11911) 2025-07-15 08:56:03 +05:30
20250722083820_add_ssl_settings_to_portals.rb chore: Automate SSL with Cloudflare (#12021) 2025-07-24 13:09:06 +04:00
20250722152516_add_index_on_contact_type_and_account_id_to_contacts.rb feat: Introduce the crm_v2 feature flag for CRM changes (#12014) 2025-07-23 17:07:02 +04:00
20250805082345_add_metadata_to_captain_documents.rb feat: Add BE changes for captain pdf support for faq generation (#12113) 2025-08-27 20:31:22 +05:30
20250805160307_add_notifications_performance_index.rb perf: fix notifications duplicate query and add composite index (#12110) 2025-08-07 15:59:40 +05:30
20250806140000_create_assignment_policies.rb feat: Add migration files for assignment v2 (#12147) 2025-08-11 21:44:38 -07:00
20250806140001_create_inbox_assignment_policies.rb feat: Add migration files for assignment v2 (#12147) 2025-08-11 21:44:38 -07:00
20250806140002_create_agent_capacity_policies.rb feat: Add migration files for assignment v2 (#12147) 2025-08-11 21:44:38 -07:00
20250806140003_create_inbox_capacity_limits.rb feat: Add migration files for assignment v2 (#12147) 2025-08-11 21:44:38 -07:00
20250806140004_add_agent_capacity_policy_to_account_users.rb feat: Add migration files for assignment v2 (#12147) 2025-08-11 21:44:38 -07:00
20250806140005_create_leaves.rb feat: Add migration files for assignment v2 (#12147) 2025-08-11 21:44:38 -07:00
20250808123008_add_feature_citation_to_assistant_config.rb fix(migrations): skip AddFeatureCitationToAssistantConfig on OSS (#12244) 2025-08-20 19:15:19 +05:30
20250820130619_add_two_factor_to_users.rb feat: MFA (#12290) 2025-09-18 20:19:24 +05:30
20250822061042_add_content_templates_to_twilio_sms.rb feat: Added the backend support for twilio content templates (#12272) 2025-08-24 10:05:15 +05:30
20250825070005_create_account_saml_settings.rb feat: add saml model & controller [CW-2958] (#12289) 2025-09-03 13:30:42 -07:00
20250826000000_drop_telegram_bots.rb chore: remove unused telegram bot model (#12417) 2025-09-11 22:25:26 +05:30
20250916024703_add_allowed_domains_to_channel_widgets.rb feat: Introduce allowed_domains for web widget (#12450) 2025-09-17 10:01:27 +05:30
20250917012759_add_verified_to_channel_email.rb feat: Clean up email configuration for from and reply to emails (#12453) 2025-09-24 11:36:53 -07:00
20250929105219_create_companies.rb feat: Add company model and API with tests (#12548) 2025-10-08 07:53:43 -07:00
20250929132305_add_company_to_contacts.rb feat: Add company model and API with tests (#12548) 2025-10-08 07:53:43 -07:00
20251003091242_create_captain_custom_tools.rb feat(ee): Captain custom http tools (#12584) 2025-10-06 07:53:15 -07:00
20251010143218_add_name_to_webhooks.rb feat(webhooks): add name to webhook (#12641) 2025-11-13 13:28:15 +05:30
20251021082242_add_unique_index_to_companies_domain.rb feat: Add company backfill migration for existing contacts (Part 1) (#12657) 2025-11-03 20:03:47 +05:30
20251022152158_add_index_to_conversations_identifier.rb perf: Add database index on conversations identifier (#12715) 2025-10-28 15:12:46 +05:30
20251022162159_add_assignee_agent_bot_id_to_conversations.rb feat: APIs to assign agents_bots as assignee in conversations (#12836) 2025-11-18 18:20:58 -08:00
20251027091242_add_tiktok_channel.rb feat: TikTok channel (#12741) 2025-12-17 07:54:50 -08:00
20251111094402_add_contacts_count_to_companies.rb feat: Backend - Companies API endpoint with pagination and search (#12840) 2025-11-18 14:28:56 +05:30
20251114173609_change_source_id_to_text.rb fix: Change contact_inboxes.source_id to text column (#12882) 2025-11-17 16:09:36 +05:30
20251119161025_change_messages_source_id_to_text.rb fix: Change messages.source_id to text column (#12908) 2025-11-20 11:41:41 +05:30
20251229081141_change_webhook_url_to_text.rb fix: the webhook url to be text (#13157) 2026-01-06 15:23:54 +05:30
20260112092041_remove_country_code_from_conversation_filters.rb fix: country_code should be checked against the contact (#13186) 2026-01-13 14:47:27 +05:30
20260114192518_add_internal_observations_to_csat_survey_responses.rb feat(ee): Review Notes for CSAT Reports (#13289) 2026-01-15 19:53:57 -08:00
20260114201315_add_observations_audit_to_csat_survey_responses.rb feat(ee): Review Notes for CSAT Reports (#13289) 2026-01-15 19:53:57 -08:00
20260120121402_enable_captain_tasks_for_existing_accounts.rb feat: new Captain Editor (#13235) 2026-01-21 13:39:07 +05:30
20260130061021_add_index_to_reporting_events_for_response_distribution.rb fix: Increase the parallelism config to fix flaky tests, revert bad commits (#13410) 2026-01-30 12:49:31 -08:00
20260211145813_create_reporting_events_rollup.rb feat(rollup): add models and write path [1/3] (#13796) 2026-03-19 13:12:36 +05:30
20260218075101_add_secret_to_webhooks.rb feat: add per-webhook secret with backfill migration (#13573) 2026-02-26 17:26:12 +05:30
20260226084618_backfill_webhook_secrets.rb feat: add per-webhook secret with backfill migration (#13573) 2026-02-26 17:26:12 +05:30
20260226153427_disable_report_rollup_for_all_accounts.rb feat: reclaim mobile_v2 flag for report_rollup (#13666) 2026-03-02 13:12:42 +05:30
20260320074636_backfill_feature_contact_attributes_for_assistants.rb feat: allow captain to access contact attributes (#13850) 2026-03-20 16:15:06 +05:30
20260324070820_add_secret_to_agent_bots.rb feat: sign webhooks for API channel and agentbots (#13892) 2026-04-06 15:28:25 +05:30
20260324070828_add_secret_to_channel_api.rb feat: sign webhooks for API channel and agentbots (#13892) 2026-04-06 15:28:25 +05:30
20260324070835_backfill_agent_bot_and_channel_api_secrets.rb feat: sign webhooks for API channel and agentbots (#13892) 2026-04-06 15:28:25 +05:30
20260324102005_repurpose_response_bot_flag_for_custom_tools.rb feat: reclaim response_bot flag for custom_tools (#13897) 2026-03-31 10:35:50 +05:30
20260408170902_create_calls.rb feat: Add unified Call model for voice calling (#14026) 2026-04-13 20:28:09 +04:00
20260409091202_enable_assignment_v2_for_new_accounts.rb feat: enable assignment v2 by default for new accounts (#14031) 2026-04-09 16:14:17 +05:30
20260410092751_add_edited_to_captain_assistant_responses.rb feat: migrations for document auto-sync [AI-141] (#14041) 2026-04-15 17:56:10 +05:30
20260410092752_add_sync_columns_to_captain_documents.rb feat: migrations for document auto-sync [AI-141] (#14041) 2026-04-15 17:56:10 +05:30
20260410092753_backfill_edited_on_captain_assistant_responses.rb feat: migrations for document auto-sync [AI-141] (#14041) 2026-04-15 17:56:10 +05:30
20260427094500_rename_company_condition_key_in_automation_rules.rb fix: standardize contact company field on company_name (#14099) 2026-04-27 18:43:26 +05:30