arxutils_sqlite3 0.1.48 → 0.1.49
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +52 -15
- data/exe/arxutils_sqlite3 +38 -28
- data/lib/arxutils_sqlite3/arx.rb +1 -1
- data/lib/arxutils_sqlite3/cli.rb +48 -25
- data/lib/arxutils_sqlite3/config.rb +45 -20
- data/lib/arxutils_sqlite3/migrate.rb +32 -33
- data/lib/arxutils_sqlite3/version.rb +1 -1
- data/lib/arxutils_sqlite3.rb +1 -1
- 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 → acrecord}/db_scheme/dbsetup.rb +0 -0
- data/lib/template/acrecord/db_scheme/opts.rb +7 -0
- data/lib/template/acrecord/db_scheme/opts.rb.sample +7 -0
- data/lib/template/{relation → acrecord}/invalid.tmpl +0 -0
- data/lib/template/{relation → acrecord}/noitem.tmpl +0 -0
- metadata +16 -14
- data/lib/template/relation/db_scheme/opts.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c193545ee59fccd118a5b0e5cac8cc391156e418a62ef8b16bfe15c68cc99671
|
4
|
+
data.tar.gz: 20995c46c24a772caa0e638089473ad4f1c703c5c98f003cb6c47c975a9d5a88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a62e6f3d47ea1920a867c77a73d6f6fe667d4d438f8ba9fa5aec5edd7a2cd238e0dd6cf5a0a1d1468eea8b3f2369dcbfcb6cb420da51e7e21ec608f18521824f
|
7
|
+
data.tar.gz: 4435b54b4f7eb8f7d53707da7bd6caedd4a9c110af82f4f30573db1f9b51721a61c1debb65b65f94d1c6fffa7020722d0ad1d5a0c24152479ced7164479d4238
|
data/Rakefile
CHANGED
@@ -1,65 +1,102 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
=begin
|
3
2
|
require "rake/testtask"
|
4
3
|
|
5
4
|
Rake::TestTask.new do |t|
|
6
5
|
t.libs << "test"
|
7
6
|
end
|
8
7
|
|
9
|
-
desc "Run test"
|
10
|
-
task default: :test
|
11
|
-
=end
|
8
|
+
#desc "Run test"
|
9
|
+
#task default: :test
|
12
10
|
|
13
|
-
# Defining a task called default that depends on the tasks setup, makeconfig, migrate, and
|
14
|
-
task default: %w[delete setup makeconfig migrate integrate]
|
11
|
+
# Defining a task called default that depends on the tasks setup, makeconfig, migrate, and acr.
|
15
12
|
|
16
|
-
|
13
|
+
desc "setup copy_db_scheme copy_opts makeconfig make_migrate_script migrate acr"
|
14
|
+
task default: %w[setup copy_db_scheme copy_opts makeconfig make_migrate_script migrate acr]
|
17
15
|
|
16
|
+
desc "delete setup copy_db_scheme copy_opts makeconfig make_migrate_script migrate acr"
|
17
|
+
task bootstrap: %w[delete setup copy_db_scheme copy_opts makeconfig make_migrate_script migrate acr]
|
18
|
+
|
19
|
+
desc "setup makeconfig migrate acr"
|
20
|
+
task scfma: %w[setup makeconfig migrate acr]
|
21
|
+
|
22
|
+
desc "delete setup makeconfig"
|
18
23
|
task dsc: %w[delete setup makeconfig]
|
19
24
|
|
25
|
+
desc "delete setup"
|
20
26
|
task ds: %w[delete setup]
|
21
27
|
|
28
|
+
desc "setup"
|
22
29
|
task s: %w[setup]
|
23
30
|
|
31
|
+
desc "setup makeconfig"
|
24
32
|
task sc: %w[setup makeconfig]
|
25
33
|
|
34
|
+
desc "delete setup makeconfig migrate"
|
26
35
|
task dscm: %w[delete setup makeconfig migrate]
|
27
36
|
|
37
|
+
desc "setup makeconfig migrate"
|
28
38
|
task scm: %w[setup makeconfig migrate]
|
29
39
|
|
30
|
-
|
40
|
+
desc "delete setup makeconfig migrate acr"
|
41
|
+
task dscma: %w[delete setup makeconfig migrate acr]
|
31
42
|
|
32
|
-
|
43
|
+
desc "setup makeconfig migrate acr"
|
44
|
+
task scma: %w[setup makeconfig migrate acr]
|
33
45
|
|
34
|
-
|
46
|
+
desc "migrate acr"
|
47
|
+
task ma: %w[migrate acr]
|
35
48
|
|
36
|
-
|
49
|
+
desc "delete_db migrate acr"
|
50
|
+
task bma: %w[delete_db migrate acr]
|
37
51
|
|
52
|
+
desc "delete_db"
|
38
53
|
task b: %w[delete_db]
|
39
54
|
|
40
55
|
# コマンドラインで指定したクラス名を含むオプション指定用ハッシュの定義を含むRubyスクリ
|
41
56
|
# プトファイルの生成
|
57
|
+
desc "produce setting.yml, db_scheme.yml.sample and opts.rb.sample with class name Enop"
|
42
58
|
task :setup do
|
43
59
|
sh "bundle exec arxutils_sqlite3 --cmd=s --klass=Enop"
|
44
60
|
end
|
45
61
|
|
62
|
+
desc "copy from db_scheme.yml.sample to db_scheme.yml"
|
63
|
+
task :copy_db_scheme do
|
64
|
+
sh "bundle exec arxutils_sqlite3 --cmd=cds"
|
65
|
+
end
|
66
|
+
|
67
|
+
desc "copy from opts.rb.sample to opts.rb"
|
68
|
+
task :copy_opts do
|
69
|
+
sh "bundle exec arxutils_sqlite3 --cmd=co"
|
70
|
+
end
|
71
|
+
|
46
72
|
# DB構成情報の生成
|
73
|
+
desc "produce sqlite3.yml"
|
47
74
|
task :makeconfig do
|
48
75
|
sh "bundle exec arxutils_sqlite3 --cmd=c"
|
49
76
|
end
|
50
|
-
|
77
|
+
|
78
|
+
# マイグレート用スクリプトファイルの生成
|
79
|
+
desc "produce migration scripts"
|
80
|
+
task :make_migrate_script do
|
81
|
+
sh "bundle exec arxutils_sqlite3 --cmd=f --yaml=config/db_scheme.yml"
|
82
|
+
end
|
83
|
+
# マイグレートの実行
|
84
|
+
desc "execute migration"
|
51
85
|
task :migrate do
|
52
|
-
sh "bundle exec arxutils_sqlite3 --cmd=m
|
86
|
+
sh "bundle exec arxutils_sqlite3 --cmd=m"
|
53
87
|
end
|
54
88
|
|
55
|
-
|
56
|
-
|
89
|
+
desc "call ActiveRecord instance method"
|
90
|
+
task :acr do
|
91
|
+
sh "bundle exec arxutils_sqlite3 --cmd=a"
|
57
92
|
end
|
58
93
|
|
94
|
+
desc "delete configuration files adn migration scripts and db files"
|
59
95
|
task :delete do
|
60
96
|
sh "bundle exec arxutils_sqlite3 --cmd=d"
|
61
97
|
end
|
62
98
|
|
99
|
+
desc "delete db files"
|
63
100
|
task :delete_db do
|
64
101
|
sh "bundle exec arxutils_sqlite3 --cmd=b"
|
65
102
|
end
|
data/exe/arxutils_sqlite3
CHANGED
@@ -8,16 +8,23 @@ require "ykxutils"
|
|
8
8
|
|
9
9
|
config = Arxutils_Sqlite3::Config.new
|
10
10
|
|
11
|
-
cli = Arxutils_Sqlite3::Cli.new(config)
|
12
|
-
|
13
11
|
config.require_opts_file
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
opts = @opts ? @opts : {}
|
14
|
+
|
15
|
+
acrecord = opts[:acrecord]
|
16
|
+
if acrecord
|
17
|
+
filename = acrecord[:filename]
|
18
|
+
basename = File.basename(filename)
|
19
|
+
|
20
|
+
begin
|
21
|
+
require "#{basename}"
|
22
|
+
rescue LoadError => ex
|
23
|
+
#pp ex.message
|
24
|
+
end
|
19
25
|
end
|
20
26
|
|
27
|
+
opts[:db_dir] = Arxutils_Sqlite3::Config::DB_DIR
|
21
28
|
|
22
29
|
klass = nil
|
23
30
|
setting = config.load_setting_yaml_file
|
@@ -26,24 +33,24 @@ klass = setting[:klass]
|
|
26
33
|
# DBセットアップクラス
|
27
34
|
config.require_dbsetup_file
|
28
35
|
|
29
|
-
banner = "Usage: bundle exec arxutils_sqlite3 --cmd=(s|c|m|
|
30
|
-
|
31
|
-
opts = @opts ? @opts : {}
|
32
|
-
opts["dbconfig"] = Arxutils_Sqlite3::Config::DBCONFIG_SQLITE3
|
36
|
+
banner = "Usage: bundle exec arxutils_sqlite3 --cmd=(s|cds|co|c|f|m|a|d|b) -y yaml_file --klass=class"
|
33
37
|
|
34
38
|
Simpleoptparse::Simpleoptparse.parse(ARGV, opts, banner, Arxutils_Sqlite3::VERSION, nil) do |parser|
|
35
|
-
parser.on("--cmd X", %w[s c m
|
39
|
+
parser.on("--cmd X", %w[s cds co c f m a d b]) { |x| opts["cmd"] = x }
|
36
40
|
parser.on("-y yaml_file", "--yaml yaml_file") { |x| opts["yaml"] = x }
|
37
41
|
parser.on("--klass klass") { |x| opts["klass"] = x }
|
38
42
|
end
|
39
43
|
klass = opts["klass"] if opts["klass"]
|
40
44
|
|
45
|
+
dbconfig = Arxutils_Sqlite3::Config::DBCONFIG_SQLITE3
|
41
46
|
env = ENV.fetch("ENV", nil)
|
42
47
|
env ||= "production"
|
43
48
|
|
49
|
+
cli = Arxutils_Sqlite3::Cli.new(config, dbconfig, env)
|
50
|
+
|
44
51
|
case opts["cmd"]
|
45
52
|
when "s"
|
46
|
-
config.check_file_exist(Arxutils_Sqlite3::Config::
|
53
|
+
#config.check_file_exist(Arxutils_Sqlite3::Config::SAMPLE_DEST_OPTS_FILE, banner, 10)
|
47
54
|
|
48
55
|
if opts["klass"].nil? || opts["klass"].strip == ""
|
49
56
|
puts banner
|
@@ -51,39 +58,42 @@ when "s"
|
|
51
58
|
end
|
52
59
|
cli.setup(klass)
|
53
60
|
|
61
|
+
when "cds"
|
62
|
+
cli.copy_db_scheme
|
63
|
+
|
64
|
+
when "co"
|
65
|
+
cli.copy_opts_file
|
66
|
+
|
54
67
|
when "c"
|
55
|
-
|
56
|
-
|
57
|
-
cli.makeconfig(dbconfig, relation, banner, 30, opts)
|
68
|
+
acrecord = opts[:acrecord]
|
69
|
+
cli.makeconfig(acrecord, banner, 30, opts)
|
58
70
|
|
59
|
-
when "
|
71
|
+
when "f"
|
60
72
|
yaml_fname = opts["yaml"]
|
61
|
-
|
62
|
-
dbconfig = opts["dbconfig"]
|
73
|
+
acrecord = opts[:acrecord]
|
63
74
|
if yaml_fname.nil? || yaml_fname.strip == ""
|
64
75
|
puts banner
|
65
76
|
exit 40
|
66
77
|
end
|
67
78
|
yaml_pn = Pathname.new(yaml_fname)
|
68
79
|
config.check_file_not_exist(yaml_pn, banner, 55)
|
80
|
+
cli.setup_for_migrate(yaml_pn, acrecord, klass)
|
69
81
|
|
70
|
-
|
82
|
+
when "m"
|
83
|
+
cli.migrate
|
71
84
|
|
72
|
-
when "
|
73
|
-
|
74
|
-
cli.integrate(dbconfig, env)
|
85
|
+
when "a"
|
86
|
+
cli.acr
|
75
87
|
|
76
88
|
when "d"
|
77
89
|
db_scheme_ary = nil
|
78
|
-
|
79
|
-
|
80
|
-
cli.delete(dbconfig, db_scheme_ary, relation)
|
90
|
+
acrecord = opts["acrecord"]
|
91
|
+
cli.delete(db_scheme_ary, acrecord)
|
81
92
|
|
82
93
|
when "b"
|
83
94
|
db_scheme_ary = nil
|
84
|
-
|
85
|
-
|
86
|
-
cli.delete_db(dbconfig, db_scheme_ary, relation)
|
95
|
+
acrecord = opts["acrecord"]
|
96
|
+
cli.delete_db(db_scheme_ary, acrecord)
|
87
97
|
else
|
88
98
|
puts "Invalid command(#{opts["cmd"]}) specified!!"
|
89
99
|
end
|
data/lib/arxutils_sqlite3/arx.rb
CHANGED
data/lib/arxutils_sqlite3/cli.rb
CHANGED
@@ -1,66 +1,89 @@
|
|
1
1
|
module Arxutils_Sqlite3
|
2
2
|
# CLI用クラス
|
3
3
|
class Cli
|
4
|
-
def initialize(config)
|
4
|
+
def initialize(config, dbconfig, env)
|
5
5
|
@config = config
|
6
|
+
@dbconfig = dbconfig
|
7
|
+
@env = env
|
6
8
|
end
|
7
9
|
|
8
10
|
def setup(klass)
|
11
|
+
p "make_config_directory"
|
9
12
|
@config.make_config_directory
|
13
|
+
p "setup_db_scheme_file"
|
10
14
|
@config.setup_db_scheme_file
|
15
|
+
p "setup_opts_file(#{klass})"
|
11
16
|
@config.setup_opts_file(klass)
|
17
|
+
p "setup_setting_yaml_file(#{klass})"
|
12
18
|
@config.setup_setting_yaml_file(klass)
|
13
19
|
#db_scheme_ary = nil
|
14
20
|
end
|
15
21
|
|
16
|
-
def
|
22
|
+
def copy_db_scheme
|
23
|
+
# DBスキームファイルが存在しなければ、サンプルファイルをDBスキームファイルとしてコピー
|
24
|
+
@config.copy_db_scheme_file
|
25
|
+
end
|
26
|
+
|
27
|
+
def copy_opts_file
|
28
|
+
# optsファイルが存在しなければ、サンプルファイルをoptsファイルとしてコピー
|
29
|
+
@config.copy_opts_file
|
30
|
+
end
|
31
|
+
|
32
|
+
def makeconfig(acrecord, banner, exit_code, opts)
|
17
33
|
db_scheme_ary = nil
|
18
|
-
dbconfig_path = @config.make_dbconfig_path(dbconfig)
|
19
|
-
|
20
|
-
mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig,
|
34
|
+
dbconfig_path = @config.make_dbconfig_path(@dbconfig)
|
35
|
+
#@config.check_file_exist(dbconfig_path, banner, exit_code)
|
36
|
+
mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
|
21
37
|
mig.make_dbconfig(opts)
|
22
38
|
end
|
23
39
|
|
24
|
-
def
|
40
|
+
def setup_for_migrate(yaml_pn, acrecord, klass)
|
25
41
|
db_scheme_ary = YAML.load_file( yaml_pn )
|
26
|
-
dbconfig_path = @config.make_dbconfig_path(dbconfig)
|
42
|
+
dbconfig_path = @config.make_dbconfig_path(@dbconfig)
|
27
43
|
|
28
44
|
dest_dbsetup_file = @config.get_dest_dbsetup_file
|
29
|
-
@config.make_dbsetup_file(db_scheme_ary,
|
30
|
-
|
31
|
-
connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(@config, dbconfig, env)
|
45
|
+
@config.make_dbsetup_file(db_scheme_ary, acrecord, klass, dest_dbsetup_file)
|
32
46
|
|
33
|
-
#
|
34
|
-
|
47
|
+
# migrate用スクリプトの出力先ディレクトリ名
|
48
|
+
migrate_dir = @config.get_migrate_dir
|
49
|
+
# マイグレーション用スクリプトの生成、acrecordのクラス定義ファイルの生成
|
50
|
+
mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
|
35
51
|
mig.output
|
52
|
+
end
|
53
|
+
|
54
|
+
def migrate
|
55
|
+
# migrate用スクリプトの出力先ディレクトリ名
|
56
|
+
migrate_dir = @config.get_migrate_dir
|
57
|
+
|
58
|
+
connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(@config, @dbconfig, @env)
|
36
59
|
|
37
60
|
# マイグレーション実行
|
38
|
-
ActiveRecord::MigrationContext.new(
|
61
|
+
ActiveRecord::MigrationContext.new(migrate_dir, ActiveRecord::SchemaMigration).up
|
39
62
|
end
|
40
63
|
|
41
|
-
def
|
42
|
-
connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(@config, dbconfig, env)
|
64
|
+
def acr
|
65
|
+
connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(@config, @dbconfig, @env)
|
43
66
|
Dbsetup.new(connect_time)
|
44
67
|
end
|
45
68
|
|
46
|
-
def delete(
|
69
|
+
def delete(db_scheme_ary, acrecord)
|
47
70
|
config_dir = @config.get_config_dir
|
48
|
-
dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, dbconfig)
|
49
|
-
mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig,
|
71
|
+
dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, @dbconfig)
|
72
|
+
mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
|
50
73
|
mig.delete_migrate_and_config_and_db
|
51
74
|
end
|
52
75
|
|
53
|
-
def delete_db(
|
54
|
-
config_dir = config.get_config_dir
|
55
|
-
dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, dbconfig)
|
56
|
-
mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig,
|
76
|
+
def delete_db(db_scheme_ary, acrecord)
|
77
|
+
config_dir = @config.get_config_dir
|
78
|
+
dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, @dbconfig)
|
79
|
+
mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
|
57
80
|
# mig.delete_migrate_config_and_db
|
58
81
|
mig.delete_db
|
59
82
|
end
|
60
83
|
|
61
|
-
def rm_dbconfig
|
62
|
-
dbconfig_path = @config.make_dbconfig_path(dbconfig)
|
63
|
-
p dbconfig_path
|
84
|
+
def rm_dbconfig
|
85
|
+
dbconfig_path = @config.make_dbconfig_path(@dbconfig)
|
86
|
+
#p dbconfig_path
|
64
87
|
FileUtils.rm_f(dbconfig_path)
|
65
88
|
end
|
66
89
|
end
|
@@ -22,19 +22,22 @@ module Arxutils_Sqlite3
|
|
22
22
|
# テンプレートディレクトリへのパス
|
23
23
|
TEMPLATE_DIR = Arxutils_Sqlite3::TOP_DIR.join("template")
|
24
24
|
# リレーションテンプレートディレクトリへのパス
|
25
|
-
|
25
|
+
TEMPLATE_ACRECORD_DIR = TEMPLATE_DIR.join("acrecord")
|
26
26
|
TEMPLATE_CONFIG_DIR = TEMPLATE_DIR.join( CONFIG_DIR )
|
27
|
-
DB_SCHEME_DIR =
|
27
|
+
DB_SCHEME_DIR = TEMPLATE_ACRECORD_DIR.join("db_scheme")
|
28
28
|
DB_SCHEME_FILE = DB_SCHEME_DIR.join("db_scheme.yml")
|
29
|
+
SAMPLE_DB_SCHEME_FILE = CONFIG_DIR.join("db_scheme.yml.sample")
|
29
30
|
DB_SCHEME_FILE_NAME = "db_scheme.yml".freeze
|
30
31
|
DB_SCHEME_FILE_NAME_2 = "db_scheme".freeze
|
31
32
|
OPTS_FILE_NAME = "opts.rb".freeze
|
33
|
+
SAMPLE_OPTS_FILE_NAME = "opts.rb.sample".freeze
|
32
34
|
OPTS_FILE_NAME_2 = "opts".freeze
|
33
35
|
DBSETUP_FILE_NAME = "dbsetup.rb".freeze
|
34
36
|
DBSETUP_FILE_NAME_2 = "dbsetup".freeze
|
35
37
|
SETTING_YAML_FILE_NAME = "setting.yml".freeze
|
36
38
|
DEST_CONFIG_DIR = Pathname.new( CONFIG_DIR )
|
37
39
|
OPTS_FILE = DB_SCHEME_DIR.join(OPTS_FILE_NAME)
|
40
|
+
SAMPLE_OPTS_FILE = CONFIG_DIR.join(SAMPLE_OPTS_FILE_NAME)
|
38
41
|
# 変換先Dbsetupクラス定義のRubyスクリプトファイルへのパス
|
39
42
|
DBSETUP_FILE = DB_SCHEME_DIR.join(DBSETUP_FILE_NAME)
|
40
43
|
# 変換先optsファイル(Rubyスクリプトファイル)へのパス
|
@@ -54,24 +57,44 @@ module Arxutils_Sqlite3
|
|
54
57
|
|
55
58
|
# DB構成ファイル格納ディレクトリの作成
|
56
59
|
def make_config_directory
|
60
|
+
p "config make_config_directory"
|
57
61
|
FileUtils.mkdir_p(CONFIG_DIR)
|
58
62
|
end
|
59
63
|
|
60
|
-
# DB
|
64
|
+
# DBスキームファイルのサンプルファイルコピー
|
61
65
|
def setup_db_scheme_file
|
62
|
-
|
66
|
+
p "config setup_db_scheme_file"
|
67
|
+
p "DB_SCHEME_FILE=#{DB_SCHEME_FILE}"
|
68
|
+
p "SAMPLE_DB_SCHEME_FILE=#{SAMPLE_DB_SCHEME_FILE}"
|
69
|
+
FileUtils.cp(DB_SCHEME_FILE, SAMPLE_DB_SCHEME_FILE)
|
63
70
|
end
|
64
71
|
|
65
|
-
#
|
72
|
+
# DBスキームファイルが存在しなければ、サンプルファイルをDBスキームファイルとしてコピー
|
73
|
+
def copy_db_scheme_file
|
74
|
+
if !File.exist?(DEST_DB_SCHEME_FILE)
|
75
|
+
FileUtils.cp(SAMPLE_DB_SCHEME_FILE, DEST_DB_SCHEME_FILE)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# optsファイル(Rubyスクリプトファイル)のサンプルファイル書き込み
|
66
80
|
def setup_opts_file(klass)
|
67
81
|
scope = Object.new
|
68
82
|
hash = {klass: klass}
|
69
83
|
result_content = Ykutils::Erubyx.erubi_render_with_template_file(OPTS_FILE, scope, hash)
|
70
|
-
File.open(
|
84
|
+
File.open(SAMPLE_OPTS_FILE, "w"){|file|
|
71
85
|
file.write(result_content)
|
72
86
|
}
|
73
87
|
end
|
74
88
|
|
89
|
+
# optsファイルが存在しなければ、サンプルファイルをoptsファイルとしてコピー
|
90
|
+
def copy_opts_file
|
91
|
+
if !File.exist?(DEST_OPTS_FILE)
|
92
|
+
p "exist? #{File.exist?(DEST_OPTS_FILE)}"
|
93
|
+
p "copy SAMPLE_OPTS_FILE(#{SAMPLE_OPTS_FILE}) to DEST_OPTS_FILE(#{DEST_OPTS_FILE})"
|
94
|
+
FileUtils.cp(SAMPLE_OPTS_FILE, DEST_OPTS_FILE)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
75
98
|
# setting.ymlへの出力
|
76
99
|
def setup_setting_yaml_file(klass)
|
77
100
|
hash = { "klass": klass }
|
@@ -94,7 +117,7 @@ module Arxutils_Sqlite3
|
|
94
117
|
begin
|
95
118
|
require opts_file
|
96
119
|
rescue LoadError => ex
|
97
|
-
pp ex.message
|
120
|
+
#pp ex.message
|
98
121
|
end
|
99
122
|
end
|
100
123
|
end
|
@@ -116,7 +139,7 @@ module Arxutils_Sqlite3
|
|
116
139
|
begin
|
117
140
|
require dbsetup_file
|
118
141
|
rescue LoadError => ex
|
119
|
-
pp ex.message
|
142
|
+
# pp ex.message
|
120
143
|
end
|
121
144
|
end
|
122
145
|
|
@@ -158,8 +181,8 @@ module Arxutils_Sqlite3
|
|
158
181
|
end
|
159
182
|
|
160
183
|
# リレーションテンプレートディレクトリへのパス
|
161
|
-
def
|
162
|
-
|
184
|
+
def get_template_acrecord_dir
|
185
|
+
TEMPLATE_ACRECORD_DIR
|
163
186
|
end
|
164
187
|
|
165
188
|
# テンプレートディレクトリへのパス
|
@@ -202,38 +225,40 @@ module Arxutils_Sqlite3
|
|
202
225
|
end
|
203
226
|
|
204
227
|
# 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
|
-
# マイグレーション用スクリプトの生成、
|
228
|
+
def make_migrate_script(db_scheme_ary, dbconfig_path, dbconfig, acrecord)
|
229
|
+
mig = Arxutils_Sqlite3::Util.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, acrecord)
|
230
|
+
# マイグレーション用スクリプトの生成、acrecordのクラス定義ファイルの生成
|
208
231
|
mig.output
|
209
232
|
end
|
210
233
|
|
211
234
|
# migrateの準備
|
212
|
-
def prepare_for_migrate(db_scheme_ary, dbconfig_dest_path, dbconfig,
|
235
|
+
def prepare_for_migrate(db_scheme_ary, dbconfig_dest_path, dbconfig, acrecord)
|
213
236
|
#db_dir = config.DB_DIR
|
214
237
|
db_dir = get_db_dir
|
215
|
-
migrate_dir = get_migrate_dir
|
216
238
|
# DB構成ファイルの出力先ディレクトリ
|
217
239
|
dbconfig_src_fname = "#{dbconfig}.tmpl"
|
240
|
+
# migrate用スクリプトの出力先ディレクトリ名
|
241
|
+
migrate_dir = get_migrate_dir
|
242
|
+
|
218
243
|
mig = Migrate.new(
|
219
244
|
self,
|
220
245
|
dbconfig_dest_path,
|
221
246
|
dbconfig_src_fname,
|
222
247
|
db_scheme_ary,
|
223
|
-
|
224
|
-
|
248
|
+
acrecord,
|
249
|
+
migrate_dir
|
250
|
+
)
|
225
251
|
end
|
226
252
|
|
227
|
-
def make_dbsetup_file(db_scheme_ary,
|
253
|
+
def make_dbsetup_file(db_scheme_ary, acrecord, klass, dest_dbsetup_file)
|
228
254
|
src_dbsetup_file = get_src_dbsetup_file
|
229
255
|
|
230
256
|
scope = Object.new
|
231
|
-
hash0 = {module_name:
|
257
|
+
hash0 = {module_name: acrecord[:module].join("::")}
|
232
258
|
hash = db_scheme_ary[0].merge( hash0 )
|
233
259
|
hash["klass"] = klass
|
234
260
|
result_content = Ykutils::Erubyx.erubi_render_with_template_file(src_dbsetup_file, scope, hash)
|
235
261
|
|
236
|
-
#p "################ dest_dbsetup_file=#{dest_dbsetup_file}"
|
237
262
|
File.open(dest_dbsetup_file, "w"){|file|
|
238
263
|
file.write(result_content)
|
239
264
|
}
|
@@ -23,7 +23,8 @@ module Arxutils_Sqlite3
|
|
23
23
|
dbconfig_dest_path,
|
24
24
|
dbconfig_src_fname,
|
25
25
|
db_scheme_ary,
|
26
|
-
|
26
|
+
acrecord_config,
|
27
|
+
migrate_dir
|
27
28
|
)
|
28
29
|
# DB格納ディレクトリ名
|
29
30
|
@db_dir = config.get_db_dir
|
@@ -34,18 +35,16 @@ module Arxutils_Sqlite3
|
|
34
35
|
# 参照用DB構成情報ファイル名
|
35
36
|
@dbconfig_src_fname = dbconfig_src_fname
|
36
37
|
|
37
|
-
# migrate用スクリプトの出力先ディレクトリ名
|
38
|
-
@migrate_dir = config.get_migrate_dir
|
39
38
|
# テンプレートファイル格納ディレクトリ名
|
40
|
-
@src_path = config.
|
41
|
-
#@src_path = Arxutils_Sqlite3::TEMPLATE_RELATION_DIR
|
39
|
+
@src_path = config.get_template_acrecord_dir
|
42
40
|
# 構成ファイル格納ディレクトリ
|
43
41
|
@src_config_path = config.get_template_config_dir
|
44
42
|
# @src_config_path = Arxutils_Sqlite3::TEMPLATE_CONFIG_DIR
|
45
43
|
# データベーススキーマ定義配列
|
46
44
|
@db_scheme_ary = db_scheme_ary
|
47
45
|
# リレーション指定
|
48
|
-
@
|
46
|
+
@acrecord_config = acrecord_config
|
47
|
+
@migrate_dir = migrate_dir
|
49
48
|
|
50
49
|
FileUtils.mkdir_p(@db_dir) if @db_dir
|
51
50
|
FileUtils.mkdir_p(@migrate_dir) if @migrate_dir
|
@@ -89,12 +88,12 @@ module Arxutils_Sqlite3
|
|
89
88
|
end
|
90
89
|
end
|
91
90
|
|
92
|
-
# マイグレーション用スクリプトの生成、
|
91
|
+
# マイグレーション用スクリプトの生成、acrecordのクラス定義ファイルの生成
|
93
92
|
def output
|
94
93
|
# migrationのスクリプトをファイル出力する
|
95
94
|
output_all_script
|
96
95
|
|
97
|
-
#
|
96
|
+
# acrecordを表すクラス定義のファイルの内容を生成
|
98
97
|
content_array = make_content_array
|
99
98
|
# p "content_array=#{content_array}"
|
100
99
|
# 複数形のクラス名を集める
|
@@ -102,7 +101,7 @@ module Arxutils_Sqlite3
|
|
102
101
|
x[:need_count_class_plural].nil?
|
103
102
|
end
|
104
103
|
need_count_class_plural = count_class_plurals.map { |x| x[:need_count_class_plural] }
|
105
|
-
#
|
104
|
+
# acrecordのmigrateが必要であれば、それをテンプレートファイルから作成して、スクリプトの内容として追加する
|
106
105
|
if content_array.find { |x| !x.nil? }
|
107
106
|
# p "####### 1"
|
108
107
|
data_count = {
|
@@ -111,12 +110,12 @@ module Arxutils_Sqlite3
|
|
111
110
|
}
|
112
111
|
# p "data_count=#{data_count}"
|
113
112
|
ary = content_array.collect { |x| x[:content] }.flatten
|
114
|
-
count_content =
|
113
|
+
count_content = convert_count_class_acrecord(data_count, "acrecord_count.tmpl")
|
115
114
|
ary.unshift(count_content)
|
116
115
|
content_array = ary
|
117
116
|
end
|
118
|
-
#
|
119
|
-
|
117
|
+
# acrecordのスクリプトを作成
|
118
|
+
output_acrecord_script(content_array, @acrecord_config)
|
120
119
|
end
|
121
120
|
|
122
121
|
# migrationのスクリプトをファイル出力する
|
@@ -128,17 +127,17 @@ module Arxutils_Sqlite3
|
|
128
127
|
end
|
129
128
|
end
|
130
129
|
|
131
|
-
#
|
130
|
+
# acrecordを表すクラス定義のファイルの内容を生成
|
132
131
|
def make_content_array
|
133
|
-
# スキーマ設定配列から、
|
134
|
-
|
135
|
-
|
132
|
+
# スキーマ設定配列から、acrecordのmigrate用のスクリプトの内容(ハッシュ形式)の配列を作成する
|
133
|
+
acrecords = @db_scheme_ary.map do |x|
|
134
|
+
make_acrecord(x, "count")
|
136
135
|
end
|
137
|
-
|
136
|
+
acrecords.select { |x| x.size.positive? }
|
138
137
|
end
|
139
138
|
|
140
|
-
# Countクラス用の
|
141
|
-
def
|
139
|
+
# Countクラス用のacrecordのスクリプトの内容に変換
|
140
|
+
def convert_count_class_acrecord(data, src_fname)
|
142
141
|
convert(data, @src_path, src_fname)
|
143
142
|
end
|
144
143
|
|
@@ -158,23 +157,23 @@ module Arxutils_Sqlite3
|
|
158
157
|
end
|
159
158
|
end
|
160
159
|
|
161
|
-
# 英子文字で表現したクラス名が、countを表していなければ、
|
160
|
+
# 英子文字で表現したクラス名が、countを表していなければ、acrecordを
|
162
161
|
# 英子文字で表現したクラス名が、countを表していれが、空のハッシュを返す
|
163
|
-
# スキーマでbase, noitem以外のフィールドが指定されていれば、そのフィールドに対する
|
164
|
-
def
|
162
|
+
# スキーマでbase, noitem以外のフィールドが指定されていれば、そのフィールドに対するacrecordの設定の内容を返す
|
163
|
+
def make_acrecord(data, count_classname_downcase)
|
165
164
|
if data[:classname_downcase] == count_classname_downcase
|
166
165
|
{}
|
167
166
|
else
|
168
|
-
# 指定フィールドのフィールド名に対応したテンプレートファイルを用いて、
|
167
|
+
# 指定フィールドのフィールド名に対応したテンプレートファイルを用いて、acrecord設定を作成
|
169
168
|
data[:flist].each_with_object({ content: [], need_count_class: nil }) do |field_name, s|
|
170
169
|
case field_name
|
171
170
|
when "base", "noitem"
|
172
|
-
name_base = "
|
173
|
-
# data[:
|
174
|
-
data[:
|
171
|
+
name_base = "acrecord"
|
172
|
+
# data[:acrecord]がnilに設定されていたら改めて空の配列を設定
|
173
|
+
data[:acrecord] = [] unless data[:acrecord]
|
175
174
|
else
|
176
175
|
data[:count_classname_downcase] = count_classname_downcase
|
177
|
-
name_base = "
|
176
|
+
name_base = "acrecord_#{field_name}"
|
178
177
|
s[:need_count_class_plural] ||= data[:plural]
|
179
178
|
end
|
180
179
|
# テンプレートファイルからスクリプトの内容を作成
|
@@ -209,18 +208,18 @@ module Arxutils_Sqlite3
|
|
209
208
|
end
|
210
209
|
end
|
211
210
|
|
212
|
-
#
|
213
|
-
def
|
214
|
-
dir =
|
215
|
-
fname =
|
211
|
+
# acrecordのスクリプトをファイル出力する
|
212
|
+
def output_acrecord_script(content_array, acrecord_config)
|
213
|
+
dir = acrecord_config[:dir]
|
214
|
+
fname = acrecord_config[:filename]
|
216
215
|
fpath = File.join(dir, fname)
|
217
216
|
File.open(fpath, "w") do |file|
|
218
|
-
|
217
|
+
acrecord_config[:module].map { |mod| file.puts("module #{mod}") }
|
219
218
|
content_array.map do |x|
|
220
219
|
file.puts x
|
221
220
|
file.puts ""
|
222
221
|
end
|
223
|
-
|
222
|
+
acrecord_config[:module].map { |_mod| file.puts("end") }
|
224
223
|
end
|
225
224
|
end
|
226
225
|
end
|
data/lib/arxutils_sqlite3.rb
CHANGED
@@ -23,5 +23,5 @@ require_relative "arxutils_sqlite3/arx"
|
|
23
23
|
require_relative "arxutils_sqlite3/transactstate"
|
24
24
|
require_relative "arxutils_sqlite3/hier"
|
25
25
|
require_relative "arxutils_sqlite3/migrate"
|
26
|
-
require_relative "arxutils_sqlite3/migrate"
|
27
26
|
require_relative "arxutils_sqlite3/util"
|
27
|
+
require_relative "dbacrecord"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,48 @@
|
|
1
|
+
---
|
2
|
+
- :flist:
|
3
|
+
- noitem
|
4
|
+
:classname: Countdatetime
|
5
|
+
:classname_downcase: countdatetime
|
6
|
+
:items:
|
7
|
+
- - countdatetime
|
8
|
+
- datetime
|
9
|
+
- 'false'
|
10
|
+
:plural: countdatetimes
|
11
|
+
:ar_version: 6.0
|
12
|
+
- :flist:
|
13
|
+
- noitem
|
14
|
+
:classname: Evnb
|
15
|
+
:classname_downcase: evnb
|
16
|
+
:items:
|
17
|
+
- - time_id
|
18
|
+
- integer
|
19
|
+
- 'false'
|
20
|
+
- - ennb_id
|
21
|
+
- integer
|
22
|
+
- 'false'
|
23
|
+
:plural: evnbs
|
24
|
+
:ar_version: 6.0
|
25
|
+
- :flist:
|
26
|
+
- noitem
|
27
|
+
- invalid
|
28
|
+
- current
|
29
|
+
:classname: Ennblist
|
30
|
+
:classname_downcase: ennblist
|
31
|
+
:items:
|
32
|
+
- - stack
|
33
|
+
- string
|
34
|
+
- 'false'
|
35
|
+
- - notebook
|
36
|
+
- string
|
37
|
+
- 'false'
|
38
|
+
- - count
|
39
|
+
- integer
|
40
|
+
- 'false'
|
41
|
+
- - tag_count
|
42
|
+
- integer
|
43
|
+
- 'false'
|
44
|
+
- - start_datetime
|
45
|
+
- datetime
|
46
|
+
- 'false'
|
47
|
+
:plural: ennblists
|
48
|
+
:ar_version: 6.0
|
File without changes
|
File without changes
|
File without changes
|
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.49
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -221,25 +221,27 @@ files:
|
|
221
221
|
- lib/arxutils_sqlite3/config.rb
|
222
222
|
- lib/arxutils_sqlite3/dbutil.rb
|
223
223
|
- lib/arxutils_sqlite3/dbutil/dbconnect.rb
|
224
|
-
- lib/arxutils_sqlite3/dbutil/dbrelation.rb
|
225
224
|
- lib/arxutils_sqlite3/hier.rb
|
226
225
|
- lib/arxutils_sqlite3/migrate.rb
|
227
226
|
- lib/arxutils_sqlite3/transactstate.rb
|
228
227
|
- lib/arxutils_sqlite3/util.rb
|
229
228
|
- lib/arxutils_sqlite3/version.rb
|
229
|
+
- lib/dbacrecord.rb
|
230
|
+
- lib/template/acrecord/acrecord.tmpl
|
231
|
+
- lib/template/acrecord/acrecord_count.tmpl
|
232
|
+
- lib/template/acrecord/acrecord_current.tmpl
|
233
|
+
- lib/template/acrecord/acrecord_invalid.tmpl
|
234
|
+
- lib/template/acrecord/base.tmpl
|
235
|
+
- lib/template/acrecord/current.tmpl
|
236
|
+
- lib/template/acrecord/db_scheme/db_scheme.yml
|
237
|
+
- lib/template/acrecord/db_scheme/db_scheme.yml.sample
|
238
|
+
- lib/template/acrecord/db_scheme/dbsetup.rb
|
239
|
+
- lib/template/acrecord/db_scheme/opts.rb
|
240
|
+
- lib/template/acrecord/db_scheme/opts.rb.sample
|
241
|
+
- lib/template/acrecord/invalid.tmpl
|
242
|
+
- lib/template/acrecord/noitem.tmpl
|
230
243
|
- lib/template/config/mysql.tmpl
|
231
244
|
- lib/template/config/sqlite3.tmpl
|
232
|
-
- lib/template/relation/base.tmpl
|
233
|
-
- lib/template/relation/current.tmpl
|
234
|
-
- lib/template/relation/db_scheme/db_scheme.yml
|
235
|
-
- lib/template/relation/db_scheme/dbsetup.rb
|
236
|
-
- lib/template/relation/db_scheme/opts.rb
|
237
|
-
- lib/template/relation/invalid.tmpl
|
238
|
-
- lib/template/relation/noitem.tmpl
|
239
|
-
- lib/template/relation/relation.tmpl
|
240
|
-
- lib/template/relation/relation_count.tmpl
|
241
|
-
- lib/template/relation/relation_current.tmpl
|
242
|
-
- lib/template/relation/relation_invalid.tmpl
|
243
245
|
homepage: https://ykominami.github.io/arxutils_sqlite3/
|
244
246
|
licenses:
|
245
247
|
- MIT
|