evil-seed 0.1.2 → 0.3.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: b241703e95ddb394e93723c78bc574b53263cb5c12b14dec89c04bd1546e86f9
4
- data.tar.gz: c0b3a2c17a43706094afcb5ddcb7102aaaa8c2fb422c1abc73a481c03458db14
3
+ metadata.gz: d2a4c8714fe895573999dae43b0e441852c8baccba4657f49aa9330db61e020d
4
+ data.tar.gz: 175c040d61f8152437c15db6f4a38fa0941239f7615cf27aa1d752c57ffdbb5d
5
5
  SHA512:
6
- metadata.gz: b5f9171b1c00fb4bd3665670b30f4f26eb427dc8202dcb1fc9a03856ce403b358754b90668e3c96ba8bcc147de39ebf451749be8ff4eed2b56f9b34c26b0a336
7
- data.tar.gz: 0b258a881c6eda7fa7a8c0b87bb3602822203490bc2415418f793735f55fd8403010bfe18790e8c4befb01a691f3d47e715bb63dfabf8aa86d6234f7a4d98667
6
+ metadata.gz: 427ec05a9b68db21101fdf293093dff447635e9b326dfd400e3d7ba69afe3a3344bfa4c97778a8c56f2158529460df9f2e1cbc62a5b9ad86e7d659498e9da37d
7
+ data.tar.gz: 2288cfb2559bc3b6eefeb28f066cb06e6ed2e0c624e5287755314e41e67a611341d90c4c9d08f97d7a724882b294bdc3dbb53ebfbe4ac431f06a078ed1ea76fc
data/.travis.yml CHANGED
@@ -1,56 +1,82 @@
1
+ dist: xenial
2
+ language: ruby
1
3
  cache: bundler
2
4
  sudo: false
3
- language: ruby
4
5
 
5
6
  addons:
7
+ postgresql: "10"
6
8
  apt:
7
9
  sources:
8
10
  - travis-ci/sqlite3
9
11
  packages:
10
12
  - sqlite3
11
13
 
14
+ services:
15
+ - mysql
16
+ - postgresql
17
+
18
+ before_install: gem install bundler -v '~> 1.17'
19
+
12
20
  matrix:
13
21
  include:
14
- - rvm: 2.5.0
22
+ - rvm: 3.0.2
15
23
  gemfile: gemfiles/activerecord_master.gemfile
16
24
  env: "DB=sqlite"
17
- - rvm: 2.5.0
25
+ - rvm: 3.0.2
18
26
  gemfile: gemfiles/activerecord_master.gemfile
19
27
  env: "DB=postgresql"
20
- - rvm: 2.5.0
28
+ - rvm: 3.0.2
21
29
  gemfile: gemfiles/activerecord_master.gemfile
22
30
  env: "DB=mysql"
23
- - rvm: 2.5.0
31
+ - rvm: 2.7.4
32
+ gemfile: gemfiles/activerecord_6_1.gemfile
33
+ env: "DB=sqlite"
34
+ - rvm: 2.7.4
35
+ gemfile: gemfiles/activerecord_6_1.gemfile
36
+ env: "DB=postgresql"
37
+ - rvm: 2.7.4
38
+ gemfile: gemfiles/activerecord_6_1.gemfile
39
+ env: "DB=mysql"
40
+ - rvm: 2.7.4
41
+ gemfile: gemfiles/activerecord_6_0.gemfile
42
+ env: "DB=sqlite"
43
+ - rvm: 2.7.4
44
+ gemfile: gemfiles/activerecord_6_0.gemfile
45
+ env: "DB=postgresql"
46
+ - rvm: 2.7.4
47
+ gemfile: gemfiles/activerecord_6_0.gemfile
48
+ env: "DB=mysql"
49
+ - rvm: 2.6.8
24
50
  gemfile: gemfiles/activerecord_5_2.gemfile
25
51
  env: "DB=sqlite"
26
- - rvm: 2.5.0
52
+ - rvm: 2.6.8
27
53
  gemfile: gemfiles/activerecord_5_2.gemfile
28
54
  env: "DB=postgresql"
29
- - rvm: 2.5.0
55
+ - rvm: 2.6.8
30
56
  gemfile: gemfiles/activerecord_5_2.gemfile
31
57
  env: "DB=mysql"
32
- - rvm: 2.5.0
58
+ - rvm: 2.5.9
33
59
  gemfile: gemfiles/activerecord_5_1.gemfile
34
60
  env: "DB=sqlite"
35
- - rvm: 2.5.0
61
+ - rvm: 2.5.9
36
62
  gemfile: gemfiles/activerecord_5_1.gemfile
37
63
  env: "DB=postgresql"
38
- - rvm: 2.5.0
64
+ - rvm: 2.5.9
39
65
  gemfile: gemfiles/activerecord_5_1.gemfile
40
66
  env: "DB=mysql"
41
- - rvm: 2.4.3
67
+ - rvm: 2.4.10
42
68
  gemfile: gemfiles/activerecord_5_0.gemfile
43
69
  env: "DB=sqlite"
44
- - rvm: 2.4.3
70
+ - rvm: 2.4.10
45
71
  gemfile: gemfiles/activerecord_5_0.gemfile
46
72
  env: "DB=postgresql"
47
- - rvm: 2.4.3
73
+ - rvm: 2.4.10
48
74
  gemfile: gemfiles/activerecord_5_0.gemfile
49
75
  env: "DB=mysql"
50
- - rvm: 2.3.6
76
+ - rvm: 2.3.8
51
77
  gemfile: gemfiles/activerecord_4_2.gemfile
52
78
  env: "DB=postgresql"
53
- - rvm: 2.3.6
79
+ - rvm: 2.3.8
54
80
  gemfile: gemfiles/activerecord_4_2.gemfile
55
81
  env: "DB=sqlite"
56
82
  # Please note that gem can't be tested against MySQL on ActiveRecord 4.2 (Dump and restore test doesn't work)!
data/Appraisals CHANGED
@@ -1,25 +1,48 @@
1
- appraise 'activerecord-4-2' do
2
- gem 'activerecord', '~> 4.2.0'
3
- gem 'pg', '~> 0.20'
4
- gem 'mysql2', '~> 0.3.18'
5
- end
6
-
7
1
  appraise 'activerecord-5-0' do
8
2
  gem 'activerecord', '~> 5.0.0'
9
- gem 'pg', '~> 0.20'
3
+ gem "pg", ">= 0.20", "< 2.0"
10
4
  gem 'mysql2', '~> 0.4.4'
5
+ gem 'sqlite3', '~> 1.3.6'
11
6
  end
12
7
 
13
8
  appraise 'activerecord-5-1' do
14
9
  gem 'activerecord', '~> 5.1.0'
10
+ gem "pg", ">= 0.20", "< 2.0"
15
11
  gem 'mysql2', '~> 0.4.4'
12
+ gem 'sqlite3', '~> 1.3'
16
13
  end
17
14
 
18
15
  appraise 'activerecord-5-2' do
19
- gem 'activerecord', '~> 5.2.0.rc2'
16
+ gem 'activerecord', '~> 5.2.0'
17
+ gem "pg", ">= 0.20", "< 2.0"
18
+ gem 'mysql2', '~> 0.4.4'
19
+ gem 'sqlite3', '~> 1.3'
20
+ end
21
+
22
+ appraise 'activerecord-6-0' do
23
+ gem 'activerecord', '~> 6.0.0'
24
+ gem "pg", ">= 0.20", "< 2.0"
20
25
  gem 'mysql2', '~> 0.4.4'
26
+ gem 'sqlite3', '~> 1.4'
27
+ end
28
+
29
+ appraise 'activerecord-6-0' do
30
+ gem 'activerecord', '~> 6.0.0'
31
+ gem "pg", ">= 0.20", "< 2.0"
32
+ gem 'mysql2', '~> 0.4.4'
33
+ gem 'sqlite3', '~> 1.4'
34
+ end
35
+
36
+ appraise 'activerecord-6-1' do
37
+ gem 'activerecord', '~> 6.1.0'
38
+ gem "pg", "~> 1.1"
39
+ gem 'mysql2', '~> 0.5'
40
+ gem 'sqlite3', '~> 1.4'
21
41
  end
22
42
 
23
43
  appraise 'activerecord-master' do
24
44
  gem 'activerecord', git: 'https://github.com/rails/rails.git'
45
+ gem "pg", "~> 1.1"
46
+ gem 'mysql2', '~> 0.5'
47
+ gem 'sqlite3', '~> 1.4'
25
48
  end
data/README.md CHANGED
@@ -72,10 +72,12 @@ 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
 
@@ -84,6 +86,7 @@ EvilSeed.configure do |config|
84
86
  config.anonymize("User")
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/evil-seed.gemspec CHANGED
@@ -25,9 +25,9 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ['lib']
27
27
 
28
- spec.required_ruby_version = '~> 2.0'
28
+ spec.required_ruby_version = '>= 2.0'
29
29
 
30
- spec.add_dependency 'activerecord', '>= 4.2'
30
+ spec.add_dependency 'activerecord', '>= 5.0'
31
31
 
32
32
  spec.add_development_dependency 'rake', '~> 12.0'
33
33
  spec.add_development_dependency 'minitest', '~> 5.0'
@@ -3,7 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 5.0.0"
6
- gem "pg", "~> 0.20"
6
+ gem "pg", ">= 0.20", "< 2.0"
7
7
  gem "mysql2", "~> 0.4.4"
8
+ gem "sqlite3", "~> 1.3.6"
8
9
 
9
10
  gemspec path: "../"
@@ -3,6 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 5.1.0"
6
+ gem "pg", ">= 0.20", "< 2.0"
6
7
  gem "mysql2", "~> 0.4.4"
8
+ gem "sqlite3", "~> 1.3"
7
9
 
8
10
  gemspec path: "../"
@@ -2,7 +2,9 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 5.2.0.rc2"
5
+ gem "activerecord", "~> 5.2.0"
6
+ gem "pg", ">= 0.20", "< 2.0"
6
7
  gem "mysql2", "~> 0.4.4"
8
+ gem "sqlite3", "~> 1.3"
7
9
 
8
10
  gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.0.0"
6
+ gem "pg", ">= 0.20", "< 2.0"
7
+ gem "mysql2", "~> 0.4.4"
8
+ gem "sqlite3", "~> 1.4"
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.1.0"
6
+ gem "pg", "~> 1.1"
7
+ gem "mysql2", "~> 0.5"
8
+ gem "sqlite3", "~> 1.4"
9
+
10
+ gemspec path: "../"
@@ -3,5 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", git: "https://github.com/rails/rails.git"
6
+ gem "pg", "~> 1.1"
7
+ gem "mysql2", "~> 0.5"
8
+ gem "sqlite3", "~> 1.4"
6
9
 
7
10
  gemspec path: "../"
@@ -27,19 +27,19 @@ 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
34
34
 
35
35
  def respond_to_missing?(attribute_name)
36
- @model_class.attribute_names.include?(attribute_name.to_s) || super
36
+ @model_class.column_names.include?(attribute_name.to_s) || super
37
37
  end
38
38
 
39
39
  private
40
40
 
41
41
  def method_missing(attribute_name, &block)
42
- return super unless @model_class.attribute_names.include?(attribute_name.to_s)
42
+ return super unless @model_class.column_names.include?(attribute_name.to_s)
43
43
  @changers[attribute_name.to_s] = block
44
44
  end
45
45
  end
@@ -53,7 +53,7 @@ module EvilSeed
53
53
  def insert_statement
54
54
  connection = model_class.connection
55
55
  table_name = connection.quote_table_name(model_class.table_name)
56
- columns = model_class.attribute_names.map { |c| connection.quote_column_name(c) }.join(', ')
56
+ columns = model_class.column_names.map { |c| connection.quote_column_name(c) }.join(', ')
57
57
  "INSERT INTO #{table_name} (#{columns}) VALUES\n"
58
58
  end
59
59
 
@@ -73,27 +73,8 @@ module EvilSeed
73
73
 
74
74
  def prepare(attributes)
75
75
  attributes.map do |key, value|
76
- model_class.connection.quote(serialize(attribute_types[key], value))
77
- end
78
- end
79
-
80
- # Handles ActiveRecord API differences between AR 4.2 and 5.0
81
- def attribute_types
82
- return @attribute_types if defined?(@attribute_types)
83
- @attribute_types = if model_class.respond_to?(:attribute_types)
84
- model_class.attribute_types
85
- else
86
- model_class.column_types
87
- end
88
- end
89
-
90
- # Handles ActiveRecord API differences between AR 4.2 and 5.0
91
- # Casts a value from the ruby type to a type that the database knows how to understand.
92
- def serialize(type, value)
93
- if type.respond_to?(:serialize)
94
- type.serialize(value)
95
- else
96
- type.type_cast_for_database(value)
76
+ type = model_class.attribute_types[key]
77
+ model_class.connection.quote(type.serialize(value))
97
78
  end
98
79
  end
99
80
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/core_ext/array/grouping'
4
+
3
5
  # As method ActiveRecord::Relation#in_batches is available only since ActiveRecord 5.0
4
6
  # we will backport it only for us via refinements for ActiveRecord 4.2 compatibility.
5
7
  unless ActiveRecord::Batches.instance_methods(false).include?(:in_batches)
@@ -122,8 +124,8 @@ module EvilSeed
122
124
  # @param relation [ActiveRecord::Relation]
123
125
  # @return [Array<Hash{String => String, Integer, Float, Boolean, nil}>]
124
126
  def fetch_attributes(relation)
125
- relation.pluck(*model_class.attribute_names).map do |row|
126
- Hash[model_class.attribute_names.zip(row)]
127
+ relation.pluck(*model_class.column_names).map do |row|
128
+ Hash[model_class.column_names.zip(row)]
127
129
  end
128
130
  end
129
131
 
@@ -144,7 +146,7 @@ module EvilSeed
144
146
  next false if reflection.options[:polymorphic] # TODO: Add support for polymorphic belongs_to
145
147
  excluded = root.excluded?("#{association_path}.#{reflection.name}") || reflection.name == inverse_reflection
146
148
  if excluded
147
- nullify_columns << reflection.foreign_key if model_class.attribute_names.include?(reflection.foreign_key)
149
+ nullify_columns << reflection.foreign_key if model_class.column_names.include?(reflection.foreign_key)
148
150
  else
149
151
  foreign_keys[reflection.name] = reflection.foreign_key
150
152
  table_names[reflection.name] = reflection.table_name
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EvilSeed
4
- VERSION = '0.1.2'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evil-seed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Novikov
8
8
  - Vladimir Dementyev
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-03-26 00:00:00.000000000 Z
12
+ date: 2022-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '4.2'
20
+ version: '5.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '4.2'
27
+ version: '5.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -172,10 +172,11 @@ files:
172
172
  - bin/setup
173
173
  - evil-seed.gemspec
174
174
  - gemfiles/.bundle/config
175
- - gemfiles/activerecord_4_2.gemfile
176
175
  - gemfiles/activerecord_5_0.gemfile
177
176
  - gemfiles/activerecord_5_1.gemfile
178
177
  - gemfiles/activerecord_5_2.gemfile
178
+ - gemfiles/activerecord_6_0.gemfile
179
+ - gemfiles/activerecord_6_1.gemfile
179
180
  - gemfiles/activerecord_master.gemfile
180
181
  - lib/evil-seed.rb
181
182
  - lib/evil/seed.rb
@@ -194,13 +195,13 @@ homepage: https://github.com/palkan/evil-seed
194
195
  licenses:
195
196
  - MIT
196
197
  metadata: {}
197
- post_install_message:
198
+ post_install_message:
198
199
  rdoc_options: []
199
200
  require_paths:
200
201
  - lib
201
202
  required_ruby_version: !ruby/object:Gem::Requirement
202
203
  requirements:
203
- - - "~>"
204
+ - - ">="
204
205
  - !ruby/object:Gem::Version
205
206
  version: '2.0'
206
207
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -209,9 +210,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
210
  - !ruby/object:Gem::Version
210
211
  version: '0'
211
212
  requirements: []
212
- rubyforge_project:
213
- rubygems_version: 2.7.6
214
- signing_key:
213
+ rubygems_version: 3.2.22
214
+ signing_key:
215
215
  specification_version: 4
216
216
  summary: Create partial and anonymized production database dumps for use in development
217
217
  test_files: []
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.2.0"
6
- gem "pg", "~> 0.20"
7
- gem "mysql2", "~> 0.3.18"
8
-
9
- gemspec path: "../"