evil-seed 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/lib/evil_seed/anonymizer.rb +1 -1
- data/lib/evil_seed/record_dumper.rb +10 -1
- data/lib/evil_seed/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a046b3aea1b09b90d510fa29ffd79df71e678101e081c72a4f1d419869eecca
|
4
|
+
data.tar.gz: 6d49dc0c48eb9c143842839697399afbdcf706c03d9164e86e15efad0a75499d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b9f060b074653b5d6bfc942ff60d90d378fd114b7efaf5100037ab75c8f49bf1fa9b7301c19df0649fc41c3545862811183bda4095efb5bbd90339332e11d35
|
7
|
+
data.tar.gz: 42369aa53c56fd5200ef78269d6379a7d454a27a1e37941e3503c4498e1e13fee7b1f85b4dd80b2679526c97d289f757babacaa81424109427d9a7a4372bf52a
|
data/README.md
CHANGED
@@ -72,18 +72,21 @@ EvilSeed.configure do |config|
|
|
72
72
|
end
|
73
73
|
|
74
74
|
# Transformations allows you to change dumped data e. g. to hide sensitive information
|
75
|
-
config.customize("User") do |
|
75
|
+
config.customize("User") do |u|
|
76
76
|
# Reset password for all users to the same for ease of debugging on developer's machine
|
77
77
|
u["encrypted_password"] = encrypt("qwerty")
|
78
|
-
|
78
|
+
# Reset or mutate other attributes at your convenience
|
79
|
+
u["metadata"].merge!("foo" => "bar")
|
80
|
+
u["created_at"] = Time.current
|
79
81
|
# Please note that there you have only hash of record attributes, not the record itself!
|
80
82
|
end
|
81
83
|
|
82
84
|
# Anonymization is a handy DSL for transformations allowing you to transform model attributes in declarative fashion
|
83
85
|
# Please note that model setters will NOT be called: results of the blocks will be assigned to
|
84
|
-
config.anonymize("User")
|
86
|
+
config.anonymize("User") do
|
85
87
|
name { Faker::Name.name }
|
86
88
|
email { Faker::Internet.email }
|
89
|
+
login { |login| "#{login}-test" }
|
87
90
|
end
|
88
91
|
```
|
89
92
|
|
data/lib/evil_seed/anonymizer.rb
CHANGED
@@ -50,14 +50,23 @@ module EvilSeed
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
def insertable_column_names
|
54
|
+
model_class.columns_hash.reject do |k,v|
|
55
|
+
v.respond_to?(:virtual?) ? v.virtual? : false
|
56
|
+
end.keys
|
57
|
+
end
|
58
|
+
|
53
59
|
def insert_statement
|
54
60
|
connection = model_class.connection
|
55
61
|
table_name = connection.quote_table_name(model_class.table_name)
|
56
|
-
columns =
|
62
|
+
columns = insertable_column_names.map { |c| connection.quote_column_name(c) }.join(', ')
|
57
63
|
"INSERT INTO #{table_name} (#{columns}) VALUES\n"
|
58
64
|
end
|
59
65
|
|
60
66
|
def write!(attributes)
|
67
|
+
# Remove non-insertable columns from attributes
|
68
|
+
attributes = attributes.slice(*insertable_column_names)
|
69
|
+
|
61
70
|
@output.write("-- #{relation_dumper.association_path}\n") && @header_written = true unless @header_written
|
62
71
|
@output.write(@tuples_written.zero? ? insert_statement : ",\n")
|
63
72
|
@output.write(" (#{prepare(attributes).join(', ')})")
|
data/lib/evil_seed/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evil-seed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Novikov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -210,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
210
|
- !ruby/object:Gem::Version
|
211
211
|
version: '0'
|
212
212
|
requirements: []
|
213
|
-
rubygems_version: 3.
|
213
|
+
rubygems_version: 3.1.6
|
214
214
|
signing_key:
|
215
215
|
specification_version: 4
|
216
216
|
summary: Create partial and anonymized production database dumps for use in development
|