evil-seed 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +79 -0
- data/Gemfile +12 -0
- data/README.md +9 -1
- data/evil-seed.gemspec +0 -1
- data/lib/evil_seed/configuration.rb +9 -0
- data/lib/evil_seed/record_dumper.rb +10 -1
- data/lib/evil_seed/relation_dumper.rb +5 -0
- data/lib/evil_seed/version.rb +1 -1
- metadata +4 -26
- data/.travis.yml +0 -82
- data/Appraisals +0 -48
- data/gemfiles/.bundle/config +0 -2
- data/gemfiles/activerecord_5_0.gemfile +0 -10
- data/gemfiles/activerecord_5_1.gemfile +0 -10
- data/gemfiles/activerecord_5_2.gemfile +0 -10
- data/gemfiles/activerecord_6_0.gemfile +0 -10
- data/gemfiles/activerecord_6_1.gemfile +0 -10
- data/gemfiles/activerecord_master.gemfile +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: beab28e2e707c60ae58a1a30d000975f7b460918f369c7177800f732f34cfee5
|
4
|
+
data.tar.gz: 710c2d0a680da6d0c558d50e448048ec5338693e6ce112745ac41a750d34cd3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0de18595e7b4498352c7056f6b9f3c1baf5fe4263cc64f202a1cc06642077767bbe8950c94553cc70fc3157f90687807e851cf6b99403f8a367329045a97bea2
|
7
|
+
data.tar.gz: df586316b366d0b4657cf25cdf6ac56610296c6faa630d1dfdc7314f605df7c2f9454c3f7af72a5f9dea1fd7987bdf553fbd5cf44dff7fd6657dd514a7c15206
|
@@ -0,0 +1,79 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- '**'
|
7
|
+
tags-ignore:
|
8
|
+
- 'v*'
|
9
|
+
pull_request:
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
test:
|
13
|
+
name: Ruby ${{ matrix.ruby }}, ActiveRecord ${{ matrix.activerecord }}, ${{ matrix.database }}
|
14
|
+
continue-on-error: ${{ matrix.ruby == 'head' }}
|
15
|
+
strategy:
|
16
|
+
fail-fast: false
|
17
|
+
matrix:
|
18
|
+
include:
|
19
|
+
- ruby: "head"
|
20
|
+
activerecord: "head"
|
21
|
+
database: sqlite
|
22
|
+
- ruby: "3.2"
|
23
|
+
activerecord: "7.0"
|
24
|
+
database: postgresql
|
25
|
+
- ruby: "3.2"
|
26
|
+
activerecord: "7.0"
|
27
|
+
database: mysql
|
28
|
+
- ruby: "3.2"
|
29
|
+
activerecord: "7.0"
|
30
|
+
database: sqlite
|
31
|
+
- ruby: "3.1"
|
32
|
+
activerecord: "6.1"
|
33
|
+
database: sqlite
|
34
|
+
- ruby: "3.0"
|
35
|
+
activerecord: "6.0"
|
36
|
+
database: sqlite
|
37
|
+
- ruby: "2.7"
|
38
|
+
activerecord: "5.2"
|
39
|
+
database: sqlite
|
40
|
+
|
41
|
+
runs-on: ubuntu-latest
|
42
|
+
|
43
|
+
services:
|
44
|
+
postgres:
|
45
|
+
image: postgres:15
|
46
|
+
env:
|
47
|
+
POSTGRES_USER: postgres
|
48
|
+
POSTGRES_PASSWORD: postgres
|
49
|
+
ports:
|
50
|
+
- 5432:5432
|
51
|
+
options: >-
|
52
|
+
--health-cmd pg_isready
|
53
|
+
--health-interval 10s
|
54
|
+
--health-timeout 5s
|
55
|
+
--health-retries 5
|
56
|
+
mysql:
|
57
|
+
image: mysql:8.0
|
58
|
+
env:
|
59
|
+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
60
|
+
MYSQL_DATABASE: evil_seed_test
|
61
|
+
ports:
|
62
|
+
- 3306:3306
|
63
|
+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
|
64
|
+
|
65
|
+
env:
|
66
|
+
CI: true
|
67
|
+
ACTIVERECORD_VERSION: "${{ matrix.activerecord }}"
|
68
|
+
DB: "${{ matrix.database }}"
|
69
|
+
POSTGRES_USER: postgres
|
70
|
+
POSTGRES_PASSWORD: postgres
|
71
|
+
|
72
|
+
steps:
|
73
|
+
- uses: actions/checkout@v3
|
74
|
+
- uses: ruby/setup-ruby@v1
|
75
|
+
with:
|
76
|
+
ruby-version: ${{ matrix.ruby }}
|
77
|
+
bundler-cache: true
|
78
|
+
- name: Run tests
|
79
|
+
run: bundle exec rake
|
data/Gemfile
CHANGED
@@ -4,3 +4,15 @@ source 'https://rubygems.org'
|
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in evil-seed.gemspec
|
6
6
|
gemspec
|
7
|
+
|
8
|
+
activerecord_version = ENV.fetch("ACTIVERECORD_VERSION", "~> 7.0")
|
9
|
+
case activerecord_version.upcase
|
10
|
+
when "HEAD"
|
11
|
+
git "https://github.com/rails/rails.git" do
|
12
|
+
gem "activerecord"
|
13
|
+
gem "rails"
|
14
|
+
end
|
15
|
+
else
|
16
|
+
activerecord_version = "~> #{activerecord_version}.0" if activerecord_version.match?(/^\d+\.\d+$/)
|
17
|
+
gem "activerecord", activerecord_version
|
18
|
+
end
|
data/README.md
CHANGED
@@ -83,11 +83,19 @@ EvilSeed.configure do |config|
|
|
83
83
|
|
84
84
|
# Anonymization is a handy DSL for transformations allowing you to transform model attributes in declarative fashion
|
85
85
|
# Please note that model setters will NOT be called: results of the blocks will be assigned to
|
86
|
-
config.anonymize("User")
|
86
|
+
config.anonymize("User") do
|
87
87
|
name { Faker::Name.name }
|
88
88
|
email { Faker::Internet.email }
|
89
89
|
login { |login| "#{login}-test" }
|
90
90
|
end
|
91
|
+
|
92
|
+
# You can ignore columns for any model. This is specially useful when working
|
93
|
+
# with encrypted columns.
|
94
|
+
#
|
95
|
+
# This will remove the columns even if the model is not a root node and is
|
96
|
+
# dumped via an association.
|
97
|
+
config.ignore_columns("Profile", :name)
|
98
|
+
end
|
91
99
|
```
|
92
100
|
|
93
101
|
### Creating dump
|
data/evil-seed.gemspec
CHANGED
@@ -11,6 +11,7 @@ module EvilSeed
|
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
@record_dumper_class = RecordDumper
|
14
|
+
@ignored_columns = Hash.new { |h, k| h[k] = [] }
|
14
15
|
end
|
15
16
|
|
16
17
|
def roots
|
@@ -33,10 +34,18 @@ module EvilSeed
|
|
33
34
|
customizers[model_class.to_s] << Anonymizer.new(model_class, &block)
|
34
35
|
end
|
35
36
|
|
37
|
+
def ignore_columns(model_class, *columns)
|
38
|
+
@ignored_columns[model_class] += columns
|
39
|
+
end
|
40
|
+
|
36
41
|
# Customizer objects for every model
|
37
42
|
# @return [Hash{String => Array<#call>}]
|
38
43
|
def customizers
|
39
44
|
@customizers ||= Hash.new { |h, k| h[k] = [] }
|
40
45
|
end
|
46
|
+
|
47
|
+
def ignored_columns_for(model_class)
|
48
|
+
@ignored_columns[model_class]
|
49
|
+
end
|
41
50
|
end
|
42
51
|
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 =
|
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(', ')})")
|
@@ -60,6 +60,9 @@ module EvilSeed
|
|
60
60
|
private
|
61
61
|
|
62
62
|
def dump!
|
63
|
+
original_ignored_columns = model_class.ignored_columns
|
64
|
+
model_class.ignored_columns += Array(configuration.ignored_columns_for(model_class.sti_name))
|
65
|
+
model_class.send(:reload_schema_from_cache) if ActiveRecord.version < Gem::Version.new("6.1.0.rc1") # See https://github.com/rails/rails/pull/37581
|
63
66
|
if identifiers.present?
|
64
67
|
# Don't use AR::Base#find_each as we will get error on Oracle if we will have more than 1000 ids in IN statement
|
65
68
|
identifiers.in_groups_of(MAX_IDENTIFIERS_IN_IN_STMT).each do |ids|
|
@@ -76,6 +79,8 @@ module EvilSeed
|
|
76
79
|
end
|
77
80
|
end
|
78
81
|
end
|
82
|
+
ensure
|
83
|
+
model_class.ignored_columns = original_ignored_columns
|
79
84
|
end
|
80
85
|
|
81
86
|
def dump_record!(attributes)
|
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.5.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:
|
12
|
+
date: 2023-02-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -137,20 +137,6 @@ dependencies:
|
|
137
137
|
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
|
-
- !ruby/object:Gem::Dependency
|
141
|
-
name: appraisal
|
142
|
-
requirement: !ruby/object:Gem::Requirement
|
143
|
-
requirements:
|
144
|
-
- - ">="
|
145
|
-
- !ruby/object:Gem::Version
|
146
|
-
version: '0'
|
147
|
-
type: :development
|
148
|
-
prerelease: false
|
149
|
-
version_requirements: !ruby/object:Gem::Requirement
|
150
|
-
requirements:
|
151
|
-
- - ">="
|
152
|
-
- !ruby/object:Gem::Version
|
153
|
-
version: '0'
|
154
140
|
description: " This gem allows you to easily dump and transform subset of your
|
155
141
|
ActiveRecord models and their relations.\n"
|
156
142
|
email:
|
@@ -160,10 +146,9 @@ executables: []
|
|
160
146
|
extensions: []
|
161
147
|
extra_rdoc_files: []
|
162
148
|
files:
|
149
|
+
- ".github/workflows/test.yml"
|
163
150
|
- ".gitignore"
|
164
151
|
- ".rubocop.yml"
|
165
|
-
- ".travis.yml"
|
166
|
-
- Appraisals
|
167
152
|
- Gemfile
|
168
153
|
- LICENSE.txt
|
169
154
|
- README.md
|
@@ -171,13 +156,6 @@ files:
|
|
171
156
|
- bin/console
|
172
157
|
- bin/setup
|
173
158
|
- evil-seed.gemspec
|
174
|
-
- gemfiles/.bundle/config
|
175
|
-
- gemfiles/activerecord_5_0.gemfile
|
176
|
-
- gemfiles/activerecord_5_1.gemfile
|
177
|
-
- gemfiles/activerecord_5_2.gemfile
|
178
|
-
- gemfiles/activerecord_6_0.gemfile
|
179
|
-
- gemfiles/activerecord_6_1.gemfile
|
180
|
-
- gemfiles/activerecord_master.gemfile
|
181
159
|
- lib/evil-seed.rb
|
182
160
|
- lib/evil/seed.rb
|
183
161
|
- lib/evil_seed.rb
|
@@ -210,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
188
|
- !ruby/object:Gem::Version
|
211
189
|
version: '0'
|
212
190
|
requirements: []
|
213
|
-
rubygems_version: 3.
|
191
|
+
rubygems_version: 3.3.7
|
214
192
|
signing_key:
|
215
193
|
specification_version: 4
|
216
194
|
summary: Create partial and anonymized production database dumps for use in development
|
data/.travis.yml
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
dist: xenial
|
2
|
-
language: ruby
|
3
|
-
cache: bundler
|
4
|
-
sudo: false
|
5
|
-
|
6
|
-
addons:
|
7
|
-
postgresql: "10"
|
8
|
-
apt:
|
9
|
-
sources:
|
10
|
-
- travis-ci/sqlite3
|
11
|
-
packages:
|
12
|
-
- sqlite3
|
13
|
-
|
14
|
-
services:
|
15
|
-
- mysql
|
16
|
-
- postgresql
|
17
|
-
|
18
|
-
before_install: gem install bundler -v '~> 1.17'
|
19
|
-
|
20
|
-
matrix:
|
21
|
-
include:
|
22
|
-
- rvm: 3.0.2
|
23
|
-
gemfile: gemfiles/activerecord_master.gemfile
|
24
|
-
env: "DB=sqlite"
|
25
|
-
- rvm: 3.0.2
|
26
|
-
gemfile: gemfiles/activerecord_master.gemfile
|
27
|
-
env: "DB=postgresql"
|
28
|
-
- rvm: 3.0.2
|
29
|
-
gemfile: gemfiles/activerecord_master.gemfile
|
30
|
-
env: "DB=mysql"
|
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
|
50
|
-
gemfile: gemfiles/activerecord_5_2.gemfile
|
51
|
-
env: "DB=sqlite"
|
52
|
-
- rvm: 2.6.8
|
53
|
-
gemfile: gemfiles/activerecord_5_2.gemfile
|
54
|
-
env: "DB=postgresql"
|
55
|
-
- rvm: 2.6.8
|
56
|
-
gemfile: gemfiles/activerecord_5_2.gemfile
|
57
|
-
env: "DB=mysql"
|
58
|
-
- rvm: 2.5.9
|
59
|
-
gemfile: gemfiles/activerecord_5_1.gemfile
|
60
|
-
env: "DB=sqlite"
|
61
|
-
- rvm: 2.5.9
|
62
|
-
gemfile: gemfiles/activerecord_5_1.gemfile
|
63
|
-
env: "DB=postgresql"
|
64
|
-
- rvm: 2.5.9
|
65
|
-
gemfile: gemfiles/activerecord_5_1.gemfile
|
66
|
-
env: "DB=mysql"
|
67
|
-
- rvm: 2.4.10
|
68
|
-
gemfile: gemfiles/activerecord_5_0.gemfile
|
69
|
-
env: "DB=sqlite"
|
70
|
-
- rvm: 2.4.10
|
71
|
-
gemfile: gemfiles/activerecord_5_0.gemfile
|
72
|
-
env: "DB=postgresql"
|
73
|
-
- rvm: 2.4.10
|
74
|
-
gemfile: gemfiles/activerecord_5_0.gemfile
|
75
|
-
env: "DB=mysql"
|
76
|
-
- rvm: 2.3.8
|
77
|
-
gemfile: gemfiles/activerecord_4_2.gemfile
|
78
|
-
env: "DB=postgresql"
|
79
|
-
- rvm: 2.3.8
|
80
|
-
gemfile: gemfiles/activerecord_4_2.gemfile
|
81
|
-
env: "DB=sqlite"
|
82
|
-
# Please note that gem can't be tested against MySQL on ActiveRecord 4.2 (Dump and restore test doesn't work)!
|
data/Appraisals
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
appraise 'activerecord-5-0' do
|
2
|
-
gem 'activerecord', '~> 5.0.0'
|
3
|
-
gem "pg", ">= 0.20", "< 2.0"
|
4
|
-
gem 'mysql2', '~> 0.4.4'
|
5
|
-
gem 'sqlite3', '~> 1.3.6'
|
6
|
-
end
|
7
|
-
|
8
|
-
appraise 'activerecord-5-1' do
|
9
|
-
gem 'activerecord', '~> 5.1.0'
|
10
|
-
gem "pg", ">= 0.20", "< 2.0"
|
11
|
-
gem 'mysql2', '~> 0.4.4'
|
12
|
-
gem 'sqlite3', '~> 1.3'
|
13
|
-
end
|
14
|
-
|
15
|
-
appraise 'activerecord-5-2' do
|
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"
|
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'
|
41
|
-
end
|
42
|
-
|
43
|
-
appraise 'activerecord-master' do
|
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'
|
48
|
-
end
|
data/gemfiles/.bundle/config
DELETED