20200707000001_data_privacy_init.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. class DataPrivacyInit < ActiveRecord::Migration[4.2]
  2. def up
  3. # return if it's a new setup
  4. return if !Setting.exists?(name: 'system_init_done')
  5. up_table
  6. up_permission
  7. up_scheduler
  8. end
  9. def up_table
  10. create_table :data_privacy_tasks do |t|
  11. t.column :name, :string, limit: 150, null: true
  12. t.column :state, :string, limit: 150, default: 'in process', null: true
  13. t.references :deletable, polymorphic: true
  14. t.string :preferences, limit: 8000, null: true
  15. t.column :updated_by_id, :integer, null: false
  16. t.column :created_by_id, :integer, null: false
  17. t.timestamps limit: 3, null: false
  18. end
  19. add_index :data_privacy_tasks, [:name]
  20. add_index :data_privacy_tasks, [:state]
  21. end
  22. def up_permission
  23. Permission.create_if_not_exists(
  24. name: 'admin.data_privacy',
  25. note: 'Manage %s',
  26. preferences: {
  27. translations: ['Data Privacy']
  28. },
  29. )
  30. end
  31. def up_scheduler
  32. Scheduler.create_or_update(
  33. name: 'Handle data privacy tasks.',
  34. method: 'DataPrivacyTaskJob.perform_now',
  35. period: 10.minutes,
  36. last_run: Time.zone.now,
  37. prio: 2,
  38. active: true,
  39. updated_by_id: 1,
  40. created_by_id: 1,
  41. )
  42. end
  43. def self.down
  44. drop_table :data_privacy_tasks
  45. end
  46. end