Guest User

Untitled

a guest
Jul 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. def param(name, space=" ")
  2. name_json = "\"#{name}\":#{space}\""
  3. name_index = "LOCATE('#{name_json}', params)"
  4. value_index = "#{name_index} + #{name_json.length}"
  5. value_end_index = "LOCATE('\"', params, #{value_index} )"
  6. "substring( params FROM #{value_index} FOR ( #{value_end_index} - #{name_index} - #{name_json.length} ) )"
  7. end
  8.  
  9. up do
  10. create_table :email_notifications do
  11. column :id, Serial
  12. column :profile_id, Integer, :nullable => false
  13. column :type, String, :nullable => true
  14. column :ueid, String, :nullable => true
  15. column :message_id, Integer, :nullable => true
  16. column :iteration, String, :nullable => true
  17. column :logins, Text, :size => 4096, :nullable => true
  18. column :created_at, DateTime
  19. end
  20.  
  21. execute "ALTER TABLE email_notifications ADD INDEX idx_iteration (iteration)"
  22. execute "ALTER TABLE email_notifications ADD INDEX idx_type (type)"
  23. execute "ALTER TABLE email_notifications ADD INDEX idx_created_at (created_at)"
  24. execute "ALTER TABLE email_notifications ADD INDEX idx_profile_id (profile_id)"
  25.  
  26. # THIS PART ISN'T DONE YET
  27. execute <<-SQL
  28. INSERT INTO email_notifications (profile_id, created_at, os, ip, browser, referer)
  29. SELECT profile_id, at, #{param('os')}, #{param('ip')}, #{param('browser')}, #{param('referrer')}
  30. FROM profile_logs WHERE action = 'email_notification' and params LIKE '%": %'
  31. SQL
  32. execute <<-SQL
  33. INSERT INTO email_notifications (profile_id, created_at, os, ip, browser, referer)
  34. SELECT profile_id, at, #{param('os','')}, #{param('ip','')}, #{param('browser','')}, #{param('referrer','')}
  35. FROM profile_logs WHERE action = 'email_notification' and params NOT LIKE '%": %'
  36. SQL
  37. end
Add Comment
Please, Sign In to add comment