Module: Six::Dbmanager::Migrate::ClassMethods

Defined in:
lib/six-updater-web/vendor/plugins/six-db_manager/lib/six/dbmanager.rb

Instance Method Summary collapse

Instance Method Details

#six_join(ar, dir = :up, uid = false) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/six-updater-web/vendor/plugins/six-db_manager/lib/six/dbmanager.rb', line 19

def six_join(ar, dir = :up, uid = false)
  table = "#{ar[0].pluralize}_#{ar[1].pluralize}"
  case dir
    when :down
      drop_table table
    when :up
      create_table table, :id => false do |t|
        if uid
          t.column "#{ar[0]}_id", :string, :limit => 36
          t.column "#{ar[1]}_id", :string, :limit => 36
        else
          t.column "#{ar[0]}_id", :integer
          t.column "#{ar[1]}_id", :integer
        end
      end
      add_index table, "#{ar[0]}_id"
      add_index table, "#{ar[1]}_id"
  end
end