Sha256: 683ad2500eee1237a0c544772485447ad99f582958be4130088b22501748fcd3
Contents?: true
Size: 1.16 KB
Versions: 47
Compression:
Stored size: 1.16 KB
Contents
class RedefineTemplateInvocationEventsIndex < ActiveRecord::Migration[6.0] def up change_table :template_invocation_events do |t| t.remove_index name: :unique_template_invocation_events_index t.integer :sequence_id end execute <<~SQL WITH extended_t AS ( SELECT id, row_number() over (PARTITION BY template_invocation_id ORDER BY timestamp ASC) AS rn FROM template_invocation_events ) UPDATE template_invocation_events SET sequence_id = extended_t.rn FROM extended_t WHERE template_invocation_events.id = extended_t.id; SQL change_table :template_invocation_events do |t| t.index [:template_invocation_id, :sequence_id], unique: true, name: 'unique_template_invocation_events_index' t.change :sequence_id, :integer, null: false end end def down change_table :template_invocation_events do |t| t.remove_index name: :unique_template_invocation_events_index t.remove :sequence_id t.index [:template_invocation_id, :timestamp, :event_type], unique: true, name: 'unique_template_invocation_events_index' end end end
Version data entries
47 entries across 47 versions & 1 rubygems