arxutils_sqlite3 0.1.44 → 0.1.48

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: 3b5f6ede0a6841ea546179192fe18757e9f35669baae096b5c7f0ed9ec79c687
4
- data.tar.gz: 592da7e2edf26c4e4a41e7d9d1ed74ebf67ffdb7dddc6e2a2732f3643a545570
3
+ metadata.gz: 68d6c8715c3a6aa14cd2d32e85d6757831555b23b5b1241417b01bf6d2527e91
4
+ data.tar.gz: 97612549672e709093582b1ccc1145cf4f5390c8fb9c17101f7c3e8e4e060db2
5
5
  SHA512:
6
- metadata.gz: 3ade5c9990a6c5553a71b62adda473541415bdba26b1c6c7162d2d588e66750d9ebe80367c8efa7bbccff064aa4410a18138fc254a571f14ea27ca2e07b03096
7
- data.tar.gz: aedfc8af290c382f5cd2eb4c67dde8b94ef533de95ee5607236a480c0cf0443a1f5a249258efaefdc35193f681f44ab6ce9502232ba388967c85a0eb6e8bd615
6
+ metadata.gz: 2b0adfce62098bfe191391da978f3a3e7387201bc3161a46359165f694744a70730ff8b92b4b9ee8748ee46b7ecabc2b81e88718b15fae29ed0ed0db7638a745
7
+ data.tar.gz: 22b7ffc62b39e1b7b227f8298ee1d1da3ed72cbc52358364657a27578cbfd50cc6f0bdbd8393931405f4574d7d1667c15ca79f24ab6fccf522531f335f504361
data/Gemfile CHANGED
@@ -20,7 +20,7 @@ gem "activesupport"
20
20
  gem "activerecord", "~> 6.1"
21
21
  gem "sqlite3"
22
22
  # spec.add_runtime_dependency "mysql2" , "~> 0.4.1"
23
- gem "encx"
23
+ #gem "encx"
24
24
 
25
25
  # spec.add_development_dependency "bundler", "~> 2.2.10"
26
26
  gem "rake", "~> 13.0"
data/Rakefile CHANGED
@@ -10,16 +10,39 @@ desc "Run test"
10
10
  task default: :test
11
11
  =end
12
12
 
13
- #=begin
14
- task default: %w[setup makeconfig migrate integrate]
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]
15
15
 
16
- task cmi: %w[makeconfig migrate integrate]
16
+ task scmi: %w[setup makeconfig migrate integrate]
17
+
18
+ task dsc: %w[delete setup makeconfig]
19
+
20
+ task ds: %w[delete setup]
21
+
22
+ task s: %w[setup]
23
+
24
+ task sc: %w[setup makeconfig]
25
+
26
+ task dscm: %w[delete setup makeconfig migrate]
27
+
28
+ task scm: %w[setup makeconfig migrate]
29
+
30
+ task dscmi: %w[delete setup makeconfig migrate integrate]
31
+
32
+ task scmi: %w[setup makeconfig migrate integrate]
33
+
34
+ task mi: %w[migrate integrate]
35
+
36
+ task bmi: %w[delete_db migrate integrate]
37
+
38
+ task b: %w[delete_db]
17
39
 
18
40
  # コマンドラインで指定したクラス名を含むオプション指定用ハッシュの定義を含むRubyスクリ
19
41
  # プトファイルの生成
20
42
  task :setup do
21
43
  sh "bundle exec arxutils_sqlite3 --cmd=s --klass=Enop"
22
44
  end
45
+
23
46
  # DB構成情報の生成
24
47
  task :makeconfig do
25
48
  sh "bundle exec arxutils_sqlite3 --cmd=c"
@@ -28,6 +51,7 @@ end
28
51
  task :migrate do
29
52
  sh "bundle exec arxutils_sqlite3 --cmd=m --yaml=config/db_scheme.yml"
30
53
  end
54
+
31
55
  task :integrate do
32
56
  sh "bundle exec arxutils_sqlite3 --cmd=i"
33
57
  end
@@ -36,5 +60,8 @@ task :delete do
36
60
  sh "bundle exec arxutils_sqlite3 --cmd=d"
37
61
  end
38
62
 
39
- #=end
63
+ task :delete_db do
64
+ sh "bundle exec arxutils_sqlite3 --cmd=b"
65
+ end
66
+
40
67
 
@@ -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
@@ -6,14 +6,11 @@ require "pp"
6
6
  require "ykutils"
7
7
  require "ykxutils"
8
8
 
9
- if File.exist?(Arxutils_Sqlite3::DEST_OPTS_FILE)
10
- opts_file = File.join("./" , Arxutils_Sqlite3::DEST_OPTS_FILE_2.to_s)
11
- begin
12
- require opts_file
13
- rescue LoadError => ex
14
- pp ex.message
15
- end
16
- end
9
+ config = Arxutils_Sqlite3::Config.new
10
+
11
+ cli = Arxutils_Sqlite3::Cli.new(config)
12
+
13
+ config.require_opts_file
17
14
 
18
15
  begin
19
16
  require "dbrelation"
@@ -21,120 +18,72 @@ rescue LoadError => ex
21
18
  pp ex.message
22
19
  end
23
20
 
21
+
22
+ klass = nil
23
+ setting = config.load_setting_yaml_file
24
+ klass = setting[:klass]
25
+
24
26
  # DBセットアップクラス
25
- if File.exist?(Arxutils_Sqlite3::DEST_DBSETUP_FILE)
26
- dbsetup_file = File.join("./" , Arxutils_Sqlite3::DEST_DBSETUP_FILE_2.to_s)
27
- begin
28
- require dbsetup_file
29
- rescue LoadError => ex
30
- pp ex.message
31
- end
32
- end
27
+ config.require_dbsetup_file
33
28
 
34
- banner = "Usage: bundle exec ruby exe/makemigrate --cmd=(s|c|m|i|d) -y yaml_file --klass=class"
29
+ banner = "Usage: bundle exec arxutils_sqlite3 --cmd=(s|c|m|i|d|b) -y yaml_file --klass=class"
35
30
 
36
31
  opts = @opts ? @opts : {}
37
-
38
- opts["dbconfig"] = Arxutils_Sqlite3::Dbutil::DBCONFIG_SQLITE3
32
+ opts["dbconfig"] = Arxutils_Sqlite3::Config::DBCONFIG_SQLITE3
39
33
 
40
34
  Simpleoptparse::Simpleoptparse.parse(ARGV, opts, banner, Arxutils_Sqlite3::VERSION, nil) do |parser|
41
- parser.on("--cmd X", %w[s c m i d]) { |x| opts["cmd"] = x }
35
+ parser.on("--cmd X", %w[s c m i d b]) { |x| opts["cmd"] = x }
42
36
  parser.on("-y yaml_file", "--yaml yaml_file") { |x| opts["yaml"] = x }
43
37
  parser.on("--klass klass") { |x| opts["klass"] = x }
44
38
  end
39
+ klass = opts["klass"] if opts["klass"]
45
40
 
46
41
  env = ENV.fetch("ENV", nil)
47
42
  env ||= "production"
48
43
 
49
44
  case opts["cmd"]
50
45
  when "s"
51
- FileUtils.cp(Arxutils_Sqlite3::DB_SCHEME_FILE, Arxutils_Sqlite3::Dbutil::CONFIG_DIR )
46
+ config.check_file_exist(Arxutils_Sqlite3::Config::DEST_OPTS_FILE, banner, 10)
47
+
52
48
  if opts["klass"].nil? || opts["klass"].strip == ""
53
49
  puts banner
54
- exit 10
50
+ exit 20
55
51
  end
56
-
57
- scope = Object.new
58
- hash = {klass: opts["klass"]}
59
- result_content = Ykutils::Erubyx.erubi_render_with_template_file(Arxutils_Sqlite3::OPTS_FILE, scope, hash)
60
-
61
- File.open(Arxutils_Sqlite3::DEST_OPTS_FILE, "w"){|file|
62
- file.write(result_content)
63
- }
64
- db_scheme_ary = nil
52
+ cli.setup(klass)
65
53
 
66
54
  when "c"
67
- db_scheme_ary = nil
68
- db_dir = Arxutils_Sqlite3::Dbutil::DB_DIR
69
- config_dir = Arxutils_Sqlite3::Dbutil::CONFIG_DIR
70
- # DB構成ファイル名
71
- dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, opts["dbconfig"])
72
-
73
- mig = Arxutils_Sqlite3::Util.prepare_for_migrate(env, db_scheme_ary, db_dir, dbconfig_path, opts)
74
- mig.make_dbconfig(opts)
55
+ dbconfig = opts["dbconfig"]
56
+ relation = opts["relation"]
57
+ cli.makeconfig(dbconfig, relation, banner, 30, opts)
75
58
 
76
59
  when "m"
77
- if opts["yaml"].nil? || opts["yaml"].strip == ""
60
+ yaml_fname = opts["yaml"]
61
+ relation = opts[:relation]
62
+ dbconfig = opts["dbconfig"]
63
+ if yaml_fname.nil? || yaml_fname.strip == ""
78
64
  puts banner
79
- exit 20
65
+ exit 40
80
66
  end
67
+ yaml_pn = Pathname.new(yaml_fname)
68
+ config.check_file_not_exist(yaml_pn, banner, 55)
81
69
 
82
- opts["migrate_cmd"] = "migrate"
83
- db_scheme_ary = YAML.load_file( opts["yaml"] )
84
-
85
- scope = Object.new
86
-
87
- hash0 = {module_name: opts[:relation][:module].join("::")}
88
- hash = db_scheme_ary[0].merge( hash0 )
89
- result_content = Ykutils::Erubyx.erubi_render_with_template_file(Arxutils_Sqlite3::DBSETUP_FILE, scope, hash)
90
-
91
- File.open(Arxutils_Sqlite3::DEST_DBSETUP_FILE, "w"){|file|
92
- file.write(result_content)
93
- }
94
- db_dir = Arxutils_Sqlite3::Dbutil::DB_DIR
95
-
96
- config_dir = Arxutils_Sqlite3::Dbutil::CONFIG_DIR
97
- # DB構成ファイル名
98
- dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, opts["dbconfig"])
99
- # DBログファイルへのパス
100
- log_path = Arxutils_Sqlite3::Util.make_log_path(db_dir, opts["dbconfig"])
101
- mig = Arxutils_Sqlite3::Util.prepare_for_migrate(env, db_scheme_ary, db_dir, dbconfig_path, opts)
102
- mig.process
103
- dbconnect = Arxutils_Sqlite3::Dbutil::Dbconnect.new(
104
- dbconfig_path,
105
- env,
106
- log_path
107
- )
108
- connect_time = dbconnect.connect
109
- #p "connect_time=#{connect_time}"
110
- ActiveRecord::MigrationContext.new(mig.migrate_dir, ActiveRecord::SchemaMigration).up
70
+ cli.migrate(yaml_pn, relation, klass, dbconfig, env)
111
71
 
112
72
  when "i"
113
- #db_scheme_ary = YAML.load_file( opts["yaml"] )
114
- db_scheme_ary = nil
115
- db_dir = Arxutils_Sqlite3::Dbutil::DB_DIR
116
-
117
- config_dir = Arxutils_Sqlite3::Dbutil::CONFIG_DIR
118
- # DB構成ファイルへのパス
119
- dbconfig_dest_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, opts["dbconfig"])
120
- # DBログファイルへのパス
121
- log_path = Arxutils_Sqlite3::Util.make_log_path(db_dir, opts["dbconfig"])
122
- dbconnect = Arxutils_Sqlite3::Dbutil::Dbconnect.new(
123
- dbconfig_dest_path,
124
- env,
125
- log_path
126
- )
127
- connect_time = dbconnect.connect
128
-
129
- Dbsetup.new(connect_time)
73
+ dbconfig = opts["dbconfig"]
74
+ cli.integrate(dbconfig, env)
130
75
 
131
76
  when "d"
132
77
  db_scheme_ary = nil
133
- mig = Arxutils_Sqlite3::Util.repare_for_migrate(env, db_scheme_ary, opts)
134
- mig.delete_migrate_config_and_db
78
+ dbconfig = opts["dbconfig"]
79
+ relation = opts["relation"]
80
+ cli.delete(dbconfig, db_scheme_ary, relation)
135
81
 
82
+ when "b"
83
+ db_scheme_ary = nil
84
+ dbconfig = opts["dbconfig"]
85
+ relation = opts["relation"]
86
+ cli.delete_db(dbconfig, db_scheme_ary, relation)
136
87
  else
137
88
  puts "Invalid command(#{opts["cmd"]}) specified!!"
138
89
  end
139
- #
140
-
@@ -1,5 +1,6 @@
1
1
  require "erb"
2
2
  require "ykutils"
3
+
3
4
  module Arxutils_Sqlite3
4
5
  # スキーマ設定に基づき、テンプレートから変換する
5
6
  class Arx
@@ -0,0 +1,67 @@
1
+ module Arxutils_Sqlite3
2
+ # CLI用クラス
3
+ class Cli
4
+ def initialize(config)
5
+ @config = config
6
+ end
7
+
8
+ def setup(klass)
9
+ @config.make_config_directory
10
+ @config.setup_db_scheme_file
11
+ @config.setup_opts_file(klass)
12
+ @config.setup_setting_yaml_file(klass)
13
+ #db_scheme_ary = nil
14
+ end
15
+
16
+ def makeconfig(dbconfig, relation, banner, exit_code, opts)
17
+ db_scheme_ary = nil
18
+ dbconfig_path = @config.make_dbconfig_path(dbconfig)
19
+ @config.check_file_exist(dbconfig_path, banner, exit_code)
20
+ mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, relation)
21
+ mig.make_dbconfig(opts)
22
+ end
23
+
24
+ def migrate(yaml_pn, relation, klass, dbconfig, env)
25
+ db_scheme_ary = YAML.load_file( yaml_pn )
26
+ dbconfig_path = @config.make_dbconfig_path(dbconfig)
27
+
28
+ dest_dbsetup_file = @config.get_dest_dbsetup_file
29
+ @config.make_dbsetup_file(db_scheme_ary, relation, klass, dest_dbsetup_file)
30
+
31
+ connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(@config, dbconfig, env)
32
+
33
+ # マイグレーション用スクリプトの生成、relationのクラス定義ファイルの生成
34
+ mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, relation)
35
+ mig.output
36
+
37
+ # マイグレーション実行
38
+ ActiveRecord::MigrationContext.new(mig.migrate_dir, ActiveRecord::SchemaMigration).up
39
+ end
40
+
41
+ def integrate(dbconfig, env)
42
+ connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(@config, dbconfig, env)
43
+ Dbsetup.new(connect_time)
44
+ end
45
+
46
+ def delete(dbconfig, db_scheme_ary, relation)
47
+ config_dir = @config.get_config_dir
48
+ dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, dbconfig)
49
+ mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, relation)
50
+ mig.delete_migrate_and_config_and_db
51
+ end
52
+
53
+ def delete_db(dbconfig, db_scheme_ary, relation)
54
+ config_dir = config.get_config_dir
55
+ dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, dbconfig)
56
+ mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, relation)
57
+ # mig.delete_migrate_config_and_db
58
+ mig.delete_db
59
+ end
60
+
61
+ def rm_dbconfig(dbconfig)
62
+ dbconfig_path = @config.make_dbconfig_path(dbconfig)
63
+ p dbconfig_path
64
+ FileUtils.rm_f(dbconfig_path)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,242 @@
1
+ require "ykutils"
2
+
3
+ module Arxutils_Sqlite3
4
+ ##
5
+ # migrateに必要なファイルをテンプレートから作成し、migarteを実行する
6
+ class Config
7
+ # DB格納ディレクトリ名
8
+ DB_DIR = "db".freeze
9
+ # migrate用スクリプト格納ディレクトリ名
10
+ MIGRATE_BASE_DIR = "migrate".freeze
11
+ # SQLITE3用DB構成名
12
+ DBCONFIG_SQLITE3 = "sqlite3".freeze
13
+ # MYSQL用DB構成名
14
+ DBCONFIG_MYSQL = "mysql".freeze
15
+ # DB構成格納用ディレクトリ名
16
+ CONFIG_DIR_NAME = "config".freeze
17
+
18
+ # コンフィグディレクトリへのパス
19
+ CONFIG_DIR = Pathname.new(CONFIG_DIR_NAME)
20
+ # データベース用ログファイル名
21
+ DATABASELOG = "database.log".freeze
22
+ # テンプレートディレクトリへのパス
23
+ TEMPLATE_DIR = Arxutils_Sqlite3::TOP_DIR.join("template")
24
+ # リレーションテンプレートディレクトリへのパス
25
+ TEMPLATE_RELATION_DIR = TEMPLATE_DIR.join("relation")
26
+ TEMPLATE_CONFIG_DIR = TEMPLATE_DIR.join( CONFIG_DIR )
27
+ DB_SCHEME_DIR = TEMPLATE_RELATION_DIR.join("db_scheme")
28
+ DB_SCHEME_FILE = DB_SCHEME_DIR.join("db_scheme.yml")
29
+ DB_SCHEME_FILE_NAME = "db_scheme.yml".freeze
30
+ DB_SCHEME_FILE_NAME_2 = "db_scheme".freeze
31
+ OPTS_FILE_NAME = "opts.rb".freeze
32
+ OPTS_FILE_NAME_2 = "opts".freeze
33
+ DBSETUP_FILE_NAME = "dbsetup.rb".freeze
34
+ DBSETUP_FILE_NAME_2 = "dbsetup".freeze
35
+ SETTING_YAML_FILE_NAME = "setting.yml".freeze
36
+ DEST_CONFIG_DIR = Pathname.new( CONFIG_DIR )
37
+ OPTS_FILE = DB_SCHEME_DIR.join(OPTS_FILE_NAME)
38
+ # 変換先Dbsetupクラス定義のRubyスクリプトファイルへのパス
39
+ DBSETUP_FILE = DB_SCHEME_DIR.join(DBSETUP_FILE_NAME)
40
+ # 変換先optsファイル(Rubyスクリプトファイル)へのパス
41
+ DEST_OPTS_FILE = DEST_CONFIG_DIR.join(OPTS_FILE_NAME)
42
+ DEST_OPTS_FILE_2 = DEST_CONFIG_DIR.join(OPTS_FILE_NAME_2)
43
+ # 変換先Dbsetupクラス定義のRubyスクリプトファイルへのパス
44
+ DEST_DBSETUP_FILE = DEST_CONFIG_DIR.join(DBSETUP_FILE_NAME)
45
+ # 変換先Dbsetupクラス定義のRubyスクリプトファイル(拡張子無し)へのパス
46
+ DEST_DBSETUP_FILE_2 = DEST_CONFIG_DIR.join(DBSETUP_FILE_NAME_2)
47
+ DEST_DB_SCHEME_FILE = DEST_CONFIG_DIR.join(DB_SCHEME_FILE_NAME)
48
+ # 変換後DBスキームファイル(拡張子無し)へのパス
49
+ DEST_DB_SCHEME_FILE_2 = DEST_CONFIG_DIR.join(DB_SCHEME_FILE_NAME_2)
50
+ SETTING_YAML_FILE = CONFIG_DIR.join(SETTING_YAML_FILE_NAME)
51
+ DB_PN = Pathname.new(DB_DIR)
52
+ # migrateディレクトリへのパス
53
+ MIGRATE_DIR = DB_PN.join(MIGRATE_BASE_DIR)
54
+
55
+ # DB構成ファイル格納ディレクトリの作成
56
+ def make_config_directory
57
+ FileUtils.mkdir_p(CONFIG_DIR)
58
+ end
59
+
60
+ # DBスキームファイルのひな型コピー
61
+ def setup_db_scheme_file
62
+ FileUtils.cp(DB_SCHEME_FILE, DEST_DB_SCHEME_FILE)
63
+ end
64
+
65
+ # optsファイル(Rubyスクリプトファイル)のrequire
66
+ def setup_opts_file(klass)
67
+ scope = Object.new
68
+ hash = {klass: klass}
69
+ result_content = Ykutils::Erubyx.erubi_render_with_template_file(OPTS_FILE, scope, hash)
70
+ File.open(DEST_OPTS_FILE, "w"){|file|
71
+ file.write(result_content)
72
+ }
73
+ end
74
+
75
+ # setting.ymlへの出力
76
+ def setup_setting_yaml_file(klass)
77
+ hash = { "klass": klass }
78
+ content = YAML.dump(hash)
79
+ File.open(SETTING_YAML_FILE, "w"){|file|
80
+ file.write(content)
81
+ }
82
+ end
83
+
84
+ # DB構成ファイルの作成
85
+ def make_dbconfig_path(dbconfig)
86
+ # DB構成ファイル名
87
+ Arxutils_Sqlite3::Util.make_dbconfig_path(CONFIG_DIR, dbconfig)
88
+ end
89
+
90
+ # optsファイル(Rubyスクリプトファイル)のrequire
91
+ def require_opts_file
92
+ if DEST_OPTS_FILE.exist?
93
+ opts_file = File.join("./" , DEST_OPTS_FILE_2.to_s)
94
+ begin
95
+ require opts_file
96
+ rescue LoadError => ex
97
+ pp ex.message
98
+ end
99
+ end
100
+ end
101
+
102
+ # setting.ymlのロード
103
+ def load_setting_yaml_file
104
+ setting = {}
105
+ # settingファイル
106
+ setting_yaml_file = SETTING_YAML_FILE
107
+ if setting_yaml_file.exist?
108
+ setting = YAML.load_file( setting_yaml_file )
109
+ end
110
+ setting
111
+ end
112
+
113
+ # Dbsetupファイル(Rubyスクリプトファイル)のrequire
114
+ def require_dbsetup_file
115
+ dbsetup_file = File.join(".", get_dest_dbsetup_file_2.to_s)
116
+ begin
117
+ require dbsetup_file
118
+ rescue LoadError => ex
119
+ pp ex.message
120
+ end
121
+ end
122
+
123
+ # 指定ファイルの存在確認
124
+ def check_file_exist(file_pn, banner, exit_code)
125
+ if file_pn.exist?
126
+ puts "#{file_pn} exists!"
127
+ puts banner
128
+ exit exit_code
129
+ end
130
+ end
131
+
132
+ # 指定ファイルの非存在確認
133
+ def check_file_not_exist(file_pn, banner, exit_code)
134
+ if !file_pn.exist?
135
+ puts "#{file_pn} does not exists!"
136
+ puts banner
137
+ exit exit_code
138
+ end
139
+ end
140
+
141
+ # 変換先optsファイル(Rubyスクリプトファイル)へのパス
142
+ def get_dest_opts_file
143
+ DEST_OPTS_FILE
144
+ end
145
+
146
+ # DB格納ディレクトリ名
147
+ def get_db_dir
148
+ DB_DIR
149
+ end
150
+
151
+ # migrateディレクトリへのパス
152
+ def get_migrate_dir
153
+ MIGRATE_DIR
154
+ end
155
+ # コンフィグディレクトリへのパス
156
+ def get_config_dir
157
+ CONFIG_DIR
158
+ end
159
+
160
+ # リレーションテンプレートディレクトリへのパス
161
+ def get_template_relation_dir
162
+ TEMPLATE_RELATION_DIR
163
+ end
164
+
165
+ # テンプレートディレクトリへのパス
166
+ def get_template_config_dir
167
+ TEMPLATE_CONFIG_DIR
168
+ end
169
+
170
+ # 変換先Dbsetupクラス定義のRubyスクリプトファイルへのパス
171
+ def get_src_dbsetup_file
172
+ DBSETUP_FILE
173
+ end
174
+
175
+ # 変換先Dbsetupクラス定義のRubyスクリプトファイルへのパス
176
+ def get_dest_dbsetup_file
177
+ DEST_DBSETUP_FILE
178
+ end
179
+
180
+ # 変換先Dbsetupクラス定義のRubyスクリプトファイル(拡張子無し)へのパス
181
+ def get_dest_dbsetup_file_2
182
+ DEST_DBSETUP_FILE_2
183
+ end
184
+
185
+ # 変換後DBスキームファイル名(拡張子無し)
186
+ def get_dest_db_scheme_file
187
+ DEST_DB_SCHEME_FILE_2
188
+ end
189
+
190
+ # DBログファイルの作成
191
+ def setup_for_db_log_path(dbconfig)
192
+ db_dir = get_db_dir
193
+ # DBログファイルへのパス
194
+ Arxutils_Sqlite3::Util.make_log_path(db_dir, dbconfig)
195
+ end
196
+
197
+ # DB構成ファイルの作成
198
+ def setup_for_dbconfig_path(dbconfig)
199
+ config_dir = get_config_dir
200
+ # DB構成ファイル名
201
+ Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, dbconfig)
202
+ end
203
+
204
+ # 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のクラス定義ファイルの生成
208
+ mig.output
209
+ end
210
+
211
+ # migrateの準備
212
+ def prepare_for_migrate(db_scheme_ary, dbconfig_dest_path, dbconfig, relation)
213
+ #db_dir = config.DB_DIR
214
+ db_dir = get_db_dir
215
+ migrate_dir = get_migrate_dir
216
+ # DB構成ファイルの出力先ディレクトリ
217
+ dbconfig_src_fname = "#{dbconfig}.tmpl"
218
+ mig = Migrate.new(
219
+ self,
220
+ dbconfig_dest_path,
221
+ dbconfig_src_fname,
222
+ db_scheme_ary,
223
+ relation
224
+ )
225
+ end
226
+
227
+ def make_dbsetup_file(db_scheme_ary, relation, klass, dest_dbsetup_file)
228
+ src_dbsetup_file = get_src_dbsetup_file
229
+
230
+ scope = Object.new
231
+ hash0 = {module_name: relation[:module].join("::")}
232
+ hash = db_scheme_ary[0].merge( hash0 )
233
+ hash["klass"] = klass
234
+ result_content = Ykutils::Erubyx.erubi_render_with_template_file(src_dbsetup_file, scope, hash)
235
+
236
+ #p "################ dest_dbsetup_file=#{dest_dbsetup_file}"
237
+ File.open(dest_dbsetup_file, "w"){|file|
238
+ file.write(result_content)
239
+ }
240
+ end
241
+ end
242
+ end
@@ -36,6 +36,20 @@ module Arxutils_Sqlite3
36
36
  format("%s-%s", dbconfig.to_s, log_file_base_name)
37
37
  end
38
38
 
39
+ def self.db_connect(config, dbconfig, env)
40
+ # DB構成ファイルへのパス
41
+ dbconfig_path = config.setup_for_dbconfig_path(dbconfig)
42
+ # DB用ログファイルへのパス
43
+ log_path = config.setup_for_db_log_path(dbconfig)
44
+ # DB接続
45
+ dbconnect = Arxutils_Sqlite3::Dbutil::Dbconnect.new(
46
+ dbconfig_path,
47
+ env,
48
+ log_path
49
+ )
50
+ dbconnect.connect
51
+ end
52
+
39
53
  # DB接続までの初期化に必要なディレクトリの確認、作成
40
54
  def initialize(dbconfig_dest_path, env, log_path)
41
55
  # 接続開始時刻
@@ -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
@@ -3,17 +3,6 @@ require_relative "dbutil/dbconnect"
3
3
  module Arxutils_Sqlite3
4
4
  # DB操作用ユーティリティクラス
5
5
  module Dbutil
6
- # DB格納ディレクトリ名
7
- DB_DIR = "db".freeze
8
- # migrate用スクリプト格納ディレクトリ名
9
- MIGRATE_DIR = "migrate".freeze
10
- # SQLITE3用DB構成名
11
- DBCONFIG_SQLITE3 = "sqlite3".freeze
12
- # MYSQL用DB構成名
13
- DBCONFIG_MYSQL = "mysql".freeze
14
- # DB構成格納用ディレクトリ名
15
- CONFIG_DIR = "config".freeze
16
- # データベース用ログファイル名
17
- DATABASELOG = "database.log".freeze
6
+ #
18
7
  end
19
8
  end
@@ -10,7 +10,7 @@ require "pp"
10
10
  module Arxutils_Sqlite3
11
11
  ##
12
12
  # migrateに必要なファイルをテンプレートから作成し、migarteを実行する
13
- class Migrate
13
+ class Migrate
14
14
  attr_reader :migrate_dir
15
15
  # migrate用スクリプトファイル名の先頭の番号の間隔
16
16
  FILENAME_COUNTER_STEP = 10
@@ -19,34 +19,33 @@ class Migrate
19
19
 
20
20
  # migrate用のスクリプトの生成、migrateの実行を行うmigratexの生成
21
21
  def initialize(
22
+ config,
22
23
  dbconfig_dest_path,
23
24
  dbconfig_src_fname,
24
- migrate_dir,
25
- db_dir,
26
25
  db_scheme_ary,
27
- relation,
28
- opts)
26
+ relation_config
27
+ )
29
28
  # DB格納ディレクトリ名
30
- @db_dir = db_dir
29
+ @db_dir = config.get_db_dir
31
30
  # DB構成ファイルの出力先ディレクトリ
32
- @dest_config_dir = Arxutils_Sqlite3::Dbutil::CONFIG_DIR
31
+ @dest_config_dir = config.get_config_dir
33
32
  # 生成するDB構成情報ファイルパス
34
33
  @dbconfig_dest_path = dbconfig_dest_path
35
34
  # 参照用DB構成情報ファイル名
36
35
  @dbconfig_src_fname = dbconfig_src_fname
37
36
 
38
37
  # migrate用スクリプトの出力先ディレクトリ名
39
- @migrate_dir = migrate_dir
38
+ @migrate_dir = config.get_migrate_dir
40
39
  # テンプレートファイル格納ディレクトリ名
41
- @src_path = Arxutils_Sqlite3::TEMPLATE_RELATION_DIR
40
+ @src_path = config.get_template_relation_dir
41
+ #@src_path = Arxutils_Sqlite3::TEMPLATE_RELATION_DIR
42
42
  # 構成ファイル格納ディレクトリ
43
- @src_config_path = Arxutils_Sqlite3::TEMPLATE_CONFIG_DIR
43
+ @src_config_path = config.get_template_config_dir
44
+ # @src_config_path = Arxutils_Sqlite3::TEMPLATE_CONFIG_DIR
44
45
  # データベーススキーマ定義配列
45
46
  @db_scheme_ary = db_scheme_ary
46
47
  # リレーション指定
47
- @relation = relation
48
- # オプション指定
49
- @opts = opts
48
+ @relation_config = relation_config
50
49
 
51
50
  FileUtils.mkdir_p(@db_dir) if @db_dir
52
51
  FileUtils.mkdir_p(@migrate_dir) if @migrate_dir
@@ -54,17 +53,44 @@ class Migrate
54
53
  end
55
54
 
56
55
  # マイグレート用スクリプト、DB構成情報ファイル、DBファイルの削除
57
- def delete_migrate_config_and_db
58
- FileUtils.rm(Dir.glob(File.join(@migrate_dir, "*"))) if @migrate_dir
59
- FileUtils.rm(Dir.glob(File.join(@dest_config_dir, "*")))
56
+ def delete_migrate_and_config_and_db
57
+ if @migrate_dir
58
+ Dir.glob(File.join(@migrate_dir, "*")).each do |x|
59
+ FileUtils.rm(x) if File.file?(x)
60
+ end
61
+ end
62
+ Dir.glob(File.join(@dest_config_dir, "*")).each do |x|
63
+ FileUtils.rm(x) if File.file?(x)
64
+ end
65
+ Dir.glob(File.join(@db_dir, "*")).each do |x|
66
+ # puts x
67
+ FileUtils.rm(x) if File.file?(x)
68
+ end
69
+ end
70
+
71
+ # マイグレート用スクリプト、DBファイルの削除
72
+ def delete_migrate_and_db
73
+ if @migrate_dir
74
+ Dir.glob(File.join(@migrate_dir, "*")).each do |x|
75
+ FileUtils.rm(x) if File.file?(x)
76
+ end
77
+ end
78
+ Dir.glob(File.join(@db_dir, "*")).each do |x|
79
+ # puts x
80
+ FileUtils.rm(x) if File.file?(x)
81
+ end
82
+ end
83
+
84
+ # DBファイルの削除
85
+ def delete_db
60
86
  Dir.glob(File.join(@db_dir, "*")).each do |x|
61
87
  # puts x
62
88
  FileUtils.rm(x) if File.file?(x)
63
89
  end
64
90
  end
65
91
 
66
- # マイグレーション用スクリプトの生成、relationのクラス定義ファイルの生成、migrate実行
67
- def process
92
+ # マイグレーション用スクリプトの生成、relationのクラス定義ファイルの生成
93
+ def output
68
94
  # migrationのスクリプトをファイル出力する
69
95
  output_all_script
70
96
 
@@ -90,7 +116,7 @@ class Migrate
90
116
  content_array = ary
91
117
  end
92
118
  # relationのスクリプトを作成
93
- output_relation_script(content_array, @relation)
119
+ output_relation_script(content_array, @relation_config)
94
120
  end
95
121
 
96
122
  # migrationのスクリプトをファイル出力する
@@ -184,19 +210,17 @@ class Migrate
184
210
  end
185
211
 
186
212
  # relationのスクリプトをファイル出力する
187
- def output_relation_script(content_array, opts)
188
- # pp "=="
189
- # pp opts
190
- dir = opts[:dir]
191
- fname = opts[:filename]
213
+ def output_relation_script(content_array, relation_config)
214
+ dir = relation_config[:dir]
215
+ fname = relation_config[:filename]
192
216
  fpath = File.join(dir, fname)
193
217
  File.open(fpath, "w") do |file|
194
- opts[:module].map { |mod| file.puts("module #{mod}") }
218
+ relation_config[:module].map { |mod| file.puts("module #{mod}") }
195
219
  content_array.map do |x|
196
220
  file.puts x
197
221
  file.puts ""
198
222
  end
199
- opts[:module].map { |_mod| file.puts("end") }
223
+ relation_config[:module].map { |_mod| file.puts("end") }
200
224
  end
201
225
  end
202
226
  end
@@ -1,29 +1,10 @@
1
1
  module Arxutils_Sqlite3
2
2
  class Util
3
- # migrateの準備
4
- def self.prepare_for_migrate(env, db_scheme_ary, db_dir, dbconfig_dest_path, opts)
5
- migrate_base_dir = Dbutil::MIGRATE_DIR
6
- # migrate用スクリプト格納ディレクトリへのパス
7
- migrate_dir = File.join(db_dir, migrate_base_dir)
8
- # DB構成ファイルの出力先ディレクトリ
9
- dest_config_dir = Dbutil::CONFIG_DIR
10
- dbconfig_src_fname = "#{opts["dbconfig"]}.tmpl"
11
- relation = opts[:relation]
12
- mig = Migrate.new(
13
- dbconfig_dest_path,
14
- dbconfig_src_fname,
15
- migrate_dir,
16
- db_dir,
17
- db_scheme_ary,
18
- relation,
19
- opts)
20
- end
21
-
22
3
  # DBログファイルへのパスの作成
23
4
  def self.make_log_path(db_dir, dbconfig)
24
5
  log_path = ""
25
6
  log_fname = Dbutil::Dbconnect.make_log_file_name(
26
- dbconfig, Dbutil::DATABASELOG)
7
+ dbconfig, Config::DATABASELOG)
27
8
  if db_dir && log_fname
28
9
  # DB用ログファイルへのパス
29
10
  log_path = File.join(db_dir, log_fname)
@@ -33,7 +14,7 @@ module Arxutils_Sqlite3
33
14
 
34
15
  # DB構成ファイルへのパスの作成
35
16
  def self.make_dbconfig_path(config_dir, dbconfig)
36
- File.join( config_dir, "#{dbconfig}.yml")
17
+ Pathname.new(config_dir).join("#{dbconfig}.yml")
37
18
  end
38
19
  end
39
20
  end
@@ -1,4 +1,4 @@
1
1
  module Arxutils_Sqlite3
2
2
  # バージョン番号
3
- VERSION = "0.1.44".freeze
3
+ VERSION = "0.1.48".freeze
4
4
  end
@@ -8,34 +8,20 @@ require "active_support/core_ext"
8
8
  require "active_record"
9
9
  require "pathname"
10
10
 
11
+ module Arxutils_Sqlite3
12
+ TOP_DIR = Pathname(__FILE__).parent
13
+ class Error < StandardError; end
14
+ # Your code goes here...
15
+ end
16
+
17
+ require_relative "arxutils_sqlite3/dbutil"
18
+ require_relative "arxutils_sqlite3/config"
19
+ require_relative "arxutils_sqlite3/cli"
20
+
11
21
  require_relative "arxutils_sqlite3/version"
12
22
  require_relative "arxutils_sqlite3/arx"
13
23
  require_relative "arxutils_sqlite3/transactstate"
14
24
  require_relative "arxutils_sqlite3/hier"
15
25
  require_relative "arxutils_sqlite3/migrate"
16
- require_relative "arxutils_sqlite3/dbutil"
17
26
  require_relative "arxutils_sqlite3/migrate"
18
27
  require_relative "arxutils_sqlite3/util"
19
-
20
- module Arxutils_Sqlite3
21
- TOP_DIR = Pathname(__FILE__).parent
22
- TEMPLATE_DIR = TOP_DIR.join("template")
23
- TEMPLATE_RELATION_DIR = TEMPLATE_DIR.join("relation")
24
- TEMPLATE_CONFIG_DIR = TEMPLATE_DIR.join( Dbutil::CONFIG_DIR )
25
- DB_SCHEME_DIR = TEMPLATE_RELATION_DIR.join("db_scheme")
26
- DB_SCHEME_FILE = DB_SCHEME_DIR.join("db_scheme.yml")
27
- OPTS_FILE_NAME = "opts.rb"
28
- OPTS_FILE_NAME_2 = "opts"
29
- DBSETUP_FILE_NAME = "dbsetup.rb"
30
- DBSETUP_FILE_NAME_2 = "dbsetup"
31
- DEST_CONFIG_DIR = Pathname.new( Dbutil::CONFIG_DIR )
32
- OPTS_FILE = DB_SCHEME_DIR.join(OPTS_FILE_NAME)
33
- DBSETUP_FILE = DB_SCHEME_DIR.join(DBSETUP_FILE_NAME)
34
- DEST_OPTS_FILE = DEST_CONFIG_DIR.join(OPTS_FILE_NAME)
35
- DEST_OPTS_FILE_2 = DEST_CONFIG_DIR.join(OPTS_FILE_NAME_2)
36
- DEST_DBSETUP_FILE = DEST_CONFIG_DIR.join(DBSETUP_FILE_NAME)
37
- DEST_DBSETUP_FILE_2 = DEST_CONFIG_DIR.join(DBSETUP_FILE_NAME_2)
38
-
39
- class Error < StandardError; end
40
- # Your code goes here...
41
- end
@@ -1,7 +1,7 @@
1
1
  class Dbsetup
2
2
  def initialize(connect_time)
3
3
  @connect_time = connect_time
4
- @ct = <%= module_name %>::<%= classname %>.create( <%= classname_downcase %>: @connect_time )
4
+ @ct = <%= klass %>::Dbutil::Countdatetime.create( countdatetime: @connect_time )
5
5
  @hs_by_notebook = {}
6
6
  @hs_by_id = {}
7
7
  end
@@ -1,5 +1,5 @@
1
1
  @opts = {
2
- db_dir: Arxutils_Sqlite3::Dbutil::DB_DIR,
2
+ db_dir: Arxutils_Sqlite3::Config::DB_DIR,
3
3
  relation: {
4
4
  module: %w[<%= klass %> Dbutil],
5
5
  filename: "dbrelation.rb",
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.44
4
+ version: 0.1.48
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-10 00:00:00.000000000 Z
11
+ date: 2022-09-13 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,8 +217,11 @@ 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
221
+ - lib/arxutils_sqlite3/config.rb
220
222
  - lib/arxutils_sqlite3/dbutil.rb
221
223
  - lib/arxutils_sqlite3/dbutil/dbconnect.rb
224
+ - lib/arxutils_sqlite3/dbutil/dbrelation.rb
222
225
  - lib/arxutils_sqlite3/hier.rb
223
226
  - lib/arxutils_sqlite3/migrate.rb
224
227
  - lib/arxutils_sqlite3/transactstate.rb