arxutils_sqlite3 0.1.47 → 0.1.49

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: e09dc03b438aa54a9f0bb3e49c46b7592593e52a4e4275220a1b66890694054e
4
- data.tar.gz: 1afd929a60c9e1fed27e11b9ff4ea87761be5dd77e15cf87cb2e090a153dbc07
3
+ metadata.gz: c193545ee59fccd118a5b0e5cac8cc391156e418a62ef8b16bfe15c68cc99671
4
+ data.tar.gz: 20995c46c24a772caa0e638089473ad4f1c703c5c98f003cb6c47c975a9d5a88
5
5
  SHA512:
6
- metadata.gz: 3f63fa45e2827cc7c16ae8fc534c2ef725e1359c4d2c9f99c4edc73af78b846eaf43319c25cb177636cffef8d997fc939e6d97e865ece6ea0a0a064d398d90df
7
- data.tar.gz: 508aa3ff67bddd7e1ec59403e6f18d024f71e79dbd23aa750dd6c736bd3a3183091f7ec9fde7b61d634091dddf41ef5885f5d6b900fcb8c4eb5a97bdde077ed7
6
+ metadata.gz: a62e6f3d47ea1920a867c77a73d6f6fe667d4d438f8ba9fa5aec5edd7a2cd238e0dd6cf5a0a1d1468eea8b3f2369dcbfcb6cb420da51e7e21ec608f18521824f
7
+ data.tar.gz: 4435b54b4f7eb8f7d53707da7bd6caedd4a9c110af82f4f30573db1f9b51721a61c1debb65b65f94d1c6fffa7020722d0ad1d5a0c24152479ced7164479d4238
data/Rakefile CHANGED
@@ -1,65 +1,102 @@
1
1
  require "bundler/gem_tasks"
2
- =begin
3
2
  require "rake/testtask"
4
3
 
5
4
  Rake::TestTask.new do |t|
6
5
  t.libs << "test"
7
6
  end
8
7
 
9
- desc "Run test"
10
- task default: :test
11
- =end
8
+ #desc "Run test"
9
+ #task default: :test
12
10
 
13
- # Defining a task called default that depends on the tasks setup, makeconfig, migrate, and integrate.
14
- task default: %w[delete setup makeconfig migrate integrate]
11
+ # Defining a task called default that depends on the tasks setup, makeconfig, migrate, and acr.
15
12
 
16
- task scmi: %w[setup makeconfig migrate integrate]
13
+ desc "setup copy_db_scheme copy_opts makeconfig make_migrate_script migrate acr"
14
+ task default: %w[setup copy_db_scheme copy_opts makeconfig make_migrate_script migrate acr]
17
15
 
16
+ desc "delete setup copy_db_scheme copy_opts makeconfig make_migrate_script migrate acr"
17
+ task bootstrap: %w[delete setup copy_db_scheme copy_opts makeconfig make_migrate_script migrate acr]
18
+
19
+ desc "setup makeconfig migrate acr"
20
+ task scfma: %w[setup makeconfig migrate acr]
21
+
22
+ desc "delete setup makeconfig"
18
23
  task dsc: %w[delete setup makeconfig]
19
24
 
25
+ desc "delete setup"
20
26
  task ds: %w[delete setup]
21
27
 
28
+ desc "setup"
22
29
  task s: %w[setup]
23
30
 
31
+ desc "setup makeconfig"
24
32
  task sc: %w[setup makeconfig]
25
33
 
34
+ desc "delete setup makeconfig migrate"
26
35
  task dscm: %w[delete setup makeconfig migrate]
27
36
 
37
+ desc "setup makeconfig migrate"
28
38
  task scm: %w[setup makeconfig migrate]
29
39
 
30
- task dscmi: %w[delete setup makeconfig migrate integrate]
40
+ desc "delete setup makeconfig migrate acr"
41
+ task dscma: %w[delete setup makeconfig migrate acr]
31
42
 
32
- task scmi: %w[setup makeconfig migrate integrate]
43
+ desc "setup makeconfig migrate acr"
44
+ task scma: %w[setup makeconfig migrate acr]
33
45
 
34
- task mi: %w[migrate integrate]
46
+ desc "migrate acr"
47
+ task ma: %w[migrate acr]
35
48
 
36
- task bmi: %w[delete_db migrate integrate]
49
+ desc "delete_db migrate acr"
50
+ task bma: %w[delete_db migrate acr]
37
51
 
52
+ desc "delete_db"
38
53
  task b: %w[delete_db]
39
54
 
40
55
  # コマンドラインで指定したクラス名を含むオプション指定用ハッシュの定義を含むRubyスクリ
41
56
  # プトファイルの生成
57
+ desc "produce setting.yml, db_scheme.yml.sample and opts.rb.sample with class name Enop"
42
58
  task :setup do
43
59
  sh "bundle exec arxutils_sqlite3 --cmd=s --klass=Enop"
44
60
  end
45
61
 
62
+ desc "copy from db_scheme.yml.sample to db_scheme.yml"
63
+ task :copy_db_scheme do
64
+ sh "bundle exec arxutils_sqlite3 --cmd=cds"
65
+ end
66
+
67
+ desc "copy from opts.rb.sample to opts.rb"
68
+ task :copy_opts do
69
+ sh "bundle exec arxutils_sqlite3 --cmd=co"
70
+ end
71
+
46
72
  # DB構成情報の生成
73
+ desc "produce sqlite3.yml"
47
74
  task :makeconfig do
48
75
  sh "bundle exec arxutils_sqlite3 --cmd=c"
49
76
  end
50
- # マイグレート用スクリプトファイルの生成とマイグレートの実行
77
+
78
+ # マイグレート用スクリプトファイルの生成
79
+ desc "produce migration scripts"
80
+ task :make_migrate_script do
81
+ sh "bundle exec arxutils_sqlite3 --cmd=f --yaml=config/db_scheme.yml"
82
+ end
83
+ # マイグレートの実行
84
+ desc "execute migration"
51
85
  task :migrate do
52
- sh "bundle exec arxutils_sqlite3 --cmd=m --yaml=config/db_scheme.yml"
86
+ sh "bundle exec arxutils_sqlite3 --cmd=m"
53
87
  end
54
88
 
55
- task :integrate do
56
- sh "bundle exec arxutils_sqlite3 --cmd=i"
89
+ desc "call ActiveRecord instance method"
90
+ task :acr do
91
+ sh "bundle exec arxutils_sqlite3 --cmd=a"
57
92
  end
58
93
 
94
+ desc "delete configuration files adn migration scripts and db files"
59
95
  task :delete do
60
96
  sh "bundle exec arxutils_sqlite3 --cmd=d"
61
97
  end
62
98
 
99
+ desc "delete db files"
63
100
  task :delete_db do
64
101
  sh "bundle exec arxutils_sqlite3 --cmd=b"
65
102
  end
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_runtime_dependency "activesupport"
37
37
  # spec.add_runtime_dependency "erb"
38
38
  # spec.add_runtime_dependency "activerecord", "~> 4.2"
39
+
39
40
  spec.add_runtime_dependency "activerecord", "~> 6.1"
40
41
  spec.add_runtime_dependency "sqlite3"
41
42
  spec.add_runtime_dependency "ykutils"
@@ -43,10 +44,9 @@ Gem::Specification.new do |spec|
43
44
  spec.add_runtime_dependency "simpleoptparse"
44
45
  # spec.add_development_dependency "bundler", "~> 2.2.10"
45
46
  spec.add_development_dependency "bundler"
46
- spec.add_development_dependency "rake"
47
- #spec.add_development_dependency "rake", ">= 12.3.3"
48
- spec.add_development_dependency "rspec"
49
- spec.add_development_dependency "rubocop"
47
+ spec.add_development_dependency "rspec" , "~> 3.0"
48
+ spec.add_development_dependency "rake", "~> 13.0"
49
+ spec.add_development_dependency "rubocop", "~> 1.7"
50
50
  spec.add_development_dependency "rubocop-rake"
51
51
  spec.add_development_dependency "rubocop-rspec"
52
52
  spec.add_development_dependency "yard"
data/exe/arxutils_sqlite3 CHANGED
@@ -10,12 +10,21 @@ config = Arxutils_Sqlite3::Config.new
10
10
 
11
11
  config.require_opts_file
12
12
 
13
- begin
14
- require "dbrelation"
15
- rescue LoadError => ex
16
- pp ex.message
13
+ opts = @opts ? @opts : {}
14
+
15
+ acrecord = opts[:acrecord]
16
+ if acrecord
17
+ filename = acrecord[:filename]
18
+ basename = File.basename(filename)
19
+
20
+ begin
21
+ require "#{basename}"
22
+ rescue LoadError => ex
23
+ #pp ex.message
24
+ end
17
25
  end
18
26
 
27
+ opts[:db_dir] = Arxutils_Sqlite3::Config::DB_DIR
19
28
 
20
29
  klass = nil
21
30
  setting = config.load_setting_yaml_file
@@ -24,105 +33,67 @@ klass = setting[:klass]
24
33
  # DBセットアップクラス
25
34
  config.require_dbsetup_file
26
35
 
27
- banner = "Usage: bundle exec arxutils_sqlite3 --cmd=(s|c|m|i|d|b) -y yaml_file --klass=class"
28
-
29
- opts = @opts ? @opts : {}
30
- opts["dbconfig"] = Arxutils_Sqlite3::Config::DBCONFIG_SQLITE3
36
+ banner = "Usage: bundle exec arxutils_sqlite3 --cmd=(s|cds|co|c|f|m|a|d|b) -y yaml_file --klass=class"
31
37
 
32
38
  Simpleoptparse::Simpleoptparse.parse(ARGV, opts, banner, Arxutils_Sqlite3::VERSION, nil) do |parser|
33
- parser.on("--cmd X", %w[s c m i d b]) { |x| opts["cmd"] = x }
39
+ parser.on("--cmd X", %w[s cds co c f m a d b]) { |x| opts["cmd"] = x }
34
40
  parser.on("-y yaml_file", "--yaml yaml_file") { |x| opts["yaml"] = x }
35
41
  parser.on("--klass klass") { |x| opts["klass"] = x }
36
42
  end
43
+ klass = opts["klass"] if opts["klass"]
37
44
 
45
+ dbconfig = Arxutils_Sqlite3::Config::DBCONFIG_SQLITE3
38
46
  env = ENV.fetch("ENV", nil)
39
47
  env ||= "production"
40
48
 
49
+ cli = Arxutils_Sqlite3::Cli.new(config, dbconfig, env)
50
+
41
51
  case opts["cmd"]
42
52
  when "s"
43
- config.check_file_exist(Arxutils_Sqlite3::Config::DEST_OPTS_FILE, banner, 10)
53
+ #config.check_file_exist(Arxutils_Sqlite3::Config::SAMPLE_DEST_OPTS_FILE, banner, 10)
44
54
 
45
55
  if opts["klass"].nil? || opts["klass"].strip == ""
46
56
  puts banner
47
57
  exit 20
48
58
  end
49
- klass = opts["klass"]
50
- config.make_config_directory
51
- config.setup_db_scheme_file
52
- config.setup_opts_file(klass)
53
- config.setup_setting_yaml_file(klass)
54
- db_scheme_ary = nil
59
+ cli.setup(klass)
60
+
61
+ when "cds"
62
+ cli.copy_db_scheme
63
+
64
+ when "co"
65
+ cli.copy_opts_file
55
66
 
56
67
  when "c"
57
- db_scheme_ary = nil
58
- dbconfig = opts["dbconfig"]
59
- replation = opts["replation"]
60
- dbconfig_path = config.make_dbconfig_path(dbconfig)
61
- config.check_file_exist(dbconfig_path, banner, 30)
62
- mig = config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, replation)
63
- mig.make_dbconfig(opts)
68
+ acrecord = opts[:acrecord]
69
+ cli.makeconfig(acrecord, banner, 30, opts)
64
70
 
65
- when "m"
71
+ when "f"
66
72
  yaml_fname = opts["yaml"]
67
- relation = opts[:relation]
68
- dbconfig = opts["dbconfig"]
73
+ acrecord = opts[:acrecord]
69
74
  if yaml_fname.nil? || yaml_fname.strip == ""
70
75
  puts banner
71
76
  exit 40
72
77
  end
73
78
  yaml_pn = Pathname.new(yaml_fname)
74
79
  config.check_file_not_exist(yaml_pn, banner, 55)
75
- db_scheme_ary = YAML.load_file( yaml_pn )
80
+ cli.setup_for_migrate(yaml_pn, acrecord, klass)
76
81
 
77
- dest_dbsetup_file = config.get_dest_dbsetup_file
78
- config.make_dbsetup_file(db_scheme_ary, relation, klass, dest_dbsetup_file)
79
-
80
- connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(config, dbconfig, env)
81
-
82
- # マイグレーション用スクリプトの生成、relationのクラス定義ファイルの生成
83
- mig = config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, relation)
84
- mig.output
85
-
86
- # マイグレーション実行
87
- ActiveRecord::MigrationContext.new(mig.migrate_dir, ActiveRecord::SchemaMigration).up
82
+ when "m"
83
+ cli.migrate
88
84
 
89
- when "i"
90
- dbconfig = opts["dbconfig"]
91
- connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(config, dbconfig, env)
92
- Dbsetup.new(connect_time)
85
+ when "a"
86
+ cli.acr
93
87
 
94
88
  when "d"
95
89
  db_scheme_ary = nil
96
- dbconfig = opts["dbconfig"]
97
- replation = opts["replation"]
98
-
99
- config_dir = config.get_config_dir
100
- dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, dbconfig)
101
- mig = config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, replation)
102
- mig.delete_migrate_and_config_and_db
90
+ acrecord = opts["acrecord"]
91
+ cli.delete(db_scheme_ary, acrecord)
103
92
 
104
93
  when "b"
105
94
  db_scheme_ary = nil
106
- dbconfig = opts["dbconfig"]
107
- replation = opts["replation"]
108
-
109
- config_dir = config.get_config_dir
110
- dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, dbconfig)
111
- mig = config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, replation)
112
- # mig.delete_migrate_config_and_db
113
- mig.delete_db
114
-
115
- when "b"
116
- db_scheme_ary = nil
117
- dbconfig = opts["dbconfig"]
118
- replation = opts["replation"]
119
-
120
- config_dir = config.get_config_dir
121
- dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, dbconfig)
122
- mig = config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, replation)
123
- # mig.delete_migrate_config_and_db
124
- mig.delete_db
125
-
95
+ acrecord = opts["acrecord"]
96
+ cli.delete_db(db_scheme_ary, acrecord)
126
97
  else
127
98
  puts "Invalid command(#{opts["cmd"]}) specified!!"
128
99
  end
@@ -1,5 +1,6 @@
1
1
  require "erb"
2
2
  require "ykutils"
3
+
3
4
  module Arxutils_Sqlite3
4
5
  # スキーマ設定に基づき、テンプレートから変換する
5
6
  class Arx
@@ -17,7 +18,7 @@ module Arxutils_Sqlite3
17
18
  # :items
18
19
  # フィールド名, 型, null許容 の配列
19
20
  # :plural
20
- # :relation
21
+ # :acrecord
21
22
  @data = data
22
23
 
23
24
  # スキーマ設定の:itemsの値を展開後格納するためのStructクラス
@@ -0,0 +1,90 @@
1
+ module Arxutils_Sqlite3
2
+ # CLI用クラス
3
+ class Cli
4
+ def initialize(config, dbconfig, env)
5
+ @config = config
6
+ @dbconfig = dbconfig
7
+ @env = env
8
+ end
9
+
10
+ def setup(klass)
11
+ p "make_config_directory"
12
+ @config.make_config_directory
13
+ p "setup_db_scheme_file"
14
+ @config.setup_db_scheme_file
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)
19
+ #db_scheme_ary = nil
20
+ end
21
+
22
+ def copy_db_scheme
23
+ # DBスキームファイルが存在しなければ、サンプルファイルをDBスキームファイルとしてコピー
24
+ @config.copy_db_scheme_file
25
+ end
26
+
27
+ def copy_opts_file
28
+ # optsファイルが存在しなければ、サンプルファイルをoptsファイルとしてコピー
29
+ @config.copy_opts_file
30
+ end
31
+
32
+ def makeconfig(acrecord, banner, exit_code, opts)
33
+ db_scheme_ary = nil
34
+ dbconfig_path = @config.make_dbconfig_path(@dbconfig)
35
+ #@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)
38
+ end
39
+
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.get_dest_dbsetup_file
45
+ @config.make_dbsetup_file(db_scheme_ary, acrecord, klass, dest_dbsetup_file)
46
+
47
+ # migrate用スクリプトの出力先ディレクトリ名
48
+ migrate_dir = @config.get_migrate_dir
49
+ # マイグレーション用スクリプトの生成、acrecordのクラス定義ファイルの生成
50
+ mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
51
+ mig.output
52
+ end
53
+
54
+ def migrate
55
+ # migrate用スクリプトの出力先ディレクトリ名
56
+ migrate_dir = @config.get_migrate_dir
57
+
58
+ connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(@config, @dbconfig, @env)
59
+
60
+ # マイグレーション実行
61
+ ActiveRecord::MigrationContext.new(migrate_dir, ActiveRecord::SchemaMigration).up
62
+ end
63
+
64
+ def acr
65
+ connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(@config, @dbconfig, @env)
66
+ Dbsetup.new(connect_time)
67
+ end
68
+
69
+ def delete(db_scheme_ary, acrecord)
70
+ config_dir = @config.get_config_dir
71
+ dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, @dbconfig)
72
+ mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
73
+ mig.delete_migrate_and_config_and_db
74
+ end
75
+
76
+ def delete_db(db_scheme_ary, acrecord)
77
+ config_dir = @config.get_config_dir
78
+ dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, @dbconfig)
79
+ mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
80
+ # mig.delete_migrate_config_and_db
81
+ mig.delete_db
82
+ end
83
+
84
+ def rm_dbconfig
85
+ dbconfig_path = @config.make_dbconfig_path(@dbconfig)
86
+ #p dbconfig_path
87
+ FileUtils.rm_f(dbconfig_path)
88
+ end
89
+ end
90
+ end
@@ -22,19 +22,22 @@ module Arxutils_Sqlite3
22
22
  # テンプレートディレクトリへのパス
23
23
  TEMPLATE_DIR = Arxutils_Sqlite3::TOP_DIR.join("template")
24
24
  # リレーションテンプレートディレクトリへのパス
25
- TEMPLATE_RELATION_DIR = TEMPLATE_DIR.join("relation")
25
+ TEMPLATE_ACRECORD_DIR = TEMPLATE_DIR.join("acrecord")
26
26
  TEMPLATE_CONFIG_DIR = TEMPLATE_DIR.join( CONFIG_DIR )
27
- DB_SCHEME_DIR = TEMPLATE_RELATION_DIR.join("db_scheme")
27
+ DB_SCHEME_DIR = TEMPLATE_ACRECORD_DIR.join("db_scheme")
28
28
  DB_SCHEME_FILE = DB_SCHEME_DIR.join("db_scheme.yml")
29
+ SAMPLE_DB_SCHEME_FILE = CONFIG_DIR.join("db_scheme.yml.sample")
29
30
  DB_SCHEME_FILE_NAME = "db_scheme.yml".freeze
30
31
  DB_SCHEME_FILE_NAME_2 = "db_scheme".freeze
31
32
  OPTS_FILE_NAME = "opts.rb".freeze
33
+ SAMPLE_OPTS_FILE_NAME = "opts.rb.sample".freeze
32
34
  OPTS_FILE_NAME_2 = "opts".freeze
33
35
  DBSETUP_FILE_NAME = "dbsetup.rb".freeze
34
36
  DBSETUP_FILE_NAME_2 = "dbsetup".freeze
35
37
  SETTING_YAML_FILE_NAME = "setting.yml".freeze
36
38
  DEST_CONFIG_DIR = Pathname.new( CONFIG_DIR )
37
39
  OPTS_FILE = DB_SCHEME_DIR.join(OPTS_FILE_NAME)
40
+ SAMPLE_OPTS_FILE = CONFIG_DIR.join(SAMPLE_OPTS_FILE_NAME)
38
41
  # 変換先Dbsetupクラス定義のRubyスクリプトファイルへのパス
39
42
  DBSETUP_FILE = DB_SCHEME_DIR.join(DBSETUP_FILE_NAME)
40
43
  # 変換先optsファイル(Rubyスクリプトファイル)へのパス
@@ -54,24 +57,44 @@ module Arxutils_Sqlite3
54
57
 
55
58
  # DB構成ファイル格納ディレクトリの作成
56
59
  def make_config_directory
60
+ p "config make_config_directory"
57
61
  FileUtils.mkdir_p(CONFIG_DIR)
58
62
  end
59
63
 
60
- # DBスキームファイルのひな型コピー
64
+ # DBスキームファイルのサンプルファイルコピー
61
65
  def setup_db_scheme_file
62
- FileUtils.cp(DB_SCHEME_FILE, DEST_DB_SCHEME_FILE)
66
+ p "config setup_db_scheme_file"
67
+ p "DB_SCHEME_FILE=#{DB_SCHEME_FILE}"
68
+ p "SAMPLE_DB_SCHEME_FILE=#{SAMPLE_DB_SCHEME_FILE}"
69
+ FileUtils.cp(DB_SCHEME_FILE, SAMPLE_DB_SCHEME_FILE)
63
70
  end
64
71
 
65
- # optsファイル(Rubyスクリプトファイル)のrequire
72
+ # DBスキームファイルが存在しなければ、サンプルファイルをDBスキームファイルとしてコピー
73
+ def copy_db_scheme_file
74
+ if !File.exist?(DEST_DB_SCHEME_FILE)
75
+ FileUtils.cp(SAMPLE_DB_SCHEME_FILE, DEST_DB_SCHEME_FILE)
76
+ end
77
+ end
78
+
79
+ # optsファイル(Rubyスクリプトファイル)のサンプルファイル書き込み
66
80
  def setup_opts_file(klass)
67
81
  scope = Object.new
68
82
  hash = {klass: klass}
69
83
  result_content = Ykutils::Erubyx.erubi_render_with_template_file(OPTS_FILE, scope, hash)
70
- File.open(DEST_OPTS_FILE, "w"){|file|
84
+ File.open(SAMPLE_OPTS_FILE, "w"){|file|
71
85
  file.write(result_content)
72
86
  }
73
87
  end
74
88
 
89
+ # optsファイルが存在しなければ、サンプルファイルをoptsファイルとしてコピー
90
+ def copy_opts_file
91
+ if !File.exist?(DEST_OPTS_FILE)
92
+ p "exist? #{File.exist?(DEST_OPTS_FILE)}"
93
+ p "copy SAMPLE_OPTS_FILE(#{SAMPLE_OPTS_FILE}) to DEST_OPTS_FILE(#{DEST_OPTS_FILE})"
94
+ FileUtils.cp(SAMPLE_OPTS_FILE, DEST_OPTS_FILE)
95
+ end
96
+ end
97
+
75
98
  # setting.ymlへの出力
76
99
  def setup_setting_yaml_file(klass)
77
100
  hash = { "klass": klass }
@@ -94,7 +117,7 @@ module Arxutils_Sqlite3
94
117
  begin
95
118
  require opts_file
96
119
  rescue LoadError => ex
97
- pp ex.message
120
+ #pp ex.message
98
121
  end
99
122
  end
100
123
  end
@@ -116,7 +139,7 @@ module Arxutils_Sqlite3
116
139
  begin
117
140
  require dbsetup_file
118
141
  rescue LoadError => ex
119
- pp ex.message
142
+ # pp ex.message
120
143
  end
121
144
  end
122
145
 
@@ -158,8 +181,8 @@ module Arxutils_Sqlite3
158
181
  end
159
182
 
160
183
  # リレーションテンプレートディレクトリへのパス
161
- def get_template_relation_dir
162
- TEMPLATE_RELATION_DIR
184
+ def get_template_acrecord_dir
185
+ TEMPLATE_ACRECORD_DIR
163
186
  end
164
187
 
165
188
  # テンプレートディレクトリへのパス
@@ -202,38 +225,40 @@ module Arxutils_Sqlite3
202
225
  end
203
226
 
204
227
  # migrate用スクリプトの生成
205
- def make_migrate_script(db_scheme_ary, dbconfig_path, dbconfig, relation)
206
- mig = Arxutils_Sqlite3::Util.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, relation)
207
- # マイグレーション用スクリプトの生成、relationのクラス定義ファイルの生成
228
+ def make_migrate_script(db_scheme_ary, dbconfig_path, dbconfig, acrecord)
229
+ mig = Arxutils_Sqlite3::Util.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, acrecord)
230
+ # マイグレーション用スクリプトの生成、acrecordのクラス定義ファイルの生成
208
231
  mig.output
209
232
  end
210
233
 
211
234
  # migrateの準備
212
- def prepare_for_migrate(db_scheme_ary, dbconfig_dest_path, dbconfig, relation)
235
+ def prepare_for_migrate(db_scheme_ary, dbconfig_dest_path, dbconfig, acrecord)
213
236
  #db_dir = config.DB_DIR
214
237
  db_dir = get_db_dir
215
- migrate_dir = get_migrate_dir
216
238
  # DB構成ファイルの出力先ディレクトリ
217
239
  dbconfig_src_fname = "#{dbconfig}.tmpl"
240
+ # migrate用スクリプトの出力先ディレクトリ名
241
+ migrate_dir = get_migrate_dir
242
+
218
243
  mig = Migrate.new(
219
244
  self,
220
245
  dbconfig_dest_path,
221
246
  dbconfig_src_fname,
222
247
  db_scheme_ary,
223
- relation
224
- )
248
+ acrecord,
249
+ migrate_dir
250
+ )
225
251
  end
226
252
 
227
- def make_dbsetup_file(db_scheme_ary, relation, klass, dest_dbsetup_file)
253
+ def make_dbsetup_file(db_scheme_ary, acrecord, klass, dest_dbsetup_file)
228
254
  src_dbsetup_file = get_src_dbsetup_file
229
255
 
230
256
  scope = Object.new
231
- hash0 = {module_name: relation[:module].join("::")}
257
+ hash0 = {module_name: acrecord[:module].join("::")}
232
258
  hash = db_scheme_ary[0].merge( hash0 )
233
259
  hash["klass"] = klass
234
260
  result_content = Ykutils::Erubyx.erubi_render_with_template_file(src_dbsetup_file, scope, hash)
235
261
 
236
- #p "################ dest_dbsetup_file=#{dest_dbsetup_file}"
237
262
  File.open(dest_dbsetup_file, "w"){|file|
238
263
  file.write(result_content)
239
264
  }
@@ -23,7 +23,8 @@ module Arxutils_Sqlite3
23
23
  dbconfig_dest_path,
24
24
  dbconfig_src_fname,
25
25
  db_scheme_ary,
26
- relation_config
26
+ acrecord_config,
27
+ migrate_dir
27
28
  )
28
29
  # DB格納ディレクトリ名
29
30
  @db_dir = config.get_db_dir
@@ -34,18 +35,16 @@ module Arxutils_Sqlite3
34
35
  # 参照用DB構成情報ファイル名
35
36
  @dbconfig_src_fname = dbconfig_src_fname
36
37
 
37
- # migrate用スクリプトの出力先ディレクトリ名
38
- @migrate_dir = config.get_migrate_dir
39
38
  # テンプレートファイル格納ディレクトリ名
40
- @src_path = config.get_template_relation_dir
41
- #@src_path = Arxutils_Sqlite3::TEMPLATE_RELATION_DIR
39
+ @src_path = config.get_template_acrecord_dir
42
40
  # 構成ファイル格納ディレクトリ
43
41
  @src_config_path = config.get_template_config_dir
44
42
  # @src_config_path = Arxutils_Sqlite3::TEMPLATE_CONFIG_DIR
45
43
  # データベーススキーマ定義配列
46
44
  @db_scheme_ary = db_scheme_ary
47
45
  # リレーション指定
48
- @relation_config = relation_config
46
+ @acrecord_config = acrecord_config
47
+ @migrate_dir = migrate_dir
49
48
 
50
49
  FileUtils.mkdir_p(@db_dir) if @db_dir
51
50
  FileUtils.mkdir_p(@migrate_dir) if @migrate_dir
@@ -89,12 +88,12 @@ module Arxutils_Sqlite3
89
88
  end
90
89
  end
91
90
 
92
- # マイグレーション用スクリプトの生成、relationのクラス定義ファイルの生成
91
+ # マイグレーション用スクリプトの生成、acrecordのクラス定義ファイルの生成
93
92
  def output
94
93
  # migrationのスクリプトをファイル出力する
95
94
  output_all_script
96
95
 
97
- # relationを表すクラス定義のファイルの内容を生成
96
+ # acrecordを表すクラス定義のファイルの内容を生成
98
97
  content_array = make_content_array
99
98
  # p "content_array=#{content_array}"
100
99
  # 複数形のクラス名を集める
@@ -102,7 +101,7 @@ module Arxutils_Sqlite3
102
101
  x[:need_count_class_plural].nil?
103
102
  end
104
103
  need_count_class_plural = count_class_plurals.map { |x| x[:need_count_class_plural] }
105
- # relationのmigrateが必要であれば、それをテンプレートファイルから作成して、スクリプトの内容として追加する
104
+ # acrecordのmigrateが必要であれば、それをテンプレートファイルから作成して、スクリプトの内容として追加する
106
105
  if content_array.find { |x| !x.nil? }
107
106
  # p "####### 1"
108
107
  data_count = {
@@ -111,12 +110,12 @@ module Arxutils_Sqlite3
111
110
  }
112
111
  # p "data_count=#{data_count}"
113
112
  ary = content_array.collect { |x| x[:content] }.flatten
114
- count_content = convert_count_class_relation(data_count, "relation_count.tmpl")
113
+ count_content = convert_count_class_acrecord(data_count, "acrecord_count.tmpl")
115
114
  ary.unshift(count_content)
116
115
  content_array = ary
117
116
  end
118
- # relationのスクリプトを作成
119
- output_relation_script(content_array, @relation_config)
117
+ # acrecordのスクリプトを作成
118
+ output_acrecord_script(content_array, @acrecord_config)
120
119
  end
121
120
 
122
121
  # migrationのスクリプトをファイル出力する
@@ -128,17 +127,17 @@ module Arxutils_Sqlite3
128
127
  end
129
128
  end
130
129
 
131
- # relationを表すクラス定義のファイルの内容を生成
130
+ # acrecordを表すクラス定義のファイルの内容を生成
132
131
  def make_content_array
133
- # スキーマ設定配列から、relationのmigrate用のスクリプトの内容(ハッシュ形式)の配列を作成する
134
- relations = @db_scheme_ary.map do |x|
135
- make_relation(x, "count")
132
+ # スキーマ設定配列から、acrecordのmigrate用のスクリプトの内容(ハッシュ形式)の配列を作成する
133
+ acrecords = @db_scheme_ary.map do |x|
134
+ make_acrecord(x, "count")
136
135
  end
137
- relations.select { |x| x.size.positive? }
136
+ acrecords.select { |x| x.size.positive? }
138
137
  end
139
138
 
140
- # Countクラス用のrelationのスクリプトの内容に変換
141
- def convert_count_class_relation(data, src_fname)
139
+ # Countクラス用のacrecordのスクリプトの内容に変換
140
+ def convert_count_class_acrecord(data, src_fname)
142
141
  convert(data, @src_path, src_fname)
143
142
  end
144
143
 
@@ -158,23 +157,23 @@ module Arxutils_Sqlite3
158
157
  end
159
158
  end
160
159
 
161
- # 英子文字で表現したクラス名が、countを表していなければ、relation
160
+ # 英子文字で表現したクラス名が、countを表していなければ、acrecord
162
161
  # 英子文字で表現したクラス名が、countを表していれが、空のハッシュを返す
163
- # スキーマでbase, noitem以外のフィールドが指定されていれば、そのフィールドに対するrelationの設定の内容を返す
164
- def make_relation(data, count_classname_downcase)
162
+ # スキーマでbase, noitem以外のフィールドが指定されていれば、そのフィールドに対するacrecordの設定の内容を返す
163
+ def make_acrecord(data, count_classname_downcase)
165
164
  if data[:classname_downcase] == count_classname_downcase
166
165
  {}
167
166
  else
168
- # 指定フィールドのフィールド名に対応したテンプレートファイルを用いて、relation設定を作成
167
+ # 指定フィールドのフィールド名に対応したテンプレートファイルを用いて、acrecord設定を作成
169
168
  data[:flist].each_with_object({ content: [], need_count_class: nil }) do |field_name, s|
170
169
  case field_name
171
170
  when "base", "noitem"
172
- name_base = "relation"
173
- # data[:relation]がnilに設定されていたら改めて空の配列を設定
174
- data[:relation] = [] unless data[:relation]
171
+ name_base = "acrecord"
172
+ # data[:acrecord]がnilに設定されていたら改めて空の配列を設定
173
+ data[:acrecord] = [] unless data[:acrecord]
175
174
  else
176
175
  data[:count_classname_downcase] = count_classname_downcase
177
- name_base = "relation_#{field_name}"
176
+ name_base = "acrecord_#{field_name}"
178
177
  s[:need_count_class_plural] ||= data[:plural]
179
178
  end
180
179
  # テンプレートファイルからスクリプトの内容を作成
@@ -209,18 +208,18 @@ module Arxutils_Sqlite3
209
208
  end
210
209
  end
211
210
 
212
- # relationのスクリプトをファイル出力する
213
- def output_relation_script(content_array, relation_config)
214
- dir = relation_config[:dir]
215
- fname = relation_config[:filename]
211
+ # acrecordのスクリプトをファイル出力する
212
+ def output_acrecord_script(content_array, acrecord_config)
213
+ dir = acrecord_config[:dir]
214
+ fname = acrecord_config[:filename]
216
215
  fpath = File.join(dir, fname)
217
216
  File.open(fpath, "w") do |file|
218
- relation_config[:module].map { |mod| file.puts("module #{mod}") }
217
+ acrecord_config[:module].map { |mod| file.puts("module #{mod}") }
219
218
  content_array.map do |x|
220
219
  file.puts x
221
220
  file.puts ""
222
221
  end
223
- relation_config[:module].map { |_mod| file.puts("end") }
222
+ acrecord_config[:module].map { |_mod| file.puts("end") }
224
223
  end
225
224
  end
226
225
  end
@@ -1,4 +1,4 @@
1
1
  module Arxutils_Sqlite3
2
2
  # バージョン番号
3
- VERSION = "0.1.47".freeze
3
+ VERSION = "0.1.49".freeze
4
4
  end
@@ -16,11 +16,12 @@ end
16
16
 
17
17
  require_relative "arxutils_sqlite3/dbutil"
18
18
  require_relative "arxutils_sqlite3/config"
19
+ require_relative "arxutils_sqlite3/cli"
19
20
 
20
21
  require_relative "arxutils_sqlite3/version"
21
22
  require_relative "arxutils_sqlite3/arx"
22
23
  require_relative "arxutils_sqlite3/transactstate"
23
24
  require_relative "arxutils_sqlite3/hier"
24
25
  require_relative "arxutils_sqlite3/migrate"
25
- require_relative "arxutils_sqlite3/migrate"
26
26
  require_relative "arxutils_sqlite3/util"
27
+ require_relative "dbacrecord"
data/lib/dbacrecord.rb ADDED
@@ -0,0 +1,26 @@
1
+ module Enop
2
+ module Dbutil
3
+ class Count < ActiveRecord::Base
4
+ has_many :invalidennblists
5
+ end
6
+
7
+ class Countdatetime < ActiveRecord::Base
8
+ end
9
+
10
+ class Evnb < ActiveRecord::Base
11
+ end
12
+
13
+ class Ennblist < ActiveRecord::Base
14
+ end
15
+
16
+ class Invalidennblist < ActiveRecord::Base
17
+ belongs_to :ennblist , foreign_key: 'org_id'
18
+ belongs_to :count , foreign_key: ''
19
+ end
20
+
21
+ class Currentennblist < ActiveRecord::Base
22
+ belongs_to :ennblist , foreign_key: 'org_id'
23
+ end
24
+
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  class <%= @data[:classname] %> < ActiveRecord::Base
2
- <% @data[:relation].each do |x| %> <%= x %>
2
+ <% @data[:acrecord].each do |x| %> <%= x %>
3
3
  <% end %> end
File without changes
File without changes
@@ -0,0 +1,48 @@
1
+ ---
2
+ - :flist:
3
+ - noitem
4
+ :classname: Countdatetime
5
+ :classname_downcase: countdatetime
6
+ :items:
7
+ - - countdatetime
8
+ - datetime
9
+ - 'false'
10
+ :plural: countdatetimes
11
+ :ar_version: 6.0
12
+ - :flist:
13
+ - noitem
14
+ :classname: Evnb
15
+ :classname_downcase: evnb
16
+ :items:
17
+ - - time_id
18
+ - integer
19
+ - 'false'
20
+ - - ennb_id
21
+ - integer
22
+ - 'false'
23
+ :plural: evnbs
24
+ :ar_version: 6.0
25
+ - :flist:
26
+ - noitem
27
+ - invalid
28
+ - current
29
+ :classname: Ennblist
30
+ :classname_downcase: ennblist
31
+ :items:
32
+ - - stack
33
+ - string
34
+ - 'false'
35
+ - - notebook
36
+ - string
37
+ - 'false'
38
+ - - count
39
+ - integer
40
+ - 'false'
41
+ - - tag_count
42
+ - integer
43
+ - 'false'
44
+ - - start_datetime
45
+ - datetime
46
+ - 'false'
47
+ :plural: ennblists
48
+ :ar_version: 6.0
@@ -0,0 +1,7 @@
1
+ @opts = {
2
+ acrecord: {
3
+ module: %w[<%= klass %> Dbutil],
4
+ filename: "dbacrecord.rb",
5
+ dir: "lib"
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ @opts = {
2
+ acrecord: {
3
+ module: %w[Enop Dbutil],
4
+ filename: "dbacrecord.rb",
5
+ dir: "lib"
6
+ }
7
+ }
File without changes
File without changes
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.47
4
+ version: 0.1.49
5
5
  platform: ruby
6
6
  authors:
7
7
  - yasuo kominami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-13 00:00:00.000000000 Z
11
+ date: 2022-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -109,47 +109,47 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: rake
112
+ name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '3.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: '3.0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: rspec
126
+ name: rake
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: '13.0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
138
+ version: '13.0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rubocop
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: '1.7'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0'
152
+ version: '1.7'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rubocop-rake
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -217,6 +217,7 @@ files:
217
217
  - exe/arxutils_sqlite3
218
218
  - lib/arxutils_sqlite3.rb
219
219
  - lib/arxutils_sqlite3/arx.rb
220
+ - lib/arxutils_sqlite3/cli.rb
220
221
  - lib/arxutils_sqlite3/config.rb
221
222
  - lib/arxutils_sqlite3/dbutil.rb
222
223
  - lib/arxutils_sqlite3/dbutil/dbconnect.rb
@@ -225,19 +226,22 @@ files:
225
226
  - lib/arxutils_sqlite3/transactstate.rb
226
227
  - lib/arxutils_sqlite3/util.rb
227
228
  - lib/arxutils_sqlite3/version.rb
229
+ - lib/dbacrecord.rb
230
+ - lib/template/acrecord/acrecord.tmpl
231
+ - lib/template/acrecord/acrecord_count.tmpl
232
+ - lib/template/acrecord/acrecord_current.tmpl
233
+ - lib/template/acrecord/acrecord_invalid.tmpl
234
+ - lib/template/acrecord/base.tmpl
235
+ - lib/template/acrecord/current.tmpl
236
+ - lib/template/acrecord/db_scheme/db_scheme.yml
237
+ - lib/template/acrecord/db_scheme/db_scheme.yml.sample
238
+ - lib/template/acrecord/db_scheme/dbsetup.rb
239
+ - lib/template/acrecord/db_scheme/opts.rb
240
+ - lib/template/acrecord/db_scheme/opts.rb.sample
241
+ - lib/template/acrecord/invalid.tmpl
242
+ - lib/template/acrecord/noitem.tmpl
228
243
  - lib/template/config/mysql.tmpl
229
244
  - lib/template/config/sqlite3.tmpl
230
- - lib/template/relation/base.tmpl
231
- - lib/template/relation/current.tmpl
232
- - lib/template/relation/db_scheme/db_scheme.yml
233
- - lib/template/relation/db_scheme/dbsetup.rb
234
- - lib/template/relation/db_scheme/opts.rb
235
- - lib/template/relation/invalid.tmpl
236
- - lib/template/relation/noitem.tmpl
237
- - lib/template/relation/relation.tmpl
238
- - lib/template/relation/relation_count.tmpl
239
- - lib/template/relation/relation_current.tmpl
240
- - lib/template/relation/relation_invalid.tmpl
241
245
  homepage: https://ykominami.github.io/arxutils_sqlite3/
242
246
  licenses:
243
247
  - MIT
@@ -1,8 +0,0 @@
1
- @opts = {
2
- db_dir: Arxutils_Sqlite3::Config::DB_DIR,
3
- relation: {
4
- module: %w[<%= klass %> Dbutil],
5
- filename: "dbrelation.rb",
6
- dir: "lib"
7
- }
8
- }