20160704000001_add_karma.rb 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. class AddKarma < ActiveRecord::Migration
  2. def up
  3. create_table :karma_users do |t|
  4. t.integer :user_id, null: false
  5. t.integer :score, null: false
  6. t.string :level, limit: 200, null: false
  7. t.timestamps limit: 3, null: false
  8. end
  9. add_index :karma_users, [:user_id], unique: true
  10. create_table :karma_activities do |t|
  11. t.string :name, limit: 200, null: false
  12. t.string :description, limit: 200, null: false
  13. t.integer :score, null: false
  14. t.integer :once_ttl, null: false
  15. t.timestamps limit: 3, null: false
  16. end
  17. add_index :karma_activities, [:name], unique: true
  18. Karma::Activity.create_or_update(
  19. name: 'ticket create',
  20. description: 'You have created a ticket',
  21. score: 10,
  22. once_ttl: 60,
  23. )
  24. Karma::Activity.create_or_update(
  25. name: 'ticket close',
  26. description: 'You have closed a ticket',
  27. score: 5,
  28. once_ttl: 60,
  29. )
  30. Karma::Activity.create_or_update(
  31. name: 'ticket answer 1h',
  32. description: 'You have answered a ticket within 1h',
  33. score: 25,
  34. once_ttl: 60,
  35. )
  36. Karma::Activity.create_or_update(
  37. name: 'ticket answer 2h',
  38. description: 'You have answered a ticket within 2h',
  39. score: 20,
  40. once_ttl: 60,
  41. )
  42. Karma::Activity.create_or_update(
  43. name: 'ticket answer 12h',
  44. description: 'You have answered a ticket within 12h',
  45. score: 10,
  46. once_ttl: 60,
  47. )
  48. Karma::Activity.create_or_update(
  49. name: 'ticket answer 24h',
  50. description: 'You have answered a ticket within 24h',
  51. score: 5,
  52. once_ttl: 60,
  53. )
  54. Karma::Activity.create_or_update(
  55. name: 'ticket pending state',
  56. description: 'Usage of advanced features',
  57. score: 2,
  58. once_ttl: 60,
  59. )
  60. Karma::Activity.create_or_update(
  61. name: 'ticket escalated',
  62. description: 'You have escalated tickets',
  63. score: -5,
  64. once_ttl: 60 * 60 * 24,
  65. )
  66. Karma::Activity.create_or_update(
  67. name: 'ticket reminder overdue (+2 days)',
  68. description: 'You have tickets that are over 2 days overdue',
  69. score: -5,
  70. once_ttl: 60 * 60 * 24,
  71. )
  72. Karma::Activity.create_or_update(
  73. name: 'text module',
  74. description: 'Usage of advanced features',
  75. score: 4,
  76. once_ttl: 60 * 30,
  77. )
  78. Karma::Activity.create_or_update(
  79. name: 'tagging',
  80. description: 'Usage of advanced features',
  81. score: 4,
  82. once_ttl: 60 * 60 * 4,
  83. )
  84. create_table :karma_activity_logs do |t|
  85. t.integer :o_id, null: false
  86. t.integer :object_lookup_id, null: false
  87. t.integer :user_id, null: false
  88. t.integer :activity_id, null: false
  89. t.integer :score, null: false
  90. t.integer :score_total, null: false
  91. t.timestamps limit: 3, null: false
  92. end
  93. add_index :karma_activity_logs, [:user_id]
  94. add_index :karma_activity_logs, [:created_at]
  95. add_index :karma_activity_logs, [:o_id, :object_lookup_id]
  96. Setting.create_if_not_exists(
  97. title: 'Define transaction backend.',
  98. name: '9200_karma',
  99. area: 'Transaction::Backend::Async',
  100. description: 'Define the transaction backend which creates the karma score.',
  101. options: {},
  102. state: 'Transaction::Karma',
  103. frontend: false
  104. )
  105. Setting.create_if_not_exists(
  106. title: 'Define karma levels.',
  107. name: 'karma_levels',
  108. area: 'Core::Karma',
  109. description: 'Define the karma levels.',
  110. options: {},
  111. state: [
  112. {
  113. name: 'Beginner',
  114. start: 0,
  115. end: 499,
  116. },
  117. {
  118. name: 'Newbie',
  119. start: 500,
  120. end: 1999,
  121. },
  122. {
  123. name: 'Intermediate',
  124. start: 2000,
  125. end: 4999,
  126. },
  127. {
  128. name: 'Professional',
  129. start: 5000,
  130. end: 6999,
  131. },
  132. {
  133. name: 'Expert',
  134. start: 7000,
  135. end: 8999,
  136. },
  137. {
  138. name: 'Master',
  139. start: 9000,
  140. end: 18_999,
  141. },
  142. {
  143. name: 'Evangelist',
  144. start: 19_000,
  145. end: 45_999,
  146. },
  147. {
  148. name: 'Hero',
  149. start: 50_000,
  150. end: nil,
  151. },
  152. ],
  153. frontend: false
  154. )
  155. end
  156. end