Class: AddRpush::RenameRapnsToRpush

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

Defined Under Namespace

Modules: Rpush

Class Method Summary collapse

Class Method Details

.downObject


315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/generators/templates/add_rpush.rb', line 315

def self.down
  update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Apns::Notification', 'Rapns::Apns::Notification')
  update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Gcm::Notification', 'Rapns::Gcm::Notification')
  update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Adm::Notification', 'Rapns::Adm::Notification')
  update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Wpns::Notification', 'Rapns::Wpns::Notification')

  update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Apns::App', 'Rapns::Apns::App')
  update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Gcm::App', 'Rapns::Gcm::App')
  update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Adm::App', 'Rapns::Adm::App')
  update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Wpns::App', 'Rapns::Wpns::App')

  if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi, true)
    rename_index :rpush_notifications, :index_rpush_notifications_multi, :index_rapns_notifications_multi
  end

  if index_name_exists?(:rpush_feedback, :index_rpush_feedback_on_device_token, true)
    rename_index :rpush_feedback, :index_rpush_feedback_on_device_token, :index_rapns_feedback_on_device_token
  end

  rename_table :rpush_notifications, :rapns_notifications
  rename_table :rpush_apps, :rapns_apps
  rename_table :rpush_feedback, :rapns_feedback
end

.upObject


291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/generators/templates/add_rpush.rb', line 291

def self.up
  rename_table :rapns_notifications, :rpush_notifications
  rename_table :rapns_apps, :rpush_apps
  rename_table :rapns_feedback, :rpush_feedback

  if index_name_exists?(:rpush_notifications, :index_rapns_notifications_multi, true)
    rename_index :rpush_notifications, :index_rapns_notifications_multi, :index_rpush_notifications_multi
  end

  if index_name_exists?(:rpush_feedback, :index_rapns_feedback_on_device_token, true)
    rename_index :rpush_feedback, :index_rapns_feedback_on_device_token, :index_rpush_feedback_on_device_token
  end

  update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Apns::Notification', 'Rpush::Apns::Notification')
  update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Gcm::Notification', 'Rpush::Gcm::Notification')
  update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Adm::Notification', 'Rpush::Adm::Notification')
  update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Wpns::Notification', 'Rpush::Wpns::Notification')

  update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Apns::App', 'Rpush::Apns::App')
  update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Gcm::App', 'Rpush::Gcm::App')
  update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Adm::App', 'Rpush::Adm::App')
  update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Wpns::App', 'Rpush::Wpns::App')
end

.update_type(model, from, to) ⇒ Object


287
288
289
# File 'lib/generators/templates/add_rpush.rb', line 287

def self.update_type(model, from, to)
  model.where(type: from).update_all(type: to)
end