20151015000001_create_macro.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. class CreateMacro < ActiveRecord::Migration
  2. def up
  3. create_table :macros do |t|
  4. t.string :name, limit: 250, null: true
  5. t.string :perform, limit: 5000, null: false
  6. t.boolean :active, null: false, default: true
  7. t.string :note, limit: 250, null: true
  8. t.integer :updated_by_id, null: false
  9. t.integer :created_by_id, null: false
  10. t.timestamps null: false
  11. end
  12. add_index :macros, [:name], unique: true
  13. # return if it's a new setup
  14. return if !Setting.find_by(name: 'system_init_done')
  15. UserInfo.current_user_id = 1
  16. Macro.create_or_update(
  17. name: 'Close & Tag as Spam',
  18. perform: {
  19. 'ticket.state_id' => {
  20. value: Ticket::State.find_by(name: 'closed').id,
  21. },
  22. 'ticket.tags' => {
  23. operator: 'add',
  24. value: 'spam',
  25. },
  26. },
  27. note: 'example macro',
  28. active: true,
  29. )
  30. end
  31. def down
  32. drop_table :macros
  33. end
  34. end