master_data_tool 0.8.0 → 0.9.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: 0c1a8cf7753997cee7c6508d745c9eb9152261ea433dcd0ea436bd9684d2b57c
4
+ data.tar.gz: ae108bb9da67df2a46e15335cc7930a6568a0e359d599323e24683bc3db761c4
5
5
  SHA512:
6
- metadata.gz: fe25e52351bd9d13f5fcd718bf21e49f297e82b99462b3666172e514beff19108dd8d49c17c9e91f5e5c6bd77f12b08575086b63f7ac46cf6e1601dafe086484
7
- data.tar.gz: e072e9911a9449691480b85ba03dfbfb971cdaa9bc58c8dce5fb4dd60fce86ce2305fc5bcea1e39ef8efd3b4b6a4e6dfcd9a2547f064bcddcc9cf37c00883565
6
+ metadata.gz: be594e338ccd11ec1bb9621452c6ff1b0834c253326b74b89fd0f4e7285b3f040f5948f69cde7eae6028581503bf37f26ba8ce0950e7543184b529f44ec51e55
7
+ data.tar.gz: a3ceed39c0d391fb2ec5774371b54f66e25a7d3dc52fff323fd8235edb6e3d750022909782e482fa347ec950b55b2e75722440f3ce613569e7fd134a4b012069
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
@@ -49,13 +60,10 @@ module MasterDataTool
49
60
  end
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
- @model_klass.all.find_each do |record|
122
+ @model_klass.order(id: :asc).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.9.0"
5
5
  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.9.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-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec