rpush 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +99 -0
  3. data/LICENSE +7 -0
  4. data/README.md +189 -0
  5. data/bin/rpush +36 -0
  6. data/config/database.yml +44 -0
  7. data/lib/generators/rpush_generator.rb +44 -0
  8. data/lib/generators/templates/add_adm.rb +23 -0
  9. data/lib/generators/templates/add_alert_is_json_to_rapns_notifications.rb +9 -0
  10. data/lib/generators/templates/add_app_to_rapns.rb +11 -0
  11. data/lib/generators/templates/add_fail_after_to_rpush_notifications.rb +9 -0
  12. data/lib/generators/templates/add_gcm.rb +102 -0
  13. data/lib/generators/templates/add_rpush.rb +349 -0
  14. data/lib/generators/templates/add_wpns.rb +16 -0
  15. data/lib/generators/templates/create_rapns_apps.rb +16 -0
  16. data/lib/generators/templates/create_rapns_feedback.rb +18 -0
  17. data/lib/generators/templates/create_rapns_notifications.rb +29 -0
  18. data/lib/generators/templates/rename_rapns_to_rpush.rb +63 -0
  19. data/lib/generators/templates/rpush.rb +104 -0
  20. data/lib/rpush.rb +62 -0
  21. data/lib/rpush/TODO +3 -0
  22. data/lib/rpush/adm/app.rb +15 -0
  23. data/lib/rpush/adm/data_validator.rb +11 -0
  24. data/lib/rpush/adm/notification.rb +29 -0
  25. data/lib/rpush/apns/app.rb +29 -0
  26. data/lib/rpush/apns/binary_notification_validator.rb +12 -0
  27. data/lib/rpush/apns/device_token_format_validator.rb +12 -0
  28. data/lib/rpush/apns/feedback.rb +16 -0
  29. data/lib/rpush/apns/notification.rb +84 -0
  30. data/lib/rpush/apns_feedback.rb +13 -0
  31. data/lib/rpush/app.rb +18 -0
  32. data/lib/rpush/configuration.rb +75 -0
  33. data/lib/rpush/daemon.rb +140 -0
  34. data/lib/rpush/daemon/adm.rb +9 -0
  35. data/lib/rpush/daemon/adm/delivery.rb +222 -0
  36. data/lib/rpush/daemon/apns.rb +16 -0
  37. data/lib/rpush/daemon/apns/certificate_expired_error.rb +20 -0
  38. data/lib/rpush/daemon/apns/delivery.rb +64 -0
  39. data/lib/rpush/daemon/apns/disconnection_error.rb +20 -0
  40. data/lib/rpush/daemon/apns/feedback_receiver.rb +79 -0
  41. data/lib/rpush/daemon/app_runner.rb +187 -0
  42. data/lib/rpush/daemon/batch.rb +115 -0
  43. data/lib/rpush/daemon/constants.rb +59 -0
  44. data/lib/rpush/daemon/delivery.rb +28 -0
  45. data/lib/rpush/daemon/delivery_error.rb +19 -0
  46. data/lib/rpush/daemon/dispatcher/http.rb +21 -0
  47. data/lib/rpush/daemon/dispatcher/tcp.rb +30 -0
  48. data/lib/rpush/daemon/dispatcher_loop.rb +54 -0
  49. data/lib/rpush/daemon/dispatcher_loop_collection.rb +33 -0
  50. data/lib/rpush/daemon/feeder.rb +68 -0
  51. data/lib/rpush/daemon/gcm.rb +9 -0
  52. data/lib/rpush/daemon/gcm/delivery.rb +222 -0
  53. data/lib/rpush/daemon/interruptible_sleep.rb +61 -0
  54. data/lib/rpush/daemon/loggable.rb +31 -0
  55. data/lib/rpush/daemon/reflectable.rb +13 -0
  56. data/lib/rpush/daemon/retry_header_parser.rb +23 -0
  57. data/lib/rpush/daemon/retryable_error.rb +20 -0
  58. data/lib/rpush/daemon/service_config_methods.rb +33 -0
  59. data/lib/rpush/daemon/store/active_record.rb +154 -0
  60. data/lib/rpush/daemon/store/active_record/reconnectable.rb +68 -0
  61. data/lib/rpush/daemon/tcp_connection.rb +143 -0
  62. data/lib/rpush/daemon/too_many_requests_error.rb +20 -0
  63. data/lib/rpush/daemon/wpns.rb +9 -0
  64. data/lib/rpush/daemon/wpns/delivery.rb +132 -0
  65. data/lib/rpush/deprecatable.rb +23 -0
  66. data/lib/rpush/deprecation.rb +23 -0
  67. data/lib/rpush/embed.rb +28 -0
  68. data/lib/rpush/gcm/app.rb +11 -0
  69. data/lib/rpush/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +11 -0
  70. data/lib/rpush/gcm/notification.rb +30 -0
  71. data/lib/rpush/logger.rb +63 -0
  72. data/lib/rpush/multi_json_helper.rb +16 -0
  73. data/lib/rpush/notification.rb +69 -0
  74. data/lib/rpush/notifier.rb +52 -0
  75. data/lib/rpush/payload_data_size_validator.rb +10 -0
  76. data/lib/rpush/push.rb +16 -0
  77. data/lib/rpush/railtie.rb +11 -0
  78. data/lib/rpush/reflection.rb +58 -0
  79. data/lib/rpush/registration_ids_count_validator.rb +10 -0
  80. data/lib/rpush/version.rb +3 -0
  81. data/lib/rpush/wpns/app.rb +9 -0
  82. data/lib/rpush/wpns/notification.rb +26 -0
  83. data/lib/tasks/cane.rake +18 -0
  84. data/lib/tasks/rpush.rake +16 -0
  85. data/lib/tasks/test.rake +38 -0
  86. data/spec/functional/adm_spec.rb +43 -0
  87. data/spec/functional/apns_spec.rb +58 -0
  88. data/spec/functional/embed_spec.rb +49 -0
  89. data/spec/functional/gcm_spec.rb +42 -0
  90. data/spec/functional/wpns_spec.rb +41 -0
  91. data/spec/support/cert_with_password.pem +90 -0
  92. data/spec/support/cert_without_password.pem +59 -0
  93. data/spec/support/install.sh +32 -0
  94. data/spec/support/simplecov_helper.rb +20 -0
  95. data/spec/support/simplecov_quality_formatter.rb +8 -0
  96. data/spec/tmp/.gitkeep +0 -0
  97. data/spec/unit/adm/app_spec.rb +58 -0
  98. data/spec/unit/adm/notification_spec.rb +45 -0
  99. data/spec/unit/apns/app_spec.rb +29 -0
  100. data/spec/unit/apns/feedback_spec.rb +9 -0
  101. data/spec/unit/apns/notification_spec.rb +208 -0
  102. data/spec/unit/apns_feedback_spec.rb +21 -0
  103. data/spec/unit/app_spec.rb +30 -0
  104. data/spec/unit/configuration_spec.rb +45 -0
  105. data/spec/unit/daemon/adm/delivery_spec.rb +243 -0
  106. data/spec/unit/daemon/apns/certificate_expired_error_spec.rb +11 -0
  107. data/spec/unit/daemon/apns/delivery_spec.rb +101 -0
  108. data/spec/unit/daemon/apns/disconnection_error_spec.rb +18 -0
  109. data/spec/unit/daemon/apns/feedback_receiver_spec.rb +117 -0
  110. data/spec/unit/daemon/app_runner_spec.rb +292 -0
  111. data/spec/unit/daemon/batch_spec.rb +232 -0
  112. data/spec/unit/daemon/delivery_error_spec.rb +13 -0
  113. data/spec/unit/daemon/delivery_spec.rb +38 -0
  114. data/spec/unit/daemon/dispatcher/http_spec.rb +33 -0
  115. data/spec/unit/daemon/dispatcher/tcp_spec.rb +38 -0
  116. data/spec/unit/daemon/dispatcher_loop_collection_spec.rb +37 -0
  117. data/spec/unit/daemon/dispatcher_loop_spec.rb +71 -0
  118. data/spec/unit/daemon/feeder_spec.rb +98 -0
  119. data/spec/unit/daemon/gcm/delivery_spec.rb +310 -0
  120. data/spec/unit/daemon/interruptible_sleep_spec.rb +68 -0
  121. data/spec/unit/daemon/reflectable_spec.rb +27 -0
  122. data/spec/unit/daemon/retryable_error_spec.rb +14 -0
  123. data/spec/unit/daemon/service_config_methods_spec.rb +33 -0
  124. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +114 -0
  125. data/spec/unit/daemon/store/active_record_spec.rb +357 -0
  126. data/spec/unit/daemon/tcp_connection_spec.rb +287 -0
  127. data/spec/unit/daemon/too_many_requests_error_spec.rb +14 -0
  128. data/spec/unit/daemon/wpns/delivery_spec.rb +159 -0
  129. data/spec/unit/daemon_spec.rb +159 -0
  130. data/spec/unit/deprecatable_spec.rb +32 -0
  131. data/spec/unit/deprecation_spec.rb +15 -0
  132. data/spec/unit/embed_spec.rb +50 -0
  133. data/spec/unit/gcm/app_spec.rb +4 -0
  134. data/spec/unit/gcm/notification_spec.rb +36 -0
  135. data/spec/unit/logger_spec.rb +127 -0
  136. data/spec/unit/notification_shared.rb +105 -0
  137. data/spec/unit/notification_spec.rb +15 -0
  138. data/spec/unit/notifier_spec.rb +49 -0
  139. data/spec/unit/push_spec.rb +43 -0
  140. data/spec/unit/reflection_spec.rb +30 -0
  141. data/spec/unit/rpush_spec.rb +9 -0
  142. data/spec/unit/wpns/app_spec.rb +4 -0
  143. data/spec/unit/wpns/notification_spec.rb +30 -0
  144. data/spec/unit_spec_helper.rb +101 -0
  145. metadata +276 -0
@@ -0,0 +1,9 @@
1
+ class AddAlertIsJsonToRapnsNotifications < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :rapns_notifications, :alert_is_json, :boolean, :null => true, :default => false
4
+ end
5
+
6
+ def self.down
7
+ remove_column :rapns_notifications, :alert_is_json
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class AddAppToRapns < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :rapns_notifications, :app, :string, :null => true
4
+ add_column :rapns_feedback, :app, :string, :null => true
5
+ end
6
+
7
+ def self.down
8
+ remove_column :rapns_notifications, :app
9
+ remove_column :rapns_feedback, :app
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ class AddFailAfterToRpushNotifications < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :rpush_notifications, :fail_after, :timestamp, :null => true
4
+ end
5
+
6
+ def self.down
7
+ remove_column :rpush_notifications, :fail_after
8
+ end
9
+ end
@@ -0,0 +1,102 @@
1
+ class AddGcm < ActiveRecord::Migration
2
+ module Rapns
3
+ class App < ActiveRecord::Base
4
+ self.table_name = 'rapns_apps'
5
+ end
6
+
7
+ class Notification < ActiveRecord::Base
8
+ belongs_to :app
9
+ self.table_name = 'rapns_notifications'
10
+ end
11
+ end
12
+
13
+ def self.up
14
+ add_column :rapns_notifications, :type, :string, :null => true
15
+ add_column :rapns_apps, :type, :string, :null => true
16
+
17
+ AddGcm::Rapns::Notification.update_all :type => 'Rapns::Apns::Notification'
18
+ AddGcm::Rapns::App.update_all :type => 'Rapns::Apns::App'
19
+
20
+ change_column :rapns_notifications, :type, :string, :null => false
21
+ change_column :rapns_apps, :type, :string, :null => false
22
+ change_column :rapns_notifications, :device_token, :string, { :null => true, :limit => 64 }
23
+ change_column :rapns_notifications, :expiry, :integer, { :null => true, :default => 1.day.to_i }
24
+ change_column :rapns_apps, :environment, :string, :null => true
25
+ change_column :rapns_apps, :certificate, :text, :null => true, :default => nil
26
+
27
+ change_column :rapns_notifications, :error_description, :text, :null => true, :default => nil
28
+ change_column :rapns_notifications, :sound, :string, :default => 'default'
29
+
30
+ rename_column :rapns_notifications, :attributes_for_device, :data
31
+ rename_column :rapns_apps, :key, :name
32
+
33
+ add_column :rapns_apps, :auth_key, :string, :null => true
34
+
35
+ add_column :rapns_notifications, :collapse_key, :string, :null => true
36
+ add_column :rapns_notifications, :delay_while_idle, :boolean, :null => false, :default => false
37
+
38
+ reg_ids_type = ActiveRecord::Base.connection.adapter_name.include?('Mysql') ? :mediumtext : :text
39
+ add_column :rapns_notifications, :registration_ids, reg_ids_type, :null => true
40
+ add_column :rapns_notifications, :app_id, :integer, :null => true
41
+ add_column :rapns_notifications, :retries, :integer, :null => true, :default => 0
42
+
43
+ AddGcm::Rapns::Notification.reset_column_information
44
+ AddGcm::Rapns::App.reset_column_information
45
+
46
+ AddGcm::Rapns::App.all.each do |app|
47
+ AddGcm::Rapns::Notification.update_all(['app_id = ?', app.id], ['app = ?', app.name])
48
+ end
49
+
50
+ change_column :rapns_notifications, :app_id, :integer, :null => false
51
+ remove_column :rapns_notifications, :app
52
+
53
+ if index_name_exists?(:rapns_notifications, "index_rapns_notifications_multi", true)
54
+ remove_index :rapns_notifications, :name => "index_rapns_notifications_multi"
55
+ elsif index_name_exists?(:rapns_notifications, "index_rapns_notifications_on_delivered_failed_deliver_after", false)
56
+ remove_index :rapns_notifications, :name => "index_rapns_notifications_on_delivered_failed_deliver_after"
57
+ end
58
+ add_index :rapns_notifications, [:app_id, :delivered, :failed, :deliver_after], :name => "index_rapns_notifications_multi"
59
+ end
60
+
61
+ def self.down
62
+ AddGcm::Rapns::Notification.where(:type => 'Rapns::Gcm::Notification').delete_all
63
+
64
+ remove_column :rapns_notifications, :type
65
+ remove_column :rapns_apps, :type
66
+
67
+ change_column :rapns_notifications, :device_token, :string, { :null => false, :limit => 64 }
68
+ change_column :rapns_notifications, :expiry, :integer, { :null => false, :default => 1.day.to_i }
69
+ change_column :rapns_apps, :environment, :string, :null => false
70
+ change_column :rapns_apps, :certificate, :text, :null => false
71
+
72
+ change_column :rapns_notifications, :error_description, :string, :null => true, :default => nil
73
+ change_column :rapns_notifications, :sound, :string, :default => '1.aiff'
74
+
75
+ rename_column :rapns_notifications, :data, :attributes_for_device
76
+ rename_column :rapns_apps, :name, :key
77
+
78
+ remove_column :rapns_apps, :auth_key
79
+
80
+ remove_column :rapns_notifications, :collapse_key
81
+ remove_column :rapns_notifications, :delay_while_idle
82
+ remove_column :rapns_notifications, :registration_ids
83
+ remove_column :rapns_notifications, :retries
84
+
85
+ add_column :rapns_notifications, :app, :string, :null => true
86
+
87
+ AddGcm::Rapns::Notification.reset_column_information
88
+ AddGcm::Rapns::App.reset_column_information
89
+
90
+ AddGcm::Rapns::App.all.each do |app|
91
+ AddGcm::Rapns::Notification.update_all(['app = ?', app.key], ['app_id = ?', app.id])
92
+ end
93
+
94
+ if index_name_exists?(:rapns_notifications, :index_rapns_notifications_multi, true)
95
+ remove_index :rapns_notifications, :name => :index_rapns_notifications_multi
96
+ end
97
+
98
+ remove_column :rapns_notifications, :app_id
99
+
100
+ add_index :rapns_notifications, [:delivered, :failed, :deliver_after], :name => :index_rapns_notifications_multi
101
+ end
102
+ end
@@ -0,0 +1,349 @@
1
+ # NOTE TO THE CURIOUS.
2
+ #
3
+ # Congratulations on being a diligent developer and vetting the migrations
4
+ # added to your project!
5
+ #
6
+ # You're probably thinking "This migration is huge!". It is, but that doesn't
7
+ # mean it'll take a long time to run, or that the reason for it being
8
+ # this size is because of lousy developers.
9
+ #
10
+ # Rpush used to be known as Rapns. In an effort to reduce clutter in db/migrate
11
+ # for new users of Rpush, what you see below is a concatenation of the
12
+ # migrations added to Rapns over its lifetime.
13
+ #
14
+ # The reason for concatenating old migrations - instead of producing a new
15
+ # one that attempts to recreate their accumulative state - is that I don't
16
+ # want to introduce any bugs by writing a new migration.
17
+ #
18
+ # So while this looks like a scary amount of code, it is in fact the safest
19
+ # approach. The constituent parts of this migration have been executed
20
+ # many times, by many people!
21
+
22
+ class AddRpush < ActiveRecord::Migration
23
+ def self.migrations
24
+ [CreateRapnsNotifications, CreateRapnsFeedback,
25
+ AddAlertIsJsonToRapnsNotifications, AddAppToRapns,
26
+ CreateRapnsApps, AddGcm, AddWpns, AddAdm, RenameRapnsToRpush,
27
+ AddFailAfterToRpushNotifications]
28
+ end
29
+
30
+ def self.up
31
+ migrations.map(&:up)
32
+ end
33
+
34
+ def self.down
35
+ migrations.reverse.each do |m|
36
+ begin
37
+ m.down
38
+ rescue ActiveRecord::StatementInvalid => e
39
+ p e
40
+ end
41
+ end
42
+ end
43
+
44
+ class CreateRapnsNotifications < ActiveRecord::Migration
45
+ def self.up
46
+ create_table :rapns_notifications do |t|
47
+ t.integer :badge, :null => true
48
+ t.string :device_token, :null => false, :limit => 64
49
+ t.string :sound, :null => true, :default => "1.aiff"
50
+ t.string :alert, :null => true
51
+ t.text :attributes_for_device, :null => true
52
+ t.integer :expiry, :null => false, :default => 1.day.to_i
53
+ t.boolean :delivered, :null => false, :default => false
54
+ t.timestamp :delivered_at, :null => true
55
+ t.boolean :failed, :null => false, :default => false
56
+ t.timestamp :failed_at, :null => true
57
+ t.integer :error_code, :null => true
58
+ t.string :error_description, :null => true
59
+ t.timestamp :deliver_after, :null => true
60
+ t.timestamps
61
+ end
62
+
63
+ add_index :rapns_notifications, [:delivered, :failed, :deliver_after], :name => 'index_rapns_notifications_multi'
64
+ end
65
+
66
+ def self.down
67
+ if index_name_exists?(:rapns_notifications, 'index_rapns_notifications_multi', true)
68
+ remove_index :rapns_notifications, :name => 'index_rapns_notifications_multi'
69
+ end
70
+ drop_table :rapns_notifications
71
+ end
72
+ end
73
+
74
+ class CreateRapnsFeedback < ActiveRecord::Migration
75
+ def self.up
76
+ create_table :rapns_feedback do |t|
77
+ t.string :device_token, :null => false, :limit => 64
78
+ t.timestamp :failed_at, :null => false
79
+ t.timestamps
80
+ end
81
+
82
+ add_index :rapns_feedback, :device_token
83
+ end
84
+
85
+ def self.down
86
+ if index_name_exists?(:rapns_feedback, :index_rapns_feedback_on_device_token, true)
87
+ remove_index :rapns_feedback, name: :index_rapns_feedback_on_device_token
88
+ end
89
+ drop_table :rapns_feedback
90
+ end
91
+ end
92
+
93
+ class AddAlertIsJsonToRapnsNotifications < ActiveRecord::Migration
94
+ def self.up
95
+ add_column :rapns_notifications, :alert_is_json, :boolean, :null => true, :default => false
96
+ end
97
+
98
+ def self.down
99
+ remove_column :rapns_notifications, :alert_is_json
100
+ end
101
+ end
102
+
103
+ class AddAppToRapns < ActiveRecord::Migration
104
+ def self.up
105
+ add_column :rapns_notifications, :app, :string, :null => true
106
+ add_column :rapns_feedback, :app, :string, :null => true
107
+ end
108
+
109
+ def self.down
110
+ remove_column :rapns_notifications, :app
111
+ remove_column :rapns_feedback, :app
112
+ end
113
+ end
114
+
115
+ class CreateRapnsApps < ActiveRecord::Migration
116
+ def self.up
117
+ create_table :rapns_apps do |t|
118
+ t.string :key, :null => false
119
+ t.string :environment, :null => false
120
+ t.text :certificate, :null => false
121
+ t.string :password, :null => true
122
+ t.integer :connections, :null => false, :default => 1
123
+ t.timestamps
124
+ end
125
+ end
126
+
127
+ def self.down
128
+ drop_table :rapns_apps
129
+ end
130
+ end
131
+
132
+ class AddGcm < ActiveRecord::Migration
133
+ module Rapns
134
+ class App < ActiveRecord::Base
135
+ self.table_name = 'rapns_apps'
136
+ end
137
+
138
+ class Notification < ActiveRecord::Base
139
+ belongs_to :app
140
+ self.table_name = 'rapns_notifications'
141
+ end
142
+ end
143
+
144
+ def self.up
145
+ add_column :rapns_notifications, :type, :string, :null => true
146
+ add_column :rapns_apps, :type, :string, :null => true
147
+
148
+ AddGcm::Rapns::Notification.update_all :type => 'Rapns::Apns::Notification'
149
+ AddGcm::Rapns::App.update_all :type => 'Rapns::Apns::App'
150
+
151
+ change_column :rapns_notifications, :type, :string, :null => false
152
+ change_column :rapns_apps, :type, :string, :null => false
153
+ change_column :rapns_notifications, :device_token, :string, { :null => true, :limit => 64 }
154
+ change_column :rapns_notifications, :expiry, :integer, { :null => true, :default => 1.day.to_i }
155
+ change_column :rapns_apps, :environment, :string, :null => true
156
+ change_column :rapns_apps, :certificate, :text, :null => true, :default => nil
157
+
158
+ change_column :rapns_notifications, :error_description, :text, :null => true, :default => nil
159
+ change_column :rapns_notifications, :sound, :string, :default => 'default'
160
+
161
+ rename_column :rapns_notifications, :attributes_for_device, :data
162
+ rename_column :rapns_apps, :key, :name
163
+
164
+ add_column :rapns_apps, :auth_key, :string, :null => true
165
+
166
+ add_column :rapns_notifications, :collapse_key, :string, :null => true
167
+ add_column :rapns_notifications, :delay_while_idle, :boolean, :null => false, :default => false
168
+
169
+ reg_ids_type = ActiveRecord::Base.connection.adapter_name.include?('Mysql') ? :mediumtext : :text
170
+ add_column :rapns_notifications, :registration_ids, reg_ids_type, :null => true
171
+ add_column :rapns_notifications, :app_id, :integer, :null => true
172
+ add_column :rapns_notifications, :retries, :integer, :null => true, :default => 0
173
+
174
+ AddGcm::Rapns::Notification.reset_column_information
175
+ AddGcm::Rapns::App.reset_column_information
176
+
177
+ AddGcm::Rapns::App.all.each do |app|
178
+ AddGcm::Rapns::Notification.update_all(['app_id = ?', app.id], ['app = ?', app.name])
179
+ end
180
+
181
+ change_column :rapns_notifications, :app_id, :integer, :null => false
182
+ remove_column :rapns_notifications, :app
183
+
184
+ if index_name_exists?(:rapns_notifications, "index_rapns_notifications_multi", true)
185
+ remove_index :rapns_notifications, :name => "index_rapns_notifications_multi"
186
+ elsif index_name_exists?(:rapns_notifications, "index_rapns_notifications_on_delivered_failed_deliver_after", false)
187
+ remove_index :rapns_notifications, :name => "index_rapns_notifications_on_delivered_failed_deliver_after"
188
+ end
189
+ add_index :rapns_notifications, [:app_id, :delivered, :failed, :deliver_after], :name => "index_rapns_notifications_multi"
190
+ end
191
+
192
+ def self.down
193
+ AddGcm::Rapns::Notification.where(:type => 'Rapns::Gcm::Notification').delete_all
194
+
195
+ remove_column :rapns_notifications, :type
196
+ remove_column :rapns_apps, :type
197
+
198
+ change_column :rapns_notifications, :device_token, :string, { :null => false, :limit => 64 }
199
+ change_column :rapns_notifications, :expiry, :integer, { :null => false, :default => 1.day.to_i }
200
+ change_column :rapns_apps, :environment, :string, :null => false
201
+ change_column :rapns_apps, :certificate, :text, :null => false
202
+
203
+ change_column :rapns_notifications, :error_description, :string, :null => true, :default => nil
204
+ change_column :rapns_notifications, :sound, :string, :default => '1.aiff'
205
+
206
+ rename_column :rapns_notifications, :data, :attributes_for_device
207
+ rename_column :rapns_apps, :name, :key
208
+
209
+ remove_column :rapns_apps, :auth_key
210
+
211
+ remove_column :rapns_notifications, :collapse_key
212
+ remove_column :rapns_notifications, :delay_while_idle
213
+ remove_column :rapns_notifications, :registration_ids
214
+ remove_column :rapns_notifications, :retries
215
+
216
+ add_column :rapns_notifications, :app, :string, :null => true
217
+
218
+ AddGcm::Rapns::Notification.reset_column_information
219
+ AddGcm::Rapns::App.reset_column_information
220
+
221
+ AddGcm::Rapns::App.all.each do |app|
222
+ AddGcm::Rapns::Notification.update_all(['app = ?', app.key], ['app_id = ?', app.id])
223
+ end
224
+
225
+ if index_name_exists?(:rapns_notifications, :index_rapns_notifications_multi, true)
226
+ remove_index :rapns_notifications, :name => :index_rapns_notifications_multi
227
+ end
228
+
229
+ remove_column :rapns_notifications, :app_id
230
+
231
+ add_index :rapns_notifications, [:delivered, :failed, :deliver_after], :name => :index_rapns_notifications_multi
232
+ end
233
+ end
234
+
235
+ class AddWpns < ActiveRecord::Migration
236
+ module Rapns
237
+ class Notification < ActiveRecord::Base
238
+ self.table_name = 'rapns_notifications'
239
+ end
240
+ end
241
+
242
+ def self.up
243
+ add_column :rapns_notifications, :uri, :string, :null => true
244
+ end
245
+
246
+ def self.down
247
+ AddWpns::Rapns::Notification.where(:type => 'Rapns::Wpns::Notification').delete_all
248
+ remove_column :rapns_notifications, :uri
249
+ end
250
+ end
251
+
252
+ class AddAdm < ActiveRecord::Migration
253
+ module Rapns
254
+ class Notification < ActiveRecord::Base
255
+ self.table_name = 'rapns_notifications'
256
+ end
257
+ end
258
+
259
+ def self.up
260
+ add_column :rapns_apps, :client_id, :string, :null => true
261
+ add_column :rapns_apps, :client_secret, :string, :null => true
262
+ add_column :rapns_apps, :access_token, :string, :null => true
263
+ add_column :rapns_apps, :access_token_expiration, :datetime, :null => true
264
+ end
265
+
266
+ def self.down
267
+ AddAdm::Rapns::Notification.where(:type => 'Rapns::Adm::Notification').delete_all
268
+
269
+ remove_column :rapns_apps, :client_id
270
+ remove_column :rapns_apps, :client_secret
271
+ remove_column :rapns_apps, :access_token
272
+ remove_column :rapns_apps, :access_token_expiration
273
+ end
274
+ end
275
+
276
+ class RenameRapnsToRpush < ActiveRecord::Migration
277
+ module Rpush
278
+ class App < ActiveRecord::Base
279
+ self.table_name = 'rpush_apps'
280
+ end
281
+
282
+ class Notification < ActiveRecord::Base
283
+ self.table_name = 'rpush_notifications'
284
+ end
285
+ end
286
+
287
+ def self.update_type(model, from, to)
288
+ model.where(type: from).update_all(type: to)
289
+ end
290
+
291
+ def self.up
292
+ rename_table :rapns_notifications, :rpush_notifications
293
+ rename_table :rapns_apps, :rpush_apps
294
+ rename_table :rapns_feedback, :rpush_feedback
295
+
296
+ if index_name_exists?(:rpush_notifications, :index_rapns_notifications_multi, true)
297
+ rename_index :rpush_notifications, :index_rapns_notifications_multi, :index_rpush_notifications_multi
298
+ end
299
+
300
+ if index_name_exists?(:rpush_feedback, :index_rapns_feedback_on_device_token, true)
301
+ rename_index :rpush_feedback, :index_rapns_feedback_on_device_token, :index_rpush_feedback_on_device_token
302
+ end
303
+
304
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Apns::Notification', 'Rpush::Apns::Notification')
305
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Gcm::Notification', 'Rpush::Gcm::Notification')
306
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Adm::Notification', 'Rpush::Adm::Notification')
307
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Wpns::Notification', 'Rpush::Wpns::Notification')
308
+
309
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Apns::App', 'Rpush::Apns::App')
310
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Gcm::App', 'Rpush::Gcm::App')
311
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Adm::App', 'Rpush::Adm::App')
312
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Wpns::App', 'Rpush::Wpns::App')
313
+ end
314
+
315
+ def self.down
316
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Apns::Notification', 'Rapns::Apns::Notification')
317
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Gcm::Notification', 'Rapns::Gcm::Notification')
318
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Adm::Notification', 'Rapns::Adm::Notification')
319
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Wpns::Notification', 'Rapns::Wpns::Notification')
320
+
321
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Apns::App', 'Rapns::Apns::App')
322
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Gcm::App', 'Rapns::Gcm::App')
323
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Adm::App', 'Rapns::Adm::App')
324
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Wpns::App', 'Rapns::Wpns::App')
325
+
326
+ if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi, true)
327
+ rename_index :rpush_notifications, :index_rpush_notifications_multi, :index_rapns_notifications_multi
328
+ end
329
+
330
+ if index_name_exists?(:rpush_feedback, :index_rpush_feedback_on_device_token, true)
331
+ rename_index :rpush_feedback, :index_rpush_feedback_on_device_token, :index_rapns_feedback_on_device_token
332
+ end
333
+
334
+ rename_table :rpush_notifications, :rapns_notifications
335
+ rename_table :rpush_apps, :rapns_apps
336
+ rename_table :rpush_feedback, :rapns_feedback
337
+ end
338
+ end
339
+
340
+ class AddFailAfterToRpushNotifications < ActiveRecord::Migration
341
+ def self.up
342
+ add_column :rpush_notifications, :fail_after, :timestamp, :null => true
343
+ end
344
+
345
+ def self.down
346
+ remove_column :rpush_notifications, :fail_after
347
+ end
348
+ end
349
+ end