Sha256: acbc4fc571908aceb035d4d7f83702c32f7b88af215166db081183e6d8aec767

Contents?: true

Size: 1.7 KB

Versions: 12

Compression:

Stored size: 1.7 KB

Contents

class ClearanceUpdateUsers<%= schema_version_constant %> < ActiveRecord::Migration
  def self.up
<%
      existing_columns = ActiveRecord::Base.connection.columns(:users).collect { |each| each.name }
      columns = [
        [:email,              't.string :email'],
        [:encrypted_password, 't.string :encrypted_password, :limit => 128'],
        [:salt,               't.string :salt, :limit => 128'],
        [:confirmation_token, 't.string :confirmation_token, :limit => 128'],
        [:remember_token,     't.string :remember_token, :limit => 128'],
        [:name,     't.string :name, :limit => 128'],
        [:fbid,     't.integer :fbid'],
        [:email_confirmed,    't.boolean :email_confirmed, :default => false, :null => false']
      ].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_id_and_confirmation_token, 'add_index :users, [:id, :confirmation_token]'],
      [:index_users_on_email,                     'add_index :users, :email'],
      [:index_users_on_fbid,                     'add_index :users, :fbid'],
      [:index_users_on_remember_token,            'add_index :users, :remember_token']
    ].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

12 entries across 12 versions & 1 rubygems

Version Path
fbdoorman-0.7.1 generators/fbdoorman/templates/migrations/update_users.rb
fbdoorman-0.7.0 generators/fbdoorman/templates/migrations/update_users.rb
fbdoorman-0.1.0 generators/fbdoorman/templates/migrations/update_users.rb
fbdoorman-0.0.9 generators/fbdoorman/templates/migrations/update_users.rb
fbdoorman-0.0.8 generators/fbdoorman/templates/migrations/update_users.rb
fbdoorman-0.0.7 generators/fbdoorman/templates/migrations/update_users.rb
fbdoorman-0.0.6 generators/fbdoorman/templates/migrations/update_users.rb
fbdoorman-0.0.5 generators/fbdoorman/templates/migrations/update_users.rb
fbdoorman-0.0.4 generators/fbdoorman/templates/migrations/update_users.rb
fbdoorman-0.0.3 generators/fbdoorman/templates/migrations/update_users.rb
fbdoorman-0.0.2 generators/fbdoorman/templates/migrations/update_users.rb
fbdoorman-0.0.1 generators/fbdoorman/templates/migrations/update_users.rb