Advertisement
Guest User

Untitled

a guest
Feb 13th, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. for things like html contents etc, you can do stuff like this
  2.  
  3. PLACEHOLDER_FAKER = {
  4. "string" => -> { FFaker::HipsterIpsum.word },
  5. "date" => -> { rand(1000).days.ago.to_date },
  6. "email" => -> { FFaker::Internet.email },
  7. "number" => -> { rand(1000) },
  8. "single_choice" => -> { 4.times.collect{ FFaker::Internet.domain_word }.join(",") },
  9. }
  10.  
  11. def anonymize_html(str)
  12. return "" unless str.present?
  13.  
  14. doc = Nokogiri::HTML(str)
  15. doc.search('//text()').each do |text|
  16. text.content = text.content.split(//).shuffle.join
  17. end
  18. doc.at("body")&.inner_html.presence
  19. end
  20.  
  21. ActiveRecord::Base.connection.execute "TRUNCATE table;"
  22. ActiveRecord::Base.connection.execute "TRUNCATE table2;"
  23.  
  24. Client.find_each do |client|
  25. # replace all template names and descriptions with random stuff
  26. templates = client.templates.with_deleted.pluck(:id, :folder_id).collect do |id, folder_id|
  27. {
  28. id: id,
  29. name: FFaker::CheesyLingo.title,
  30. description: FFaker::BaconIpsum.sentence,
  31. type: "fake",
  32. client_id: client.id,
  33. folder_id: folder_id,
  34. created_at: Time.now,
  35. updated_at: Time.now,
  36. }
  37. end
  38. Template.import(templates,
  39. on_duplicate_key_update: [:name, :description], validate: false, timestamps: false)
  40.  
  41. sections = client.template_nodes.where(type: 'Section').with_deleted.pluck(:id).collect do |id|
  42. {
  43. id: id,
  44. title: FFaker::Game.title,
  45. client_id: client.id,
  46. created_at: Time.now,
  47. updated_at: Time.now,
  48. }
  49. end
  50. Section.import(sections,
  51. on_duplicate_key_update: [:title], validate: false, timestamps: false)
  52. placeholders = document_placeholders.collect do |id, template_placeholder_id, data_type|
  53. {
  54. id: id,
  55. value: PLACEHOLDER_FAKER[data_type].call,
  56. document_id: SecureRandom.uuid,
  57. template_placeholder_id: template_placeholder_id,
  58. client_id: client.id,
  59. created_at: Time.now,
  60. updated_at: Time.now,
  61. }
  62. end
  63. DocumentPlaceholder.import(placeholders,
  64. on_duplicate_key_update: [:value], validate: false, timestamps: false)
  65.  
  66. comments or folders?
  67. let's goooo
  68. comments = client.comments.with_deleted.pluck(:id).collect do |id|
  69. {
  70. id: id,
  71. comment: FFaker::Tweet.tweet,
  72. document_id: SecureRandom.uuid,
  73. template_id: SecureRandom.uuid,
  74. template_node_id: SecureRandom.uuid,
  75. user_id: SecureRandom.uuid,
  76. client_id: client.id,
  77. type: "fake",
  78. created_at: Time.now,
  79. updated_at: Time.now,
  80. }
  81. end
  82. Comment.import(comments,
  83. on_duplicate_key_update: [:comment], validate: false, timestamps: false)
  84.  
  85. folders = client.folders.find_each do |folder|
  86. folder.update_column(:name, FFaker::Game.title)
  87. end
  88.  
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement