arxutils_sqlite3 0.1.40 → 0.1.45
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/Gemfile +1 -1
- data/Rakefile +24 -7
- data/arxutils_sqlite3.gemspec +11 -8
- data/exe/arxutils_sqlite3 +51 -76
- data/lib/arxutils_sqlite3/config.rb +242 -0
- data/lib/arxutils_sqlite3/dbutil/dbconnect.rb +21 -34
- data/lib/arxutils_sqlite3/dbutil.rb +0 -13
- data/lib/arxutils_sqlite3/migrate.rb +158 -183
- data/lib/arxutils_sqlite3/util.rb +20 -0
- data/lib/arxutils_sqlite3/version.rb +1 -1
- data/lib/arxutils_sqlite3.rb +11 -25
- data/lib/template/relation/db_scheme/dbsetup.rb +1 -1
- data/lib/template/relation/db_scheme/opts.rb +1 -1
- metadata +144 -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: 7186c960b82d6762345ea6f0d8a52282025c001a52a4a9398ca7c7f15e4c21eb
|
4
|
+
data.tar.gz: 859c88d305e3b9227a9ed1464d5a254d13b096ccc30447acb6043cd7fd73a71f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 357450af1e2fc3051d4c0b9c3289022a39b779de484db79ca3576baff144c5a8c25529f181dc5e77ca0a6de5453d20bfae409898dc84d430cd46afaea48d8c21
|
7
|
+
data.tar.gz: 00142e1c2494bea9a3158628f778f553aae4ac1d4b02a18c7e576aea2b947b47f3ab5df1ffc200d58c9f84d4570ac916076b4acb41437d6e0be64179e668604b
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -11,29 +11,46 @@ task default: :test
|
|
11
11
|
=end
|
12
12
|
|
13
13
|
#=begin
|
14
|
-
task default
|
14
|
+
# Defining a task called default that depends on the tasks setup, makeconfig, migrate, and integrate.
|
15
|
+
task default: %w[delete setup makeconfig migrate integrate]
|
15
16
|
|
16
|
-
task
|
17
|
+
task scmi: %w[setup makeconfig migrate integrate]
|
18
|
+
|
19
|
+
task dsc: %w[delete setup makeconfig]
|
20
|
+
|
21
|
+
task ds: %w[delete setup]
|
22
|
+
|
23
|
+
task s: %w[setup]
|
24
|
+
|
25
|
+
task sc: %w[setup makeconfig]
|
26
|
+
|
27
|
+
task dscm: %w[delete setup makeconfig migrate]
|
28
|
+
|
29
|
+
task scm: %w[setup makeconfig migrate]
|
30
|
+
|
31
|
+
task dscmi: %w[delete setup makeconfig migrate integrate]
|
32
|
+
|
33
|
+
task scmi: %w[setup makeconfig migrate integrate]
|
17
34
|
|
18
35
|
# コマンドラインで指定したクラス名を含むオプション指定用ハッシュの定義を含むRubyスクリ
|
19
36
|
# プトファイルの生成
|
20
37
|
task :setup do
|
21
|
-
sh "bundle exec
|
38
|
+
sh "bundle exec arxutils_sqlite3 --cmd=s --klass=Enop"
|
22
39
|
end
|
23
40
|
# DB構成情報の生成
|
24
41
|
task :makeconfig do
|
25
|
-
sh "bundle exec
|
42
|
+
sh "bundle exec arxutils_sqlite3 --cmd=c"
|
26
43
|
end
|
27
44
|
# マイグレート用スクリプトファイルの生成とマイグレートの実行
|
28
45
|
task :migrate do
|
29
|
-
sh "bundle exec
|
46
|
+
sh "bundle exec arxutils_sqlite3 --cmd=m --yaml=config/db_scheme.yml"
|
30
47
|
end
|
31
48
|
task :integrate do
|
32
|
-
sh "bundle exec
|
49
|
+
sh "bundle exec arxutils_sqlite3 --cmd=i"
|
33
50
|
end
|
34
51
|
|
35
52
|
task :delete do
|
36
|
-
sh "bundle exec
|
53
|
+
sh "bundle exec arxutils_sqlite3 --cmd=d"
|
37
54
|
end
|
38
55
|
|
39
56
|
#=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
@@ -6,14 +6,9 @@ require "pp"
|
|
6
6
|
require "ykutils"
|
7
7
|
require "ykxutils"
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
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,40 +16,18 @@ 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
19
|
|
20
|
+
klass = nil
|
21
|
+
setting = config.load_setting_yaml_file
|
22
|
+
klass = setting[:klass]
|
34
23
|
|
35
|
-
|
36
|
-
|
37
|
-
opts["dbconfig"], Arxutils_Sqlite3::Dbutil::DATABASELOG)
|
38
|
-
dbconnect = Arxutils_Sqlite3::Dbutil::Dbconnect.new(
|
39
|
-
Arxutils_Sqlite3::Dbutil::DB_DIR,
|
40
|
-
Arxutils_Sqlite3::Dbutil::MIGRATE_DIR,
|
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)
|
49
|
-
end
|
50
|
-
dbconnect
|
51
|
-
end
|
24
|
+
# DBセットアップクラス
|
25
|
+
config.require_dbsetup_file
|
52
26
|
|
53
27
|
banner = "Usage: bundle exec ruby exe/makemigrate --cmd=(s|c|m|i|d) -y yaml_file --klass=class"
|
54
28
|
|
55
29
|
opts = @opts ? @opts : {}
|
56
|
-
|
57
|
-
opts["dbconfig"] = Arxutils_Sqlite3::Dbutil::DBCONFIG_SQLITE3
|
30
|
+
opts["dbconfig"] = Arxutils_Sqlite3::Config::DBCONFIG_SQLITE3
|
58
31
|
|
59
32
|
Simpleoptparse::Simpleoptparse.parse(ARGV, opts, banner, Arxutils_Sqlite3::VERSION, nil) do |parser|
|
60
33
|
parser.on("--cmd X", %w[s c m i d]) { |x| opts["cmd"] = x }
|
@@ -67,68 +40,70 @@ env ||= "production"
|
|
67
40
|
|
68
41
|
case opts["cmd"]
|
69
42
|
when "s"
|
70
|
-
|
43
|
+
config.check_file_exist(Arxutils_Sqlite3::Config::DEST_OPTS_FILE, banner, 10)
|
44
|
+
|
71
45
|
if opts["klass"].nil? || opts["klass"].strip == ""
|
72
46
|
puts banner
|
73
|
-
exit
|
47
|
+
exit 20
|
74
48
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
File.open(Arxutils_Sqlite3::DEST_OPTS_FILE, "w"){|file|
|
81
|
-
file.write(result_content)
|
82
|
-
}
|
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)
|
83
54
|
db_scheme_ary = nil
|
84
55
|
|
85
56
|
when "c"
|
86
|
-
opts["migrate_cmd"] = "makeconfig"
|
87
|
-
#opts["remigrate"] = false
|
88
57
|
db_scheme_ary = nil
|
58
|
+
dbconfig = opts["dbconfig"]
|
59
|
+
replation = opts["replation"]
|
60
|
+
dbconfig_path = config.make_dbconfig_path(dbconfig)
|
61
|
+
config.check_file_exist(dbconfig_path, banner, 30)
|
62
|
+
mig = config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, replation)
|
63
|
+
mig.make_dbconfig(opts)
|
89
64
|
|
90
|
-
prepare_for_migrate(env, db_scheme_ary, opts)
|
91
65
|
when "m"
|
92
|
-
|
66
|
+
yaml_fname = opts["yaml"]
|
67
|
+
relation = opts[:relation]
|
68
|
+
dbconfig = opts["dbconfig"]
|
69
|
+
|
70
|
+
if yaml_fname.nil? || yaml_fname.strip == ""
|
93
71
|
puts banner
|
94
|
-
exit
|
72
|
+
exit 40
|
95
73
|
end
|
74
|
+
yaml_pn = Pathname.new(yaml_fname)
|
75
|
+
config.check_file_not_exist(yaml_pn, banner, 55)
|
76
|
+
db_scheme_ary = YAML.load_file( yaml_pn )
|
96
77
|
|
97
|
-
|
98
|
-
|
78
|
+
dest_dbsetup_file = config.get_dest_dbsetup_file
|
79
|
+
config.check_file_exist(dest_dbsetup_file, banner, 50)
|
99
80
|
|
100
|
-
|
101
|
-
# p "==="
|
102
|
-
# p opts
|
103
|
-
# p "=== END"
|
81
|
+
config.make_dbsetup_file(db_scheme_ary, relation, klass, dest_dbsetup_file)
|
104
82
|
|
105
|
-
|
106
|
-
hash = db_scheme_ary[0].merge( hash0 )
|
107
|
-
result_content = Ykutils::Erubyx.erubi_render_with_template_file(Arxutils_Sqlite3::DBSETUP_FILE, scope, hash)
|
83
|
+
connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(config, dbconfig, env)
|
108
84
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
# FileUtils.cp(Arxutils_Sqlite3::DBSETUP_FILE, Arxutils_Sqlite3::CONFIG_DIR )
|
85
|
+
# マイグレーション用スクリプトの生成、relationのクラス定義ファイルの生成
|
86
|
+
mig = config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, relation)
|
87
|
+
mig.output
|
113
88
|
|
114
|
-
#
|
115
|
-
|
116
|
-
dbconnect.connect
|
117
|
-
#db_migrate_dir = File.join(Dbutil::DB_DIR, Dbutil::MIGRATE_DIR)
|
118
|
-
ActiveRecord::MigrationContext.new(dbconnect.migrate_dir, ActiveRecord::SchemaMigration).up
|
89
|
+
# マイグレーション実行
|
90
|
+
ActiveRecord::MigrationContext.new(mig.migrate_dir, ActiveRecord::SchemaMigration).up
|
119
91
|
|
120
92
|
when "i"
|
121
|
-
|
122
|
-
|
123
|
-
dbconnect = prepare_for_migrate(env, db_scheme_ary, opts)
|
124
|
-
connect_time = dbconnect.connect
|
125
|
-
|
93
|
+
dbconfig = opts["dbconfig"]
|
94
|
+
connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(config, dbconfig, env)
|
126
95
|
Dbsetup.new(connect_time)
|
127
96
|
|
128
97
|
when "d"
|
129
|
-
opts["migrate_cmd"] = "delete"
|
130
98
|
db_scheme_ary = nil
|
131
|
-
|
99
|
+
dbconfig = opts["dbconfig"]
|
100
|
+
replation = opts["replation"]
|
101
|
+
|
102
|
+
config_dir = config.get_config_dir
|
103
|
+
dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, dbconfig)
|
104
|
+
mig = config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, replation)
|
105
|
+
mig.delete_migrate_config_and_db
|
106
|
+
|
132
107
|
else
|
133
108
|
puts "Invalid command(#{opts["cmd"]}) specified!!"
|
134
109
|
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 10
|
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 10
|
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
|
@@ -32,60 +32,47 @@ 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
|
|
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
|
+
|
46
53
|
# DB接続までの初期化に必要なディレクトリの確認、作成
|
47
|
-
def initialize(
|
54
|
+
def initialize(dbconfig_dest_path, env, log_path)
|
48
55
|
# 接続開始時刻
|
49
56
|
@connect_time = nil
|
50
57
|
# 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
|
-
# 環境の指定
|
58
|
+
@dbconfig_dest_path = dbconfig_dest_path
|
65
59
|
@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)
|
60
|
+
@log_path = log_path
|
78
61
|
end
|
79
62
|
|
80
63
|
# DB接続、DB用ログファイルの設定
|
81
64
|
def connect
|
82
65
|
unless @connect_time
|
83
66
|
begin
|
67
|
+
#p "@dbconfig_dest_path=#{@dbconfig_dest_path}"
|
84
68
|
dbconfig = Ykxutils.yaml_load_file_compati(@dbconfig_dest_path)
|
69
|
+
#p "dbconfig=#{dbconfig}"
|
70
|
+
#p "@env=#{@env}"
|
85
71
|
ActiveRecord::Base.establish_connection(dbconfig[@env])
|
86
72
|
ActiveRecord::Base.logger = Logger.new(@log_path)
|
87
73
|
@connect_time = DateTime.now.new_offset
|
88
74
|
rescue => ex
|
75
|
+
p ex.message
|
89
76
|
end
|
90
77
|
end
|
91
78
|
@connect_time
|
@@ -1,22 +1,9 @@
|
|
1
1
|
require_relative "dbutil/dbconnect"
|
2
|
-
#require_relative "dbutil/dbmgr"
|
3
2
|
|
4
3
|
module Arxutils_Sqlite3
|
5
4
|
# DB操作用ユーティリティクラス
|
6
5
|
module Dbutil
|
7
6
|
# DB格納ディレクトリ名
|
8
7
|
DB_DIR = "db".freeze
|
9
|
-
# migrate用スクリプト格納ディレクトリ名
|
10
|
-
MIGRATE_DIR = "migrate".freeze
|
11
|
-
# SQLITE3用DB構成名
|
12
|
-
DBCONFIG_SQLITE3 = "sqlite3".freeze
|
13
|
-
# MYSQL用DB構成名
|
14
|
-
DBCONFIG_MYSQL = "mysql".freeze
|
15
|
-
# DB構成格納用ディレクトリ名
|
16
|
-
CONFIG_DIR = "config".freeze
|
17
|
-
# データベース用ログファイル名
|
18
|
-
DATABASELOG = "database.log".freeze
|
19
|
-
|
20
|
-
# DB接続までの初期化を行う
|
21
8
|
end
|
22
9
|
end
|
@@ -8,218 +8,193 @@ require "pp"
|
|
8
8
|
|
9
9
|
# ActiveRecord用ユーティリティモジュール
|
10
10
|
module Arxutils_Sqlite3
|
11
|
-
|
12
|
-
|
11
|
+
##
|
12
|
+
# migrateに必要なファイルをテンプレートから作成し、migarteを実行する
|
13
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
|
+
config,
|
23
|
+
dbconfig_dest_path,
|
24
|
+
dbconfig_src_fname,
|
25
|
+
db_scheme_ary,
|
26
|
+
relation_config
|
27
|
+
)
|
28
|
+
# DB格納ディレクトリ名
|
29
|
+
@db_dir = config.get_db_dir
|
30
|
+
# DB構成ファイルの出力先ディレクトリ
|
31
|
+
@dest_config_dir = config.get_config_dir
|
32
|
+
# 生成するDB構成情報ファイルパス
|
33
|
+
@dbconfig_dest_path = dbconfig_dest_path
|
34
|
+
# 参照用DB構成情報ファイル名
|
35
|
+
@dbconfig_src_fname = dbconfig_src_fname
|
36
|
+
|
37
|
+
# migrate用スクリプトの出力先ディレクトリ名
|
38
|
+
@migrate_dir = config.get_migrate_dir
|
39
|
+
# テンプレートファイル格納ディレクトリ名
|
40
|
+
@src_path = config.get_template_relation_dir
|
41
|
+
#@src_path = Arxutils_Sqlite3::TEMPLATE_RELATION_DIR
|
42
|
+
# 構成ファイル格納ディレクトリ
|
43
|
+
@src_config_path = config.get_template_config_dir
|
44
|
+
# @src_config_path = Arxutils_Sqlite3::TEMPLATE_CONFIG_DIR
|
45
|
+
# データベーススキーマ定義配列
|
46
|
+
@db_scheme_ary = db_scheme_ary
|
47
|
+
# リレーション指定
|
48
|
+
@relation_config = relation_config
|
49
|
+
|
50
|
+
FileUtils.mkdir_p(@db_dir) if @db_dir
|
51
|
+
FileUtils.mkdir_p(@migrate_dir) if @migrate_dir
|
52
|
+
FileUtils.mkdir_p(@dest_config_dir)
|
33
53
|
end
|
34
54
|
|
35
|
-
#
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
55
|
+
# マイグレート用スクリプト、DB構成情報ファイル、DBファイルの削除
|
56
|
+
def delete_migrate_config_and_db
|
57
|
+
FileUtils.rm(Dir.glob(File.join(@migrate_dir, "*"))) if @migrate_dir
|
58
|
+
FileUtils.rm(Dir.glob(File.join(@dest_config_dir, "*")))
|
59
|
+
Dir.glob(File.join(@db_dir, "*")).each do |x|
|
60
|
+
# puts x
|
61
|
+
FileUtils.rm(x) if File.file?(x)
|
41
62
|
end
|
42
63
|
end
|
43
64
|
|
44
|
-
#
|
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
|
65
|
+
# マイグレーション用スクリプトの生成、relationのクラス定義ファイルの生成
|
66
|
+
def output
|
67
|
+
# migrationのスクリプトをファイル出力する
|
68
|
+
output_all_script
|
71
69
|
|
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
|
70
|
+
# relationを表すクラス定義のファイルの内容を生成
|
71
|
+
content_array = make_content_array
|
72
|
+
# p "content_array=#{content_array}"
|
73
|
+
# 複数形のクラス名を集める
|
74
|
+
count_class_plurals = content_array.reject do |x|
|
75
|
+
x[:need_count_class_plural].nil?
|
84
76
|
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)
|
77
|
+
need_count_class_plural = count_class_plurals.map { |x| x[:need_count_class_plural] }
|
78
|
+
# relationのmigrateが必要であれば、それをテンプレートファイルから作成して、スクリプトの内容として追加する
|
79
|
+
if content_array.find { |x| !x.nil? }
|
80
|
+
# p "####### 1"
|
81
|
+
data_count = {
|
82
|
+
count_classname: "Count",
|
83
|
+
need_count_class_plural: need_count_class_plural
|
84
|
+
}
|
85
|
+
# p "data_count=#{data_count}"
|
86
|
+
ary = content_array.collect { |x| x[:content] }.flatten
|
87
|
+
count_content = convert_count_class_relation(data_count, "relation_count.tmpl")
|
88
|
+
ary.unshift(count_content)
|
89
|
+
content_array = ary
|
114
90
|
end
|
91
|
+
# relationのスクリプトを作成
|
92
|
+
output_relation_script(content_array, @relation_config)
|
93
|
+
end
|
115
94
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
end
|
95
|
+
# migrationのスクリプトをファイル出力する
|
96
|
+
def output_all_script
|
97
|
+
# スキーマ設定配列から、migrate用のスクリプトを作成する
|
98
|
+
@db_scheme_ary.map { |x| make_script_group(x) }.flatten(1).each_with_index do |data, index|
|
99
|
+
idy = (index + 1) * FILENAME_COUNTER_STEP
|
100
|
+
output_script(idy, *data)
|
123
101
|
end
|
102
|
+
end
|
124
103
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
relations.select { |x| x.size.positive? }
|
104
|
+
# relationを表すクラス定義のファイルの内容を生成
|
105
|
+
def make_content_array
|
106
|
+
# スキーマ設定配列から、relationのmigrate用のスクリプトの内容(ハッシュ形式)の配列を作成する
|
107
|
+
relations = @db_scheme_ary.map do |x|
|
108
|
+
make_relation(x, "count")
|
132
109
|
end
|
110
|
+
relations.select { |x| x.size.positive? }
|
111
|
+
end
|
133
112
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
113
|
+
# Countクラス用のrelationのスクリプトの内容に変換
|
114
|
+
def convert_count_class_relation(data, src_fname)
|
115
|
+
convert(data, @src_path, src_fname)
|
116
|
+
end
|
138
117
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
118
|
+
# テンプレートファイルからスクリプトの内容に変換
|
119
|
+
def convert(data, src_dir, src_fname)
|
120
|
+
arx = Arx.new(data, File.join(src_dir, src_fname))
|
121
|
+
# 指定テンプレートファイルからスクリプトの内容に作成
|
122
|
+
arx.create
|
123
|
+
end
|
145
124
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
end
|
125
|
+
# データベース構成ファイルをテンプレートから生成する
|
126
|
+
def make_dbconfig(data)
|
127
|
+
content = convert(data, @src_config_path, @dbconfig_src_fname)
|
128
|
+
File.open(
|
129
|
+
@dbconfig_dest_path, "w:utf-8") do |f|
|
130
|
+
f.puts(content)
|
153
131
|
end
|
132
|
+
end
|
154
133
|
|
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
|
134
|
+
# 英子文字で表現したクラス名が、countを表していなければ、relationを
|
135
|
+
# 英子文字で表現したクラス名が、countを表していれが、空のハッシュを返す
|
136
|
+
# スキーマでbase, noitem以外のフィールドが指定されていれば、そのフィールドに対するrelationの設定の内容を返す
|
137
|
+
def make_relation(data, count_classname_downcase)
|
138
|
+
if data[:classname_downcase] == count_classname_downcase
|
139
|
+
{}
|
140
|
+
else
|
141
|
+
# 指定フィールドのフィールド名に対応したテンプレートファイルを用いて、relation設定を作成
|
142
|
+
data[:flist].each_with_object({ content: [], need_count_class: nil }) do |field_name, s|
|
143
|
+
case field_name
|
144
|
+
when "base", "noitem"
|
145
|
+
name_base = "relation"
|
146
|
+
# data[:relation]がnilに設定されていたら改めて空の配列を設定
|
147
|
+
data[:relation] = [] unless data[:relation]
|
148
|
+
else
|
149
|
+
data[:count_classname_downcase] = count_classname_downcase
|
150
|
+
name_base = "relation_#{field_name}"
|
151
|
+
s[:need_count_class_plural] ||= data[:plural]
|
177
152
|
end
|
153
|
+
# テンプレートファイルからスクリプトの内容を作成
|
154
|
+
content = convert(data, @src_path, "#{name_base}.tmpl")
|
155
|
+
s[:content] << content
|
178
156
|
end
|
179
157
|
end
|
158
|
+
end
|
180
159
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
160
|
+
# スキーマ設定からmigarte用スクリプトの内容を生成
|
161
|
+
def make_script_group(data)
|
162
|
+
#p data
|
163
|
+
data[:flist].map {
|
164
|
+
|kind|
|
165
|
+
[kind,
|
166
|
+
convert(data, @src_path, "#{kind}.tmpl"),
|
167
|
+
data[:classname_downcase]
|
168
|
+
] }
|
169
|
+
end
|
191
170
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
end
|
171
|
+
# migrationのスクリプトをファイル出力する
|
172
|
+
def output_script(idy, kind, content, classname_downcase)
|
173
|
+
additional = case kind
|
174
|
+
when "base", "noitem"
|
175
|
+
""
|
176
|
+
else
|
177
|
+
kind
|
178
|
+
end
|
179
|
+
fname = File.join(@migrate_dir, format("%03d_create_%s%s.rb", idy, additional, classname_downcase))
|
180
|
+
File.open(fname, "w", **{ encoding: Encoding::UTF_8 }) do |f|
|
181
|
+
f.puts(content)
|
204
182
|
end
|
183
|
+
end
|
205
184
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
file.puts x
|
217
|
-
file.puts ""
|
218
|
-
end
|
219
|
-
opts[:module].map { |_mod| file.puts("end") }
|
185
|
+
# relationのスクリプトをファイル出力する
|
186
|
+
def output_relation_script(content_array, relation_config)
|
187
|
+
dir = relation_config[:dir]
|
188
|
+
fname = relation_config[:filename]
|
189
|
+
fpath = File.join(dir, fname)
|
190
|
+
File.open(fpath, "w") do |file|
|
191
|
+
relation_config[:module].map { |mod| file.puts("module #{mod}") }
|
192
|
+
content_array.map do |x|
|
193
|
+
file.puts x
|
194
|
+
file.puts ""
|
220
195
|
end
|
196
|
+
relation_config[:module].map { |_mod| file.puts("end") }
|
221
197
|
end
|
222
|
-
|
223
198
|
end
|
224
199
|
end
|
225
200
|
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
|
data/lib/arxutils_sqlite3.rb
CHANGED
@@ -8,33 +8,19 @@ require "active_support/core_ext"
|
|
8
8
|
require "active_record"
|
9
9
|
require "pathname"
|
10
10
|
|
11
|
-
require_relative "arxutils_sqlite3/version"
|
12
|
-
require_relative "arxutils_sqlite3/arx"
|
13
|
-
require_relative "arxutils_sqlite3/transactstate"
|
14
|
-
require_relative "arxutils_sqlite3/hier"
|
15
|
-
require_relative "arxutils_sqlite3/migrate"
|
16
|
-
require_relative "arxutils_sqlite3/dbutil"
|
17
|
-
|
18
11
|
module Arxutils_Sqlite3
|
19
12
|
TOP_DIR = Pathname(__FILE__).parent
|
20
|
-
TEMPLATE_DIR = TOP_DIR.join("template")
|
21
|
-
TEMPLATE_RELATION_DIR = TEMPLATE_DIR.join("relation")
|
22
|
-
TEMPLATE_CONFIG_DIR = TEMPLATE_DIR.join("config")
|
23
|
-
CONFIG_DIR = "config".freeze
|
24
|
-
DEST_CONFIG_DIR = Pathname.new("config")
|
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
|
-
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
13
|
class Error < StandardError; end
|
39
14
|
# Your code goes here...
|
40
15
|
end
|
16
|
+
|
17
|
+
require_relative "arxutils_sqlite3/dbutil"
|
18
|
+
require_relative "arxutils_sqlite3/config"
|
19
|
+
|
20
|
+
require_relative "arxutils_sqlite3/version"
|
21
|
+
require_relative "arxutils_sqlite3/arx"
|
22
|
+
require_relative "arxutils_sqlite3/transactstate"
|
23
|
+
require_relative "arxutils_sqlite3/hier"
|
24
|
+
require_relative "arxutils_sqlite3/migrate"
|
25
|
+
require_relative "arxutils_sqlite3/migrate"
|
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 = <%=
|
4
|
+
@ct = <%= klass %>::Dbutil::Countdatetime.create( countdatetime: @connect_time )
|
5
5
|
@hs_by_notebook = {}
|
6
6
|
@hs_by_id = {}
|
7
7
|
end
|
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.45
|
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-12 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
|
@@ -77,12 +217,13 @@ files:
|
|
77
217
|
- exe/arxutils_sqlite3
|
78
218
|
- lib/arxutils_sqlite3.rb
|
79
219
|
- lib/arxutils_sqlite3/arx.rb
|
220
|
+
- lib/arxutils_sqlite3/config.rb
|
80
221
|
- lib/arxutils_sqlite3/dbutil.rb
|
81
222
|
- lib/arxutils_sqlite3/dbutil/dbconnect.rb
|
82
|
-
- lib/arxutils_sqlite3/dbutil/dbmgr.rb
|
83
223
|
- lib/arxutils_sqlite3/hier.rb
|
84
224
|
- lib/arxutils_sqlite3/migrate.rb
|
85
225
|
- lib/arxutils_sqlite3/transactstate.rb
|
226
|
+
- lib/arxutils_sqlite3/util.rb
|
86
227
|
- lib/arxutils_sqlite3/version.rb
|
87
228
|
- lib/template/config/mysql.tmpl
|
88
229
|
- lib/template/config/sqlite3.tmpl
|
@@ -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
|