module Earth::Model::Schema

Constants

COMMENT

ostermiller.org/findcomment.html

SEMICOLON
WHITESPACE

Public Instance Methods

create_table!(force = true) click to toggle source
# File lib/earth/model.rb, line 37
def create_table!(force = true)
  c = ActiveRecord::Base.connection_pool.checkout

  if c.table_exists?(table_name)
    return unless force
    c.drop_table table_name
  end

  statements = const_get(:TABLE_STRUCTURE).gsub(COMMENT, '').gsub(WHITESPACE, ' ').split(SEMICOLON).select(&:present?)

  statements.each do |sql|
    c.execute sql
  end

  # safely reset column information
  if c.respond_to?(:schema_cache)
    c.schema_cache.clear!
  end
  reset_column_information
  descendants.each do |descendant|
    descendant.reset_column_information
  end

  nil
ensure
  ActiveRecord::Base.connection_pool.checkin c
end