master_data_tool 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/exe/master_data_tool +11 -27
- data/lib/master_data_tool/config.rb +7 -7
- data/lib/master_data_tool/import/executor.rb +13 -1
- data/lib/master_data_tool/master_data.rb +11 -1
- data/lib/master_data_tool/version.rb +1 -1
- data/lib/master_data_tool.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69795950505c4ab8feeb32605e77d588da3922793d21e2eeb59995c6a3ac2238
|
4
|
+
data.tar.gz: dd153019b32a9808bc5c8da0f6dba8add7ffcb753f85940882efce22a2aac3b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2107f256a35f5a8ad8e9a9cfb8f6b668e9518b185eeb91a42b4aac7b56695841abf1f627a1c182e0afc6f06a441c2b5569c5f9e62985d76f76d89f30c5a37d2d
|
7
|
+
data.tar.gz: 587736de3714b372e702e9338a6dfa6e45c44251fcf584b1d0c117a7bca8120cb12a9c97a9635ccaad34e0dd6693e5149253ac20a7201802f9b84f572bc474bd
|
data/README.md
CHANGED
@@ -45,6 +45,7 @@ Or install it yourself as:
|
|
45
45
|
| --except-verify-tables | [] | 指定したテーブルのバリデーションチェックを行わない |
|
46
46
|
| --skip-no-change | true | CSVファイルに更新がないテーブルをスキップする |
|
47
47
|
| --silent | false | 結果の出力をやめる |
|
48
|
+
| --delete-all-ignore-foreign-key | false | 外部キー制約を無視してレコードを消すかどうか |
|
48
49
|
|
49
50
|
```bash
|
50
51
|
bundle exec master_data_tool import
|
@@ -61,7 +62,8 @@ bundle exec thor master_data_tool import \
|
|
61
62
|
--only-verify-tables="" \
|
62
63
|
--except-verify-tables="" \
|
63
64
|
--skip-no-change=true \
|
64
|
-
--silent=false
|
65
|
+
--silent=false \
|
66
|
+
--delete-all-ignore-foreign-key=false
|
65
67
|
```
|
66
68
|
|
67
69
|
### ダンプ
|
data/exe/master_data_tool
CHANGED
@@ -9,35 +9,19 @@ require environment_path
|
|
9
9
|
|
10
10
|
module MasterDataTool
|
11
11
|
class CLI < Thor
|
12
|
-
option :dry_run, default:
|
13
|
-
option :verify, default:
|
14
|
-
option :only_import_tables, default:
|
15
|
-
option :except_import_tables, default:
|
16
|
-
option :only_verify_tables, default:
|
17
|
-
option :except_verify_tables, default:
|
18
|
-
option :skip_no_change, default:
|
19
|
-
option :silent, default:
|
12
|
+
option :dry_run, default: nil, type: :boolean
|
13
|
+
option :verify, default: nil, type: :boolean
|
14
|
+
option :only_import_tables, default: nil, type: :array
|
15
|
+
option :except_import_tables, default: nil, type: :array
|
16
|
+
option :only_verify_tables, default: nil, type: :array
|
17
|
+
option :except_verify_tables, default: nil, type: :array
|
18
|
+
option :skip_no_change, default: nil, type: :boolean
|
19
|
+
option :silent, default: nil, type: :boolean
|
20
|
+
option :delete_all_ignore_foreign_key, default: nil, type: :boolean
|
20
21
|
desc 'import', 'import'
|
21
22
|
def import
|
22
|
-
|
23
|
-
|
24
|
-
only_import_tables = options[:only_import_tables]
|
25
|
-
except_import_tables = options[:except_import_tables]
|
26
|
-
only_verify_tables = options[:only_verify_tables]
|
27
|
-
except_verify_tables = options[:except_verify_tables]
|
28
|
-
skip_no_change = options[:skip_no_change]
|
29
|
-
silent = options[:silent]
|
30
|
-
|
31
|
-
executor = MasterDataTool::Import::Executor.new(
|
32
|
-
dry_run: dry_run,
|
33
|
-
verify: verify,
|
34
|
-
only_import_tables: only_import_tables,
|
35
|
-
except_import_tables: except_import_tables,
|
36
|
-
only_verify_tables: only_verify_tables,
|
37
|
-
except_verify_tables: except_verify_tables,
|
38
|
-
skip_no_change: skip_no_change,
|
39
|
-
silent: silent
|
40
|
-
)
|
23
|
+
new_options = MasterDataTool.config.default_import_options.with_indifferent_access.merge(options)
|
24
|
+
executor = MasterDataTool::Import::Executor.new(**new_options.symbolize_keys)
|
41
25
|
executor.execute
|
42
26
|
end
|
43
27
|
|
@@ -7,15 +7,15 @@ module MasterDataTool
|
|
7
7
|
config_accessor :master_data_dir
|
8
8
|
config_accessor :dump_ignore_tables
|
9
9
|
config_accessor :dump_ignore_columns
|
10
|
+
config_accessor :default_import_options
|
10
11
|
config_accessor :logger
|
11
12
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
13
|
+
def initialize
|
14
|
+
self.master_data_dir = nil
|
15
|
+
self.dump_ignore_tables = %w[]
|
16
|
+
self.dump_ignore_columns = %w[]
|
17
|
+
self.default_import_options = {}
|
18
|
+
self.logger = Logger.new(nil)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -11,6 +11,7 @@ module MasterDataTool
|
|
11
11
|
except_verify_tables: [],
|
12
12
|
skip_no_change: true,
|
13
13
|
silent: false,
|
14
|
+
delete_all_ignore_foreign_key: false,
|
14
15
|
report_printer: MasterDataTool::Report::DefaultPrinter.new)
|
15
16
|
|
16
17
|
@dry_run = dry_run
|
@@ -21,12 +22,15 @@ module MasterDataTool
|
|
21
22
|
@except_verify_tables = Array(except_verify_tables)
|
22
23
|
@skip_no_change = skip_no_change
|
23
24
|
@silent = silent
|
25
|
+
@delete_all_ignore_foreign_key = delete_all_ignore_foreign_key
|
24
26
|
@report_printer = report_printer
|
25
27
|
@report_printer.silent = silent
|
26
28
|
end
|
27
29
|
|
28
30
|
def execute
|
29
31
|
ApplicationRecord.transaction do
|
32
|
+
print_execute_options
|
33
|
+
|
30
34
|
master_data_list = build_master_data_list
|
31
35
|
|
32
36
|
import_all!(master_data_list)
|
@@ -45,6 +49,14 @@ module MasterDataTool
|
|
45
49
|
|
46
50
|
private
|
47
51
|
|
52
|
+
def print_execute_options
|
53
|
+
puts "==== execute ===="
|
54
|
+
instance_variables.each do |k|
|
55
|
+
puts "#{k}: #{instance_variable_get(k)}"
|
56
|
+
end
|
57
|
+
puts "================="
|
58
|
+
end
|
59
|
+
|
48
60
|
def build_master_data_list
|
49
61
|
[].tap do |master_data_list|
|
50
62
|
extract_master_data_csv_paths.each do |path|
|
@@ -65,7 +77,7 @@ module MasterDataTool
|
|
65
77
|
next unless master_data.loaded?
|
66
78
|
next if import_skip_table?(master_data.table_name)
|
67
79
|
|
68
|
-
report = master_data.import!(dry_run: @dry_run)
|
80
|
+
report = master_data.import!(dry_run: @dry_run, delete_all_ignore_foreign_key: @delete_all_ignore_foreign_key)
|
69
81
|
report.print(@report_printer)
|
70
82
|
end
|
71
83
|
end
|
@@ -103,14 +103,16 @@ module MasterDataTool
|
|
103
103
|
@model_klass.table_name
|
104
104
|
end
|
105
105
|
|
106
|
-
def import!(dry_run: true)
|
106
|
+
def import!(dry_run: true, delete_all_ignore_foreign_key: false)
|
107
107
|
raise MasterDataTool::NotLoadedError unless @loaded
|
108
108
|
|
109
109
|
MasterDataTool::Report::ImportReport.new(self).tap do |report|
|
110
110
|
return report if dry_run
|
111
111
|
return report unless affected?
|
112
112
|
|
113
|
+
disable_foreign_key_checks if delete_all_ignore_foreign_key
|
113
114
|
@model_klass.delete_all
|
115
|
+
enable_foreign_key_checks if delete_all_ignore_foreign_key
|
114
116
|
|
115
117
|
# マスターデータ間の依存がある場合に投入順制御するのは大変なのでこのタイミングでのバリデーションはしない
|
116
118
|
@model_klass.import(import_records, validate: false, on_duplicate_key_update: @columns, timestamps: true)
|
@@ -152,5 +154,13 @@ module MasterDataTool
|
|
152
154
|
end
|
153
155
|
end
|
154
156
|
end
|
157
|
+
|
158
|
+
def enable_foreign_key_checks
|
159
|
+
ApplicationRecord.connection.execute('SET FOREIGN_KEY_CHECKS = 1')
|
160
|
+
end
|
161
|
+
|
162
|
+
def disable_foreign_key_checks
|
163
|
+
ApplicationRecord.connection.execute('SET FOREIGN_KEY_CHECKS = 0')
|
164
|
+
end
|
155
165
|
end
|
156
166
|
end
|
data/lib/master_data_tool.rb
CHANGED