Files
leadchat/db/migrate/20260410092753_backfill_edited_on_captain_assistant_responses.rb
Aakash Bakhle 5264de24b0 feat: migrations for document auto-sync [AI-141] (#14041)
# Pull Request Template

## Description

Add migrations for document auto-sync

Fixes # (issue)

## Type of change

- [x] New feature (non-breaking change which adds functionality)

## How Has This Been Tested?
locally

## Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [x] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] Any dependent changes have been merged and published in downstream
modules
2026-04-15 17:56:10 +05:30

21 lines
795 B
Ruby

class BackfillEditedOnCaptainAssistantResponses < ActiveRecord::Migration[7.0]
def up
return unless ChatwootApp.enterprise?
# rubocop:disable Rails/SkipsModelValidations
# NOTE: Since there is no way of knowing currently which FAQs were edited by a human
# we use a heuristic based on time passed between created_at and updated_at.
# 15 days is arbitrary but seems reasonable for a user to go back and edit an FAQ.
Captain::AssistantResponse
.where('updated_at - created_at > make_interval(days := ?)', 15)
.in_batches(of: 1000) do |batch|
batch.update_all(edited: true)
end
# rubocop:enable Rails/SkipsModelValidations
end
def down
# no-op: rolling back migration of edited column will drop the edited column entirely
end
end