arxutils_sqlite3 0.1.43 → 0.1.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b67a7e8b8c74b99735830d7a77ed35c489a2f94334ed2e9d648e28a1dd7e619
4
- data.tar.gz: daa960e9e9ed7f7a4e4457e8c1d8cc986abfea6a2ea0bff25c6da7ad3db9dd0c
3
+ metadata.gz: e09dc03b438aa54a9f0bb3e49c46b7592593e52a4e4275220a1b66890694054e
4
+ data.tar.gz: 1afd929a60c9e1fed27e11b9ff4ea87761be5dd77e15cf87cb2e090a153dbc07
5
5
  SHA512:
6
- metadata.gz: e213121d613bfb5445a2b701dabfb7718eec7a3a34b034c6bfe6a979d7302dbe64c2b8ed921f09f5ad49039e9ea782bdd1f115065dd5214267f549bb61354eae
7
- data.tar.gz: f3ce79fb5d0162c515705f5132c143dc37dd17f438b3599871567e96a717b19f951cd2f82bfc6e320d70bd5fbb8932d0359d3c9466ba2743a5f128fd0c89a979
6
+ metadata.gz: 3f63fa45e2827cc7c16ae8fc534c2ef725e1359c4d2c9f99c4edc73af78b846eaf43319c25cb177636cffef8d997fc939e6d97e865ece6ea0a0a064d398d90df
7
+ data.tar.gz: 508aa3ff67bddd7e1ec59403e6f18d024f71e79dbd23aa750dd6c736bd3a3183091f7ec9fde7b61d634091dddf41ef5885f5d6b900fcb8c4eb5a97bdde077ed7
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
 
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.bindir = "exe"
33
33
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
34
- p spec.executables
34
+ #p spec.executables
35
35
  spec.require_paths = ["lib"]
36
36
  spec.add_runtime_dependency "activesupport"
37
37
  # spec.add_runtime_dependency "erb"
data/exe/arxutils_sqlite3 CHANGED
@@ -6,14 +6,9 @@ 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
+ config.require_opts_file
17
12
 
18
13
  begin
19
14
  require "dbrelation"
@@ -21,59 +16,21 @@ rescue LoadError => ex
21
16
  pp ex.message
22
17
  end
23
18
 
24
- # 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
33
-
34
-
35
- def prepare_for_migrate(env, db_scheme_ary, db_dir, dbconfig_dest_path, opts)
36
- migrate_base_dir = Arxutils_Sqlite3::Dbutil::MIGRATE_DIR
37
- # migrate用スクリプト格納ディレクトリへのパス
38
- migrate_dir = File.join(db_dir, migrate_base_dir)
39
- # DB構成ファイルの出力先ディレクトリ
40
- dest_config_dir = Arxutils_Sqlite3::Dbutil::CONFIG_DIR
41
- dbconfig_src_fname = "#{opts["dbconfig"]}.tmpl"
42
- p "dbconfig_dest_path=#{dbconfig_dest_path}"
43
- relation = opts[:relation]
44
- mig = Arxutils_Sqlite3::Migrate.new(
45
- dbconfig_dest_path,
46
- dbconfig_src_fname,
47
- migrate_dir,
48
- db_dir,
49
- db_scheme_ary,
50
- relation,
51
- opts)
52
- end
53
19
 
54
- def make_log_path(db_dir, dbconfig)
55
- log_path = ""
56
- log_fname = Arxutils_Sqlite3::Dbutil::Dbconnect.make_log_file_name(
57
- dbconfig, Arxutils_Sqlite3::Dbutil::DATABASELOG)
58
- if db_dir && log_fname
59
- # DB用ログファイルへのパス
60
- log_path = File.join(db_dir, log_fname)
61
- end
62
- log_path
63
- end
20
+ klass = nil
21
+ setting = config.load_setting_yaml_file
22
+ klass = setting[:klass]
64
23
 
65
- def make_dbconfig_path(config_dir, dbconfig)
66
- File.join( config_dir, "#{dbconfig}.yml")
67
- end
24
+ # DBセットアップクラス
25
+ config.require_dbsetup_file
68
26
 
69
- banner = "Usage: bundle exec ruby exe/makemigrate --cmd=(s|c|m|i|d) -y yaml_file --klass=class"
27
+ banner = "Usage: bundle exec arxutils_sqlite3 --cmd=(s|c|m|i|d|b) -y yaml_file --klass=class"
70
28
 
71
29
  opts = @opts ? @opts : {}
72
-
73
- opts["dbconfig"] = Arxutils_Sqlite3::Dbutil::DBCONFIG_SQLITE3
30
+ opts["dbconfig"] = Arxutils_Sqlite3::Config::DBCONFIG_SQLITE3
74
31
 
75
32
  Simpleoptparse::Simpleoptparse.parse(ARGV, opts, banner, Arxutils_Sqlite3::VERSION, nil) do |parser|
76
- parser.on("--cmd X", %w[s c m i d]) { |x| opts["cmd"] = x }
33
+ parser.on("--cmd X", %w[s c m i d b]) { |x| opts["cmd"] = x }
77
34
  parser.on("-y yaml_file", "--yaml yaml_file") { |x| opts["yaml"] = x }
78
35
  parser.on("--klass klass") { |x| opts["klass"] = x }
79
36
  end
@@ -83,94 +40,89 @@ env ||= "production"
83
40
 
84
41
  case opts["cmd"]
85
42
  when "s"
86
- FileUtils.cp(Arxutils_Sqlite3::DB_SCHEME_FILE, Arxutils_Sqlite3::Dbutil::CONFIG_DIR )
43
+ config.check_file_exist(Arxutils_Sqlite3::Config::DEST_OPTS_FILE, banner, 10)
44
+
87
45
  if opts["klass"].nil? || opts["klass"].strip == ""
88
46
  puts banner
89
- exit 10
47
+ exit 20
90
48
  end
91
-
92
- scope = Object.new
93
- hash = {klass: opts["klass"]}
94
- result_content = Ykutils::Erubyx.erubi_render_with_template_file(Arxutils_Sqlite3::OPTS_FILE, scope, hash)
95
-
96
- File.open(Arxutils_Sqlite3::DEST_OPTS_FILE, "w"){|file|
97
- file.write(result_content)
98
- }
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)
99
54
  db_scheme_ary = nil
100
55
 
101
56
  when "c"
102
57
  db_scheme_ary = nil
103
- db_dir = Arxutils_Sqlite3::Dbutil::DB_DIR
104
- config_dir = Arxutils_Sqlite3::Dbutil::CONFIG_DIR
105
- # DB構成ファイル名
106
- dbconfig_path = make_dbconfig_path(config_dir, opts["dbconfig"])
107
-
108
- mig = prepare_for_migrate(env, db_scheme_ary, db_dir, dbconfig_path, opts)
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)
109
63
  mig.make_dbconfig(opts)
110
64
 
111
65
  when "m"
112
- if opts["yaml"].nil? || opts["yaml"].strip == ""
66
+ yaml_fname = opts["yaml"]
67
+ relation = opts[:relation]
68
+ dbconfig = opts["dbconfig"]
69
+ if yaml_fname.nil? || yaml_fname.strip == ""
113
70
  puts banner
114
- exit 20
71
+ exit 40
115
72
  end
73
+ yaml_pn = Pathname.new(yaml_fname)
74
+ config.check_file_not_exist(yaml_pn, banner, 55)
75
+ db_scheme_ary = YAML.load_file( yaml_pn )
76
+
77
+ dest_dbsetup_file = config.get_dest_dbsetup_file
78
+ config.make_dbsetup_file(db_scheme_ary, relation, klass, dest_dbsetup_file)
116
79
 
117
- opts["migrate_cmd"] = "migrate"
118
- db_scheme_ary = YAML.load_file( opts["yaml"] )
119
-
120
- scope = Object.new
121
-
122
- hash0 = {module_name: opts[:relation][:module].join("::")}
123
- hash = db_scheme_ary[0].merge( hash0 )
124
- result_content = Ykutils::Erubyx.erubi_render_with_template_file(Arxutils_Sqlite3::DBSETUP_FILE, scope, hash)
125
-
126
- File.open(Arxutils_Sqlite3::DEST_DBSETUP_FILE, "w"){|file|
127
- file.write(result_content)
128
- }
129
- db_dir = Arxutils_Sqlite3::Dbutil::DB_DIR
130
-
131
- config_dir = Arxutils_Sqlite3::Dbutil::CONFIG_DIR
132
- # DB構成ファイル名
133
- dbconfig_path = make_dbconfig_path(config_dir, opts["dbconfig"])
134
- # DBログファイルへのパス
135
- log_path = make_log_path(db_dir, opts["dbconfig"])
136
- mig = prepare_for_migrate(env, db_scheme_ary, db_dir, dbconfig_path, opts)
137
- mig.process
138
- dbconnect = Arxutils_Sqlite3::Dbutil::Dbconnect.new(
139
- dbconfig_path,
140
- env,
141
- log_path
142
- )
143
- connect_time = dbconnect.connect
144
- p "connect_time=#{connect_time}"
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
+ # マイグレーション実行
145
87
  ActiveRecord::MigrationContext.new(mig.migrate_dir, ActiveRecord::SchemaMigration).up
146
88
 
147
89
  when "i"
148
- #db_scheme_ary = YAML.load_file( opts["yaml"] )
149
- db_scheme_ary = nil
150
- db_dir = Arxutils_Sqlite3::Dbutil::DB_DIR
151
-
152
- config_dir = Arxutils_Sqlite3::Dbutil::CONFIG_DIR
153
- # DB構成ファイルへのパス
154
- dbconfig_dest_path = make_dbconfig_path(config_dir, opts["dbconfig"])
155
- # DBログファイルへのパス
156
- log_path = make_log_path(db_dir, opts["dbconfig"])
157
- dbconnect = Arxutils_Sqlite3::Dbutil::Dbconnect.new(
158
- dbconfig_dest_path,
159
- env,
160
- log_path
161
- )
162
- connect_time = dbconnect.connect
163
-
90
+ dbconfig = opts["dbconfig"]
91
+ connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(config, dbconfig, env)
164
92
  Dbsetup.new(connect_time)
165
93
 
166
94
  when "d"
167
95
  db_scheme_ary = nil
168
- mig = repare_for_migrate(env, db_scheme_ary, opts)
169
- mig.delete_migrate_config_and_db
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
103
+
104
+ when "b"
105
+ 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
170
125
 
171
126
  else
172
127
  puts "Invalid command(#{opts["cmd"]}) specified!!"
173
128
  end
174
-
175
- #
176
-
@@ -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
  # 接続開始時刻
@@ -50,10 +64,10 @@ module Arxutils_Sqlite3
50
64
  def connect
51
65
  unless @connect_time
52
66
  begin
53
- p "@dbconfig_dest_path=#{@dbconfig_dest_path}"
67
+ #p "@dbconfig_dest_path=#{@dbconfig_dest_path}"
54
68
  dbconfig = Ykxutils.yaml_load_file_compati(@dbconfig_dest_path)
55
- p "dbconfig=#{dbconfig}"
56
- p "@env=#{@env}"
69
+ #p "dbconfig=#{dbconfig}"
70
+ #p "@env=#{@env}"
57
71
  ActiveRecord::Base.establish_connection(dbconfig[@env])
58
72
  ActiveRecord::Base.logger = Logger.new(@log_path)
59
73
  @connect_time = DateTime.now.new_offset
@@ -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
@@ -0,0 +1,20 @@
1
+ module Arxutils_Sqlite3
2
+ class Util
3
+ # DBログファイルへのパスの作成
4
+ def self.make_log_path(db_dir, dbconfig)
5
+ log_path = ""
6
+ log_fname = Dbutil::Dbconnect.make_log_file_name(
7
+ dbconfig, Config::DATABASELOG)
8
+ if db_dir && log_fname
9
+ # DB用ログファイルへのパス
10
+ log_path = File.join(db_dir, log_fname)
11
+ end
12
+ log_path
13
+ end
14
+
15
+ # DB構成ファイルへのパスの作成
16
+ def self.make_dbconfig_path(config_dir, dbconfig)
17
+ Pathname.new(config_dir).join("#{dbconfig}.yml")
18
+ end
19
+ end
20
+ end
@@ -1,4 +1,4 @@
1
1
  module Arxutils_Sqlite3
2
2
  # バージョン番号
3
- VERSION = "0.1.43".freeze
3
+ VERSION = "0.1.47".freeze
4
4
  end
@@ -8,33 +8,19 @@ 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
+
11
20
  require_relative "arxutils_sqlite3/version"
12
21
  require_relative "arxutils_sqlite3/arx"
13
22
  require_relative "arxutils_sqlite3/transactstate"
14
23
  require_relative "arxutils_sqlite3/hier"
15
24
  require_relative "arxutils_sqlite3/migrate"
16
- require_relative "arxutils_sqlite3/dbutil"
17
25
  require_relative "arxutils_sqlite3/migrate"
18
-
19
- module Arxutils_Sqlite3
20
- TOP_DIR = Pathname(__FILE__).parent
21
- TEMPLATE_DIR = TOP_DIR.join("template")
22
- TEMPLATE_RELATION_DIR = TEMPLATE_DIR.join("relation")
23
- TEMPLATE_CONFIG_DIR = TEMPLATE_DIR.join( Dbutil::CONFIG_DIR )
24
- DB_SCHEME_DIR = TEMPLATE_RELATION_DIR.join("db_scheme")
25
- DB_SCHEME_FILE = DB_SCHEME_DIR.join("db_scheme.yml")
26
- OPTS_FILE_NAME = "opts.rb"
27
- OPTS_FILE_NAME_2 = "opts"
28
- DBSETUP_FILE_NAME = "dbsetup.rb"
29
- DBSETUP_FILE_NAME_2 = "dbsetup"
30
- DEST_CONFIG_DIR = Pathname.new( Dbutil::CONFIG_DIR )
31
- OPTS_FILE = DB_SCHEME_DIR.join(OPTS_FILE_NAME)
32
- DBSETUP_FILE = DB_SCHEME_DIR.join(DBSETUP_FILE_NAME)
33
- DEST_OPTS_FILE = DEST_CONFIG_DIR.join(OPTS_FILE_NAME)
34
- DEST_OPTS_FILE_2 = DEST_CONFIG_DIR.join(OPTS_FILE_NAME_2)
35
- DEST_DBSETUP_FILE = DEST_CONFIG_DIR.join(DBSETUP_FILE_NAME)
36
- DEST_DBSETUP_FILE_2 = DEST_CONFIG_DIR.join(DBSETUP_FILE_NAME_2)
37
-
38
- class Error < StandardError; end
39
- # Your code goes here...
40
- end
26
+ require_relative "arxutils_sqlite3/util"
@@ -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.43
4
+ version: 0.1.47
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
@@ -217,11 +217,13 @@ files:
217
217
  - exe/arxutils_sqlite3
218
218
  - lib/arxutils_sqlite3.rb
219
219
  - lib/arxutils_sqlite3/arx.rb
220
+ - lib/arxutils_sqlite3/config.rb
220
221
  - lib/arxutils_sqlite3/dbutil.rb
221
222
  - lib/arxutils_sqlite3/dbutil/dbconnect.rb
222
223
  - lib/arxutils_sqlite3/hier.rb
223
224
  - lib/arxutils_sqlite3/migrate.rb
224
225
  - lib/arxutils_sqlite3/transactstate.rb
226
+ - lib/arxutils_sqlite3/util.rb
225
227
  - lib/arxutils_sqlite3/version.rb
226
228
  - lib/template/config/mysql.tmpl
227
229
  - lib/template/config/sqlite3.tmpl