Sha256: 2cdb677353be849f9e74975d1bf231c695d128d58d2a488eb8a47148d8fc6917

Contents?: true

Size: 673 Bytes

Versions: 11

Compression:

Stored size: 673 Bytes

Contents

class AddStartedAtAndEndedAtOnTasks < ActiveRecord::Migration
  def up
    add_column :tasks, :started_at, :datetime, null: true
    add_column :tasks, :ended_at, :datetime, null: true

    say "Migrating #{Shipit::Task.count} tasks:"
    Shipit::Task.find_each.with_index do |task, index|
      unless task.started_at
        task.update_columns(
          started_at: task.created_at,
          ended_at: task.updated_at, # good enough approximation but not perfect
        )
        puts if index % 100 == 0
        print '.'
      end
    end
    puts
    say "Done"
  end

  def down
    remove_column :tasks, :started_at
    remove_column :tasks, :ended_at
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
shipit-engine-0.18.0 db/migrate/20160324155046_add_started_at_and_ended_at_on_tasks.rb
shipit-engine-0.17.0 db/migrate/20160324155046_add_started_at_and_ended_at_on_tasks.rb
shipit-engine-0.16.0 db/migrate/20160324155046_add_started_at_and_ended_at_on_tasks.rb
shipit-engine-0.15.0 db/migrate/20160324155046_add_started_at_and_ended_at_on_tasks.rb
shipit-engine-0.14.0 db/migrate/20160324155046_add_started_at_and_ended_at_on_tasks.rb
shipit-engine-0.13.0 db/migrate/20160324155046_add_started_at_and_ended_at_on_tasks.rb
shipit-engine-0.12.1 db/migrate/20160324155046_add_started_at_and_ended_at_on_tasks.rb
shipit-engine-0.12.0 db/migrate/20160324155046_add_started_at_and_ended_at_on_tasks.rb
shipit-engine-0.11.0 db/migrate/20160324155046_add_started_at_and_ended_at_on_tasks.rb
shipit-engine-0.10.0 db/migrate/20160324155046_add_started_at_and_ended_at_on_tasks.rb
shipit-engine-0.9.0 db/migrate/20160324155046_add_started_at_and_ended_at_on_tasks.rb