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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49f3bab8298bfc4a918791ff92abb7d60d63f7a8d14bbb37b353bfa59fe33818
4
- data.tar.gz: f11da93930102998a035b1ea83e1bc3c382ad829d43490a6ef7263af27d8e7c7
3
+ metadata.gz: 9a046b3aea1b09b90d510fa29ffd79df71e678101e081c72a4f1d419869eecca
4
+ data.tar.gz: 6d49dc0c48eb9c143842839697399afbdcf706c03d9164e86e15efad0a75499d
5
5
  SHA512:
6
- metadata.gz: f446f6c8634d9385d75f8ccdf7e2a76cdfea9b17886759ca63993a70044bc15e77f111442e9d323c4c158907c7751ee927c778b3c58e43c06f81bef737e26ff6
7
- data.tar.gz: 604448e710c92999cffe29a6e137a4cee328f3f8bec5b2c44fa5c3ee3fb9b1393c87b104c2826e8792f4724cec34bfd576bd55e588dfc8bdd50eb63c991e0a56
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 |user_attributes|
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
- u["created_at"] =
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
 
@@ -27,7 +27,7 @@ module EvilSeed
27
27
  def call(attributes)
28
28
  attributes.deep_dup.tap do |attrs|
29
29
  @changers.each do |attribute, changer|
30
- attrs[attribute] = changer.call
30
+ attrs[attribute] = changer.call(attrs[attribute])
31
31
  end
32
32
  end
33
33
  end
@@ -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 = model_class.column_names.map { |c| connection.quote_column_name(c) }.join(', ')
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(', ')})")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EvilSeed
4
- VERSION = '0.2.0'
4
+ VERSION = '0.4.0'
5
5
  end
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.2.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-03-09 00:00:00.000000000 Z
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.2.22
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