arxutils_sqlite3 0.1.48 → 0.1.50
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -2
- data/.rubocop_todo.yml +209 -109
- data/Gemfile +13 -16
- data/Gemfile.lock +112 -0
- data/Rakefile +12 -58
- data/arxutils_sqlite3.gemspec +4 -4
- data/config/.gitignore +1 -0
- data/config/setting.yml +2 -0
- data/exe/arxutils_sqlite3 +38 -29
- data/lib/arxutils_sqlite3/arx.rb +3 -3
- data/lib/arxutils_sqlite3/cli.rb +48 -27
- data/lib/arxutils_sqlite3/config.rb +96 -72
- data/lib/arxutils_sqlite3/dbutil/dbconnect.rb +4 -26
- data/lib/arxutils_sqlite3/dbutil.rb +0 -1
- data/lib/arxutils_sqlite3/hier.rb +3 -3
- data/lib/arxutils_sqlite3/migrate.rb +59 -53
- data/lib/arxutils_sqlite3/util.rb +2 -1
- data/lib/arxutils_sqlite3/version.rb +1 -1
- data/lib/arxutils_sqlite3.rb +2 -1
- data/lib/arxutils_sqlite3_rake_task.rb +68 -0
- data/lib/{arxutils_sqlite3/dbutil/dbrelation.rb → dbacrecord.rb} +0 -0
- data/lib/template/{relation/relation.tmpl → acrecord/acrecord.tmpl} +1 -1
- data/lib/template/{relation/relation_count.tmpl → acrecord/acrecord_count.tmpl} +0 -0
- data/lib/template/{relation/relation_current.tmpl → acrecord/acrecord_current.tmpl} +0 -0
- data/lib/template/{relation/relation_invalid.tmpl → acrecord/acrecord_invalid.tmpl} +0 -0
- data/lib/template/{relation → acrecord}/base.tmpl +0 -0
- data/lib/template/{relation → acrecord}/current.tmpl +0 -0
- data/lib/template/{relation → acrecord}/db_scheme/db_scheme.yml +0 -0
- data/lib/template/acrecord/db_scheme/db_scheme.yml.sample +48 -0
- data/lib/template/{relation/db_scheme/dbsetup.rb → acrecord/db_scheme/dbsetup.tmpl} +2 -2
- data/lib/template/acrecord/db_scheme/opts.rb.sample +7 -0
- data/lib/template/acrecord/db_scheme/opts.tmpl +7 -0
- data/lib/template/{relation → acrecord}/invalid.tmpl +0 -0
- data/lib/template/{relation → acrecord}/noitem.tmpl +0 -0
- metadata +30 -26
- data/LICENSE.txt +0 -21
- data/lib/template/relation/db_scheme/opts.rb +0 -8
@@ -4,6 +4,7 @@ module Arxutils_Sqlite3
|
|
4
4
|
##
|
5
5
|
# migrateに必要なファイルをテンプレートから作成し、migarteを実行する
|
6
6
|
class Config
|
7
|
+
EXCLUDE_FILES = %W!setting.yml!
|
7
8
|
# DB格納ディレクトリ名
|
8
9
|
DB_DIR = "db".freeze
|
9
10
|
# migrate用スクリプト格納ディレクトリ名
|
@@ -22,31 +23,37 @@ module Arxutils_Sqlite3
|
|
22
23
|
# テンプレートディレクトリへのパス
|
23
24
|
TEMPLATE_DIR = Arxutils_Sqlite3::TOP_DIR.join("template")
|
24
25
|
# リレーションテンプレートディレクトリへのパス
|
25
|
-
|
26
|
-
TEMPLATE_CONFIG_DIR = TEMPLATE_DIR.join(
|
27
|
-
DB_SCHEME_DIR =
|
26
|
+
TEMPLATE_ACRECORD_DIR = TEMPLATE_DIR.join("acrecord")
|
27
|
+
TEMPLATE_CONFIG_DIR = TEMPLATE_DIR.join(CONFIG_DIR)
|
28
|
+
DB_SCHEME_DIR = TEMPLATE_ACRECORD_DIR.join("db_scheme")
|
28
29
|
DB_SCHEME_FILE = DB_SCHEME_DIR.join("db_scheme.yml")
|
30
|
+
SAMPLE_DB_SCHEME_FILE = CONFIG_DIR.join("db_scheme.yml.sample")
|
29
31
|
DB_SCHEME_FILE_NAME = "db_scheme.yml".freeze
|
30
|
-
|
31
|
-
OPTS_FILE_NAME = "opts.
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
DB_SCHEME_FILE_NAME_B = "db_scheme".freeze
|
33
|
+
OPTS_FILE_NAME = "opts.tmpl".freeze
|
34
|
+
SAMPLE_OPTS_FILE_NAME = "opts.rb.sample".freeze
|
35
|
+
OPTS_FILE_NAME_B = "opts".freeze
|
36
|
+
DEST_OPTS_FILE_NAME = "opts.rb".freeze
|
37
|
+
DEST_OPTS_FILE_NAME_B = "opts".freeze
|
38
|
+
DBSETUP_FILE_NAME = "dbsetup.tmpl".freeze
|
39
|
+
DBSETUP_FILE_NAME_B = "dbsetup".freeze
|
40
|
+
DEST_DBSETUP_FILE_NAME = "dbsetup.rb".freeze
|
35
41
|
SETTING_YAML_FILE_NAME = "setting.yml".freeze
|
36
|
-
DEST_CONFIG_DIR = Pathname.new(
|
42
|
+
DEST_CONFIG_DIR = Pathname.new(CONFIG_DIR)
|
37
43
|
OPTS_FILE = DB_SCHEME_DIR.join(OPTS_FILE_NAME)
|
44
|
+
SAMPLE_OPTS_FILE = CONFIG_DIR.join(SAMPLE_OPTS_FILE_NAME)
|
38
45
|
# 変換先Dbsetupクラス定義のRubyスクリプトファイルへのパス
|
39
46
|
DBSETUP_FILE = DB_SCHEME_DIR.join(DBSETUP_FILE_NAME)
|
40
47
|
# 変換先optsファイル(Rubyスクリプトファイル)へのパス
|
41
|
-
DEST_OPTS_FILE = DEST_CONFIG_DIR.join(
|
42
|
-
|
48
|
+
DEST_OPTS_FILE = DEST_CONFIG_DIR.join(DEST_OPTS_FILE_NAME)
|
49
|
+
DEST_OPTS_FILE_B = DEST_CONFIG_DIR.join(OPTS_FILE_NAME_B)
|
43
50
|
# 変換先Dbsetupクラス定義のRubyスクリプトファイルへのパス
|
44
|
-
DEST_DBSETUP_FILE = DEST_CONFIG_DIR.join(
|
51
|
+
DEST_DBSETUP_FILE = DEST_CONFIG_DIR.join(DEST_DBSETUP_FILE_NAME)
|
45
52
|
# 変換先Dbsetupクラス定義のRubyスクリプトファイル(拡張子無し)へのパス
|
46
|
-
|
53
|
+
DEST_DBSETUP_FILE_B = DEST_CONFIG_DIR.join(DBSETUP_FILE_NAME_B)
|
47
54
|
DEST_DB_SCHEME_FILE = DEST_CONFIG_DIR.join(DB_SCHEME_FILE_NAME)
|
48
55
|
# 変換後DBスキームファイル(拡張子無し)へのパス
|
49
|
-
|
56
|
+
DEST_DB_SCHEME_FILE_B = DEST_CONFIG_DIR.join(DB_SCHEME_FILE_NAME_B)
|
50
57
|
SETTING_YAML_FILE = CONFIG_DIR.join(SETTING_YAML_FILE_NAME)
|
51
58
|
DB_PN = Pathname.new(DB_DIR)
|
52
59
|
# migrateディレクトリへのパス
|
@@ -54,31 +61,47 @@ module Arxutils_Sqlite3
|
|
54
61
|
|
55
62
|
# DB構成ファイル格納ディレクトリの作成
|
56
63
|
def make_config_directory
|
64
|
+
# p "config make_config_directory"
|
57
65
|
FileUtils.mkdir_p(CONFIG_DIR)
|
58
66
|
end
|
59
67
|
|
60
|
-
# DB
|
68
|
+
# DBスキームファイルのサンプルファイルコピー
|
61
69
|
def setup_db_scheme_file
|
62
|
-
|
70
|
+
# p "config setup_db_scheme_file"
|
71
|
+
# p "DB_SCHEME_FILE=#{DB_SCHEME_FILE}"
|
72
|
+
# p "SAMPLE_DB_SCHEME_FILE=#{SAMPLE_DB_SCHEME_FILE}"
|
73
|
+
FileUtils.cp(DB_SCHEME_FILE, SAMPLE_DB_SCHEME_FILE)
|
63
74
|
end
|
64
75
|
|
65
|
-
#
|
76
|
+
# DBスキームファイルが存在しなければ、サンプルファイルをDBスキームファイルとしてコピー
|
77
|
+
def copy_db_scheme_file
|
78
|
+
return if File.exist?(DEST_DB_SCHEME_FILE)
|
79
|
+
|
80
|
+
FileUtils.cp(SAMPLE_DB_SCHEME_FILE, DEST_DB_SCHEME_FILE)
|
81
|
+
end
|
82
|
+
|
83
|
+
# optsファイル(Rubyスクリプトファイル)のサンプルファイル書き込み
|
66
84
|
def setup_opts_file(klass)
|
67
85
|
scope = Object.new
|
68
|
-
hash = {klass: klass}
|
86
|
+
hash = { klass: klass }
|
69
87
|
result_content = Ykutils::Erubyx.erubi_render_with_template_file(OPTS_FILE, scope, hash)
|
70
|
-
File.
|
71
|
-
|
72
|
-
|
88
|
+
File.write(SAMPLE_OPTS_FILE, result_content)
|
89
|
+
end
|
90
|
+
|
91
|
+
# optsファイルが存在しなければ、サンプルファイルをoptsファイルとしてコピー
|
92
|
+
def copy_opts_file
|
93
|
+
return if File.exist?(DEST_OPTS_FILE)
|
94
|
+
|
95
|
+
# p "exist? #{File.exist?(DEST_OPTS_FILE)}"
|
96
|
+
# p "copy SAMPLE_OPTS_FILE(#{SAMPLE_OPTS_FILE}) to DEST_OPTS_FILE(#{DEST_OPTS_FILE})"
|
97
|
+
FileUtils.cp(SAMPLE_OPTS_FILE, DEST_OPTS_FILE)
|
73
98
|
end
|
74
99
|
|
75
100
|
# setting.ymlへの出力
|
76
101
|
def setup_setting_yaml_file(klass)
|
77
|
-
hash = {
|
102
|
+
hash = { klass: klass }
|
78
103
|
content = YAML.dump(hash)
|
79
|
-
File.
|
80
|
-
file.write(content)
|
81
|
-
}
|
104
|
+
File.write(SETTING_YAML_FILE, content)
|
82
105
|
end
|
83
106
|
|
84
107
|
# DB構成ファイルの作成
|
@@ -89,13 +112,13 @@ module Arxutils_Sqlite3
|
|
89
112
|
|
90
113
|
# optsファイル(Rubyスクリプトファイル)のrequire
|
91
114
|
def require_opts_file
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
115
|
+
return unless DEST_OPTS_FILE.exist?
|
116
|
+
|
117
|
+
opts_file = File.join("./", DEST_OPTS_FILE_B.to_s)
|
118
|
+
begin
|
119
|
+
require opts_file
|
120
|
+
rescue LoadError
|
121
|
+
# pp ex.message
|
99
122
|
end
|
100
123
|
end
|
101
124
|
|
@@ -104,40 +127,38 @@ module Arxutils_Sqlite3
|
|
104
127
|
setting = {}
|
105
128
|
# settingファイル
|
106
129
|
setting_yaml_file = SETTING_YAML_FILE
|
107
|
-
if setting_yaml_file.exist?
|
108
|
-
setting = YAML.load_file( setting_yaml_file )
|
109
|
-
end
|
130
|
+
setting = YAML.load_file(setting_yaml_file) if setting_yaml_file.exist?
|
110
131
|
setting
|
111
132
|
end
|
112
133
|
|
113
134
|
# Dbsetupファイル(Rubyスクリプトファイル)のrequire
|
114
135
|
def require_dbsetup_file
|
115
|
-
dbsetup_file = File.join(".",
|
136
|
+
dbsetup_file = File.join(".", get_dest_dbsetup_file_b.to_s)
|
116
137
|
begin
|
117
138
|
require dbsetup_file
|
118
|
-
rescue LoadError
|
119
|
-
pp ex.message
|
139
|
+
rescue LoadError
|
140
|
+
# pp ex.message
|
120
141
|
end
|
121
142
|
end
|
122
143
|
|
123
144
|
# 指定ファイルの存在確認
|
124
145
|
def check_file_exist(file_pn, banner, exit_code)
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
146
|
+
return unless file_pn.exist?
|
147
|
+
|
148
|
+
puts "#{file_pn} exists!"
|
149
|
+
puts banner
|
150
|
+
exit exit_code
|
130
151
|
end
|
131
152
|
|
132
153
|
# 指定ファイルの非存在確認
|
133
154
|
def check_file_not_exist(file_pn, banner, exit_code)
|
134
|
-
if
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
155
|
+
return if file_pn.exist?
|
156
|
+
|
157
|
+
puts "#{file_pn} does not exists!"
|
158
|
+
puts banner
|
159
|
+
exit exit_code
|
139
160
|
end
|
140
|
-
|
161
|
+
|
141
162
|
# 変換先optsファイル(Rubyスクリプトファイル)へのパス
|
142
163
|
def get_dest_opts_file
|
143
164
|
DEST_OPTS_FILE
|
@@ -152,14 +173,15 @@ module Arxutils_Sqlite3
|
|
152
173
|
def get_migrate_dir
|
153
174
|
MIGRATE_DIR
|
154
175
|
end
|
176
|
+
|
155
177
|
# コンフィグディレクトリへのパス
|
156
178
|
def get_config_dir
|
157
179
|
CONFIG_DIR
|
158
180
|
end
|
159
181
|
|
160
182
|
# リレーションテンプレートディレクトリへのパス
|
161
|
-
def
|
162
|
-
|
183
|
+
def get_template_acrecord_dir
|
184
|
+
TEMPLATE_ACRECORD_DIR
|
163
185
|
end
|
164
186
|
|
165
187
|
# テンプレートディレクトリへのパス
|
@@ -178,13 +200,13 @@ module Arxutils_Sqlite3
|
|
178
200
|
end
|
179
201
|
|
180
202
|
# 変換先Dbsetupクラス定義のRubyスクリプトファイル(拡張子無し)へのパス
|
181
|
-
def
|
182
|
-
|
203
|
+
def get_dest_dbsetup_file_b
|
204
|
+
DEST_DBSETUP_FILE_B
|
183
205
|
end
|
184
206
|
|
185
207
|
# 変換後DBスキームファイル名(拡張子無し)
|
186
208
|
def get_dest_db_scheme_file
|
187
|
-
|
209
|
+
DEST_DB_SCHEME_FILE_B
|
188
210
|
end
|
189
211
|
|
190
212
|
# DBログファイルの作成
|
@@ -202,41 +224,43 @@ module Arxutils_Sqlite3
|
|
202
224
|
end
|
203
225
|
|
204
226
|
# migrate用スクリプトの生成
|
205
|
-
def make_migrate_script(db_scheme_ary, dbconfig_path, dbconfig,
|
206
|
-
mig = Arxutils_Sqlite3::Util.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig,
|
207
|
-
# マイグレーション用スクリプトの生成、
|
227
|
+
def make_migrate_script(db_scheme_ary, dbconfig_path, dbconfig, acrecord)
|
228
|
+
mig = Arxutils_Sqlite3::Util.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, acrecord)
|
229
|
+
# マイグレーション用スクリプトの生成、acrecordのクラス定義ファイルの生成
|
208
230
|
mig.output
|
209
231
|
end
|
210
232
|
|
211
233
|
# migrateの準備
|
212
|
-
def prepare_for_migrate(db_scheme_ary, dbconfig_dest_path, dbconfig,
|
213
|
-
#db_dir = config.DB_DIR
|
214
|
-
db_dir = get_db_dir
|
215
|
-
migrate_dir = get_migrate_dir
|
234
|
+
def prepare_for_migrate(db_scheme_ary, dbconfig_dest_path, dbconfig, acrecord)
|
216
235
|
# DB構成ファイルの出力先ディレクトリ
|
217
236
|
dbconfig_src_fname = "#{dbconfig}.tmpl"
|
218
|
-
|
237
|
+
# migrate用スクリプトの出力先ディレクトリ名
|
238
|
+
migrate_dir = get_migrate_dir
|
239
|
+
|
240
|
+
Migrate.new(
|
219
241
|
self,
|
220
242
|
dbconfig_dest_path,
|
221
243
|
dbconfig_src_fname,
|
222
244
|
db_scheme_ary,
|
223
|
-
|
224
|
-
|
245
|
+
acrecord,
|
246
|
+
migrate_dir
|
247
|
+
)
|
225
248
|
end
|
226
249
|
|
227
|
-
def make_dbsetup_file(db_scheme_ary,
|
250
|
+
def make_dbsetup_file(db_scheme_ary, acrecord, klass, dest_dbsetup_file)
|
228
251
|
src_dbsetup_file = get_src_dbsetup_file
|
229
252
|
|
230
253
|
scope = Object.new
|
231
|
-
hash0 = {module_name:
|
232
|
-
hash = db_scheme_ary[0].merge(
|
254
|
+
hash0 = { module_name: acrecord[:module].join("::") }
|
255
|
+
hash = db_scheme_ary[0].merge(hash0)
|
233
256
|
hash["klass"] = klass
|
234
257
|
result_content = Ykutils::Erubyx.erubi_render_with_template_file(src_dbsetup_file, scope, hash)
|
235
258
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
259
|
+
File.write(dest_dbsetup_file, result_content)
|
260
|
+
end
|
261
|
+
|
262
|
+
def exclude_file?( fname )
|
263
|
+
EXCLUDE_FILES.index( fname ) != nil
|
240
264
|
end
|
241
265
|
end
|
242
|
-
end
|
266
|
+
end
|
@@ -6,28 +6,6 @@ require "active_record"
|
|
6
6
|
require "sqlite3"
|
7
7
|
require "ykxutils"
|
8
8
|
|
9
|
-
def require_x(path)
|
10
|
-
require path
|
11
|
-
rescue StandardError => e
|
12
|
-
p "1 request_x"
|
13
|
-
p e
|
14
|
-
rescue LoadError => e
|
15
|
-
p "21 request_x"
|
16
|
-
p e
|
17
|
-
rescue NotImplementedError => e
|
18
|
-
p "22 request_x"
|
19
|
-
p e
|
20
|
-
rescue SyntaxError => e
|
21
|
-
p "23 request_x"
|
22
|
-
p e
|
23
|
-
rescue ScriptError => e
|
24
|
-
p "20 request_x"
|
25
|
-
p e
|
26
|
-
rescue Exception => e
|
27
|
-
p "9 request_x"
|
28
|
-
p e
|
29
|
-
end
|
30
|
-
|
31
9
|
module Arxutils_Sqlite3
|
32
10
|
module Dbutil
|
33
11
|
# DB操作用ユーティリティクラス
|
@@ -64,14 +42,14 @@ module Arxutils_Sqlite3
|
|
64
42
|
def connect
|
65
43
|
unless @connect_time
|
66
44
|
begin
|
67
|
-
#p "@dbconfig_dest_path=#{@dbconfig_dest_path}"
|
45
|
+
# p "@dbconfig_dest_path=#{@dbconfig_dest_path}"
|
68
46
|
dbconfig = Ykxutils.yaml_load_file_compati(@dbconfig_dest_path)
|
69
|
-
#p "dbconfig=#{dbconfig}"
|
70
|
-
#p "@env=#{@env}"
|
47
|
+
# p "dbconfig=#{dbconfig}"
|
48
|
+
# p "@env=#{@env}"
|
71
49
|
ActiveRecord::Base.establish_connection(dbconfig[@env])
|
72
50
|
ActiveRecord::Base.logger = Logger.new(@log_path)
|
73
51
|
@connect_time = DateTime.now.new_offset
|
74
|
-
rescue => ex
|
52
|
+
rescue StandardError => ex
|
75
53
|
p ex.message
|
76
54
|
end
|
77
55
|
end
|
@@ -142,10 +142,10 @@ module Arxutils_Sqlite3
|
|
142
142
|
hier = @hier_klass.find_by(child_id: num)
|
143
143
|
level = hier.level
|
144
144
|
parent_id = hier.parent_id
|
145
|
-
base = @base_klass.find_by(ord_id: num)
|
145
|
+
# base = @base_klass.find_by(ord_id: num)
|
146
146
|
|
147
|
-
parent_base = @base_klass.find_by(ord_id: parent_id)
|
148
|
-
parent_hier_string = parent_base.__send__ @hier_symbol
|
147
|
+
# parent_base = @base_klass.find_by(ord_id: parent_id)
|
148
|
+
# parent_hier_string = parent_base.__send__ @hier_symbol
|
149
149
|
|
150
150
|
# 属する子を探す
|
151
151
|
children_hier = @hier_klass.where(parent_id: num)
|
@@ -1,21 +1,22 @@
|
|
1
|
-
#require "arxutils_sqlite3"
|
1
|
+
# require "arxutils_sqlite3"
|
2
2
|
require "ykutils"
|
3
3
|
require "fileutils"
|
4
|
-
#require "active_support"
|
4
|
+
# require "active_support"
|
5
5
|
require "active_record"
|
6
6
|
require "active_record/migration"
|
7
7
|
require "pp"
|
8
8
|
|
9
9
|
# ActiveRecord用ユーティリティモジュール
|
10
10
|
module Arxutils_Sqlite3
|
11
|
-
##
|
12
|
-
# migrateに必要なファイルをテンプレートから作成し、migarteを実行する
|
11
|
+
##
|
12
|
+
# migrateに必要なファイルをテンプレートから作成し、migarteを実行する
|
13
13
|
class Migrate
|
14
14
|
attr_reader :migrate_dir
|
15
|
+
|
15
16
|
# migrate用スクリプトファイル名の先頭の番号の間隔
|
16
17
|
FILENAME_COUNTER_STEP = 10
|
17
18
|
# DB接続までの初期化を行うDbinitクラスのインスタンス
|
18
|
-
#attr_reader :dbinit
|
19
|
+
# attr_reader :dbinit
|
19
20
|
|
20
21
|
# migrate用のスクリプトの生成、migrateの実行を行うmigratexの生成
|
21
22
|
def initialize(
|
@@ -23,8 +24,11 @@ module Arxutils_Sqlite3
|
|
23
24
|
dbconfig_dest_path,
|
24
25
|
dbconfig_src_fname,
|
25
26
|
db_scheme_ary,
|
26
|
-
|
27
|
-
|
27
|
+
acrecord_config,
|
28
|
+
migrate_dir
|
29
|
+
)
|
30
|
+
# アプリ構成情報
|
31
|
+
@config = config
|
28
32
|
# DB格納ディレクトリ名
|
29
33
|
@db_dir = config.get_db_dir
|
30
34
|
# DB構成ファイルの出力先ディレクトリ
|
@@ -34,18 +38,16 @@ module Arxutils_Sqlite3
|
|
34
38
|
# 参照用DB構成情報ファイル名
|
35
39
|
@dbconfig_src_fname = dbconfig_src_fname
|
36
40
|
|
37
|
-
# migrate用スクリプトの出力先ディレクトリ名
|
38
|
-
@migrate_dir = config.get_migrate_dir
|
39
41
|
# テンプレートファイル格納ディレクトリ名
|
40
|
-
@src_path = config.
|
41
|
-
#@src_path = Arxutils_Sqlite3::TEMPLATE_RELATION_DIR
|
42
|
+
@src_path = config.get_template_acrecord_dir
|
42
43
|
# 構成ファイル格納ディレクトリ
|
43
44
|
@src_config_path = config.get_template_config_dir
|
44
|
-
# @src_config_path = Arxutils_Sqlite3::TEMPLATE_CONFIG_DIR
|
45
|
+
# @src_config_path = Arxutils_Sqlite3::TEMPLATE_CONFIG_DIR
|
45
46
|
# データベーススキーマ定義配列
|
46
47
|
@db_scheme_ary = db_scheme_ary
|
47
48
|
# リレーション指定
|
48
|
-
@
|
49
|
+
@acrecord_config = acrecord_config
|
50
|
+
@migrate_dir = migrate_dir
|
49
51
|
|
50
52
|
FileUtils.mkdir_p(@db_dir) if @db_dir
|
51
53
|
FileUtils.mkdir_p(@migrate_dir) if @migrate_dir
|
@@ -60,7 +62,11 @@ module Arxutils_Sqlite3
|
|
60
62
|
end
|
61
63
|
end
|
62
64
|
Dir.glob(File.join(@dest_config_dir, "*")).each do |x|
|
63
|
-
|
65
|
+
basename = File.basename(x)
|
66
|
+
ret = !@config.exclude_file?( basename )
|
67
|
+
ret_file = File.file?(x)
|
68
|
+
ret2 = (ret_file && ret)
|
69
|
+
FileUtils.rm(x) if ret2
|
64
70
|
end
|
65
71
|
Dir.glob(File.join(@db_dir, "*")).each do |x|
|
66
72
|
# puts x
|
@@ -89,12 +95,12 @@ module Arxutils_Sqlite3
|
|
89
95
|
end
|
90
96
|
end
|
91
97
|
|
92
|
-
# マイグレーション用スクリプトの生成、
|
98
|
+
# マイグレーション用スクリプトの生成、acrecordのクラス定義ファイルの生成
|
93
99
|
def output
|
94
100
|
# migrationのスクリプトをファイル出力する
|
95
101
|
output_all_script
|
96
102
|
|
97
|
-
#
|
103
|
+
# acrecordを表すクラス定義のファイルの内容を生成
|
98
104
|
content_array = make_content_array
|
99
105
|
# p "content_array=#{content_array}"
|
100
106
|
# 複数形のクラス名を集める
|
@@ -102,7 +108,7 @@ module Arxutils_Sqlite3
|
|
102
108
|
x[:need_count_class_plural].nil?
|
103
109
|
end
|
104
110
|
need_count_class_plural = count_class_plurals.map { |x| x[:need_count_class_plural] }
|
105
|
-
#
|
111
|
+
# acrecordのmigrateが必要であれば、それをテンプレートファイルから作成して、スクリプトの内容として追加する
|
106
112
|
if content_array.find { |x| !x.nil? }
|
107
113
|
# p "####### 1"
|
108
114
|
data_count = {
|
@@ -111,12 +117,12 @@ module Arxutils_Sqlite3
|
|
111
117
|
}
|
112
118
|
# p "data_count=#{data_count}"
|
113
119
|
ary = content_array.collect { |x| x[:content] }.flatten
|
114
|
-
count_content =
|
120
|
+
count_content = convert_count_class_acrecord(data_count, "acrecord_count.tmpl")
|
115
121
|
ary.unshift(count_content)
|
116
122
|
content_array = ary
|
117
123
|
end
|
118
|
-
#
|
119
|
-
|
124
|
+
# acrecordのスクリプトを作成
|
125
|
+
output_acrecord_script(content_array, @acrecord_config)
|
120
126
|
end
|
121
127
|
|
122
128
|
# migrationのスクリプトをファイル出力する
|
@@ -128,17 +134,17 @@ module Arxutils_Sqlite3
|
|
128
134
|
end
|
129
135
|
end
|
130
136
|
|
131
|
-
#
|
137
|
+
# acrecordを表すクラス定義のファイルの内容を生成
|
132
138
|
def make_content_array
|
133
|
-
# スキーマ設定配列から、
|
134
|
-
|
135
|
-
|
139
|
+
# スキーマ設定配列から、acrecordのmigrate用のスクリプトの内容(ハッシュ形式)の配列を作成する
|
140
|
+
acrecords = @db_scheme_ary.map do |x|
|
141
|
+
make_acrecord(x, "count")
|
136
142
|
end
|
137
|
-
|
143
|
+
acrecords.select { |x| x.size.positive? }
|
138
144
|
end
|
139
145
|
|
140
|
-
# Countクラス用の
|
141
|
-
def
|
146
|
+
# Countクラス用のacrecordのスクリプトの内容に変換
|
147
|
+
def convert_count_class_acrecord(data, src_fname)
|
142
148
|
convert(data, @src_path, src_fname)
|
143
149
|
end
|
144
150
|
|
@@ -153,28 +159,29 @@ module Arxutils_Sqlite3
|
|
153
159
|
def make_dbconfig(data)
|
154
160
|
content = convert(data, @src_config_path, @dbconfig_src_fname)
|
155
161
|
File.open(
|
156
|
-
@dbconfig_dest_path, "w:utf-8"
|
162
|
+
@dbconfig_dest_path, "w:utf-8"
|
163
|
+
) do |f|
|
157
164
|
f.puts(content)
|
158
165
|
end
|
159
166
|
end
|
160
167
|
|
161
|
-
# 英子文字で表現したクラス名が、countを表していなければ、
|
168
|
+
# 英子文字で表現したクラス名が、countを表していなければ、acrecordを
|
162
169
|
# 英子文字で表現したクラス名が、countを表していれが、空のハッシュを返す
|
163
|
-
# スキーマでbase, noitem以外のフィールドが指定されていれば、そのフィールドに対する
|
164
|
-
def
|
170
|
+
# スキーマでbase, noitem以外のフィールドが指定されていれば、そのフィールドに対するacrecordの設定の内容を返す
|
171
|
+
def make_acrecord(data, count_classname_downcase)
|
165
172
|
if data[:classname_downcase] == count_classname_downcase
|
166
173
|
{}
|
167
174
|
else
|
168
|
-
# 指定フィールドのフィールド名に対応したテンプレートファイルを用いて、
|
175
|
+
# 指定フィールドのフィールド名に対応したテンプレートファイルを用いて、acrecord設定を作成
|
169
176
|
data[:flist].each_with_object({ content: [], need_count_class: nil }) do |field_name, s|
|
170
177
|
case field_name
|
171
178
|
when "base", "noitem"
|
172
|
-
name_base = "
|
173
|
-
# data[:
|
174
|
-
data[:
|
179
|
+
name_base = "acrecord"
|
180
|
+
# data[:acrecord]がnilに設定されていたら改めて空の配列を設定
|
181
|
+
data[:acrecord] = [] unless data[:acrecord]
|
175
182
|
else
|
176
183
|
data[:count_classname_downcase] = count_classname_downcase
|
177
|
-
name_base = "
|
184
|
+
name_base = "acrecord_#{field_name}"
|
178
185
|
s[:need_count_class_plural] ||= data[:plural]
|
179
186
|
end
|
180
187
|
# テンプレートファイルからスクリプトの内容を作成
|
@@ -186,41 +193,40 @@ module Arxutils_Sqlite3
|
|
186
193
|
|
187
194
|
# スキーマ設定からmigarte用スクリプトの内容を生成
|
188
195
|
def make_script_group(data)
|
189
|
-
#p data
|
190
|
-
data[:flist].map
|
191
|
-
|kind|
|
196
|
+
# p data
|
197
|
+
data[:flist].map do |kind|
|
192
198
|
[kind,
|
193
|
-
|
194
|
-
|
195
|
-
|
199
|
+
convert(data, @src_path, "#{kind}.tmpl"),
|
200
|
+
data[:classname_downcase]]
|
201
|
+
end
|
196
202
|
end
|
197
203
|
|
198
204
|
# migrationのスクリプトをファイル出力する
|
199
205
|
def output_script(idy, kind, content, classname_downcase)
|
200
206
|
additional = case kind
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
207
|
+
when "base", "noitem"
|
208
|
+
""
|
209
|
+
else
|
210
|
+
kind
|
211
|
+
end
|
206
212
|
fname = File.join(@migrate_dir, format("%03d_create_%s%s.rb", idy, additional, classname_downcase))
|
207
213
|
File.open(fname, "w", **{ encoding: Encoding::UTF_8 }) do |f|
|
208
214
|
f.puts(content)
|
209
215
|
end
|
210
216
|
end
|
211
217
|
|
212
|
-
#
|
213
|
-
def
|
214
|
-
dir =
|
215
|
-
fname =
|
218
|
+
# acrecordのスクリプトをファイル出力する
|
219
|
+
def output_acrecord_script(content_array, acrecord_config)
|
220
|
+
dir = acrecord_config[:dir]
|
221
|
+
fname = acrecord_config[:filename]
|
216
222
|
fpath = File.join(dir, fname)
|
217
223
|
File.open(fpath, "w") do |file|
|
218
|
-
|
224
|
+
acrecord_config[:module].map { |mod| file.puts("module #{mod}") }
|
219
225
|
content_array.map do |x|
|
220
226
|
file.puts x
|
221
227
|
file.puts ""
|
222
228
|
end
|
223
|
-
|
229
|
+
acrecord_config[:module].map { |_mod| file.puts("end") }
|
224
230
|
end
|
225
231
|
end
|
226
232
|
end
|
@@ -4,7 +4,8 @@ module Arxutils_Sqlite3
|
|
4
4
|
def self.make_log_path(db_dir, dbconfig)
|
5
5
|
log_path = ""
|
6
6
|
log_fname = Dbutil::Dbconnect.make_log_file_name(
|
7
|
-
dbconfig, Config::DATABASELOG
|
7
|
+
dbconfig, Config::DATABASELOG
|
8
|
+
)
|
8
9
|
if db_dir && log_fname
|
9
10
|
# DB用ログファイルへのパス
|
10
11
|
log_path = File.join(db_dir, log_fname)
|
data/lib/arxutils_sqlite3.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "ykutils"
|
3
4
|
require "ykxutils"
|
4
5
|
|
@@ -23,5 +24,5 @@ require_relative "arxutils_sqlite3/arx"
|
|
23
24
|
require_relative "arxutils_sqlite3/transactstate"
|
24
25
|
require_relative "arxutils_sqlite3/hier"
|
25
26
|
require_relative "arxutils_sqlite3/migrate"
|
26
|
-
require_relative "arxutils_sqlite3/migrate"
|
27
27
|
require_relative "arxutils_sqlite3/util"
|
28
|
+
require_relative "dbacrecord"
|