master_data_tool 0.10.0 → 0.13.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: 14d09ea955d0a1aa9a9af1631d1693a966bf8f865e95c11f830eb35037eb1d79
4
- data.tar.gz: 1f3e61ebc99c806615f631c463440c1ef1f7a09ecf7b3790e9c226338ccc810b
3
+ metadata.gz: d8d4c2c62c923b5e23871ac9e4df2f91c535c36cd8c66a6cb3d3a05ca6c7275d
4
+ data.tar.gz: 39c776e2196f8a080d7caac86eb4a689701f7263b7aa2d856a4061bd8893863f
5
5
  SHA512:
6
- metadata.gz: 337d5dd89ceb3f8531b144391f1f3c1e5d5e6407817d06a446e4c72379cba3f2add92121fd28f5074da382f2c5f8ea1394123588084ccd1fe2566398d96dab16
7
- data.tar.gz: bf1241162ed8c45535b754904244b03cc9937895e565aa2777135c9eaabf29050af2bee36dbe8f0af78b831bd5014ad2351c3d8a9b1a323e9ef4774aaa6e3d25
6
+ metadata.gz: 624bf1b07e720e1d062c607c9dd697d5709bbc28d19f6396510a2426a0e423b56791682d57f72b6323e36a34c3b70e22f1f1e40dfa9d687cb8dc2fd071a39116
7
+ data.tar.gz: 1bc885ac91429ba21b201ccf7bc275bcba05377004ac0517aec0ec0ceedb3ead0c1bb2324fe29c435a8e06a9e50101e3e7b85636c5b700ec79b4f44528585ae0
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/docker-compose.yml CHANGED
@@ -4,12 +4,18 @@ x-mysql: &mysql
4
4
  image: mysql:5.7
5
5
  container_name: master_data_tool_mysql57
6
6
  environment:
7
- MYSQL_ROOT_PASSWORD: 'f3WpxNreVT2NgQry'
7
+ MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-f3WpxNreVT2NgQry}
8
8
  platform: linux/x86_64
9
9
  ports:
10
- - 127.0.0.1::3306
10
+ - 127.0.0.1:${DB_PORT:-33306}:3306
11
11
  volumes:
12
12
  - mysql:/var/lib/mysql
13
+ command: >
14
+ mysqld
15
+ --sql-mode=NO_ENGINE_SUBSTITUTION
16
+ --character-set-server=utf8mb4
17
+ --innodb-file-per-table=1
18
+ --innodb-large-prefix
13
19
 
14
20
  services:
15
21
  mysql:
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: true, type: :boolean
13
- option :verify, default: true, type: :boolean
14
- option :only_import_tables, default: [], type: :array
15
- option :except_import_tables, default: [], type: :array
16
- option :only_verify_tables, default: [], type: :array
17
- option :except_verify_tables, default: [], type: :array
18
- option :skip_no_change, default: true, type: :boolean
19
- option :silent, default: false, type: :boolean
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
- dry_run = options[:dry_run]
23
- verify = options[:verify]
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 self.default_config
13
- new.tap do |config|
14
- config.master_data_dir = nil # Rails.root.join('db/fixtures')
15
- config.dump_ignore_tables = %w[]
16
- config.dump_ignore_columns = %w[]
17
- config.logger = Logger.new(nil)
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,16 @@ module MasterDataTool
45
49
 
46
50
  private
47
51
 
52
+ def print_execute_options
53
+ return if @silent
54
+
55
+ puts "==== execute ===="
56
+ instance_variables.each do |k|
57
+ puts "#{k}: #{instance_variable_get(k)}"
58
+ end
59
+ puts "================="
60
+ end
61
+
48
62
  def build_master_data_list
49
63
  [].tap do |master_data_list|
50
64
  extract_master_data_csv_paths.each do |path|
@@ -57,7 +71,7 @@ module MasterDataTool
57
71
 
58
72
  master_data_list << master_data
59
73
  end
60
- end
74
+ end.sort_by { |m| m.csv_path } # 外部キー制約などがある場合には先に入れておかないといけないデータなどがある。なので、プレフィックスを付けて順序を指定して貰う
61
75
  end
62
76
 
63
77
  def import_all!(master_data_list)
@@ -65,7 +79,7 @@ module MasterDataTool
65
79
  next unless master_data.loaded?
66
80
  next if import_skip_table?(master_data.table_name)
67
81
 
68
- report = master_data.import!(dry_run: @dry_run)
82
+ report = master_data.import!(dry_run: @dry_run, delete_all_ignore_foreign_key: @delete_all_ignore_foreign_key)
69
83
  report.print(@report_printer)
70
84
  end
71
85
  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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MasterDataTool
4
- VERSION = "0.10.0"
4
+ VERSION = "0.13.0"
5
5
  end
@@ -17,7 +17,7 @@ module MasterDataTool
17
17
 
18
18
  class << self
19
19
  def config
20
- @config ||= Config.default_config
20
+ @config ||= Config.new
21
21
  end
22
22
 
23
23
  def configure
@@ -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
@@ -0,0 +1,42 @@
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
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.10.0
4
+ version: 0.13.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-22 00:00:00.000000000 Z
11
+ date: 2022-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -205,6 +205,7 @@ 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
208
209
  - scripts/setup.sh
209
210
  - sig/master_data_tool.rbs
210
211
  homepage: https://github.com/taka0125/master_data_tool
@@ -227,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
228
  - !ruby/object:Gem::Version
228
229
  version: '0'
229
230
  requirements: []
230
- rubygems_version: 3.0.3
231
+ rubygems_version: 3.2.22
231
232
  signing_key:
232
233
  specification_version: 4
233
234
  summary: マスタデータの管理ツール