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

Ignoring columns or avoiding errors #10

Closed masterzeus05 closed 2 years ago

masterzeus05 commented 2 years ago

Hi! After starting to use this gem, I found that adding translations to models breaks the queries done by EvilSeed. For example, by using I18n and Globalize:

class Person < ActiveRecord
  translates :name
  globalize_accessors locales: [:en, :pt, :es], attributes: [:name]
end

And when dumping the database, it aborts and shows the following error: PG::UndefinedColumn: ERROR: column "name" does not exist

Is there any way to ignore columns or avoid these translations? Thanks!

Envek commented 2 years ago

Can you please tell a bit about your actual database schema? I suppose that name column is actually in some different translations table, right?

Also please tell ActiveRecord and globalize versions you're using. Thanks!

masterzeus05 commented 2 years ago

Yup exactly. The gems versions are:

globalize (5.3.1)
globalize-accessors (0.3.0)
i18n (1.8.10)
activerecord (= 5.2.6)

The schema is composed by the table person and person_translations that has a foreign key person_id, the locale and the name.

Thank you for being so quick!

masterzeus05 commented 2 years ago

From what I understood, this problem is related to the fetch_attributes, which uses the model_class.attribute_names method, and this method returns the column names plus some attributes that are not in the table. I'm not sure if that is what is pretended, but I found out that we can use column_names instead and this returns only the columns in the table.

I'm not sure if this helps or not, but either this or an option to ignore attributes would improve the gem I think!

Envek commented 2 years ago

You're totally right! I can't really remember why I used attribute_names when it definitely should be column_names, but I believe that ActiveRecord Attributes API was pretty new thing these days (almost 5 years ago!).

Released evil-seed 0.2.0, please try it!

Thank you!

masterzeus05 commented 2 years ago

Looks good! I'll bring you feedback later, thank you so much for your quickness!

EDIT: Everything is working nicely, thank you!