arxutils_sqlite3 0.1.40 → 0.1.43
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 +4 -4
- data/Rakefile +5 -5
- data/arxutils_sqlite3.gemspec +11 -8
- data/exe/arxutils_sqlite3 +73 -31
- data/lib/arxutils_sqlite3/dbutil/dbconnect.rb +7 -34
- data/lib/arxutils_sqlite3/dbutil.rb +0 -3
- data/lib/arxutils_sqlite3/migrate.rb +162 -184
- data/lib/arxutils_sqlite3/version.rb +1 -1
- data/lib/arxutils_sqlite3.rb +3 -3
- metadata +142 -3
- data/lib/arxutils_sqlite3/dbutil/dbmgr.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b67a7e8b8c74b99735830d7a77ed35c489a2f94334ed2e9d648e28a1dd7e619
|
4
|
+
data.tar.gz: daa960e9e9ed7f7a4e4457e8c1d8cc986abfea6a2ea0bff25c6da7ad3db9dd0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e213121d613bfb5445a2b701dabfb7718eec7a3a34b034c6bfe6a979d7302dbe64c2b8ed921f09f5ad49039e9ea782bdd1f115065dd5214267f549bb61354eae
|
7
|
+
data.tar.gz: f3ce79fb5d0162c515705f5132c143dc37dd17f438b3599871567e96a717b19f951cd2f82bfc6e320d70bd5fbb8932d0359d3c9466ba2743a5f128fd0c89a979
|
data/Rakefile
CHANGED
@@ -18,22 +18,22 @@ task cmi: %w[makeconfig migrate integrate]
|
|
18
18
|
# コマンドラインで指定したクラス名を含むオプション指定用ハッシュの定義を含むRubyスクリ
|
19
19
|
# プトファイルの生成
|
20
20
|
task :setup do
|
21
|
-
sh "bundle exec
|
21
|
+
sh "bundle exec arxutils_sqlite3 --cmd=s --klass=Enop"
|
22
22
|
end
|
23
23
|
# DB構成情報の生成
|
24
24
|
task :makeconfig do
|
25
|
-
sh "bundle exec
|
25
|
+
sh "bundle exec arxutils_sqlite3 --cmd=c"
|
26
26
|
end
|
27
27
|
# マイグレート用スクリプトファイルの生成とマイグレートの実行
|
28
28
|
task :migrate do
|
29
|
-
sh "bundle exec
|
29
|
+
sh "bundle exec arxutils_sqlite3 --cmd=m --yaml=config/db_scheme.yml"
|
30
30
|
end
|
31
31
|
task :integrate do
|
32
|
-
sh "bundle exec
|
32
|
+
sh "bundle exec arxutils_sqlite3 --cmd=i"
|
33
33
|
end
|
34
34
|
|
35
35
|
task :delete do
|
36
|
-
sh "bundle exec
|
36
|
+
sh "bundle exec arxutils_sqlite3 --cmd=d"
|
37
37
|
end
|
38
38
|
|
39
39
|
#=end
|
data/arxutils_sqlite3.gemspec
CHANGED
@@ -31,22 +31,25 @@ 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
35
|
spec.require_paths = ["lib"]
|
35
|
-
#p "====-"
|
36
|
-
#p "spec.executables=#{spec.executables}"
|
37
|
-
#p "====----"
|
38
36
|
spec.add_runtime_dependency "activesupport"
|
39
37
|
# spec.add_runtime_dependency "erb"
|
40
38
|
# spec.add_runtime_dependency "activerecord", "~> 4.2"
|
41
39
|
spec.add_runtime_dependency "activerecord", "~> 6.1"
|
42
40
|
spec.add_runtime_dependency "sqlite3"
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
spec.add_runtime_dependency "ykutils"
|
42
|
+
spec.add_runtime_dependency "ykxutils"
|
43
|
+
spec.add_runtime_dependency "simpleoptparse"
|
46
44
|
# spec.add_development_dependency "bundler", "~> 2.2.10"
|
47
|
-
|
45
|
+
spec.add_development_dependency "bundler"
|
46
|
+
spec.add_development_dependency "rake"
|
48
47
|
#spec.add_development_dependency "rake", ">= 12.3.3"
|
49
|
-
|
48
|
+
spec.add_development_dependency "rspec"
|
49
|
+
spec.add_development_dependency "rubocop"
|
50
|
+
spec.add_development_dependency "rubocop-rake"
|
51
|
+
spec.add_development_dependency "rubocop-rspec"
|
52
|
+
spec.add_development_dependency "yard"
|
50
53
|
# Uncomment to register a new dependency of your gem
|
51
54
|
# spec.add_dependency "example-gem", "~> 1.0"
|
52
55
|
|
data/exe/arxutils_sqlite3
CHANGED
@@ -32,22 +32,38 @@ if File.exist?(Arxutils_Sqlite3::DEST_DBSETUP_FILE)
|
|
32
32
|
end
|
33
33
|
|
34
34
|
|
35
|
-
def prepare_for_migrate(env, db_scheme_ary, opts)
|
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
|
+
|
54
|
+
def make_log_path(db_dir, dbconfig)
|
55
|
+
log_path = ""
|
36
56
|
log_fname = Arxutils_Sqlite3::Dbutil::Dbconnect.make_log_file_name(
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
Arxutils_Sqlite3::Dbutil::CONFIG_DIR,
|
42
|
-
opts["dbconfig"],
|
43
|
-
env,
|
44
|
-
log_fname,
|
45
|
-
opts
|
46
|
-
)
|
47
|
-
if opts["cmd"] != "i"
|
48
|
-
Arxutils_Sqlite3::Migrate.migrate(dbconnect, db_scheme_ary, opts["migrate_cmd"], opts[:relation], opts)
|
57
|
+
dbconfig, Arxutils_Sqlite3::Dbutil::DATABASELOG)
|
58
|
+
if db_dir && log_fname
|
59
|
+
# DB用ログファイルへのパス
|
60
|
+
log_path = File.join(db_dir, log_fname)
|
49
61
|
end
|
50
|
-
|
62
|
+
log_path
|
63
|
+
end
|
64
|
+
|
65
|
+
def make_dbconfig_path(config_dir, dbconfig)
|
66
|
+
File.join( config_dir, "#{dbconfig}.yml")
|
51
67
|
end
|
52
68
|
|
53
69
|
banner = "Usage: bundle exec ruby exe/makemigrate --cmd=(s|c|m|i|d) -y yaml_file --klass=class"
|
@@ -67,7 +83,7 @@ env ||= "production"
|
|
67
83
|
|
68
84
|
case opts["cmd"]
|
69
85
|
when "s"
|
70
|
-
FileUtils.cp(Arxutils_Sqlite3::DB_SCHEME_FILE, Arxutils_Sqlite3::CONFIG_DIR )
|
86
|
+
FileUtils.cp(Arxutils_Sqlite3::DB_SCHEME_FILE, Arxutils_Sqlite3::Dbutil::CONFIG_DIR )
|
71
87
|
if opts["klass"].nil? || opts["klass"].strip == ""
|
72
88
|
puts banner
|
73
89
|
exit 10
|
@@ -83,11 +99,15 @@ when "s"
|
|
83
99
|
db_scheme_ary = nil
|
84
100
|
|
85
101
|
when "c"
|
86
|
-
opts["migrate_cmd"] = "makeconfig"
|
87
|
-
#opts["remigrate"] = false
|
88
102
|
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)
|
109
|
+
mig.make_dbconfig(opts)
|
89
110
|
|
90
|
-
prepare_for_migrate(env, db_scheme_ary, opts)
|
91
111
|
when "m"
|
92
112
|
if opts["yaml"].nil? || opts["yaml"].strip == ""
|
93
113
|
puts banner
|
@@ -98,9 +118,6 @@ when "m"
|
|
98
118
|
db_scheme_ary = YAML.load_file( opts["yaml"] )
|
99
119
|
|
100
120
|
scope = Object.new
|
101
|
-
# p "==="
|
102
|
-
# p opts
|
103
|
-
# p "=== END"
|
104
121
|
|
105
122
|
hash0 = {module_name: opts[:relation][:module].join("::")}
|
106
123
|
hash = db_scheme_ary[0].merge( hash0 )
|
@@ -109,26 +126,51 @@ when "m"
|
|
109
126
|
File.open(Arxutils_Sqlite3::DEST_DBSETUP_FILE, "w"){|file|
|
110
127
|
file.write(result_content)
|
111
128
|
}
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
#
|
118
|
-
|
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}"
|
145
|
+
ActiveRecord::MigrationContext.new(mig.migrate_dir, ActiveRecord::SchemaMigration).up
|
119
146
|
|
120
147
|
when "i"
|
121
148
|
#db_scheme_ary = YAML.load_file( opts["yaml"] )
|
122
149
|
db_scheme_ary = nil
|
123
|
-
|
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
|
+
)
|
124
162
|
connect_time = dbconnect.connect
|
125
163
|
|
126
164
|
Dbsetup.new(connect_time)
|
127
165
|
|
128
166
|
when "d"
|
129
|
-
opts["migrate_cmd"] = "delete"
|
130
167
|
db_scheme_ary = nil
|
131
|
-
|
168
|
+
mig = repare_for_migrate(env, db_scheme_ary, opts)
|
169
|
+
mig.delete_migrate_config_and_db
|
170
|
+
|
132
171
|
else
|
133
172
|
puts "Invalid command(#{opts["cmd"]}) specified!!"
|
134
173
|
end
|
174
|
+
|
175
|
+
#
|
176
|
+
|
@@ -32,60 +32,33 @@ module Arxutils_Sqlite3
|
|
32
32
|
module Dbutil
|
33
33
|
# DB操作用ユーティリティクラス
|
34
34
|
class Dbconnect
|
35
|
-
# 生成するDB構成情報ファイルパス
|
36
|
-
attr_accessor :dbconfig_dest_path
|
37
|
-
# 参照用DB構成情報ファイル名
|
38
|
-
attr_accessor :dbconfig_src_fname
|
39
|
-
# migrate用スクリプトの出力先ディレクトリ名
|
40
|
-
attr_accessor :migrate_dir, :dest_config_dir, :db_dir
|
41
|
-
|
42
35
|
def self.make_log_file_name(dbconfig, log_file_base_name)
|
43
36
|
format("%s-%s", dbconfig.to_s, log_file_base_name)
|
44
37
|
end
|
45
38
|
|
46
39
|
# DB接続までの初期化に必要なディレクトリの確認、作成
|
47
|
-
def initialize(
|
40
|
+
def initialize(dbconfig_dest_path, env, log_path)
|
48
41
|
# 接続開始時刻
|
49
42
|
@connect_time = nil
|
50
43
|
# DB格納ディレクトリ名
|
51
|
-
@
|
52
|
-
# DB構成ファイルのテンプレート格納ディレクトリ
|
53
|
-
@src_config_dir = src_config_dir
|
54
|
-
# DB構成ファイルの出力先ディレクトリ
|
55
|
-
@dest_config_dir = CONFIG_DIR
|
56
|
-
# DB構成ファイル名
|
57
|
-
@dbconfig_dest_fname = "#{dbconfig}.yml"
|
58
|
-
# DB構成ファイル用テンプレートファイル名
|
59
|
-
@dbconfig_src_fname = "#{dbconfig}.tmpl"
|
60
|
-
# DB構成ファイルへのパス
|
61
|
-
@dbconfig_dest_path = File.join(@dest_config_dir, @dbconfig_dest_fname)
|
62
|
-
# DB構成ファイル用テンプレートファイルへのパス
|
63
|
-
@dbconfig_src_path = File.join(@src_config_dir, @dbconfig_src_fname)
|
64
|
-
# 環境の指定
|
44
|
+
@dbconfig_dest_path = dbconfig_dest_path
|
65
45
|
@env = env
|
66
|
-
|
67
|
-
@log_fname = log_fname
|
68
|
-
|
69
|
-
if @db_dir && @log_fname
|
70
|
-
# DB用ログファイルへのパス
|
71
|
-
@log_path = File.join(@db_dir, @log_fname)
|
72
|
-
# migrate用スクリプト格納ディレクトリへのパス
|
73
|
-
@migrate_dir = File.join(@db_dir, migrate_base_dir)
|
74
|
-
end
|
75
|
-
FileUtils.mkdir_p(@db_dir) if @db_dir
|
76
|
-
FileUtils.mkdir_p(@migrate_dir) if @migrate_dir
|
77
|
-
FileUtils.mkdir_p(@dest_config_dir)
|
46
|
+
@log_path = log_path
|
78
47
|
end
|
79
48
|
|
80
49
|
# DB接続、DB用ログファイルの設定
|
81
50
|
def connect
|
82
51
|
unless @connect_time
|
83
52
|
begin
|
53
|
+
p "@dbconfig_dest_path=#{@dbconfig_dest_path}"
|
84
54
|
dbconfig = Ykxutils.yaml_load_file_compati(@dbconfig_dest_path)
|
55
|
+
p "dbconfig=#{dbconfig}"
|
56
|
+
p "@env=#{@env}"
|
85
57
|
ActiveRecord::Base.establish_connection(dbconfig[@env])
|
86
58
|
ActiveRecord::Base.logger = Logger.new(@log_path)
|
87
59
|
@connect_time = DateTime.now.new_offset
|
88
60
|
rescue => ex
|
61
|
+
p ex.message
|
89
62
|
end
|
90
63
|
end
|
91
64
|
@connect_time
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative "dbutil/dbconnect"
|
2
|
-
#require_relative "dbutil/dbmgr"
|
3
2
|
|
4
3
|
module Arxutils_Sqlite3
|
5
4
|
# DB操作用ユーティリティクラス
|
@@ -16,7 +15,5 @@ module Arxutils_Sqlite3
|
|
16
15
|
CONFIG_DIR = "config".freeze
|
17
16
|
# データベース用ログファイル名
|
18
17
|
DATABASELOG = "database.log".freeze
|
19
|
-
|
20
|
-
# DB接続までの初期化を行う
|
21
18
|
end
|
22
19
|
end
|
@@ -8,218 +8,196 @@ require "pp"
|
|
8
8
|
|
9
9
|
# ActiveRecord用ユーティリティモジュール
|
10
10
|
module Arxutils_Sqlite3
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
##
|
12
|
+
# migrateに必要なファイルをテンプレートから作成し、migarteを実行する
|
13
|
+
class Migrate
|
14
|
+
attr_reader :migrate_dir
|
14
15
|
# migrate用スクリプトファイル名の先頭の番号の間隔
|
15
16
|
FILENAME_COUNTER_STEP = 10
|
16
|
-
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
17
|
+
# DB接続までの初期化を行うDbinitクラスのインスタンス
|
18
|
+
#attr_reader :dbinit
|
19
|
+
|
20
|
+
# migrate用のスクリプトの生成、migrateの実行を行うmigratexの生成
|
21
|
+
def initialize(
|
22
|
+
dbconfig_dest_path,
|
23
|
+
dbconfig_src_fname,
|
24
|
+
migrate_dir,
|
25
|
+
db_dir,
|
26
|
+
db_scheme_ary,
|
27
|
+
relation,
|
28
|
+
opts)
|
29
|
+
# DB格納ディレクトリ名
|
30
|
+
@db_dir = db_dir
|
31
|
+
# DB構成ファイルの出力先ディレクトリ
|
32
|
+
@dest_config_dir = Arxutils_Sqlite3::Dbutil::CONFIG_DIR
|
33
|
+
# 生成するDB構成情報ファイルパス
|
34
|
+
@dbconfig_dest_path = dbconfig_dest_path
|
35
|
+
# 参照用DB構成情報ファイル名
|
36
|
+
@dbconfig_src_fname = dbconfig_src_fname
|
37
|
+
|
38
|
+
# migrate用スクリプトの出力先ディレクトリ名
|
39
|
+
@migrate_dir = migrate_dir
|
40
|
+
# テンプレートファイル格納ディレクトリ名
|
41
|
+
@src_path = Arxutils_Sqlite3::TEMPLATE_RELATION_DIR
|
42
|
+
# 構成ファイル格納ディレクトリ
|
43
|
+
@src_config_path = Arxutils_Sqlite3::TEMPLATE_CONFIG_DIR
|
44
|
+
# データベーススキーマ定義配列
|
45
|
+
@db_scheme_ary = db_scheme_ary
|
46
|
+
# リレーション指定
|
47
|
+
@relation = relation
|
48
|
+
# オプション指定
|
49
|
+
@opts = opts
|
50
|
+
|
51
|
+
FileUtils.mkdir_p(@db_dir) if @db_dir
|
52
|
+
FileUtils.mkdir_p(@migrate_dir) if @migrate_dir
|
53
|
+
FileUtils.mkdir_p(@dest_config_dir)
|
33
54
|
end
|
34
55
|
|
35
|
-
#
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
56
|
+
# マイグレート用スクリプト、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, "*")))
|
60
|
+
Dir.glob(File.join(@db_dir, "*")).each do |x|
|
61
|
+
# puts x
|
62
|
+
FileUtils.rm(x) if File.file?(x)
|
41
63
|
end
|
42
64
|
end
|
43
65
|
|
44
|
-
# migrate
|
45
|
-
|
46
|
-
#
|
47
|
-
|
48
|
-
|
49
|
-
# migrate用のスクリプトの生成、migrateの実行を行うmigratexの生成
|
50
|
-
def initialize(dbconnect, db_scheme_ary, relation, opts)
|
51
|
-
# DB接続までの初期化を行うDbinitクラスのインスタンス
|
52
|
-
@dbconnect = dbconnect
|
53
|
-
# 生成するDB構成情報ファイルパス
|
54
|
-
@dbconfig_dest_path = @dbconnect.dbconfig_dest_path
|
55
|
-
# 参照用DB構成情報ファイル名
|
56
|
-
@dbconfig_src_fname = @dbconnect.dbconfig_src_fname
|
57
|
-
|
58
|
-
# migrate用スクリプトの出力先ディレクトリ名
|
59
|
-
@migrate_dir = @dbconnect.migrate_dir
|
60
|
-
# テンプレートファイル格納ディレクトリ名
|
61
|
-
@src_path = Arxutils_Sqlite3::TEMPLATE_RELATION_DIR
|
62
|
-
# 構成ファイル格納ディレクトリ
|
63
|
-
@src_config_path = Arxutils_Sqlite3::TEMPLATE_CONFIG_DIR
|
64
|
-
# データベーススキーマ定義配列
|
65
|
-
@db_scheme_ary = db_scheme_ary
|
66
|
-
# リレーション指定
|
67
|
-
@relation = relation
|
68
|
-
# オプション指定
|
69
|
-
@opts = opts
|
70
|
-
end
|
66
|
+
# マイグレーション用スクリプトの生成、relationのクラス定義ファイルの生成、migrate実行
|
67
|
+
def process
|
68
|
+
# migrationのスクリプトをファイル出力する
|
69
|
+
output_all_script
|
71
70
|
|
72
|
-
#
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
FileUtils.rm(Dir.glob(File.join(migrate_dir, "*"))) if migrate_dir
|
79
|
-
FileUtils.rm(Dir.glob(File.join(dest_config_dir, "*")))
|
80
|
-
Dir.glob(File.join(db_dir, "*")).each do |x|
|
81
|
-
# puts x
|
82
|
-
FileUtils.rm(x) if File.file?(x)
|
83
|
-
end
|
71
|
+
# relationを表すクラス定義のファイルの内容を生成
|
72
|
+
content_array = make_content_array
|
73
|
+
# p "content_array=#{content_array}"
|
74
|
+
# 複数形のクラス名を集める
|
75
|
+
count_class_plurals = content_array.reject do |x|
|
76
|
+
x[:need_count_class_plural].nil?
|
84
77
|
end
|
85
|
-
|
86
|
-
#
|
87
|
-
|
88
|
-
#
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
# p "
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
need_count_class_plural = count_class_plurals.map { |x| x[:need_count_class_plural] }
|
99
|
-
# relationのmigrateが必要であれば、それをテンプレートファイルから作成して、スクリプトの内容として追加する
|
100
|
-
if content_array.find { |x| !x.nil? }
|
101
|
-
# p "####### 1"
|
102
|
-
data_count = {
|
103
|
-
count_classname: "Count",
|
104
|
-
need_count_class_plural: need_count_class_plural
|
105
|
-
}
|
106
|
-
# p "data_count=#{data_count}"
|
107
|
-
ary = content_array.collect { |x| x[:content] }.flatten
|
108
|
-
count_content = convert_count_class_relation(data_count, "relation_count.tmpl")
|
109
|
-
ary.unshift(count_content)
|
110
|
-
content_array = ary
|
111
|
-
end
|
112
|
-
# relationのスクリプトを作成
|
113
|
-
output_relation_script(content_array, @relation)
|
78
|
+
need_count_class_plural = count_class_plurals.map { |x| x[:need_count_class_plural] }
|
79
|
+
# relationのmigrateが必要であれば、それをテンプレートファイルから作成して、スクリプトの内容として追加する
|
80
|
+
if content_array.find { |x| !x.nil? }
|
81
|
+
# p "####### 1"
|
82
|
+
data_count = {
|
83
|
+
count_classname: "Count",
|
84
|
+
need_count_class_plural: need_count_class_plural
|
85
|
+
}
|
86
|
+
# p "data_count=#{data_count}"
|
87
|
+
ary = content_array.collect { |x| x[:content] }.flatten
|
88
|
+
count_content = convert_count_class_relation(data_count, "relation_count.tmpl")
|
89
|
+
ary.unshift(count_content)
|
90
|
+
content_array = ary
|
114
91
|
end
|
92
|
+
# relationのスクリプトを作成
|
93
|
+
output_relation_script(content_array, @relation)
|
94
|
+
end
|
115
95
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
end
|
96
|
+
# migrationのスクリプトをファイル出力する
|
97
|
+
def output_all_script
|
98
|
+
# スキーマ設定配列から、migrate用のスクリプトを作成する
|
99
|
+
@db_scheme_ary.map { |x| make_script_group(x) }.flatten(1).each_with_index do |data, index|
|
100
|
+
idy = (index + 1) * FILENAME_COUNTER_STEP
|
101
|
+
output_script(idy, *data)
|
123
102
|
end
|
103
|
+
end
|
124
104
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
relations.select { |x| x.size.positive? }
|
105
|
+
# relationを表すクラス定義のファイルの内容を生成
|
106
|
+
def make_content_array
|
107
|
+
# スキーマ設定配列から、relationのmigrate用のスクリプトの内容(ハッシュ形式)の配列を作成する
|
108
|
+
relations = @db_scheme_ary.map do |x|
|
109
|
+
make_relation(x, "count")
|
132
110
|
end
|
111
|
+
relations.select { |x| x.size.positive? }
|
112
|
+
end
|
133
113
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
114
|
+
# Countクラス用のrelationのスクリプトの内容に変換
|
115
|
+
def convert_count_class_relation(data, src_fname)
|
116
|
+
convert(data, @src_path, src_fname)
|
117
|
+
end
|
138
118
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
119
|
+
# テンプレートファイルからスクリプトの内容に変換
|
120
|
+
def convert(data, src_dir, src_fname)
|
121
|
+
arx = Arx.new(data, File.join(src_dir, src_fname))
|
122
|
+
# 指定テンプレートファイルからスクリプトの内容に作成
|
123
|
+
arx.create
|
124
|
+
end
|
145
125
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
end
|
126
|
+
# データベース構成ファイルをテンプレートから生成する
|
127
|
+
def make_dbconfig(data)
|
128
|
+
content = convert(data, @src_config_path, @dbconfig_src_fname)
|
129
|
+
File.open(
|
130
|
+
@dbconfig_dest_path, "w:utf-8") do |f|
|
131
|
+
f.puts(content)
|
153
132
|
end
|
133
|
+
end
|
154
134
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
end
|
174
|
-
# テンプレートファイルからスクリプトの内容を作成
|
175
|
-
content = convert(data, @src_path, "#{name_base}.tmpl")
|
176
|
-
s[:content] << content
|
135
|
+
# 英子文字で表現したクラス名が、countを表していなければ、relationを
|
136
|
+
# 英子文字で表現したクラス名が、countを表していれが、空のハッシュを返す
|
137
|
+
# スキーマでbase, noitem以外のフィールドが指定されていれば、そのフィールドに対するrelationの設定の内容を返す
|
138
|
+
def make_relation(data, count_classname_downcase)
|
139
|
+
if data[:classname_downcase] == count_classname_downcase
|
140
|
+
{}
|
141
|
+
else
|
142
|
+
# 指定フィールドのフィールド名に対応したテンプレートファイルを用いて、relation設定を作成
|
143
|
+
data[:flist].each_with_object({ content: [], need_count_class: nil }) do |field_name, s|
|
144
|
+
case field_name
|
145
|
+
when "base", "noitem"
|
146
|
+
name_base = "relation"
|
147
|
+
# data[:relation]がnilに設定されていたら改めて空の配列を設定
|
148
|
+
data[:relation] = [] unless data[:relation]
|
149
|
+
else
|
150
|
+
data[:count_classname_downcase] = count_classname_downcase
|
151
|
+
name_base = "relation_#{field_name}"
|
152
|
+
s[:need_count_class_plural] ||= data[:plural]
|
177
153
|
end
|
154
|
+
# テンプレートファイルからスクリプトの内容を作成
|
155
|
+
content = convert(data, @src_path, "#{name_base}.tmpl")
|
156
|
+
s[:content] << content
|
178
157
|
end
|
179
158
|
end
|
159
|
+
end
|
180
160
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
161
|
+
# スキーマ設定からmigarte用スクリプトの内容を生成
|
162
|
+
def make_script_group(data)
|
163
|
+
#p data
|
164
|
+
data[:flist].map {
|
165
|
+
|kind|
|
166
|
+
[kind,
|
167
|
+
convert(data, @src_path, "#{kind}.tmpl"),
|
168
|
+
data[:classname_downcase]
|
169
|
+
] }
|
170
|
+
end
|
191
171
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
end
|
172
|
+
# migrationのスクリプトをファイル出力する
|
173
|
+
def output_script(idy, kind, content, classname_downcase)
|
174
|
+
additional = case kind
|
175
|
+
when "base", "noitem"
|
176
|
+
""
|
177
|
+
else
|
178
|
+
kind
|
179
|
+
end
|
180
|
+
fname = File.join(@migrate_dir, format("%03d_create_%s%s.rb", idy, additional, classname_downcase))
|
181
|
+
File.open(fname, "w", **{ encoding: Encoding::UTF_8 }) do |f|
|
182
|
+
f.puts(content)
|
204
183
|
end
|
184
|
+
end
|
205
185
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
end
|
219
|
-
opts[:module].map { |_mod| file.puts("end") }
|
186
|
+
# relationのスクリプトをファイル出力する
|
187
|
+
def output_relation_script(content_array, opts)
|
188
|
+
# pp "=="
|
189
|
+
# pp opts
|
190
|
+
dir = opts[:dir]
|
191
|
+
fname = opts[:filename]
|
192
|
+
fpath = File.join(dir, fname)
|
193
|
+
File.open(fpath, "w") do |file|
|
194
|
+
opts[:module].map { |mod| file.puts("module #{mod}") }
|
195
|
+
content_array.map do |x|
|
196
|
+
file.puts x
|
197
|
+
file.puts ""
|
220
198
|
end
|
199
|
+
opts[:module].map { |_mod| file.puts("end") }
|
221
200
|
end
|
222
|
-
|
223
201
|
end
|
224
202
|
end
|
225
203
|
end
|
data/lib/arxutils_sqlite3.rb
CHANGED
@@ -14,20 +14,20 @@ require_relative "arxutils_sqlite3/transactstate"
|
|
14
14
|
require_relative "arxutils_sqlite3/hier"
|
15
15
|
require_relative "arxutils_sqlite3/migrate"
|
16
16
|
require_relative "arxutils_sqlite3/dbutil"
|
17
|
+
require_relative "arxutils_sqlite3/migrate"
|
17
18
|
|
18
19
|
module Arxutils_Sqlite3
|
19
20
|
TOP_DIR = Pathname(__FILE__).parent
|
20
21
|
TEMPLATE_DIR = TOP_DIR.join("template")
|
21
22
|
TEMPLATE_RELATION_DIR = TEMPLATE_DIR.join("relation")
|
22
|
-
TEMPLATE_CONFIG_DIR = TEMPLATE_DIR.join(
|
23
|
-
CONFIG_DIR = "config".freeze
|
24
|
-
DEST_CONFIG_DIR = Pathname.new("config")
|
23
|
+
TEMPLATE_CONFIG_DIR = TEMPLATE_DIR.join( Dbutil::CONFIG_DIR )
|
25
24
|
DB_SCHEME_DIR = TEMPLATE_RELATION_DIR.join("db_scheme")
|
26
25
|
DB_SCHEME_FILE = DB_SCHEME_DIR.join("db_scheme.yml")
|
27
26
|
OPTS_FILE_NAME = "opts.rb"
|
28
27
|
OPTS_FILE_NAME_2 = "opts"
|
29
28
|
DBSETUP_FILE_NAME = "dbsetup.rb"
|
30
29
|
DBSETUP_FILE_NAME_2 = "dbsetup"
|
30
|
+
DEST_CONFIG_DIR = Pathname.new( Dbutil::CONFIG_DIR )
|
31
31
|
OPTS_FILE = DB_SCHEME_DIR.join(OPTS_FILE_NAME)
|
32
32
|
DBSETUP_FILE = DB_SCHEME_DIR.join(DBSETUP_FILE_NAME)
|
33
33
|
DEST_OPTS_FILE = DEST_CONFIG_DIR.join(OPTS_FILE_NAME)
|
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.
|
4
|
+
version: 0.1.43
|
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-
|
11
|
+
date: 2022-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,6 +52,146 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ykutils
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ykxutils
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simpleoptparse
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop-rake
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rubocop-rspec
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: yard
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
55
195
|
description: utility functions for ActiveRecord.
|
56
196
|
email:
|
57
197
|
- ykominami@gmail.com
|
@@ -79,7 +219,6 @@ files:
|
|
79
219
|
- lib/arxutils_sqlite3/arx.rb
|
80
220
|
- lib/arxutils_sqlite3/dbutil.rb
|
81
221
|
- lib/arxutils_sqlite3/dbutil/dbconnect.rb
|
82
|
-
- lib/arxutils_sqlite3/dbutil/dbmgr.rb
|
83
222
|
- lib/arxutils_sqlite3/hier.rb
|
84
223
|
- lib/arxutils_sqlite3/migrate.rb
|
85
224
|
- lib/arxutils_sqlite3/transactstate.rb
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require "arxutils_sqlite3/dbutil/dbinit"
|
2
|
-
require "date"
|
3
|
-
require "pp"
|
4
|
-
|
5
|
-
module Arxutils_Sqlite3
|
6
|
-
module Dbutil
|
7
|
-
# DB接続時に、現在日時も取得したい場合のユーティリティクラス
|
8
|
-
class DbMgr
|
9
|
-
# DB接続の状態を示す
|
10
|
-
@ret = nil
|
11
|
-
# DB接続、現在日時取得
|
12
|
-
def self.setup(dbinit)
|
13
|
-
unless @ret
|
14
|
-
begin
|
15
|
-
dbinit.setup
|
16
|
-
@ret = DateTime.now.new_offset
|
17
|
-
rescue StandardError => e
|
18
|
-
pp e.class
|
19
|
-
pp e.message
|
20
|
-
pp e.backtrace
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
@ret
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|