Sha256: c20df548149a4537e77d27b54b1e72cea83fe4bb50cf616408bcf815994564c1

Contents?: true

Size: 1.61 KB

Versions: 43

Compression:

Stored size: 1.61 KB

Contents

class AddColumnsToUser < ActiveRecord::Migration[4.2]
  def up
    if table_exists?("users")
      unless column_exists?("users", "username")
        add_column "users", "username", :string, default: "", null: false
      end
      unless column_exists?("users", "first_name")
        add_column "users", "first_name", :string
      end
      unless column_exists?("users", "middle_name")
        add_column "users", "middle_name", :string
      end
      unless column_exists?("users", "nickname")
        add_column "users", "nickname", :string
      end
      unless column_exists?("users", "last_name")
        add_column "users", "last_name", :string
      end
      unless column_exists?("users", "display_name")
        add_column "users", "display_name", :string
      end

      # If the email index exists and is set such that email must be unique (which is the initial
      # setting typically set by Devise(?)), remove and we'll re-add it as non-unique below.
      if index_exists?("users", ["email"])
        if index_exists?("users", ["email"], unique: true)
          remove_index "users", ["email"]
        end
      end

      # Either the email index didn't exist when we started or, more likely, we removed above
      # because it existed but required email to be unique.
      unless index_exists?("users", ["email"])
        add_index "users", ["email"], name: "index_users_on_email"
      end

      unless index_exists?("users", ["username"])
        add_index "users", ["username"], name: "index_users_on_username", unique: true
      end
    end
  end

  def down
    raise ActiveRecord::IrreversibleMigration
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
ddr-core-1.17.0 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.16.0 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.15.0 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.14.0 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.13.2 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.13.1 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.13.0 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.12.2 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.12.1 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.12.0 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.11.0 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.10.0 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.9.0 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.8.0 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.7.0 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.6.6 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.6.5 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.6.4 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.6.3 db/migrate/20141107124012_add_columns_to_user.rb
ddr-core-1.6.2 db/migrate/20141107124012_add_columns_to_user.rb