evilmartians / evil-seed

A Gem for creating partial anonymized dumps of your database using your app model relations.
MIT License
447 stars 19 forks source link

What would be the best way to anonymize specific attributes in a JSONB column #12

Closed cmer closed 2 years ago

cmer commented 2 years ago

One of my models has a JSONB column with attributes a few levels deep. What is the preferred way to clean up some of these attributes?

Envek commented 2 years ago

You can use customize syntax (anonymize is a sugar for it basically).

E.g. following snippet will add suffix -test to values of key key in data column:

EvilSeed.configure do |config|
  config.customize('User') do |attributes|
    attributes['data'].merge!('key' => attributes['data']['key] + '-test')
  end
end
Envek commented 2 years ago

Released version 0.3.0 in which you can also accept column value in anonymizer block and modify it like this:

EvilSeed.configure do |config|
  config.anonymize("User")
    metadata { |metadata| metadata&.merge("foo" => "bar") }
  end
end

Enjoy!

cmer commented 2 years ago

This is awesome thank you!!!