master_data_tool 0.3.0 → 0.7.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: e948beea211d4b3fba1d194412cbafd3b6d7d8c768215bf038b5ea89bbaf1b17
4
- data.tar.gz: d72dc44dce6c653c75713440bba5691b062bef9ca766a6159ed233d640f00724
3
+ metadata.gz: a92262ac7a93ea8237ec6740589c865ca6bce067f1fba4a48403a6f3cd42a379
4
+ data.tar.gz: d738dce7d637aa27ae2b9b27e9ed1a7d4ae119e41cf240b24f874e86cf6cde4f
5
5
  SHA512:
6
- metadata.gz: 355a59050f15b91c854e3c79602d89f4c41fd7d7abf49ae0a9cc9be2bc6fbdb212aa4af8d714619e1c0231ad7fd6f321a66e65b6b43cbf0751c4eaf7aa25d7ea
7
- data.tar.gz: 48daa315d4805233c1f357ffc80de821c1cd55cba71401723cbb1e33524d4fa483a24e8a6acef42065be58bd0ba4cda208d1b3229679b73c3423098eb38f71c1
6
+ metadata.gz: b9ebcb430a6d91175cff4e36a512958b30ac5318639f855d4f82e8ab2a74c147a0eeec25f90c5dc97b11a5c3ab7c81b7e1666bee5fee5ad046a8d4cbfcb9a5bc
7
+ data.tar.gz: 76587a7eb98d0b2b0ac28f2cbf9c59e649c05a1d456ea4011cd9f83daa89c9193509b7a25c89780b5e5ec7a6e25cc4f79b31745f3a6c70a619eb5c271915c2b2
data/Appraisals ADDED
@@ -0,0 +1,13 @@
1
+ appraise 'activerecord52' do
2
+ gem 'activerecord', '~> 5.2'
3
+ end
4
+
5
+ appraise 'activerecord61' do
6
+ gem 'activerecord', '~> 6.1'
7
+ end
8
+
9
+ if RUBY_VERSION >= '2.7.0'
10
+ appraise 'activerecord70' do
11
+ gem 'activerecord', '~> 7.0'
12
+ end
13
+ end
data/README.md CHANGED
@@ -35,13 +35,14 @@ Or install it yourself as:
35
35
 
36
36
  ### マスタデータの投入
37
37
 
38
- | option | default | 内容 |
39
- |----------------------| --- |--------------------------------------|
40
- | --dry-run | true | dry-runモードで実行する(データ変更は行わない) |
41
- | --verify | true | データ投入後に全テーブル・全レコードのバリデーションチェックを行う |
42
- | --only-import-tables | [] | 指定したテーブルのみデータ投入を行う |
43
- | --only-verify-tables | [] | 指定したテーブルのみ投入後のバリデーションチェックを行う |
44
- | --skip-no-change | true | CSVファイルに更新がないテーブルをスキップする |
38
+ | option | default | 内容 |
39
+ |----------------------| --- |-----------------------------------|
40
+ | --dry-run | true | dry-runモードで実行する(データ変更は行わない) |
41
+ | --verify | true | データ投入後に全テーブル・全レコードのバリデーションチェックを行う |
42
+ | --only-import-tables | [] | 指定したテーブルのみデータ投入を行う |
43
+ | --only-verify-tables | [] | 指定したテーブルのみ投入後のバリデーションチェックを行う |
44
+ | --skip-no-change | true | CSVファイルに更新がないテーブルをスキップする |
45
+ | --silent | false | 結果の出力をやめる |
45
46
 
46
47
  ```bash
47
48
  bundle exec master_data_tool import
@@ -55,7 +56,8 @@ bundle exec thor master_data_tool import \
55
56
  --verify=true \
56
57
  --only-import-tables="" \
57
58
  --only-verify-tables="" \
58
- --skip-no-change=true
59
+ --skip-no-change=true \
60
+ --silent=false
59
61
  ```
60
62
 
61
63
  ### ダンプ
@@ -141,6 +143,40 @@ grep 'operation:import' /tmp/dry-run.txt | grep 'label:detail' | grep 'status:ne
141
143
 
142
144
  - upsert_allに移行する
143
145
 
146
+ ## Test
147
+
148
+ docker-composeでMySQLを立ち上げてテストを実行する。
149
+
150
+ ```
151
+ docker-compose up -d
152
+ ```
153
+
154
+ 以下のENVを設定すること。
155
+
156
+ ```
157
+ export DB_HOST=127.0.0.1
158
+ export DB_PORT=`docker port master_data_tool_mysql57 3306 | cut -f 2 -d ':'`
159
+ export DB_USERNAME=root
160
+ export DB_PASSWORD=f3WpxNreVT2NgQry
161
+ export DB_NAME=master_data_tool_test
162
+ ```
163
+
164
+ - dockerでMySQLを立ち上げるたびにポートは変わるのでDB_PORTは都度設定する
165
+ - direnvを使っているならば `direnv reload` すればいい
166
+
167
+ ```
168
+ ./scripts/setup.sh
169
+ ```
170
+
171
+ ## rspec
172
+
173
+ ```
174
+ bundle exec appraisal activerecord52 rspec
175
+ bundle exec appraisal activerecord61 rspec
176
+ bundle exec appraisal activerecord70 rspec
177
+ ```
178
+
179
+
144
180
  ## Contributing
145
181
 
146
182
  Bug reports and pull requests are welcome on GitHub at https://github.com/taka0125/master_data_tool.
@@ -0,0 +1,19 @@
1
+ version: '3.9'
2
+
3
+ x-mysql: &mysql
4
+ image: mysql:5.7
5
+ container_name: master_data_tool_mysql57
6
+ environment:
7
+ MYSQL_ROOT_PASSWORD: 'f3WpxNreVT2NgQry'
8
+ platform: linux/x86_64
9
+ ports:
10
+ - 127.0.0.1::3306
11
+ volumes:
12
+ - mysql:/var/lib/mysql
13
+
14
+ services:
15
+ mysql:
16
+ <<: *mysql
17
+
18
+ volumes:
19
+ mysql:
data/exe/master_data_tool CHANGED
@@ -14,6 +14,7 @@ module MasterDataTool
14
14
  option :only_import_tables, default: [], type: :array
15
15
  option :only_verify_tables, default: [], type: :array
16
16
  option :skip_no_change, default: true, type: :boolean
17
+ option :silent, default: false, type: :boolean
17
18
  desc 'import', 'import'
18
19
  def import
19
20
  dry_run = options[:dry_run]
@@ -21,13 +22,15 @@ module MasterDataTool
21
22
  only_import_tables = options[:only_import_tables]
22
23
  only_verify_tables = options[:only_verify_tables]
23
24
  skip_no_change = options[:skip_no_change]
25
+ silent = options[:silent]
24
26
 
25
27
  executor = MasterDataTool::Import::Executor.new(
26
28
  dry_run: dry_run,
27
29
  verify: verify,
28
30
  only_import_tables: only_import_tables,
29
31
  only_verify_tables: only_verify_tables,
30
- skip_no_change: skip_no_change
32
+ skip_no_change: skip_no_change,
33
+ silent: silent
31
34
  )
32
35
  executor.execute
33
36
  end
@@ -49,7 +52,12 @@ module MasterDataTool
49
52
  ignore_column_names: ignore_column_names,
50
53
  verbose: verbose
51
54
  )
52
- executor.execute
55
+ errors = executor.execute
56
+
57
+ return if errors.empty?
58
+
59
+ message = errors.map { |error| "table:#{error.table}\tmessage:#{error.exception.message}" }.join("\n")
60
+ raise message
53
61
  end
54
62
  end
55
63
  end
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "rspec", "~> 3.0"
7
+ gem "activerecord", "~> 5.2"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "rspec", "~> 3.0"
7
+ gem "activerecord", "~> 6.1"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "rspec", "~> 3.0"
7
+ gem "activerecord", "~> 7.0"
8
+
9
+ gemspec path: "../"
@@ -11,10 +11,10 @@ module MasterDataTool
11
11
 
12
12
  def self.default_config
13
13
  new.tap do |config|
14
- config.master_data_dir = Rails.root.join('db/fixtures')
14
+ config.master_data_dir = nil # Rails.root.join('db/fixtures')
15
15
  config.dump_ignore_tables = %w[]
16
16
  config.dump_ignore_columns = %w[]
17
- config.logger = Rails.logger
17
+ config.logger = Logger.new(nil)
18
18
  end
19
19
  end
20
20
  end
@@ -39,7 +39,7 @@ module MasterDataTool
39
39
  end
40
40
 
41
41
  def dump_to_csv(table)
42
- model_klass = Rails.const_get(table.classify)
42
+ model_klass = Object.const_get(table.classify)
43
43
  if ignore?(model_klass)
44
44
  print_message "[ignore] #{table}"
45
45
 
@@ -3,13 +3,15 @@
3
3
  module MasterDataTool
4
4
  module Import
5
5
  class Executor
6
- def initialize(dry_run: true, verify: true, only_import_tables: [], only_verify_tables: [], skip_no_change: true, report_printer: MasterDataTool::Report::DefaultPrinter.new)
6
+ def initialize(dry_run: true, verify: true, only_import_tables: [], only_verify_tables: [], skip_no_change: true, silent: false, report_printer: MasterDataTool::Report::DefaultPrinter.new)
7
7
  @dry_run = dry_run
8
8
  @verify = verify
9
9
  @only_import_tables = Array(only_import_tables)
10
10
  @only_verify_tables = Array(only_verify_tables)
11
11
  @skip_no_change = skip_no_change
12
+ @silent = silent
12
13
  @report_printer = report_printer
14
+ @report_printer.silent = silent
13
15
  end
14
16
 
15
17
  def execute
@@ -38,7 +40,7 @@ module MasterDataTool
38
40
  table_name = MasterDataTool.resolve_table_name(path)
39
41
  load_skip = load_skip_table?(table_name, path)
40
42
 
41
- model_klass = Rails.const_get(table_name.classify)
43
+ model_klass = Object.const_get(table_name.classify)
42
44
  master_data = MasterData.new(path, model_klass)
43
45
  master_data.load unless load_skip
44
46
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'active_record'
4
4
  require 'activerecord-import'
5
+ require 'openssl'
5
6
 
6
7
  module MasterDataTool
7
8
  class MasterDataStatus < ::ActiveRecord::Base
@@ -3,7 +3,15 @@
3
3
  module MasterDataTool
4
4
  module Report
5
5
  module Printer
6
+ attr_accessor :silent
7
+
8
+ def initialize(silent: false)
9
+ @silent = silent
10
+ end
11
+
6
12
  def print(message)
13
+ return if @silent
14
+
7
15
  raise NotImplementedError
8
16
  end
9
17
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MasterDataTool
4
- VERSION = "0.3.0"
4
+ VERSION = "0.7.0"
5
5
  end
data/log/test.log ADDED
File without changes
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/master_data_tool/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "master_data_tool"
7
+ spec.version = MasterDataTool::VERSION
8
+ spec.authors = ["Takahiro Ooishi"]
9
+ spec.email = ["taka0125@gmail.com"]
10
+
11
+ spec.summary = "マスタデータの管理ツール"
12
+ spec.description = "システムが稼働する上で最初から必要なデータ(マスタデータ)を管理するツールです。"
13
+ spec.homepage = "https://github.com/taka0125/master_data_tool"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
24
+ end
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency 'rspec'
31
+ spec.add_development_dependency 'mysql2'
32
+ spec.add_development_dependency 'psych', '~> 3.1'
33
+ spec.add_development_dependency 'appraisal'
34
+ spec.add_development_dependency 'ridgepole'
35
+ spec.add_development_dependency 'database_cleaner-active_record'
36
+
37
+ spec.add_dependency 'activerecord', '>= 5.1.7'
38
+ spec.add_dependency 'activesupport'
39
+ spec.add_dependency 'thor'
40
+ spec.add_dependency 'activerecord-import'
41
+ end
data/scripts/setup.sh ADDED
@@ -0,0 +1,17 @@
1
+ #!/bin/bash
2
+ set -ex
3
+
4
+ CURRENT=$(cd $(dirname $0);pwd)
5
+
6
+ mysql \
7
+ -u ${DB_USERNAME} \
8
+ -h ${DB_HOST} \
9
+ -p${DB_PASSWORD} \
10
+ --port ${DB_PORT} \
11
+ -e "CREATE DATABASE IF NOT EXISTS ${DB_NAME}"
12
+
13
+ bundle exec ridgepole \
14
+ -c ${CURRENT}/../spec/dummy-common/config/database.yml \
15
+ --apply \
16
+ -f ${CURRENT}/../spec/dummy-common/db/Schemafile \
17
+ -E test
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: master_data_tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takahiro Ooishi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-17 00:00:00.000000000 Z
11
+ date: 2022-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec-rails
14
+ name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,21 +25,35 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rails
28
+ name: mysql2
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 5.2.6.2
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 5.2.6.2
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: mysql2
42
+ name: psych
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: appraisal
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -53,21 +67,35 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: psych
70
+ name: ridgepole
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - "~>"
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: '3.1'
75
+ version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - "~>"
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: '3.1'
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: database_cleaner-active_record
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
- name: rails
98
+ name: activerecord
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
101
  - - ">="
@@ -80,6 +108,20 @@ dependencies:
80
108
  - - ">="
81
109
  - !ruby/object:Gem::Version
82
110
  version: 5.1.7
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
83
125
  - !ruby/object:Gem::Dependency
84
126
  name: thor
85
127
  requirement: !ruby/object:Gem::Requirement
@@ -117,12 +159,18 @@ extensions: []
117
159
  extra_rdoc_files: []
118
160
  files:
119
161
  - ".rspec"
162
+ - Appraisals
120
163
  - Gemfile
121
164
  - README.md
122
165
  - Rakefile
123
166
  - bin/console
124
167
  - bin/setup
168
+ - docker-compose.yml
125
169
  - exe/master_data_tool
170
+ - gemfiles/.bundle/config
171
+ - gemfiles/activerecord52.gemfile
172
+ - gemfiles/activerecord61.gemfile
173
+ - gemfiles/activerecord70.gemfile
126
174
  - lib/generators/master_data_tool/install/install_generator.rb
127
175
  - lib/generators/master_data_tool/install/templates/create_master_data_statuses.rb.erb
128
176
  - lib/master_data_tool.rb
@@ -141,6 +189,9 @@ files:
141
189
  - lib/master_data_tool/report/printer.rb
142
190
  - lib/master_data_tool/report/verify_report.rb
143
191
  - lib/master_data_tool/version.rb
192
+ - log/test.log
193
+ - master_data_tool.gemspec
194
+ - scripts/setup.sh
144
195
  - sig/master_data_tool.rbs
145
196
  homepage: https://github.com/taka0125/master_data_tool
146
197
  licenses: []
@@ -162,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
213
  - !ruby/object:Gem::Version
163
214
  version: '0'
164
215
  requirements: []
165
- rubygems_version: 3.0.3
216
+ rubygems_version: 3.2.22
166
217
  signing_key:
167
218
  specification_version: 4
168
219
  summary: マスタデータの管理ツール