Module: Zing::DbHelper

Defined in:
lib/zing/db_helper.rb

Class Method Summary collapse

Class Method Details

.connect_db(models_file_path) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/zing/db_helper.rb', line 6

def self.connect_db(models_file_path)
  begin

    if File.exist?(models_file_path)

        # check if db connection can be made
        require models_file_path
        if ActiveRecord::Base.connection and ActiveRecord::Base.connected?
          puts "passed".green + " Database Connection"
        else
          puts "errors".red + " Database Connection not exist"
          raise
        end
    else
      raise
    end

  rescue 
    puts "ERROR: Are you sure DB is properly configured in #{models_file_path}?".red
    raise
  end
end

.create_admin_user_tableObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/zing/db_helper.rb', line 29

def self.create_admin_user_table

  if ActiveRecord::Base.connection.table_exists?(:admin_users)
    puts "exists".yellow + " AdminUser Table"
  else
     ActiveRecord::Base.connection.create_table :admin_users do |t|
       t.string :username, :limit => 40, :null => false
       t.string :password, :limit => 40
       t.integer :utime, :limit => 16
       t.timestamps
    end
    if ActiveRecord::Base.connection.table_exists?(:admin_users)
      puts "passed".green + " AdminUser Table Creation"
    else
      puts "failed".red + " AdminUser Table Creation"
      raise
    end
  end

end

.create_apn_log_tableObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/zing/db_helper.rb', line 106

def self.create_apn_log_table

  if ActiveRecord::Base.connection.table_exists?(:apn_logs)
    puts "exists".yellow + " ApnLog Table"
  else
     ActiveRecord::Base.connection.create_table :apn_logs do |t|
       t.integer :notification_id
       t.integer :notification_size, :limit => 16
       t.text    :log_text
       t.integer :utime, :limit => 16
       t.timestamps
    end
    if ActiveRecord::Base.connection.table_exists?(:apn_logs)
      puts "passed".green + " ApnLog Table Creation"
    else
      puts "failed".red + " ApnLog Table Creation"
      raise
    end
  end

end

.create_notification_tableObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/zing/db_helper.rb', line 80

def self.create_notification_table

  if ActiveRecord::Base.connection.table_exists?(:notifications)
    puts "exists".yellow + " Notification Table"
  else
     ActiveRecord::Base.connection.create_table :notifications do |t|
       t.string :message
       t.string :btn_name, :limit => 64
       t.string :sound, :limit => 64
       t.string :url
       t.string :category, :limit => 64
       t.string :carrier, :limit => 64
       t.string :test_udids, :limit => 512
       t.integer :utime, :limit => 16
       t.timestamps
    end
    if ActiveRecord::Base.connection.table_exists?(:notifications)
      puts "passed".green + " Notification Table Creation"
    else
      puts "failed".red + " Notification Table Creation"
      raise
    end
  end

end

.create_token_tableObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/zing/db_helper.rb', line 50

def self.create_token_table

  if ActiveRecord::Base.connection.table_exists?(:tokens)
    puts "exists".yellow + " Token Table"
  else
     ActiveRecord::Base.connection.create_table :tokens do |t|
       t.string :udid, :limit => 40, :null => false
       t.string :owner, :limit => 40
       t.string :token, :limit => 255, :null => false
       t.boolean :buuuk, :default => 0
       t.boolean :valid_udid, :default => 1
       t.string :carrier
       t.integer :utime, :limit => 16
       t.string :network_code, :limit => 12
       t.string :country_code, :limit => 12
       t.string :device, :limit => 32
       t.string :country
       t.string :version, :limit => 16
       t.timestamps
    end
    if ActiveRecord::Base.connection.table_exists?(:tokens)
      puts "passed".green + " Token Table Creation"
    else
      puts "failed".red + " Token Table Creation"
      raise
    end
  end

end