Sha256: 9789cce1f4d73ac66f63b8f3ac71fcc6e56d5452ddc85a834d9c5e854c9fed7f

Contents?: true

Size: 1.05 KB

Versions: 16

Compression:

Stored size: 1.05 KB

Contents

class Landable::Migration < ActiveRecord::Migration
  class << self
    def connection_search_path(conn)
      conn.execute("SHOW SEARCH_PATH")[0]["search_path"]
    end

    def models
      @models ||= begin
        c = Landable.constants.map { |c| "Landable::#{c.to_s}".constantize }
        c += Landable::Traffic.constants.map { |c| "Landable::Traffic::#{c.to_s}".constantize }
        c.select { |c| c.kind_of? Class and c.ancestors.include? ActiveRecord::Base }
      end
    end

    def clear_cache!
      models.each &:reset_primary_key
      ActiveRecord::Base.connection.schema_cache.clear!
    end
  end

  def exec_migration(conn, direction)
    # come what may, keep the connection's schema search path intact
    with_clean_connection(conn) do
      super
    end

    # reset a few things, lest we pollute the way for those who follow
    self.class.clear_cache!
  end


  protected

  def with_clean_connection(conn)
    original_search_path = self.class.connection_search_path conn
    yield
    conn.schema_search_path = original_search_path
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
landable-1.13.1 lib/landable/migration.rb
landable-1.12.3 lib/landable/migration.rb
landable-1.12.2 lib/landable/migration.rb
landable-1.12.1 lib/landable/migration.rb
landable-1.11.1 lib/landable/migration.rb
landable-1.11.0 lib/landable/migration.rb
landable-1.10.0.rc2 lib/landable/migration.rb
landable-1.10.0.rc1 lib/landable/migration.rb
landable-1.9.2 lib/landable/migration.rb
landable-1.9.1 lib/landable/migration.rb
landable-1.9.0 lib/landable/migration.rb
landable-1.9.0.rc2 lib/landable/migration.rb
landable-1.9.0.rc1 lib/landable/migration.rb
landable-1.8.0 lib/landable/migration.rb
landable-1.7.1.rc1 lib/landable/migration.rb
landable-1.7.0 lib/landable/migration.rb