Sha256: e2cd24feb2a64367504693e6160c150b1107085393755cd4b6077866b4493e1e

Contents?: true

Size: 1.72 KB

Versions: 21

Compression:

Stored size: 1.72 KB

Contents

class HeadstartUpdateUsers<%= schema_version_constant %> < ActiveRecord::Migration
  def self.up
<%
      existing_columns = ActiveRecord::Base.connection.columns(:users).collect { |each| each.name }
      columns = [
        [:email,                't.string :email, :limit => 100'],
        [:first_name,           't.string :first_name, :limit => 50'],
        [:last_name,            't.string :last_name, :limit => 50'],
        [:role,                 't.string :role, :limit => 50'],
        [:encrypted_password,   't.string :encrypted_password, :limit => 128'],
        [:salt,                 't.string :salt, :limit => 128'],
        [:remember_token,       't.string :remember_token, :limit => 128'],
        [:facebook_uid,         't.string :facebook_uid, :limit => 50'],
        [:password_reset_token, 't.string :password_reset_token, :limit => 128']
      ].delete_if {|c| existing_columns.include?(c.first.to_s)}
-%>
    change_table(:users) do |t|
<% columns.each do |c| -%>
      <%= c.last %>
<% end -%>
    end

<%
    existing_indexes = ActiveRecord::Base.connection.indexes(:users)
    index_names = existing_indexes.collect { |each| each.name }
    new_indexes = [
      [:index_users_on_email,                     'add_index :users, :email'],
      [:index_users_on_remember_token,            'add_index :users, :remember_token'],
      [:index_users_on_facebook_uid,              'add_index :users, :facebook_uid']
    ].delete_if { |each| index_names.include?(each.first.to_s) }
-%>
<% new_indexes.each do |each| -%>
    <%= each.last %>
<% end -%>
  end

  def self.down
    change_table(:users) do |t|
<% unless columns.empty? -%>
      t.remove <%= columns.collect { |each| ":#{each.first}" }.join(',') %>
<% end -%>
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
headstart-0.11.2 generators/headstart/templates/migrations/update_users.rb
headstart-0.11.1 generators/headstart/templates/migrations/update_users.rb
headstart-0.9.2 generators/headstart/templates/migrations/update_users.rb
headstart-0.9.1 generators/headstart/templates/migrations/update_users.rb
headstart-0.9.0 generators/headstart/templates/migrations/update_users.rb
headstart-0.8.0 generators/headstart/templates/migrations/update_users.rb
headstart-0.7.0 generators/headstart/templates/migrations/update_users.rb
headstart-0.6.2 generators/headstart/templates/migrations/update_users.rb
headstart-0.6.1 generators/headstart/templates/migrations/update_users.rb
headstart-0.6.0 generators/headstart/templates/migrations/update_users.rb
headstart-0.5.5 generators/headstart/templates/migrations/update_users.rb
headstart-0.5.4 generators/headstart/templates/migrations/update_users.rb
headstart-0.5.3 generators/headstart/templates/migrations/update_users.rb
headstart-0.5.2 generators/headstart/templates/migrations/update_users.rb
headstart-0.5.1 generators/headstart/templates/migrations/update_users.rb
headstart-0.5.0 generators/headstart/templates/migrations/update_users.rb
headstart-0.4.2 generators/headstart/templates/migrations/update_users.rb
headstart-0.4.1 generators/headstart/templates/migrations/update_users.rb
headstart-0.4.0 generators/headstart/templates/migrations/update_users.rb
headstart-0.3.0 generators/headstart/templates/migrations/update_users.rb