Sha256: 2cd07f0d72de567bd08a7992a6c2afebf7b0dc1bb7e46620312927b847e09abf

Contents?: true

Size: 1.5 KB

Versions: 17

Compression:

Stored size: 1.5 KB

Contents

class ReplaceEnvironmentIdWithEnvironmentName < ActiveRecord::Migration
  RENAMES = {"dev" => "Staging", "master" => "Production"}

  class Environment < ActiveRecord::Base; end

  def up
    add_column :deploys, :environment_name, :string, null: false, default: "Production"
    add_index :deploys, :environment_name
    add_index :deploys, [:project_id, :environment_name]

    Deploy.tap(&:reset_column_information).reorder(nil).each do |deploy|
      if deploy.respond_to?(:environment_id) && (environment = Environment.find_by_id(deploy.environment_id))
        deploy.update_column(:environment_name, environment.name)
      end
    end

    add_column :releases, :project_id, :integer, null: false, default: -1
    add_column :releases, :environment_name, :string, null: false, default: "Production"
    add_index :releases, :project_id
    add_index :releases, [:project_id, :environment_name]

    Release.tap(&:reset_column_information).all.each do |release|
      if release.respond_to?(:environment_id) && (environment = Environment.find_by_id(release.environment_id))
        release.update_column(:project_id, environment.project_id)
        release.update_column(:environment_name, environment.name)
      end
    end

    rename_column :user_notifications, :environment, :environment_name
  end

  def down
    remove_column :deploys, :environment_name
    remove_column :releases, :project_id
    remove_column :releases, :environment_name

    rename_column :user_notifications, :environment_name, :environment
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
houston-core-0.8.0.pre db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.7.0 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.7.0.beta4 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.7.0.beta3 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.7.0.beta2 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.7.0.beta db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.6.3 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.6.2 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.6.1 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.6.0 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.5.6 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.5.5 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.5.4 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.5.3 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.5.2 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.5.1 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb
houston-core-0.5.0 db/migrate/20121225175106_replace_environment_id_with_environment_name.rb