title: Adding a sqlite3 trigger in Ruby on rails migration
body: <p>I have these two migrations:</p>
  
  <pre><code>class CreateBreakdowns &lt; ActiveRecord::Migration[5.1]
    def change
      create_table :breakdowns do |t|
        t.date :date
        t.string :content
        t.decimal :amount
        t.timestamps
      end
    end
  end
  
  class CreateDailyTotals &lt; ActiveRecord::Migration[5.1]
   def change
      create_table :daily_totals do |t|
        t.date      :date
        t.decimal   :total
        t.timestamps
      end
    end
  end
  </code></pre>
  
  <p>And, I want to add below trigger to the migration:</p>
  
  <pre><code>CREATE TRIGGER update_total AFTER INSERT ON breakdowns
      BEGIN
        UPDATE daily_totals
        SET total = (SELECT SUM(amount) FROM breakdowns WHERE New.date = date)
        WHERE New.date = date;
      END;
  </code></pre>
  
  <p>The purpose is when the user inserts a data into the breakdowns table, then execute a trigger to update the daily_totals.</p>
  
  <p>My question is which migration file do I have to add this trigger? And, will it just work if I add this trigger into the migration file?</p>
  
  <p>I tried the trigger with my testing db and it works, it's just not working with the rails. Again, I'm using sqlite3, not mySQL or Oracle SQL.</p>
  
  <p>Thank you!</p>