This repository has been archived by the owner on Mar 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
/
rapns_add_gcm_support.rb
96 lines (71 loc) · 3.77 KB
/
rapns_add_gcm_support.rb
1
2
3
4
5
6
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
47
48
49
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
class RapnsAddGcmSupport < ActiveRecord::Migration
module Rapns
class App < ActiveRecord::Base
self.table_name = 'rapns_apps'
end
class Notification < ActiveRecord::Base
belongs_to :app
self.table_name = 'rapns_notifications'
end
end
def self.up
add_column :rapns_notifications, :type, :string, :null => true
add_column :rapns_apps, :type, :string, :null => true
RapnsAddGcmSupport::Rapns::Notification.update_all :type => 'Rapns::Apns::Notification'
RapnsAddGcmSupport::Rapns::App.update_all :type => 'Rapns::Apns::App'
change_column_null :rapns_notifications, :type, false
change_column_null :rapns_apps, :type, false
change_column_null :rapns_notifications, :device_token, true
change_column_null :rapns_notifications, :expiry, true
change_column_null :rapns_apps, :environment, true
change_column_null :rapns_apps, :certificate, true
change_column :rapns_notifications, :error_description, :text
change_column :rapns_notifications, :sound, :string, :default => 'default'
rename_column :rapns_notifications, :attributes_for_device, :data
rename_column :rapns_apps, :key, :name
add_column :rapns_apps, :auth_key, :string, :null => true
add_column :rapns_notifications, :collapse_key, :string, :null => true
add_column :rapns_notifications, :delay_while_idle, :boolean, :null => false, :default => false
reg_ids_type = ActiveRecord::Base.connection.adapter_name.include?('Mysql') ? :mediumtext : :text
add_column :rapns_notifications, :registration_ids, reg_ids_type, :null => true
add_column :rapns_notifications, :app_id, :integer, :null => true
add_column :rapns_notifications, :retries, :integer, :null => true, :default => 0
Rapns::Notification.reset_column_information
Rapns::App.reset_column_information
Rapns::App.all.each do |app|
Rapns::Notification.update_all(['app_id = ?', app.id], ['app = ?', app.name])
end
change_column_null :rapns_notifications, :app_id, false
remove_column :rapns_notifications, :app
remove_index :rapns_notifications, :name => "index_rapns_notifications_multi"
add_index :rapns_notifications, [:app_id, :delivered, :failed, :deliver_after], :name => "index_rapns_notifications_multi"
end
def self.down
RapnsAddGcmSupport::Rapns::Notification.where(:type => 'Rapns::Gcm::Notification').delete_all
remove_column :rapns_notifications, :type
remove_column :rapns_apps, :type
change_column_null :rapns_notifications, :device_token, false
change_column_null :rapns_notifications, :expiry, false
change_column_null :rapns_apps, :environment, false
change_column_null :rapns_apps, :certificate, false
change_column :rapns_notifications, :error_description, :string
change_column :rapns_notifications, :sound, :string, :default => '1.aiff'
rename_column :rapns_notifications, :data, :attributes_for_device
rename_column :rapns_apps, :name, :key
remove_column :rapns_apps, :auth_key
remove_column :rapns_notifications, :collapse_key
remove_column :rapns_notifications, :delay_while_idle
remove_column :rapns_notifications, :registration_ids
remove_column :rapns_notifications, :retries
add_column :rapns_notifications, :app, :string, :null => true
Rapns::Notification.reset_column_information
Rapns::App.reset_column_information
Rapns::App.all.each do |app|
Rapns::Notification.update_all(['app = ?', app.key], ['app_id = ?', app.id])
end
change_column_null :rapns_notifications, :key, false
remove_column :rapns_notifications, :app_id
remove_index :rapns_notifications, :name => "index_rapns_notifications_multi"
add_index :rapns_notifications, [:delivered, :failed, :deliver_after], :name => "index_rapns_notifications_multi"
end
end