Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for things like html contents etc, you can do stuff like this
- PLACEHOLDER_FAKER = {
- "string" => -> { FFaker::HipsterIpsum.word },
- "date" => -> { rand(1000).days.ago.to_date },
- "email" => -> { FFaker::Internet.email },
- "number" => -> { rand(1000) },
- "single_choice" => -> { 4.times.collect{ FFaker::Internet.domain_word }.join(",") },
- }
- def anonymize_html(str)
- return "" unless str.present?
- doc = Nokogiri::HTML(str)
- doc.search('//text()').each do |text|
- text.content = text.content.split(//).shuffle.join
- end
- doc.at("body")&.inner_html.presence
- end
- ActiveRecord::Base.connection.execute "TRUNCATE table;"
- ActiveRecord::Base.connection.execute "TRUNCATE table2;"
- Client.find_each do |client|
- # replace all template names and descriptions with random stuff
- templates = client.templates.with_deleted.pluck(:id, :folder_id).collect do |id, folder_id|
- {
- id: id,
- name: FFaker::CheesyLingo.title,
- description: FFaker::BaconIpsum.sentence,
- type: "fake",
- client_id: client.id,
- folder_id: folder_id,
- created_at: Time.now,
- updated_at: Time.now,
- }
- end
- Template.import(templates,
- on_duplicate_key_update: [:name, :description], validate: false, timestamps: false)
- sections = client.template_nodes.where(type: 'Section').with_deleted.pluck(:id).collect do |id|
- {
- id: id,
- title: FFaker::Game.title,
- client_id: client.id,
- created_at: Time.now,
- updated_at: Time.now,
- }
- end
- Section.import(sections,
- on_duplicate_key_update: [:title], validate: false, timestamps: false)
- placeholders = document_placeholders.collect do |id, template_placeholder_id, data_type|
- {
- id: id,
- value: PLACEHOLDER_FAKER[data_type].call,
- document_id: SecureRandom.uuid,
- template_placeholder_id: template_placeholder_id,
- client_id: client.id,
- created_at: Time.now,
- updated_at: Time.now,
- }
- end
- DocumentPlaceholder.import(placeholders,
- on_duplicate_key_update: [:value], validate: false, timestamps: false)
- comments or folders?
- let's goooo
- comments = client.comments.with_deleted.pluck(:id).collect do |id|
- {
- id: id,
- comment: FFaker::Tweet.tweet,
- document_id: SecureRandom.uuid,
- template_id: SecureRandom.uuid,
- template_node_id: SecureRandom.uuid,
- user_id: SecureRandom.uuid,
- client_id: client.id,
- type: "fake",
- created_at: Time.now,
- updated_at: Time.now,
- }
- end
- Comment.import(comments,
- on_duplicate_key_update: [:comment], validate: false, timestamps: false)
- folders = client.folders.find_each do |folder|
- folder.update_column(:name, FFaker::Game.title)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement