20200707000001_data_privacy_init.rb 1.6 KB

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