arxutils_sqlite3 0.1.55 → 0.1.57

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: 5088d67aaf0d344baa38409d59917374132f161d7e3f9f24d4e947dfe83ae4ce
4
- data.tar.gz: 405fdb8388ab606d8c2036f26966707bf05dddc498cc50ebb4730d0fcf03f73a
3
+ metadata.gz: fc3d7553db8a9f3ab369bb8cd52ddc1c2dad405a5bc902dab4df7f10cf092371
4
+ data.tar.gz: 051160b94504da313197d003017d925c30c035b17c7bc14dd8dfd957e23d2014
5
5
  SHA512:
6
- metadata.gz: 48294fc512c0ea001f5f4e2f2adba8c4e8aea126c921fcdc0e769c70fce1530cf084778b65133cd0402b8c2ca728e8bf971f364f6d7f51451785e41d8808b7e8
7
- data.tar.gz: 8a0a987962aad35da0c289b4f716abf70f626b35ad5b5c739981240cebbab08d68f98c9ac61c4c22bd1a1b89da195abae806642a48cfd6e39e56df007c9a7bd2
6
+ metadata.gz: a0925a9111aa889b00d36609fd1027a5e6b925f855e5bc1934dbbae5df85134c7eb1d1b1edd3d5133b59323151d88bae047954a9febf8fd22837b0ecda2fb06b
7
+ data.tar.gz: 1fb3f7177523006d793adedb9080557fe6a7d132163d70cc19436e22c4d789c08c0e75060219f53f1d9a026fa2a89d828eaf1c0c02fcd12ac9b559b062c287e7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arxutils_sqlite3 (0.1.55)
4
+ arxutils_sqlite3 (0.1.57)
5
5
  activerecord (~> 6.1)
6
6
  activesupport
7
7
  simpleoptparse
@@ -109,4 +109,4 @@ DEPENDENCIES
109
109
  ykxutils (> 0.1.0)
110
110
 
111
111
  BUNDLED WITH
112
- 2.3.17
112
+ 2.3.22
data/config/setting.yml CHANGED
@@ -1,2 +1,2 @@
1
1
  ---
2
- :klass: Xenop
2
+ :mod: Xenop
data/exe/arxutils_sqlite3 CHANGED
@@ -8,34 +8,37 @@ require "ykxutils"
8
8
 
9
9
  config = Arxutils_Sqlite3::Config.new
10
10
 
11
- opts, klass = config.setupx(self)
11
+ opts, mod = config.setupx(self)
12
12
  # p opts
13
- # p klass
13
+ # p mod
14
14
  # exit
15
15
 
16
- banner = "Usage: bundle exec arxutils_sqlite3 --cmd=(s|cds|co|c|f|m|a|d|b|y) -y yaml_file --klass=class"
16
+ banner = "Usage: bundle exec arxutils_sqlite3 --cmd=(s|cds|co|c|f|m|a|d|del|b|y|dm) -y yaml_file --mod=mod"
17
17
 
18
18
  Simpleoptparse::Simpleoptparse.parse(ARGV, opts, banner, Arxutils_Sqlite3::VERSION, nil) do |parser|
19
- parser.on("--cmd X", %w[s cds co c f m a d b y]) { |x| opts["cmd"] = x }
19
+ parser.on("--cmd X", %w[s cds co c f m a d del b y dm]) { |x| opts["cmd"] = x }
20
20
  parser.on("-y yaml_file", "--yaml yaml_file") { |x| opts["yaml"] = x }
21
- parser.on("--klass klass") { |x| opts["klass"] = x }
21
+ parser.on("--mod mod") { |x| opts["mod"] = x }
22
22
  end
23
23
 
24
24
  dbconfig = Arxutils_Sqlite3::Config::DBCONFIG_SQLITE3
25
25
  env = ENV.fetch("ENV", nil)
26
26
  env ||= "production"
27
27
 
28
- cli = Arxutils_Sqlite3::Cli.new(config, dbconfig, env)
28
+ acrecord = opts[:acrecord]
29
+ yaml_fname = opts["yaml"]
30
+ mod ||= opts["mod"]
31
+ cli = Arxutils_Sqlite3::Cli.new(config, dbconfig, env, acrecord, yaml_fname, mod)
29
32
 
30
33
  case opts["cmd"]
31
34
  when "s"
32
35
  # config.check_file_exist(Arxutils_Sqlite3::Config::SAMPLE_DEST_OPTS_FILE, banner, 10)
33
36
 
34
- if opts["klass"].nil? || opts["klass"].strip == ""
37
+ if opts["mod"].nil? || opts["mod"].strip == ""
35
38
  puts banner
36
39
  exit 20
37
40
  end
38
- cli.setup(klass)
41
+ cli.setup(mod)
39
42
 
40
43
  when "cds"
41
44
  cli.copy_db_scheme
@@ -44,20 +47,16 @@ when "co"
44
47
  cli.copy_opts_file
45
48
 
46
49
  when "c"
47
- acrecord = opts[:acrecord]
48
- cli.makeconfig(acrecord, banner, 30, opts)
50
+ cli.makeconfig(opts)
49
51
 
50
52
  when "f"
51
- yaml_fname = opts["yaml"]
52
- acrecord = opts[:acrecord]
53
53
  if yaml_fname.nil? || yaml_fname.strip == ""
54
54
  puts banner
55
55
  exit 40
56
56
  end
57
57
  yaml_pn = Pathname.new(yaml_fname)
58
58
  config.check_file_not_exist(yaml_pn, banner, 55)
59
- cli.setup_for_migrate(yaml_pn, acrecord, klass)
60
-
59
+ cli.make_migrate_script
61
60
  when "m"
62
61
  cli.migrate
63
62
 
@@ -65,17 +64,20 @@ when "a"
65
64
  cli.acr
66
65
 
67
66
  when "d"
68
- db_scheme_ary = nil
69
- acrecord = opts["acrecord"]
70
- cli.delete(db_scheme_ary, acrecord)
67
+ cli.clean
68
+
69
+ when "del"
70
+ cli.delete
71
71
 
72
72
  when "b"
73
- db_scheme_ary = nil
74
- acrecord = opts["acrecord"]
75
- cli.delete_db(db_scheme_ary, acrecord)
73
+ cli.delete_db
76
74
 
77
75
  when "y"
78
76
  cli.delete_setting_yaml
77
+
78
+ when "dm"
79
+ cli.delete_migrate
80
+
79
81
  else
80
82
  puts "Invalid command(#{opts["cmd"]}) specified!!"
81
83
  end
@@ -1,21 +1,30 @@
1
1
  module Arxutils_Sqlite3
2
2
  # CLI用クラス
3
3
  class Cli
4
- def initialize(config, dbconfig, env)
4
+ def initialize(config, dbconfig, env, acrecord, yaml_fname, _mod)
5
5
  @config = config
6
6
  @dbconfig = dbconfig
7
7
  @env = env
8
+ @acrecord = acrecord
9
+ @dbconfig_path = @config.make_dbconfig_path(@dbconfig)
10
+
11
+ @db_scheme_ary = nil
12
+ if yaml_fname && yaml_fname.strip != ""
13
+ yaml_pn = Pathname.new(yaml_fname)
14
+ @db_scheme_ary = YAML.load_file(yaml_pn)
15
+ end
16
+ @mig = @config.prepare_for_migrate(@db_scheme_ary, @dbconfig_path, @dbconfig, @acrecord)
8
17
  end
9
18
 
10
- def setup(klass)
19
+ def setup(mod)
11
20
  # p "make_config_directory"
12
21
  @config.make_config_directory
13
22
  # p "setup_db_scheme_file"
14
- @config.setup_db_scheme_file(klass)
15
- # p "setup_opts_file(#{klass})"
16
- @config.setup_opts_file(klass)
17
- # p "setup_setting_yaml_file(#{klass})"
18
- @config.setup_setting_yaml_file(klass)
23
+ @config.setup_db_scheme_file(mod)
24
+ # p "setup_opts_file(#{mod})"
25
+ @config.setup_opts_file(mod)
26
+ # p "setup_setting_yaml_file(#{mod})"
27
+ @config.setup_setting_yaml_file(mod)
19
28
  # db_scheme_ary = nil
20
29
  end
21
30
 
@@ -29,24 +38,24 @@ module Arxutils_Sqlite3
29
38
  @config.copy_opts_file
30
39
  end
31
40
 
32
- def makeconfig(acrecord, _banner, _exit_code, opts)
41
+ def setup_for_migrate
42
+ ret = :SUCCESS
33
43
  db_scheme_ary = nil
34
44
  dbconfig_path = @config.make_dbconfig_path(@dbconfig)
35
45
  # @config.check_file_exist(dbconfig_path, banner, exit_code)
36
- mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
37
- mig.make_dbconfig(opts)
46
+ @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, @acrecord)
47
+ ret
38
48
  end
39
49
 
40
- def setup_for_migrate(yaml_pn, acrecord, klass)
41
- db_scheme_ary = YAML.load_file(yaml_pn)
42
- dbconfig_path = @config.make_dbconfig_path(@dbconfig)
43
-
44
- dest_dbsetup_file = @config.dest_dbsetup_file
45
- @config.make_dbsetup_file(db_scheme_ary, acrecord, klass, dest_dbsetup_file)
50
+ def makeconfig(opts)
51
+ @mig.make_dbconfig(opts)
52
+ end
46
53
 
54
+ def make_migrate_script
55
+ @dest_dbsetup_file = @config.dest_dbsetup_file
56
+ @config.make_dbsetup_file(@db_scheme_ary, @acrecord, @mod, @dest_dbsetup_file)
47
57
  # マイグレーション用スクリプトの生成、acrecordのクラス定義ファイルの生成
48
- mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
49
- mig.output
58
+ @mig.output
50
59
  end
51
60
 
52
61
  # マイグレーション実行
@@ -68,32 +77,38 @@ module Arxutils_Sqlite3
68
77
  ret = :SUCCESS
69
78
  begin
70
79
  Dbsetup.new(connect_time)
71
- rescue StandardError
80
+ rescue StandardError => e
81
+ puts e.message
72
82
  ret = :StandardError
73
83
  end
74
84
 
75
85
  ret
76
86
  end
77
87
 
78
- def delete(db_scheme_ary, acrecord)
79
- config_dir = @config.config_dir
80
- dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, @dbconfig)
81
- mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
82
- mig.delete_migrate_and_config_and_db
88
+ def clean
89
+ @mig.delete_migrate_and_config_and_db
83
90
  end
84
91
 
85
- def delete_db(db_scheme_ary, acrecord)
86
- config_dir = @config.config_dir
87
- dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, @dbconfig)
88
- mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
89
- # mig.delete_migrate_config_and_db
90
- mig.delete_db
92
+ def delete
93
+ @mig.delete_migrate_and_db
94
+ end
95
+
96
+ def delete_db
97
+ @mig.delete_db
98
+ end
99
+
100
+ def delete_nigrate
101
+ @mig.delete_migrate
91
102
  end
92
103
 
93
104
  def delete_setting_yaml
94
105
  FileUtils.rm_f(@config.setting_yaml_file)
95
106
  end
96
107
 
108
+ def delete_migrate
109
+ @mig.delete_migrate
110
+ end
111
+
97
112
  def rm_dbconfig
98
113
  dbconfig_path = @config.make_dbconfig_path(@dbconfig)
99
114
  # p dbconfig_path
@@ -61,10 +61,10 @@ module Arxutils_Sqlite3
61
61
  # 削除しないファイル群
62
62
  EXCLUDE_FILES = %w[SETTING_YAML_FILE_NAME].freeze
63
63
  # 作成対象のActiveRecordの子クラスのデフォルトクラス名
64
- DEFAULT_KLASS = "Xenop".freeze
64
+ DEFAULT_MOD = "Xenop".freeze
65
65
 
66
- def default_klass
67
- DEFAULT_KLASS
66
+ def default_mod
67
+ DEFAULT_MOD
68
68
  end
69
69
 
70
70
  def setting_yaml_file
@@ -95,13 +95,13 @@ module Arxutils_Sqlite3
95
95
 
96
96
  setting = load_setting_yaml_file
97
97
  # p "setting=#{setting}"
98
- klass = setting[:klass]
99
- klass ||= DEFAULT_KLASS
98
+ mod = setting[:mod]
99
+ mod ||= DEFAULT_MOD
100
100
 
101
101
  # DBセットアップクラス
102
102
  require_dbsetup_file
103
103
 
104
- [opts, klass]
104
+ [opts, mod]
105
105
  end
106
106
 
107
107
  # DB構成ファイル格納ディレクトリの作成
@@ -111,12 +111,12 @@ module Arxutils_Sqlite3
111
111
  end
112
112
 
113
113
  # DBスキームファイルのサンプルファイコピー
114
- def setup_db_scheme_file(klass)
114
+ def setup_db_scheme_file(mod)
115
115
  # p "config setup_db_scheme_file"
116
116
  # p "DB_SCHEME_FILE=#{DB_SCHEME_FILE}"
117
117
  # p "SAMPLE_DB_SCHEME_FILE=#{SAMPLE_DB_SCHEME_FILE}"
118
118
  scope = {}
119
- value_hash = { klass: klass }
119
+ value_hash = { mod: mod }
120
120
  content = Ykutils::Erubyx.erubi_render_with_template_file(DB_SCHEME_FILE, scope, value_hash)
121
121
  Ykxutils.yaml_load_compati(content)
122
122
  File.write(SAMPLE_DB_SCHEME_FILE, content)
@@ -130,9 +130,9 @@ module Arxutils_Sqlite3
130
130
  end
131
131
 
132
132
  # optsファイル(Rubyスクリプトファイル)のサンプルファイル書き込み
133
- def setup_opts_file(klass)
133
+ def setup_opts_file(mod)
134
134
  scope = Object.new
135
- hash = { klass: klass }
135
+ hash = { mod_name: mod }
136
136
  result_content = Ykutils::Erubyx.erubi_render_with_template_file(OPTS_FILE, scope, hash)
137
137
  File.write(SAMPLE_OPTS_FILE, result_content)
138
138
  end
@@ -147,8 +147,8 @@ module Arxutils_Sqlite3
147
147
  end
148
148
 
149
149
  # setting.ymlへの出力
150
- def setup_setting_yaml_file(klass)
151
- hash = { klass: klass }
150
+ def setup_setting_yaml_file(mod)
151
+ hash = { mod: mod }
152
152
  content = YAML.dump(hash)
153
153
  ret = :SUCCESS
154
154
  begin
@@ -285,11 +285,10 @@ module Arxutils_Sqlite3
285
285
  )
286
286
  end
287
287
 
288
- def make_dbsetup_file(db_scheme_ary, acrecord, klass, dest_dbsetup_file)
288
+ def make_dbsetup_file(db_scheme_ary, acrecord, _mod, dest_dbsetup_file)
289
289
  scope = Object.new
290
- hash0 = { module_name: acrecord[:module].join("::") }
290
+ hash0 = { mod_name: acrecord[:module].join("::") }
291
291
  hash = db_scheme_ary[0].merge(hash0)
292
- hash["klass"] = klass
293
292
  result_content = Ykutils::Erubyx.erubi_render_with_template_file(src_dbsetup_file, scope, hash)
294
293
 
295
294
  File.write(dest_dbsetup_file, result_content)
@@ -85,7 +85,6 @@ module Arxutils_Sqlite3
85
85
  # DBファイルの削除
86
86
  def delete_db
87
87
  Dir.glob(File.join(@db_dir, "*")).each do |x|
88
- # puts x
89
88
  FileUtils.rm(x) if File.file?(x)
90
89
  end
91
90
  end
@@ -2,10 +2,10 @@
2
2
  require "arxutils_sqlite3"
3
3
  config = Arxutils_Sqlite3::Config.new
4
4
 
5
- klass = nil
5
+ mod = nil
6
6
  setting = config.load_setting_yaml_file
7
- klass = setting[:klass]
8
- klass = config.default_klass if klass.nil?
7
+ mod = setting[:mod]
8
+ mod = config.default_mod if mod.nil?
9
9
 
10
10
  desc_arxutils_sqlite3 = "setup copy_db_scheme copy_opts makeconfig make_migrate_script migrate acr"
11
11
 
@@ -29,9 +29,9 @@ task "arx:ds": %w[arx:delete_setting]
29
29
 
30
30
  # コマンドラインで指定したクラス名を含むオプション指定用ハッシュの定義を含むRubyスクリ
31
31
  # プトファイルの生成
32
- desc "produce setting.yml, db_scheme.yml.sample and opts.rb.sample with class name #{klass}"
32
+ desc "produce setting.yml, db_scheme.yml.sample and opts.rb.sample with class name #{mod}"
33
33
  task "arx:setup" do
34
- sh "bundle exec arxutils_sqlite3 --cmd=s --klass=#{klass}"
34
+ sh "bundle exec arxutils_sqlite3 --cmd=s --mod=#{mod}"
35
35
  end
36
36
 
37
37
  desc "copy from db_scheme.yml.sample to db_scheme.yml"
@@ -68,6 +68,11 @@ end
68
68
 
69
69
  desc "delete configuration files adn migration scripts and db files"
70
70
  task "arx:delete" do
71
+ sh "bundle exec arxutils_sqlite3 --cmd=del"
72
+ end
73
+
74
+ desc "delete configuration files adn migration scripts and db files"
75
+ task "arx:clean" do
71
76
  sh "bundle exec arxutils_sqlite3 --cmd=d"
72
77
  end
73
78
 
@@ -80,3 +85,8 @@ desc "delete setting yaml"
80
85
  task "arx:delete_setting" do
81
86
  sh "bundle exec arxutils_sqlite3 --cmd=y"
82
87
  end
88
+
89
+ desc "delete migrate scripts"
90
+ task "arx:delete_migrate" do
91
+ sh "bundle exec arxutils_sqlite3 --cmd=dm"
92
+ end
@@ -1,4 +1,4 @@
1
1
  module Arxutils_Sqlite3
2
2
  # バージョン番号
3
- VERSION = "0.1.55".freeze
3
+ VERSION = "0.1.57".freeze
4
4
  end
data/lib/dbacrecord.rb CHANGED
@@ -14,12 +14,12 @@ module Dbutil
14
14
  end
15
15
 
16
16
  class Invalidxenoplist < ActiveRecord::Base
17
- belongs_to :xenoplist, foreign_key: 'org_id'
18
- belongs_to :count, foreign_key: ''
17
+ belongs_to :xenoplist, foreign_key: "org_id"
18
+ belongs_to :count, foreign_key: ""
19
19
  end
20
20
 
21
21
  class Currentxenoplist < ActiveRecord::Base
22
- belongs_to :xenoplist , foreign_key: 'org_id'
22
+ belongs_to :xenoplist, foreign_key: "org_id"
23
23
  end
24
24
 
25
25
  end
@@ -11,8 +11,8 @@
11
11
  :ar_version: 6.0
12
12
  - :flist:
13
13
  - noitem
14
- :classname: <%= klass %>
15
- :classname_downcase: <%= klass.downcase %>
14
+ :classname: <%= mod %>
15
+ :classname_downcase: <%= mod.downcase %>
16
16
  :items:
17
17
  - - time_id
18
18
  - integer
@@ -20,14 +20,14 @@
20
20
  - - ennb_id
21
21
  - integer
22
22
  - 'false'
23
- :plural: <%= klass.downcase %>s
23
+ :plural: <%= mod.downcase %>s
24
24
  :ar_version: 6.0
25
25
  - :flist:
26
26
  - noitem
27
27
  - invalid
28
28
  - current
29
- :classname: <%= klass %>list
30
- :classname_downcase: <%= klass.downcase %>list
29
+ :classname: <%= mod %>list
30
+ :classname_downcase: <%= mod.downcase %>list
31
31
  :items:
32
32
  - - stack
33
33
  - string
@@ -44,5 +44,5 @@
44
44
  - - start_datetime
45
45
  - datetime
46
46
  - 'false'
47
- :plural: <%= klass.downcase %>lists
47
+ :plural: <%= mod.downcase %>lists
48
48
  :ar_version: 6.0
@@ -3,7 +3,7 @@ require_relative "../lib/dbacrecord"
3
3
  class Dbsetup
4
4
  def initialize(connect_time)
5
5
  @connect_time = connect_time
6
- @ct = <%= klass %>::Dbutil::Countdatetime.create(countdatetime: @connect_time)
6
+ @ct = <%= mod_name %>::Countdatetime.create(countdatetime: @connect_time)
7
7
  @hs_by_notebook = {}
8
8
  @hs_by_id = {}
9
9
  end
@@ -1,6 +1,6 @@
1
1
  @opts = {
2
2
  acrecord: {
3
- module: %w[<%= klass %> Dbutil],
3
+ module: %w[<%= mod %> Dbutil],
4
4
  filename: "dbacrecord.rb",
5
5
  dir: "lib"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  @opts = {
2
2
  acrecord: {
3
- module: %w[<%= klass %> Dbutil],
3
+ module: %w[<%= mod_name %> Dbutil],
4
4
  filename: "dbacrecord.rb",
5
5
  dir: "lib"
6
6
  }
data/memo.md ADDED
@@ -0,0 +1,7 @@
1
+ ```mermaid
2
+ graph TD;
3
+ Cli#makeconfig-->config.prepare_for_migrate;
4
+ Cli#delete-->config.prepare_for_migrate;
5
+ Cli#delete_db-->config.prepare_for_migrate;
6
+ Cli#delete_migrate-->config.prepare_for_migrate;
7
+ ```
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arxutils_sqlite3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.55
4
+ version: 0.1.57
5
5
  platform: ruby
6
6
  authors:
7
7
  - yasuo kominami
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-23 00:00:00.000000000 Z
11
+ date: 2022-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -243,13 +243,14 @@ files:
243
243
  - lib/template/acrecord/noitem.tmpl
244
244
  - lib/template/config/mysql.tmpl
245
245
  - lib/template/config/sqlite3.tmpl
246
+ - memo.md
246
247
  homepage: https://ykominami.github.io/arxutils_sqlite3/
247
248
  licenses:
248
249
  - MIT
249
250
  metadata:
250
251
  homepage_uri: https://ykominami.github.io/arxutils_sqlite3/
251
252
  rubygems_mfa_required: 'true'
252
- post_install_message:
253
+ post_install_message:
253
254
  rdoc_options: []
254
255
  require_paths:
255
256
  - lib
@@ -264,8 +265,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
265
  - !ruby/object:Gem::Version
265
266
  version: '0'
266
267
  requirements: []
267
- rubygems_version: 3.3.7
268
- signing_key:
268
+ rubygems_version: 3.1.6
269
+ signing_key:
269
270
  specification_version: 4
270
271
  summary: utility functions for ActiveRecord.
271
272
  test_files: []