Module: RoadRunnerModule::Dbhelper

Defined in:
lib/db.rb

Class Method Summary collapse

Class Method Details

.migrate(tables) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/db.rb', line 7

def migrate(tables)
  tables.each do |table|
    case table
    when "scenarios"  then
      unless ActiveRecord::Base.connection.tables.include?(table.to_s) then
        ActiveRecord::Base.connection.create_table(table.to_sym) do |t|
           t.column :name, :string, :limit => 256
           t.column :create_at,:string, :limit => 32
           t.column :script, :string,:limit => 10240
           t.column :author, :string, :default => 'Anonymous'
           t.column :author, :tps, :int
           t.column :desc, :string
         end
      end

    when "transactions"  then
      unless ActiveRecord::Base.connection.tables.include?(table.to_s) then
        ActiveRecord::Base.connection.create_table(table.to_sym) do |t|
           t.column :name,:string,:limit => 256
           t.column :scenario_id,:string,:limit => 256
           t.column :success_rate,:string, :limit => 8
           t.column :create_at,:string, :limit => 32

         end
      end
      
    when "records"  then
      unless ActiveRecord::Base.connection.tables.include?(table.to_s) then
        ActiveRecord::Base.connection.create_table(table.to_sym) do |t|
           t.column :cost, :string, :limit => 32
           t.column :ts, :string, :limit => 32
           t.column :seq, :int
           t.column :stats,:int
           t.column :transaction_id,:string,:limit => 256
           t.column :create_at,:string, :limit => 32
         end
      end
    end
  end
end