Class: AddRpush::AddGcm

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/templates/add_rpush.rb

Defined Under Namespace

Modules: Rapns

Class Method Summary collapse

Class Method Details

.downObject



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/generators/templates/add_rpush.rb', line 195

def self.down
  AddGcm::Rapns::Notification.where(type: 'Rapns::Gcm::Notification').delete_all

  remove_column :rapns_notifications, :type
  remove_column :rapns_apps, :type

  change_column :rapns_notifications, :device_token, :string, null: false, limit: 64
  change_column :rapns_notifications, :expiry, :integer, null: false, default: 1.day.to_i
  change_column :rapns_apps, :environment, :string, null: false
  change_column :rapns_apps, :certificate, :text, null: false

  change_column :rapns_notifications, :error_description, :string, null: true, default: nil
  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

  AddGcm::Rapns::Notification.reset_column_information
  AddGcm::Rapns::App.reset_column_information

  AddGcm::Rapns::App.all.each do |app|
    AddGcm::Rapns::Notification.where(app_id: app.id).update_all(app: app.key)
  end

  if index_name_exists?(:rapns_notifications, :index_rapns_notifications_multi)
    remove_index :rapns_notifications, name: :index_rapns_notifications_multi
  end

  remove_column :rapns_notifications, :app_id

  add_index :rapns_notifications, [:delivered, :failed, :deliver_after], name: :index_rapns_notifications_multi
end

.upObject



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/generators/templates/add_rpush.rb', line 146

def self.up
  add_column :rapns_notifications, :type, :string, null: true
  add_column :rapns_apps, :type, :string, null: true

  AddGcm::Rapns::Notification.update_all type: 'Rapns::Apns::Notification'
  AddGcm::Rapns::App.update_all type: 'Rapns::Apns::App'

  change_column :rapns_notifications, :type, :string, null: false
  change_column :rapns_apps, :type, :string, null: false
  change_column :rapns_notifications, :device_token, :string, null: true, limit: 64
  change_column :rapns_notifications, :expiry, :integer, null: true, default: 1.day.to_i
  change_column :rapns_apps, :environment, :string, null: true
  change_column :rapns_apps, :certificate, :text, null: true, default: nil

  change_column :rapns_notifications, :error_description, :text, null: true, default: nil
  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

  AddGcm::Rapns::Notification.reset_column_information
  AddGcm::Rapns::App.reset_column_information

  AddGcm::Rapns::App.all.each do |app|
    AddGcm::Rapns::Notification.where(app: app.name).update_all(app_id: app.id)
  end

  change_column :rapns_notifications, :app_id, :integer, null: false
  remove_column :rapns_notifications, :app

  if index_name_exists?(:rapns_notifications, "index_rapns_notifications_multi")
    remove_index :rapns_notifications, name: "index_rapns_notifications_multi"
  elsif index_name_exists?(:rapns_notifications, "index_rapns_notifications_on_delivered_failed_deliver_after")
    remove_index :rapns_notifications, name: "index_rapns_notifications_on_delivered_failed_deliver_after"
  end

  add_index :rapns_notifications, [:app_id, :delivered, :failed, :deliver_after], name: "index_rapns_notifications_multi"
end