rpush_extended 3.2.5

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 (248) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +365 -0
  3. data/LICENSE +7 -0
  4. data/README.md +393 -0
  5. data/bin/rpush +4 -0
  6. data/lib/generators/rpush_config_generator.rb +7 -0
  7. data/lib/generators/rpush_migration_generator.rb +66 -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 +117 -0
  13. data/lib/generators/templates/add_rpush.rb +402 -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 +25 -0
  17. data/lib/generators/templates/create_rapns_notifications.rb +36 -0
  18. data/lib/generators/templates/rename_rapns_to_rpush.rb +87 -0
  19. data/lib/generators/templates/rpush.rb +135 -0
  20. data/lib/generators/templates/rpush_2_0_0_updates.rb +79 -0
  21. data/lib/generators/templates/rpush_2_1_0_updates.rb +11 -0
  22. data/lib/generators/templates/rpush_2_6_0_updates.rb +10 -0
  23. data/lib/generators/templates/rpush_2_7_0_updates.rb +12 -0
  24. data/lib/generators/templates/rpush_3_0_0_updates.rb +11 -0
  25. data/lib/generators/templates/rpush_3_0_1_updates.rb +13 -0
  26. data/lib/generators/templates/rpush_3_1_0_add_pushy.rb +9 -0
  27. data/lib/generators/templates/rpush_3_1_1_updates.rb +15 -0
  28. data/lib/generators/templates/rpush_3_2_0_add_apns_p8.rb +15 -0
  29. data/lib/generators/templates/rpush_3_2_4_updates.rb +9 -0
  30. data/lib/generators/templates/rpush_3_3_0_updates.rb +9 -0
  31. data/lib/generators/templates/rpush_3_3_1_updates.rb +11 -0
  32. data/lib/rpush/apns_feedback.rb +17 -0
  33. data/lib/rpush/cli.rb +213 -0
  34. data/lib/rpush/client/active_model/adm/app.rb +23 -0
  35. data/lib/rpush/client/active_model/adm/data_validator.rb +14 -0
  36. data/lib/rpush/client/active_model/adm/notification.rb +28 -0
  37. data/lib/rpush/client/active_model/apns/app.rb +37 -0
  38. data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +16 -0
  39. data/lib/rpush/client/active_model/apns/device_token_format_validator.rb +14 -0
  40. data/lib/rpush/client/active_model/apns/notification.rb +104 -0
  41. data/lib/rpush/client/active_model/apns2/app.rb +15 -0
  42. data/lib/rpush/client/active_model/apns2/notification.rb +9 -0
  43. data/lib/rpush/client/active_model/apnsp8/app.rb +23 -0
  44. data/lib/rpush/client/active_model/apnsp8/notification.rb +9 -0
  45. data/lib/rpush/client/active_model/gcm/app.rb +19 -0
  46. data/lib/rpush/client/active_model/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +14 -0
  47. data/lib/rpush/client/active_model/gcm/notification.rb +59 -0
  48. data/lib/rpush/client/active_model/notification.rb +22 -0
  49. data/lib/rpush/client/active_model/payload_data_size_validator.rb +13 -0
  50. data/lib/rpush/client/active_model/pushy/app.rb +20 -0
  51. data/lib/rpush/client/active_model/pushy/notification.rb +31 -0
  52. data/lib/rpush/client/active_model/pushy/time_to_live_validator.rb +14 -0
  53. data/lib/rpush/client/active_model/registration_ids_count_validator.rb +13 -0
  54. data/lib/rpush/client/active_model/wns/app.rb +23 -0
  55. data/lib/rpush/client/active_model/wns/notification.rb +32 -0
  56. data/lib/rpush/client/active_model/wpns/app.rb +13 -0
  57. data/lib/rpush/client/active_model/wpns/notification.rb +28 -0
  58. data/lib/rpush/client/active_model.rb +34 -0
  59. data/lib/rpush/client/active_record/adm/app.rb +11 -0
  60. data/lib/rpush/client/active_record/adm/notification.rb +11 -0
  61. data/lib/rpush/client/active_record/apns/app.rb +11 -0
  62. data/lib/rpush/client/active_record/apns/feedback.rb +18 -0
  63. data/lib/rpush/client/active_record/apns/notification.rb +40 -0
  64. data/lib/rpush/client/active_record/apns2/app.rb +11 -0
  65. data/lib/rpush/client/active_record/apns2/notification.rb +10 -0
  66. data/lib/rpush/client/active_record/apnsp8/app.rb +11 -0
  67. data/lib/rpush/client/active_record/apnsp8/notification.rb +10 -0
  68. data/lib/rpush/client/active_record/app.rb +13 -0
  69. data/lib/rpush/client/active_record/gcm/app.rb +11 -0
  70. data/lib/rpush/client/active_record/gcm/notification.rb +11 -0
  71. data/lib/rpush/client/active_record/notification.rb +42 -0
  72. data/lib/rpush/client/active_record/pushy/app.rb +11 -0
  73. data/lib/rpush/client/active_record/pushy/notification.rb +11 -0
  74. data/lib/rpush/client/active_record/wns/app.rb +11 -0
  75. data/lib/rpush/client/active_record/wns/badge_notification.rb +15 -0
  76. data/lib/rpush/client/active_record/wns/notification.rb +11 -0
  77. data/lib/rpush/client/active_record/wns/raw_notification.rb +13 -0
  78. data/lib/rpush/client/active_record/wpns/app.rb +11 -0
  79. data/lib/rpush/client/active_record/wpns/notification.rb +11 -0
  80. data/lib/rpush/client/active_record.rb +33 -0
  81. data/lib/rpush/client/redis/adm/app.rb +14 -0
  82. data/lib/rpush/client/redis/adm/notification.rb +11 -0
  83. data/lib/rpush/client/redis/apns/app.rb +11 -0
  84. data/lib/rpush/client/redis/apns/feedback.rb +20 -0
  85. data/lib/rpush/client/redis/apns/notification.rb +11 -0
  86. data/lib/rpush/client/redis/apns2/app.rb +11 -0
  87. data/lib/rpush/client/redis/apns2/notification.rb +11 -0
  88. data/lib/rpush/client/redis/apnsp8/app.rb +11 -0
  89. data/lib/rpush/client/redis/apnsp8/notification.rb +11 -0
  90. data/lib/rpush/client/redis/app.rb +29 -0
  91. data/lib/rpush/client/redis/gcm/app.rb +11 -0
  92. data/lib/rpush/client/redis/gcm/notification.rb +11 -0
  93. data/lib/rpush/client/redis/notification.rb +74 -0
  94. data/lib/rpush/client/redis/pushy/app.rb +16 -0
  95. data/lib/rpush/client/redis/pushy/notification.rb +18 -0
  96. data/lib/rpush/client/redis/wns/app.rb +14 -0
  97. data/lib/rpush/client/redis/wns/badge_notification.rb +15 -0
  98. data/lib/rpush/client/redis/wns/notification.rb +11 -0
  99. data/lib/rpush/client/redis/wns/raw_notification.rb +11 -0
  100. data/lib/rpush/client/redis/wpns/app.rb +11 -0
  101. data/lib/rpush/client/redis/wpns/notification.rb +11 -0
  102. data/lib/rpush/client/redis.rb +56 -0
  103. data/lib/rpush/configuration.rb +115 -0
  104. data/lib/rpush/daemon/adm/delivery.rb +226 -0
  105. data/lib/rpush/daemon/adm.rb +9 -0
  106. data/lib/rpush/daemon/apns/delivery.rb +43 -0
  107. data/lib/rpush/daemon/apns/feedback_receiver.rb +90 -0
  108. data/lib/rpush/daemon/apns.rb +17 -0
  109. data/lib/rpush/daemon/apns2/delivery.rb +127 -0
  110. data/lib/rpush/daemon/apns2.rb +10 -0
  111. data/lib/rpush/daemon/apnsp8/delivery.rb +166 -0
  112. data/lib/rpush/daemon/apnsp8/token.rb +43 -0
  113. data/lib/rpush/daemon/apnsp8.rb +10 -0
  114. data/lib/rpush/daemon/app_runner.rb +190 -0
  115. data/lib/rpush/daemon/batch.rb +138 -0
  116. data/lib/rpush/daemon/constants.rb +59 -0
  117. data/lib/rpush/daemon/delivery.rb +46 -0
  118. data/lib/rpush/daemon/delivery_error.rb +27 -0
  119. data/lib/rpush/daemon/dispatcher/apns_http2.rb +51 -0
  120. data/lib/rpush/daemon/dispatcher/apns_tcp.rb +152 -0
  121. data/lib/rpush/daemon/dispatcher/apnsp8_http2.rb +33 -0
  122. data/lib/rpush/daemon/dispatcher/http.rb +21 -0
  123. data/lib/rpush/daemon/dispatcher/tcp.rb +22 -0
  124. data/lib/rpush/daemon/dispatcher_loop.rb +73 -0
  125. data/lib/rpush/daemon/errors.rb +18 -0
  126. data/lib/rpush/daemon/feeder.rb +69 -0
  127. data/lib/rpush/daemon/gcm/delivery.rb +241 -0
  128. data/lib/rpush/daemon/gcm.rb +9 -0
  129. data/lib/rpush/daemon/interruptible_sleep.rb +24 -0
  130. data/lib/rpush/daemon/loggable.rb +33 -0
  131. data/lib/rpush/daemon/proc_title.rb +17 -0
  132. data/lib/rpush/daemon/pushy/delivery.rb +90 -0
  133. data/lib/rpush/daemon/pushy.rb +9 -0
  134. data/lib/rpush/daemon/queue_payload.rb +12 -0
  135. data/lib/rpush/daemon/retry_header_parser.rb +23 -0
  136. data/lib/rpush/daemon/retryable_error.rb +22 -0
  137. data/lib/rpush/daemon/ring_buffer.rb +16 -0
  138. data/lib/rpush/daemon/rpc/client.rb +27 -0
  139. data/lib/rpush/daemon/rpc/server.rb +82 -0
  140. data/lib/rpush/daemon/rpc.rb +9 -0
  141. data/lib/rpush/daemon/service_config_methods.rb +51 -0
  142. data/lib/rpush/daemon/signal_handler.rb +75 -0
  143. data/lib/rpush/daemon/store/active_record/reconnectable.rb +80 -0
  144. data/lib/rpush/daemon/store/active_record.rb +214 -0
  145. data/lib/rpush/daemon/store/interface.rb +20 -0
  146. data/lib/rpush/daemon/store/redis.rb +166 -0
  147. data/lib/rpush/daemon/string_helpers.rb +15 -0
  148. data/lib/rpush/daemon/synchronizer.rb +62 -0
  149. data/lib/rpush/daemon/tcp_connection.rb +190 -0
  150. data/lib/rpush/daemon/wns/badge_request.rb +32 -0
  151. data/lib/rpush/daemon/wns/delivery.rb +178 -0
  152. data/lib/rpush/daemon/wns/post_request.rb +33 -0
  153. data/lib/rpush/daemon/wns/raw_request.rb +22 -0
  154. data/lib/rpush/daemon/wns/toast_request.rb +54 -0
  155. data/lib/rpush/daemon/wns.rb +9 -0
  156. data/lib/rpush/daemon/wpns/delivery.rb +132 -0
  157. data/lib/rpush/daemon/wpns.rb +9 -0
  158. data/lib/rpush/daemon.rb +179 -0
  159. data/lib/rpush/deprecatable.rb +24 -0
  160. data/lib/rpush/deprecation.rb +26 -0
  161. data/lib/rpush/embed.rb +41 -0
  162. data/lib/rpush/logger.rb +92 -0
  163. data/lib/rpush/multi_json_helper.rb +16 -0
  164. data/lib/rpush/plugin.rb +44 -0
  165. data/lib/rpush/push.rb +11 -0
  166. data/lib/rpush/reflectable.rb +13 -0
  167. data/lib/rpush/reflection_collection.rb +44 -0
  168. data/lib/rpush/reflection_public_methods.rb +11 -0
  169. data/lib/rpush/version.rb +14 -0
  170. data/lib/rpush.rb +43 -0
  171. data/lib/tasks/quality.rake +35 -0
  172. data/lib/tasks/test.rake +69 -0
  173. data/spec/.rubocop.yml +4 -0
  174. data/spec/functional/adm_spec.rb +50 -0
  175. data/spec/functional/apns2_spec.rb +232 -0
  176. data/spec/functional/apns_spec.rb +162 -0
  177. data/spec/functional/cli_spec.rb +36 -0
  178. data/spec/functional/embed_spec.rb +49 -0
  179. data/spec/functional/gcm_spec.rb +46 -0
  180. data/spec/functional/new_app_spec.rb +44 -0
  181. data/spec/functional/pushy_spec.rb +22 -0
  182. data/spec/functional/retry_spec.rb +42 -0
  183. data/spec/functional/synchronization_spec.rb +97 -0
  184. data/spec/functional/wpns_spec.rb +71 -0
  185. data/spec/functional_spec_helper.rb +32 -0
  186. data/spec/spec_helper.rb +69 -0
  187. data/spec/support/active_record_setup.rb +73 -0
  188. data/spec/support/cert_with_password.pem +90 -0
  189. data/spec/support/cert_without_password.pem +59 -0
  190. data/spec/support/config/database.yml +44 -0
  191. data/spec/support/simplecov_helper.rb +24 -0
  192. data/spec/support/simplecov_quality_formatter.rb +12 -0
  193. data/spec/tmp/.gitkeep +0 -0
  194. data/spec/unit/apns_feedback_spec.rb +28 -0
  195. data/spec/unit/client/active_record/adm/app_spec.rb +58 -0
  196. data/spec/unit/client/active_record/adm/notification_spec.rb +43 -0
  197. data/spec/unit/client/active_record/apns/app_spec.rb +29 -0
  198. data/spec/unit/client/active_record/apns/feedback_spec.rb +9 -0
  199. data/spec/unit/client/active_record/apns/notification_spec.rb +324 -0
  200. data/spec/unit/client/active_record/app_spec.rb +30 -0
  201. data/spec/unit/client/active_record/gcm/app_spec.rb +4 -0
  202. data/spec/unit/client/active_record/gcm/notification_spec.rb +67 -0
  203. data/spec/unit/client/active_record/notification_spec.rb +21 -0
  204. data/spec/unit/client/active_record/pushy/app_spec.rb +17 -0
  205. data/spec/unit/client/active_record/pushy/notification_spec.rb +65 -0
  206. data/spec/unit/client/active_record/wns/badge_notification_spec.rb +15 -0
  207. data/spec/unit/client/active_record/wns/raw_notification_spec.rb +26 -0
  208. data/spec/unit/client/active_record/wpns/app_spec.rb +4 -0
  209. data/spec/unit/client/active_record/wpns/notification_spec.rb +21 -0
  210. data/spec/unit/configuration_spec.rb +46 -0
  211. data/spec/unit/daemon/adm/delivery_spec.rb +253 -0
  212. data/spec/unit/daemon/apns/certificate_expired_error_spec.rb +11 -0
  213. data/spec/unit/daemon/apns/delivery_spec.rb +108 -0
  214. data/spec/unit/daemon/apns/feedback_receiver_spec.rb +119 -0
  215. data/spec/unit/daemon/app_runner_spec.rb +188 -0
  216. data/spec/unit/daemon/batch_spec.rb +169 -0
  217. data/spec/unit/daemon/delivery_error_spec.rb +13 -0
  218. data/spec/unit/daemon/delivery_spec.rb +51 -0
  219. data/spec/unit/daemon/dispatcher/http_spec.rb +34 -0
  220. data/spec/unit/daemon/dispatcher/tcp_spec.rb +32 -0
  221. data/spec/unit/daemon/dispatcher_loop_spec.rb +53 -0
  222. data/spec/unit/daemon/feeder_spec.rb +96 -0
  223. data/spec/unit/daemon/gcm/delivery_spec.rb +387 -0
  224. data/spec/unit/daemon/proc_title_spec.rb +11 -0
  225. data/spec/unit/daemon/pushy/delivery_spec.rb +159 -0
  226. data/spec/unit/daemon/retryable_error_spec.rb +14 -0
  227. data/spec/unit/daemon/service_config_methods_spec.rb +36 -0
  228. data/spec/unit/daemon/signal_handler_spec.rb +99 -0
  229. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +165 -0
  230. data/spec/unit/daemon/store/active_record_spec.rb +357 -0
  231. data/spec/unit/daemon/store/redis_spec.rb +365 -0
  232. data/spec/unit/daemon/tcp_connection_spec.rb +292 -0
  233. data/spec/unit/daemon/wns/delivery_spec.rb +176 -0
  234. data/spec/unit/daemon/wns/post_request_spec.rb +117 -0
  235. data/spec/unit/daemon/wpns/delivery_spec.rb +167 -0
  236. data/spec/unit/daemon_spec.rb +138 -0
  237. data/spec/unit/deprecatable_spec.rb +32 -0
  238. data/spec/unit/deprecation_spec.rb +15 -0
  239. data/spec/unit/embed_spec.rb +47 -0
  240. data/spec/unit/logger_spec.rb +127 -0
  241. data/spec/unit/notification_shared.rb +53 -0
  242. data/spec/unit/plugin_spec.rb +36 -0
  243. data/spec/unit/push_spec.rb +34 -0
  244. data/spec/unit/reflectable_spec.rb +27 -0
  245. data/spec/unit/reflection_collection_spec.rb +26 -0
  246. data/spec/unit/rpush_spec.rb +8 -0
  247. data/spec/unit_spec_helper.rb +26 -0
  248. metadata +709 -0
@@ -0,0 +1,402 @@
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::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : 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::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : 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 ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
68
+ if index_name_exists?(:rapns_notifications, 'index_rapns_notifications_multi')
69
+ remove_index :rapns_notifications, name: 'index_rapns_notifications_multi'
70
+ end
71
+ else
72
+ if index_name_exists?(:rapns_notifications, 'index_rapns_notifications_multi', true)
73
+ remove_index :rapns_notifications, name: 'index_rapns_notifications_multi'
74
+ end
75
+ end
76
+
77
+ drop_table :rapns_notifications
78
+ end
79
+ end
80
+
81
+ class CreateRapnsFeedback < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
82
+ def self.up
83
+ create_table :rapns_feedback do |t|
84
+ t.string :device_token, null: false, limit: 64
85
+ t.timestamp :failed_at, null: false
86
+ t.timestamps
87
+ end
88
+
89
+ add_index :rapns_feedback, :device_token
90
+ end
91
+
92
+ def self.down
93
+ if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
94
+ if index_name_exists?(:rapns_feedback, :index_rapns_feedback_on_device_token)
95
+ remove_index :rapns_feedback, name: :index_rapns_feedback_on_device_token
96
+ end
97
+ else
98
+ if index_name_exists?(:rapns_feedback, :index_rapns_feedback_on_device_token, true)
99
+ remove_index :rapns_feedback, name: :index_rapns_feedback_on_device_token
100
+ end
101
+ end
102
+
103
+ drop_table :rapns_feedback
104
+ end
105
+ end
106
+
107
+ class AddAlertIsJsonToRapnsNotifications < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
108
+ def self.up
109
+ add_column :rapns_notifications, :alert_is_json, :boolean, null: true, default: false
110
+ end
111
+
112
+ def self.down
113
+ remove_column :rapns_notifications, :alert_is_json
114
+ end
115
+ end
116
+
117
+ class AddAppToRapns < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
118
+ def self.up
119
+ add_column :rapns_notifications, :app, :string, null: true
120
+ add_column :rapns_feedback, :app, :string, null: true
121
+ end
122
+
123
+ def self.down
124
+ remove_column :rapns_notifications, :app
125
+ remove_column :rapns_feedback, :app
126
+ end
127
+ end
128
+
129
+ class CreateRapnsApps < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
130
+ def self.up
131
+ create_table :rapns_apps do |t|
132
+ t.string :key, null: false
133
+ t.string :environment, null: false
134
+ t.text :certificate, null: false
135
+ t.string :password, null: true
136
+ t.integer :connections, null: false, default: 1
137
+ t.timestamps
138
+ end
139
+ end
140
+
141
+ def self.down
142
+ drop_table :rapns_apps
143
+ end
144
+ end
145
+
146
+ class AddGcm < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
147
+ module Rapns
148
+ class App < ActiveRecord::Base
149
+ self.table_name = 'rapns_apps'
150
+ end
151
+
152
+ class Notification < ActiveRecord::Base
153
+ belongs_to :app
154
+ self.table_name = 'rapns_notifications'
155
+ end
156
+ end
157
+
158
+ def self.up
159
+ add_column :rapns_notifications, :type, :string, null: true
160
+ add_column :rapns_apps, :type, :string, null: true
161
+
162
+ AddGcm::Rapns::Notification.update_all type: 'Rapns::Apns::Notification'
163
+ AddGcm::Rapns::App.update_all type: 'Rapns::Apns::App'
164
+
165
+ change_column :rapns_notifications, :type, :string, null: false
166
+ change_column :rapns_apps, :type, :string, null: false
167
+ change_column :rapns_notifications, :device_token, :string, { null: true, limit: 64 }
168
+ change_column :rapns_notifications, :expiry, :integer, { null: true, default: 1.day.to_i }
169
+ change_column :rapns_apps, :environment, :string, null: true
170
+ change_column :rapns_apps, :certificate, :text, null: true, default: nil
171
+
172
+ change_column :rapns_notifications, :error_description, :text, null: true, default: nil
173
+ change_column :rapns_notifications, :sound, :string, default: 'default'
174
+
175
+ rename_column :rapns_notifications, :attributes_for_device, :data
176
+ rename_column :rapns_apps, :key, :name
177
+
178
+ add_column :rapns_apps, :auth_key, :string, null: true
179
+
180
+ add_column :rapns_notifications, :collapse_key, :string, null: true
181
+ add_column :rapns_notifications, :delay_while_idle, :boolean, null: false, default: false
182
+
183
+ reg_ids_type = ActiveRecord::Base.connection.adapter_name.include?('Mysql') ? :mediumtext : :text
184
+ add_column :rapns_notifications, :registration_ids, reg_ids_type, null: true
185
+ add_column :rapns_notifications, :app_id, :integer, null: true
186
+ add_column :rapns_notifications, :retries, :integer, null: true, default: 0
187
+
188
+ AddGcm::Rapns::Notification.reset_column_information
189
+ AddGcm::Rapns::App.reset_column_information
190
+
191
+ AddGcm::Rapns::App.all.each do |app|
192
+ AddGcm::Rapns::Notification.where(app: app.name).update_all(app_id: app.id)
193
+ end
194
+
195
+ change_column :rapns_notifications, :app_id, :integer, null: false
196
+ remove_column :rapns_notifications, :app
197
+
198
+ if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
199
+ if index_name_exists?(:rapns_notifications, "index_rapns_notifications_multi")
200
+ remove_index :rapns_notifications, name: "index_rapns_notifications_multi"
201
+ elsif index_name_exists?(:rapns_notifications, "index_rapns_notifications_on_delivered_failed_deliver_after")
202
+ remove_index :rapns_notifications, name: "index_rapns_notifications_on_delivered_failed_deliver_after"
203
+ end
204
+ else
205
+ if index_name_exists?(:rapns_notifications, "index_rapns_notifications_multi", true)
206
+ remove_index :rapns_notifications, name: "index_rapns_notifications_multi"
207
+ elsif index_name_exists?(:rapns_notifications, "index_rapns_notifications_on_delivered_failed_deliver_after", false)
208
+ remove_index :rapns_notifications, name: "index_rapns_notifications_on_delivered_failed_deliver_after"
209
+ end
210
+ end
211
+
212
+ add_index :rapns_notifications, [:app_id, :delivered, :failed, :deliver_after], name: "index_rapns_notifications_multi"
213
+ end
214
+
215
+ def self.down
216
+ AddGcm::Rapns::Notification.where(type: 'Rapns::Gcm::Notification').delete_all
217
+
218
+ remove_column :rapns_notifications, :type
219
+ remove_column :rapns_apps, :type
220
+
221
+ change_column :rapns_notifications, :device_token, :string, { null: false, limit: 64 }
222
+ change_column :rapns_notifications, :expiry, :integer, { null: false, default: 1.day.to_i }
223
+ change_column :rapns_apps, :environment, :string, null: false
224
+ change_column :rapns_apps, :certificate, :text, null: false
225
+
226
+ change_column :rapns_notifications, :error_description, :string, null: true, default: nil
227
+ change_column :rapns_notifications, :sound, :string, default: '1.aiff'
228
+
229
+ rename_column :rapns_notifications, :data, :attributes_for_device
230
+ rename_column :rapns_apps, :name, :key
231
+
232
+ remove_column :rapns_apps, :auth_key
233
+
234
+ remove_column :rapns_notifications, :collapse_key
235
+ remove_column :rapns_notifications, :delay_while_idle
236
+ remove_column :rapns_notifications, :registration_ids
237
+ remove_column :rapns_notifications, :retries
238
+
239
+ add_column :rapns_notifications, :app, :string, null: true
240
+
241
+ AddGcm::Rapns::Notification.reset_column_information
242
+ AddGcm::Rapns::App.reset_column_information
243
+
244
+ AddGcm::Rapns::App.all.each do |app|
245
+ AddGcm::Rapns::Notification.where(app_id: app.id).update_all(app: app.key)
246
+ end
247
+
248
+ if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
249
+ if index_name_exists?(:rapns_notifications, :index_rapns_notifications_multi)
250
+ remove_index :rapns_notifications, name: :index_rapns_notifications_multi
251
+ end
252
+ else
253
+ if index_name_exists?(:rapns_notifications, :index_rapns_notifications_multi, true)
254
+ remove_index :rapns_notifications, name: :index_rapns_notifications_multi
255
+ end
256
+ end
257
+
258
+ remove_column :rapns_notifications, :app_id
259
+
260
+ add_index :rapns_notifications, [:delivered, :failed, :deliver_after], name: :index_rapns_notifications_multi
261
+ end
262
+ end
263
+
264
+ class AddWpns < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
265
+ module Rapns
266
+ class Notification < ActiveRecord::Base
267
+ self.table_name = 'rapns_notifications'
268
+ end
269
+ end
270
+
271
+ def self.up
272
+ add_column :rapns_notifications, :uri, :string, null: true
273
+ end
274
+
275
+ def self.down
276
+ AddWpns::Rapns::Notification.where(type: 'Rapns::Wpns::Notification').delete_all
277
+ remove_column :rapns_notifications, :uri
278
+ end
279
+ end
280
+
281
+ class AddAdm < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
282
+ module Rapns
283
+ class Notification < ActiveRecord::Base
284
+ self.table_name = 'rapns_notifications'
285
+ end
286
+ end
287
+
288
+ def self.up
289
+ add_column :rapns_apps, :client_id, :string, null: true
290
+ add_column :rapns_apps, :client_secret, :string, null: true
291
+ add_column :rapns_apps, :access_token, :string, null: true
292
+ add_column :rapns_apps, :access_token_expiration, :datetime, null: true
293
+ end
294
+
295
+ def self.down
296
+ AddAdm::Rapns::Notification.where(type: 'Rapns::Adm::Notification').delete_all
297
+
298
+ remove_column :rapns_apps, :client_id
299
+ remove_column :rapns_apps, :client_secret
300
+ remove_column :rapns_apps, :access_token
301
+ remove_column :rapns_apps, :access_token_expiration
302
+ end
303
+ end
304
+
305
+ class RenameRapnsToRpush < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
306
+ module Rpush
307
+ class App < ActiveRecord::Base
308
+ self.table_name = 'rpush_apps'
309
+ end
310
+
311
+ class Notification < ActiveRecord::Base
312
+ self.table_name = 'rpush_notifications'
313
+ end
314
+ end
315
+
316
+ def self.update_type(model, from, to)
317
+ model.where(type: from).update_all(type: to)
318
+ end
319
+
320
+ def self.up
321
+ rename_table :rapns_notifications, :rpush_notifications
322
+ rename_table :rapns_apps, :rpush_apps
323
+ rename_table :rapns_feedback, :rpush_feedback
324
+
325
+ if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
326
+ if index_name_exists?(:rpush_notifications, :index_rapns_notifications_multi)
327
+ rename_index :rpush_notifications, :index_rapns_notifications_multi, :index_rpush_notifications_multi
328
+ end
329
+ else
330
+ if index_name_exists?(:rpush_notifications, :index_rapns_notifications_multi, true)
331
+ rename_index :rpush_notifications, :index_rapns_notifications_multi, :index_rpush_notifications_multi
332
+ end
333
+ end
334
+
335
+ if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
336
+ if index_name_exists?(:rpush_feedback, :index_rapns_feedback_on_device_token)
337
+ rename_index :rpush_feedback, :index_rapns_feedback_on_device_token, :index_rpush_feedback_on_device_token
338
+ end
339
+ else
340
+ if index_name_exists?(:rpush_feedback, :index_rapns_feedback_on_device_token, true)
341
+ rename_index :rpush_feedback, :index_rapns_feedback_on_device_token, :index_rpush_feedback_on_device_token
342
+ end
343
+ end
344
+
345
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Apns::Notification', 'Rpush::Apns::Notification')
346
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Gcm::Notification', 'Rpush::Gcm::Notification')
347
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Adm::Notification', 'Rpush::Adm::Notification')
348
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Wpns::Notification', 'Rpush::Wpns::Notification')
349
+
350
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Apns::App', 'Rpush::Apns::App')
351
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Gcm::App', 'Rpush::Gcm::App')
352
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Adm::App', 'Rpush::Adm::App')
353
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Wpns::App', 'Rpush::Wpns::App')
354
+ end
355
+
356
+ def self.down
357
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Apns::Notification', 'Rapns::Apns::Notification')
358
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Gcm::Notification', 'Rapns::Gcm::Notification')
359
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Adm::Notification', 'Rapns::Adm::Notification')
360
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Wpns::Notification', 'Rapns::Wpns::Notification')
361
+
362
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Apns::App', 'Rapns::Apns::App')
363
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Gcm::App', 'Rapns::Gcm::App')
364
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Adm::App', 'Rapns::Adm::App')
365
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Wpns::App', 'Rapns::Wpns::App')
366
+
367
+ if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
368
+ if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi)
369
+ rename_index :rpush_notifications, :index_rpush_notifications_multi, :index_rapns_notifications_multi
370
+ end
371
+ else
372
+ if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi, true)
373
+ rename_index :rpush_notifications, :index_rpush_notifications_multi, :index_rapns_notifications_multi
374
+ end
375
+ end
376
+
377
+ if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
378
+ if index_name_exists?(:rpush_feedback, :index_rpush_feedback_on_device_token)
379
+ rename_index :rpush_feedback, :index_rpush_feedback_on_device_token, :index_rapns_feedback_on_device_token
380
+ end
381
+ else
382
+ if index_name_exists?(:rpush_feedback, :index_rpush_feedback_on_device_token, true)
383
+ rename_index :rpush_feedback, :index_rpush_feedback_on_device_token, :index_rapns_feedback_on_device_token
384
+ end
385
+ end
386
+
387
+ rename_table :rpush_notifications, :rapns_notifications
388
+ rename_table :rpush_apps, :rapns_apps
389
+ rename_table :rpush_feedback, :rapns_feedback
390
+ end
391
+ end
392
+
393
+ class AddFailAfterToRpushNotifications < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
394
+ def self.up
395
+ add_column :rpush_notifications, :fail_after, :timestamp, null: true
396
+ end
397
+
398
+ def self.down
399
+ remove_column :rpush_notifications, :fail_after
400
+ end
401
+ end
402
+ end
@@ -0,0 +1,16 @@
1
+ class AddWpns < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
2
+ module Rapns
3
+ class Notification < ActiveRecord::Base
4
+ self.table_name = 'rapns_notifications'
5
+ end
6
+ end
7
+
8
+ def self.up
9
+ add_column :rapns_notifications, :uri, :string, null: true
10
+ end
11
+
12
+ def self.down
13
+ AddWpns::Rapns::Notification.where(type: 'Rapns::Wpns::Notification').delete_all
14
+ remove_column :rapns_notifications, :uri
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ class CreateRapnsApps < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
2
+ def self.up
3
+ create_table :rapns_apps do |t|
4
+ t.string :key, null: false
5
+ t.string :environment, null: false
6
+ t.text :certificate, null: false
7
+ t.string :password, null: true
8
+ t.integer :connections, null: false, default: 1
9
+ t.timestamps
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :rapns_apps
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ class CreateRapnsFeedback < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
2
+ def self.up
3
+ create_table :rapns_feedback do |t|
4
+ t.string :device_token, null: false, limit: 64
5
+ t.timestamp :failed_at, null: false
6
+ t.timestamps
7
+ end
8
+
9
+ add_index :rapns_feedback, :device_token
10
+ end
11
+
12
+ def self.down
13
+ if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
14
+ if index_name_exists?(:rapns_feedback, :index_rapns_feedback_on_device_token)
15
+ remove_index :rapns_feedback, name: :index_rapns_feedback_on_device_token
16
+ end
17
+ else
18
+ if index_name_exists?(:rapns_feedback, :index_rapns_feedback_on_device_token, true)
19
+ remove_index :rapns_feedback, name: :index_rapns_feedback_on_device_token
20
+ end
21
+ end
22
+
23
+ drop_table :rapns_feedback
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ class CreateRapnsNotifications < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
2
+ def self.up
3
+ create_table :rapns_notifications do |t|
4
+ t.integer :badge, null: true
5
+ t.string :device_token, null: false, limit: 64
6
+ t.string :sound, null: true, default: "1.aiff"
7
+ t.string :alert, null: true
8
+ t.text :attributes_for_device, null: true
9
+ t.integer :expiry, null: false, default: 1.day.to_i
10
+ t.boolean :delivered, null: false, default: false
11
+ t.timestamp :delivered_at, null: true
12
+ t.boolean :failed, null: false, default: false
13
+ t.timestamp :failed_at, null: true
14
+ t.integer :error_code, null: true
15
+ t.string :error_description, null: true
16
+ t.timestamp :deliver_after, null: true
17
+ t.timestamps
18
+ end
19
+
20
+ add_index :rapns_notifications, [:delivered, :failed, :deliver_after], name: 'index_rapns_notifications_multi'
21
+ end
22
+
23
+ def self.down
24
+ if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
25
+ if index_name_exists?(:rapns_notifications, 'index_rapns_notifications_multi')
26
+ remove_index :rapns_notifications, name: 'index_rapns_notifications_multi'
27
+ end
28
+ else
29
+ if index_name_exists?(:rapns_notifications, 'index_rapns_notifications_multi', true)
30
+ remove_index :rapns_notifications, name: 'index_rapns_notifications_multi'
31
+ end
32
+ end
33
+
34
+ drop_table :rapns_notifications
35
+ end
36
+ end
@@ -0,0 +1,87 @@
1
+ class RenameRapnsToRpush < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
2
+ module Rpush
3
+ class App < ActiveRecord::Base
4
+ self.table_name = 'rpush_apps'
5
+ end
6
+
7
+ class Notification < ActiveRecord::Base
8
+ self.table_name = 'rpush_notifications'
9
+ end
10
+ end
11
+
12
+ def self.update_type(model, from, to)
13
+ model.where(type: from).update_all(type: to)
14
+ end
15
+
16
+ def self.up
17
+ rename_table :rapns_notifications, :rpush_notifications
18
+ rename_table :rapns_apps, :rpush_apps
19
+ rename_table :rapns_feedback, :rpush_feedback
20
+
21
+ if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
22
+ if index_name_exists?(:rpush_notifications, :index_rapns_notifications_multi)
23
+ rename_index :rpush_notifications, :index_rapns_notifications_multi, :index_rpush_notifications_multi
24
+ end
25
+ else
26
+ if index_name_exists?(:rpush_notifications, :index_rapns_notifications_multi, true)
27
+ rename_index :rpush_notifications, :index_rapns_notifications_multi, :index_rpush_notifications_multi
28
+ end
29
+ end
30
+
31
+ if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
32
+ if index_name_exists?(:rpush_feedback, :index_rapns_feedback_on_device_token)
33
+ rename_index :rpush_feedback, :index_rapns_feedback_on_device_token, :index_rpush_feedback_on_device_token
34
+ end
35
+ else
36
+ if index_name_exists?(:rpush_feedback, :index_rapns_feedback_on_device_token, true)
37
+ rename_index :rpush_feedback, :index_rapns_feedback_on_device_token, :index_rpush_feedback_on_device_token
38
+ end
39
+ end
40
+
41
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Apns::Notification', 'Rpush::Apns::Notification')
42
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Gcm::Notification', 'Rpush::Gcm::Notification')
43
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Adm::Notification', 'Rpush::Adm::Notification')
44
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Wpns::Notification', 'Rpush::Wpns::Notification')
45
+
46
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Apns::App', 'Rpush::Apns::App')
47
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Gcm::App', 'Rpush::Gcm::App')
48
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Adm::App', 'Rpush::Adm::App')
49
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Wpns::App', 'Rpush::Wpns::App')
50
+ end
51
+
52
+ def self.down
53
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Apns::Notification', 'Rapns::Apns::Notification')
54
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Gcm::Notification', 'Rapns::Gcm::Notification')
55
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Adm::Notification', 'Rapns::Adm::Notification')
56
+ update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Wpns::Notification', 'Rapns::Wpns::Notification')
57
+
58
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Apns::App', 'Rapns::Apns::App')
59
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Gcm::App', 'Rapns::Gcm::App')
60
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Adm::App', 'Rapns::Adm::App')
61
+ update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Wpns::App', 'Rapns::Wpns::App')
62
+
63
+ if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
64
+ if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi)
65
+ rename_index :rpush_notifications, :index_rpush_notifications_multi, :index_rapns_notifications_multi
66
+ end
67
+ else
68
+ if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi, true)
69
+ rename_index :rpush_notifications, :index_rpush_notifications_multi, :index_rapns_notifications_multi
70
+ end
71
+ end
72
+
73
+ if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
74
+ if index_name_exists?(:rpush_feedback, :index_rpush_feedback_on_device_token)
75
+ rename_index :rpush_feedback, :index_rpush_feedback_on_device_token, :index_rapns_feedback_on_device_token
76
+ end
77
+ else
78
+ if index_name_exists?(:rpush_feedback, :index_rpush_feedback_on_device_token, true)
79
+ rename_index :rpush_feedback, :index_rpush_feedback_on_device_token, :index_rapns_feedback_on_device_token
80
+ end
81
+ end
82
+
83
+ rename_table :rpush_notifications, :rapns_notifications
84
+ rename_table :rpush_apps, :rapns_apps
85
+ rename_table :rpush_feedback, :rapns_feedback
86
+ end
87
+ end