20160316000006_renew_triggers.rb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. class RenewTriggers < ActiveRecord::Migration
  2. def up
  3. drop_table :triggers
  4. create_table :triggers do |t|
  5. t.column :name, :string, limit: 250, null: false
  6. t.column :condition, :string, limit: 2500, null: false
  7. t.column :perform, :string, limit: 2500, null: false
  8. t.column :disable_notification, :boolean, null: false, default: true
  9. t.column :note, :string, limit: 250, null: true
  10. t.column :active, :boolean, null: false, default: true
  11. t.column :updated_by_id, :integer, null: false
  12. t.column :created_by_id, :integer, null: false
  13. t.timestamps limit: 3, null: false
  14. end
  15. add_index :triggers, [:name], unique: true
  16. drop_table :jobs
  17. create_table :jobs do |t|
  18. t.column :name, :string, limit: 250, null: false
  19. t.column :timeplan, :string, limit: 1000, null: false
  20. t.column :condition, :string, limit: 2500, null: false
  21. t.column :perform, :string, limit: 2500, null: false
  22. t.column :disable_notification, :boolean, null: false, default: true
  23. t.column :last_run_at, :timestamp, null: true
  24. t.column :next_run_at, :timestamp, null: true
  25. t.column :running, :boolean, null: false, default: false
  26. t.column :processed, :integer, null: false, default: 0
  27. t.column :matching, :integer, null: false, default: 0
  28. t.column :pid, :string, limit: 250, null: true
  29. t.column :note, :string, limit: 250, null: true
  30. t.column :active, :boolean, null: false, default: false
  31. t.column :updated_by_id, :integer, null: false
  32. t.column :created_by_id, :integer, null: false
  33. t.timestamps limit: 3, null: false
  34. end
  35. add_index :jobs, [:name], unique: true
  36. Scheduler.create_if_not_exists(
  37. name: 'Execute jobs',
  38. method: 'Job.run',
  39. period: 5 * 60,
  40. prio: 2,
  41. active: true,
  42. updated_by_id: 1,
  43. created_by_id: 1,
  44. )
  45. end
  46. end