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

Version Path
foreman_remote_execution-14.1.2 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-14.1.1 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-14.1.0 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-14.0.2 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-14.0.1 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-13.2.6 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-14.0.0 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-13.2.5 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-13.2.4 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-13.2.3 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-13.2.2 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-12.0.7 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-13.2.1 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-13.2.0 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-10.1.3 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-13.0.0 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-12.0.5 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-12.0.4 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-12.0.1 db/migrate/20221129170145_redefine_template_invocation_events_index.rb
foreman_remote_execution-12.0.2 db/migrate/20221129170145_redefine_template_invocation_events_index.rb