master_data_tool 0.8.0 → 0.11.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: 64c169242f5fd0a16a4b5153dc597473146c057ddb72b8a1f8451cd9ec82032f
4
- data.tar.gz: 65bd3c7a4bb1537a2853796d1947df6ab0665e9ddb737db6a913b6d21c1626a5
3
+ metadata.gz: c8ebd8a88c9055d0c745c87114670f1ee0d7e6d898883e9472c54ca37ea3a22c
4
+ data.tar.gz: 5b3cdba7ee2a9f3690087ed90abf74d3838543ea8d268979ec789f28dd060399
5
5
  SHA512:
6
- metadata.gz: fe25e52351bd9d13f5fcd718bf21e49f297e82b99462b3666172e514beff19108dd8d49c17c9e91f5e5c6bd77f12b08575086b63f7ac46cf6e1601dafe086484
7
- data.tar.gz: e072e9911a9449691480b85ba03dfbfb971cdaa9bc58c8dce5fb4dd60fce86ce2305fc5bcea1e39ef8efd3b4b6a4e6dfcd9a2547f064bcddcc9cf37c00883565
6
+ metadata.gz: 94d4272694cb2fd10c6fec969ca3b8b877d9f40173586f0300bcf97f1ad54d7ef3cd240b0c96e7cfd33627560e841ae1f336acc58fd188ac323b39d44428c7d9
7
+ data.tar.gz: bdae562479f4e795e13f3140add0c58046669ad6a69164b8d409954ae095b99574e1ad6d951585d82b491d482862219c6bc30acd7415cec42c7ea8a81b6a1aba
data/README.md CHANGED
@@ -40,7 +40,9 @@ Or install it yourself as:
40
40
  | --dry-run | true | dry-runモードで実行する(データ変更は行わない) |
41
41
  | --verify | true | データ投入後に全テーブル・全レコードのバリデーションチェックを行う |
42
42
  | --only-import-tables | [] | 指定したテーブルのみデータ投入を行う |
43
+ | --except-import-tables | [] | 指定したテーブルのデータ投入を行わない |
43
44
  | --only-verify-tables | [] | 指定したテーブルのみ投入後のバリデーションチェックを行う |
45
+ | --except-verify-tables | [] | 指定したテーブルのバリデーションチェックを行わない |
44
46
  | --skip-no-change | true | CSVファイルに更新がないテーブルをスキップする |
45
47
  | --silent | false | 結果の出力をやめる |
46
48
 
@@ -55,7 +57,9 @@ bundle exec thor master_data_tool import \
55
57
  --dry-run=true \
56
58
  --verify=true \
57
59
  --only-import-tables="" \
60
+ --except-import-tables="" \
58
61
  --only-verify-tables="" \
62
+ --except-verify-tables="" \
59
63
  --skip-no-change=true \
60
64
  --silent=false
61
65
  ```
data/exe/master_data_tool CHANGED
@@ -12,7 +12,9 @@ module MasterDataTool
12
12
  option :dry_run, default: true, type: :boolean
13
13
  option :verify, default: true, type: :boolean
14
14
  option :only_import_tables, default: [], type: :array
15
+ option :except_import_tables, default: [], type: :array
15
16
  option :only_verify_tables, default: [], type: :array
17
+ option :except_verify_tables, default: [], type: :array
16
18
  option :skip_no_change, default: true, type: :boolean
17
19
  option :silent, default: false, type: :boolean
18
20
  desc 'import', 'import'
@@ -20,7 +22,9 @@ module MasterDataTool
20
22
  dry_run = options[:dry_run]
21
23
  verify = options[:verify]
22
24
  only_import_tables = options[:only_import_tables]
25
+ except_import_tables = options[:except_import_tables]
23
26
  only_verify_tables = options[:only_verify_tables]
27
+ except_verify_tables = options[:except_verify_tables]
24
28
  skip_no_change = options[:skip_no_change]
25
29
  silent = options[:silent]
26
30
 
@@ -28,7 +32,9 @@ module MasterDataTool
28
32
  dry_run: dry_run,
29
33
  verify: verify,
30
34
  only_import_tables: only_import_tables,
35
+ except_import_tables: except_import_tables,
31
36
  only_verify_tables: only_verify_tables,
37
+ except_verify_tables: except_verify_tables,
32
38
  skip_no_change: skip_no_change,
33
39
  silent: silent
34
40
  )
@@ -3,11 +3,22 @@
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, silent: false, report_printer: MasterDataTool::Report::DefaultPrinter.new)
6
+ def initialize(dry_run: true,
7
+ verify: true,
8
+ only_import_tables: [],
9
+ except_import_tables: [],
10
+ only_verify_tables: [],
11
+ except_verify_tables: [],
12
+ skip_no_change: true,
13
+ silent: false,
14
+ report_printer: MasterDataTool::Report::DefaultPrinter.new)
15
+
7
16
  @dry_run = dry_run
8
17
  @verify = verify
9
18
  @only_import_tables = Array(only_import_tables)
19
+ @except_import_tables = Array(except_import_tables)
10
20
  @only_verify_tables = Array(only_verify_tables)
21
+ @except_verify_tables = Array(except_verify_tables)
11
22
  @skip_no_change = skip_no_change
12
23
  @silent = silent
13
24
  @report_printer = report_printer
@@ -46,16 +57,13 @@ module MasterDataTool
46
57
 
47
58
  master_data_list << master_data
48
59
  end
49
- end
60
+ end.sort_by { |m| m.csv_path } # 外部キー制約などがある場合には先に入れておかないといけないデータなどがある。なので、プレフィックスを付けて順序を指定して貰う
50
61
  end
51
62
 
52
- # 1. 変更があるかどうかのチェックをスキップした
53
- # 2. 変更があるかどうかのチェックを実行し、変更がないので処理をスキップした
54
- # 3. 変更があるかどうかのチェックを実行し、変更があるので実行した
55
- # の3パターンがある
56
63
  def import_all!(master_data_list)
57
64
  master_data_list.each do |master_data|
58
65
  next unless master_data.loaded?
66
+ next if import_skip_table?(master_data.table_name)
59
67
 
60
68
  report = master_data.import!(dry_run: @dry_run)
61
69
  report.print(@report_printer)
@@ -66,7 +74,7 @@ module MasterDataTool
66
74
  master_data_list.each do |master_data|
67
75
  next if verify_skip_table?(master_data.table_name)
68
76
 
69
- report = master_data.verify!(dry_run: @dry_run)
77
+ report = master_data.verify!(ignore_fail: @dry_run)
70
78
  report.print(@report_printer)
71
79
  end
72
80
  end
@@ -74,6 +82,8 @@ module MasterDataTool
74
82
  def save_master_data_statuses!(master_data_list)
75
83
  records = []
76
84
  master_data_list.each do |master_data|
85
+ next unless master_data.loaded?
86
+
77
87
  records << MasterDataTool::MasterDataStatus.build(master_data.csv_path)
78
88
  end
79
89
 
@@ -91,29 +101,33 @@ module MasterDataTool
91
101
  end
92
102
 
93
103
  def load_skip_table?(table_name, csv_path)
94
- return load_skip_table_when_target_all_table?(table_name) unless @skip_no_change
95
-
96
- load_skip_table_when_target_changed_table?(table_name, csv_path)
97
- end
98
-
99
- def load_skip_table_when_target_changed_table?(table_name, csv_path)
100
- unless @only_import_tables.empty?
101
- return true if @only_import_tables.exclude?(table_name)
102
- end
104
+ return true if import_skip_table?(table_name)
105
+ return false unless @skip_no_change
103
106
 
104
107
  !MasterDataTool::MasterDataStatus.master_data_will_change?(csv_path)
105
108
  end
106
109
 
107
- def load_skip_table_when_target_all_table?(table_name)
108
- return false if @only_import_tables.empty?
109
-
110
- @only_import_tables.exclude?(table_name)
110
+ def import_skip_table?(table_name)
111
+ need_skip_table?(table_name, @only_import_tables, @except_import_tables)
111
112
  end
112
113
 
113
114
  def verify_skip_table?(table_name)
114
- return false if @only_verify_tables.empty?
115
+ need_skip_table?(table_name, @only_verify_tables, @except_verify_tables)
116
+ end
117
+
118
+ # 1. onlyを指定した時点でそのリストに含まれるものだけになるべき
119
+ # 2. exceptのリストはどんな状況でも除外されるべき
120
+ # 3. それ以外はすべて実行する
121
+ def need_skip_table?(table_name, only, except)
122
+ only_result = only.presence&.include?(table_name)
123
+ except_result = except.presence&.include?(table_name)
124
+
125
+ # onlyが指定された時点でデフォルトはskipとする
126
+ default = only_result.nil? ? false : true
127
+ return true if except_result == true
128
+ return false if only_result == true
115
129
 
116
- @only_verify_tables.exclude?(table_name)
130
+ default
117
131
  end
118
132
 
119
133
  def extract_master_data_csv_paths
@@ -117,12 +117,12 @@ module MasterDataTool
117
117
  end
118
118
  end
119
119
 
120
- def verify!(dry_run: true)
120
+ def verify!(ignore_fail: false)
121
121
  MasterDataTool::Report::VerifyReport.new(self).tap do |report|
122
122
  @model_klass.all.find_each do |record|
123
123
  valid = record.valid?
124
124
  report.append(MasterDataTool::Report::VerifyReport.build_verify_record_report(self, record, valid))
125
- next if dry_run
125
+ next if ignore_fail
126
126
 
127
127
  raise MasterDataTool::VerifyFailed.new("[#{table_name}] id = #{record.id} is invalid") unless valid
128
128
  end
@@ -5,11 +5,6 @@ module MasterDataTool
5
5
  class PrintAffectedTableReport
6
6
  include Core
7
7
 
8
- def initialize(master_data)
9
- super(master_data)
10
- @reports = []
11
- end
12
-
13
8
  def print(printer)
14
9
  printer.print(convert_to_ltsv({operation: :affected_table, table_name: @master_data.table_name}))
15
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MasterDataTool
4
- VERSION = "0.8.0"
4
+ VERSION = "0.11.0"
5
5
  end
@@ -25,7 +25,8 @@ module MasterDataTool
25
25
  end
26
26
 
27
27
  def resolve_table_name(csv_path)
28
- csv_path.relative_path_from(config.master_data_dir).to_s.delete_suffix('.csv')
28
+ # 0001_table_nameのように投入順序を制御可能にする
29
+ csv_path.relative_path_from(config.master_data_dir).to_s.gsub(/^\d+_/, '').delete_suffix('.csv')
29
30
  end
30
31
  end
31
32
  end
data/scripts/setup.sh CHANGED
@@ -11,7 +11,7 @@ mysql \
11
11
  -e "CREATE DATABASE IF NOT EXISTS ${DB_NAME}"
12
12
 
13
13
  bundle exec ridgepole \
14
- -c ${CURRENT}/../spec/dummy-common/config/database.yml \
14
+ -c ${CURRENT}/../spec/dummy/config/database.yml \
15
15
  --apply \
16
- -f ${CURRENT}/../spec/dummy-common/db/Schemafile \
16
+ -f ${CURRENT}/../spec/dummy/db/Schemafile \
17
17
  -E test
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: master_data_tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.11.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-18 00:00:00.000000000 Z
11
+ date: 2022-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -205,7 +205,6 @@ files:
205
205
  - lib/master_data_tool/report/verify_report.rb
206
206
  - lib/master_data_tool/version.rb
207
207
  - log/test.log
208
- - master_data_tool.gemspec
209
208
  - scripts/setup.sh
210
209
  - sig/master_data_tool.rbs
211
210
  homepage: https://github.com/taka0125/master_data_tool
@@ -228,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
227
  - !ruby/object:Gem::Version
229
228
  version: '0'
230
229
  requirements: []
231
- rubygems_version: 3.2.22
230
+ rubygems_version: 3.0.3
232
231
  signing_key:
233
232
  specification_version: 4
234
233
  summary: マスタデータの管理ツール
@@ -1,42 +0,0 @@
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
- spec.add_development_dependency 'standalone_activerecord_boot_loader'
37
-
38
- spec.add_dependency 'activerecord', '>= 5.1.7'
39
- spec.add_dependency 'activesupport'
40
- spec.add_dependency 'thor'
41
- spec.add_dependency 'activerecord-import'
42
- end