Class: Landable::Migration

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/landable/migration.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clear_cache!Object



15
16
17
18
# File 'lib/landable/migration.rb', line 15

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

.connection_search_path(conn) ⇒ Object



3
4
5
# File 'lib/landable/migration.rb', line 3

def connection_search_path(conn)
  conn.execute("SHOW SEARCH_PATH")[0]["search_path"]
end

.modelsObject



7
8
9
10
11
12
13
# File 'lib/landable/migration.rb', line 7

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

Instance Method Details

#exec_migration(conn, direction) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/landable/migration.rb', line 21

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