Sha256: 9fc20cd4bee2895c84c33e3c5eb21a9f4a22d62c93c02a3d82694e1731ce0264

Contents?: true

Size: 700 Bytes

Versions: 24

Compression:

Stored size: 700 Bytes

Contents

class AddCacheCounters < ActiveRecord::Migration
  def self.up
    add_column :pageflow_accounts, :users_count, :integer, default: 0, null: false
    add_column :pageflow_accounts, :entries_count, :integer, default: 0, null: false

    execute(<<-SQL)
      UPDATE pageflow_accounts SET users_count = (
        SELECT COUNT(*)
        FROM users
        WHERE users.account_id = pageflow_accounts.id
      ), entries_count = (
        SELECT COUNT(*)
        FROM pageflow_entries
        WHERE pageflow_entries.account_id = pageflow_accounts.id
      );
    SQL
  end

  def self.down
    remove_column :pageflow_accounts, :users_count
    remove_column :pageflow_accounts, :entries_count
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
pageflow-12.6.0 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.5.0 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.4.1 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.4.0 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.3.0 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.2.0 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.1.0 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.0.4 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.0.3 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.0.2 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.0.1 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.0.0 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.0.0.rc7 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.0.0.rc6 db/migrate/20160131222203_add_cache_counters.rb
pageflow-0.11.4 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.0.0.rc5 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.0.0.rc4 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.0.0.rc3 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.0.0.rc2 db/migrate/20160131222203_add_cache_counters.rb
pageflow-12.0.0.rc1 db/migrate/20160131222203_add_cache_counters.rb