evilmartians / evil-seed Goto Github PK
View Code? Open in Web Editor NEWA Gem for creating partial anonymized dumps of your database using your app model relations.
License: MIT License
A Gem for creating partial anonymized dumps of your database using your app model relations.
License: MIT License
Is there an easy way to ignore specific columns, specifically generated columns?
Error:
BasicsTest#test_basic_runthrough:
ActiveRecord::StatementInvalid: PG::GeneratedAlways: ERROR: cannot insert a non-DEFAULT value into column "full_name"
DETAIL: Column "full_name" is a generated column.
test/system/basics_test.rb:26:in `block (2 levels) in init_seeds'
test/system/basics_test.rb:25:in `each'
test/system/basics_test.rb:25:in `block in init_seeds'
test/system/basics_test.rb:19:in `init_seeds'
test/system/basics_test.rb:37:in `block in <class:BasicsTest>'
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?
def dump_belongs_to_associations!
belongs_to_reflections.map do |reflection|
next if to_load_map[reflection.name].empty?
RelationDumper.new(
build_relation(reflection),
root_dumper,
"#{association_path}.#{reflection.name}",
search_key: reflection.association_primary_key,
identifiers: to_load_map[reflection.name],
limitable: false,
).call
end
end
From RelationDumper
- to me it seems like this is recursive, which might cause some resource issues in a larger DB with a lot of relationships.
Hi,
I'm very interesting by your script but I not a ruby developer, so I don't know how to configure active records according to my mysql credentials !
thanks a lot
First of all, thanks for your wonderful work. This gem is 100000x better than our custom dump script.
Your docs mention the exclude
method for excluding associations of a model, but there are a few tables where I would like to exclude all data from the dump. I tried to add a constraint of created_at > Time.now
to exclude in slightly naive way, but of course by the time the dump of the tables occurred Time.now
had passed.
Apologies if I have accidentally skimmed over how to do this in your documentation
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!
Had this error trying to run EvilSeed.dump('...')
:
Errno::EMFILE: Too many open files @ rb_sysopen - /tmp/evil_seed_prompts_users_20230929-89080-1h4sbb.sql
Resolved it by running ulimit -n 10240
before doing the dump (limit was 1024). This cannot be run inside the script itself, as it won't change the limit of the ruby process itself.
Just adding this in case it may help someone. And maybe there's a way to improve the dumping logic to not open so many files?
Thanks a lot for the great gem!
Hey! Sorry to bother again, but this time I found an issue that I don't know if it is really a bug or just something about my schema or configuration.
For example, I have 3 models, Person
, Car
, PersonCarBorrow
, and the PersonCarBorrow
has defined:
belongs_to :person
belongs_to :car
And when dumping this schema, with root on Person
, the PersonCarBorrow will have the Person
foreign key person_id
NULL, and the Car
foreign key with the correct value.
My gems versions:
activerecord (= 5.2.6)
evil-seed (0.2.0)
After a little search, I think the issue is related with this line relation_dumper#149, as the foreign_key is nullified because of the condition on excluded = ... || reflection.name == inverse_reflection
.
A fork of this gem already made a change related to this shippio/evil-seed-41025192b46649cf43af91d7fd7a80358a9e7379.
Thank you for your help.
When I try to anonymize a model with an active storage attachment. E.g. User with a profile picture
# lib/extensions/evil_seed.rb
require "evil_seed"
EvilSeed.configure do |config|
config.root("User", id: 13055) do |root|
root.exclude(/.*/) # exclude all associations
end
config.anonymize("User") do
name { Faker::Name.name }
end
end
I get a method_missing for has_one_attached on this model.
/Users/billabel/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-6.1.7.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `has_one_attached' for User:Class (NoMethodError)
Is there a fix or workaround? Is this a ruby 3.2 issue?
Hello. In our Rails 4.2.11 app on jruby 9.2.5.0, I'm seeing the following error. I put some print statements into the refinements configuration code that back ports the in_batches
method to ActiveRecord::Relation
in Rails 4.2, and they print out as expected. So I'm not sure why this isn't available at runtime. This error happens on a simple usage based on the documentation, trying to navigate the first configured model's associations.
NoMethodError: undefined method `in_batches' for #<User::ActiveRecord_Relation:0x39352f6b>
Do you know if refinements work in jruby?
It appears that may not be the case, which was surprising. (still investigating) jruby/jruby#4330
With no Evil Seed configuration on the root model, just the model name, it seems like the SQL being generated includes an ORDER BY with the table name and then no field name, which is invalid, this bit: ORDER BY "users"."" ASC
.
EvilSeed.configure do |config|
config.root('User') do |root|
end
end
EvilSeed.dump(File.join(__dir__, "dump.sql").to_s)
I'm getting this kind of error:
ActiveRecord::StatementInvalid: ActiveRecord::JDBCError: org.postgresql.util.PSQLException: ERROR: zero-length delimited identifier at or near """"
Position: 50: SELECT "users".* FROM "users" ORDER BY "users"."" ASC LIMIT 1000
Rails 4.2.11, Jruby 9.2.5.0, I have hacked the in_batches
to be find_in_batches
locally, which I don't think is related. Do you know where this order by clause is coming in? Do you have a suggestion on how to get it removed? Without the order by clause, the rest of the statement is valid.
My issue is i have a belongs_to
relationship with a foreign_key defined but it's looking for the rails foreign key instead of my belongs_to foreign_key
attribute i am wondering if this has happened or if the library is still supported
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.