arxutils_sqlite3 0.1.49 → 0.1.50
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/.rubocop.yml +3 -2
- data/.rubocop_todo.yml +209 -109
- data/Gemfile +13 -16
- data/Gemfile.lock +112 -0
- data/Rakefile +12 -95
- data/arxutils_sqlite3.gemspec +4 -4
- data/config/.gitignore +1 -0
- data/config/setting.yml +2 -0
- data/exe/arxutils_sqlite3 +5 -6
- data/lib/arxutils_sqlite3/arx.rb +2 -2
- data/lib/arxutils_sqlite3/cli.rb +10 -12
- data/lib/arxutils_sqlite3/config.rb +67 -68
- data/lib/arxutils_sqlite3/dbutil/dbconnect.rb +4 -26
- data/lib/arxutils_sqlite3/dbutil.rb +0 -1
- data/lib/arxutils_sqlite3/hier.rb +3 -3
- data/lib/arxutils_sqlite3/migrate.rb +27 -20
- data/lib/arxutils_sqlite3/util.rb +2 -1
- data/lib/arxutils_sqlite3/version.rb +1 -1
- data/lib/arxutils_sqlite3.rb +2 -1
- data/lib/arxutils_sqlite3_rake_task.rb +68 -0
- data/lib/template/acrecord/db_scheme/{dbsetup.rb → dbsetup.tmpl} +2 -2
- data/lib/template/acrecord/db_scheme/{opts.rb → opts.tmpl} +0 -0
- metadata +18 -16
- data/LICENSE.txt +0 -21
data/Gemfile.lock
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
arxutils_sqlite3 (0.1.50)
|
5
|
+
activerecord (~> 6.1)
|
6
|
+
activesupport
|
7
|
+
simpleoptparse
|
8
|
+
sqlite3
|
9
|
+
ykutils
|
10
|
+
ykxutils
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
activemodel (6.1.7)
|
16
|
+
activesupport (= 6.1.7)
|
17
|
+
activerecord (6.1.7)
|
18
|
+
activemodel (= 6.1.7)
|
19
|
+
activesupport (= 6.1.7)
|
20
|
+
activesupport (6.1.7)
|
21
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
22
|
+
i18n (>= 1.6, < 2)
|
23
|
+
minitest (>= 5.1)
|
24
|
+
tzinfo (~> 2.0)
|
25
|
+
zeitwerk (~> 2.3)
|
26
|
+
ast (2.4.2)
|
27
|
+
concurrent-ruby (1.1.10)
|
28
|
+
diff-lcs (1.5.0)
|
29
|
+
erubi (1.11.0)
|
30
|
+
erubis (2.7.0)
|
31
|
+
filex (0.1.7)
|
32
|
+
erubis
|
33
|
+
messagex
|
34
|
+
i18n (1.12.0)
|
35
|
+
concurrent-ruby (~> 1.0)
|
36
|
+
json (2.6.2)
|
37
|
+
messagex (0.1.5)
|
38
|
+
minitest (5.16.3)
|
39
|
+
parallel (1.22.1)
|
40
|
+
parser (3.1.2.1)
|
41
|
+
ast (~> 2.4.1)
|
42
|
+
rainbow (3.1.1)
|
43
|
+
rake (13.0.6)
|
44
|
+
regexp_parser (2.5.0)
|
45
|
+
rexml (3.2.5)
|
46
|
+
rspec (3.11.0)
|
47
|
+
rspec-core (~> 3.11.0)
|
48
|
+
rspec-expectations (~> 3.11.0)
|
49
|
+
rspec-mocks (~> 3.11.0)
|
50
|
+
rspec-core (3.11.0)
|
51
|
+
rspec-support (~> 3.11.0)
|
52
|
+
rspec-expectations (3.11.1)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.11.0)
|
55
|
+
rspec-mocks (3.11.1)
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
+
rspec-support (~> 3.11.0)
|
58
|
+
rspec-support (3.11.1)
|
59
|
+
rubocop (1.36.0)
|
60
|
+
json (~> 2.3)
|
61
|
+
parallel (~> 1.10)
|
62
|
+
parser (>= 3.1.2.1)
|
63
|
+
rainbow (>= 2.2.2, < 4.0)
|
64
|
+
regexp_parser (>= 1.8, < 3.0)
|
65
|
+
rexml (>= 3.2.5, < 4.0)
|
66
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
67
|
+
ruby-progressbar (~> 1.7)
|
68
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
69
|
+
rubocop-ast (1.21.0)
|
70
|
+
parser (>= 3.1.1.0)
|
71
|
+
rubocop-rake (0.6.0)
|
72
|
+
rubocop (~> 1.0)
|
73
|
+
rubocop-rspec (2.13.1)
|
74
|
+
rubocop (~> 1.33)
|
75
|
+
ruby-progressbar (1.11.0)
|
76
|
+
simpleoptparse (0.1.2)
|
77
|
+
sqlite3 (1.5.0-x86_64-linux)
|
78
|
+
tilt (2.0.11)
|
79
|
+
tzinfo (2.0.5)
|
80
|
+
concurrent-ruby (~> 1.0)
|
81
|
+
unicode-display_width (2.3.0)
|
82
|
+
webrick (1.7.0)
|
83
|
+
yard (0.9.28)
|
84
|
+
webrick (~> 1.7.0)
|
85
|
+
ykutils (0.1.6)
|
86
|
+
erubi
|
87
|
+
filex
|
88
|
+
tilt
|
89
|
+
ykxutils (0.1.5)
|
90
|
+
zeitwerk (2.6.0)
|
91
|
+
|
92
|
+
PLATFORMS
|
93
|
+
x86_64-linux
|
94
|
+
|
95
|
+
DEPENDENCIES
|
96
|
+
activerecord (~> 6.1)
|
97
|
+
activesupport
|
98
|
+
arxutils_sqlite3!
|
99
|
+
bundler
|
100
|
+
rake (~> 13.0)
|
101
|
+
rspec (~> 3.0)
|
102
|
+
rubocop (~> 1.7)
|
103
|
+
rubocop-rake
|
104
|
+
rubocop-rspec
|
105
|
+
simpleoptparse
|
106
|
+
sqlite3
|
107
|
+
yard
|
108
|
+
ykutils (> 0.1.3)
|
109
|
+
ykxutils (> 0.1.0)
|
110
|
+
|
111
|
+
BUNDLED WITH
|
112
|
+
2.3.17
|
data/Rakefile
CHANGED
@@ -1,104 +1,21 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
require "rake/testtask"
|
2
|
+
# require "rake/testtask"
|
3
3
|
|
4
|
-
Rake::TestTask.new do |t|
|
5
|
-
t.libs << "test"
|
6
|
-
end
|
4
|
+
# Rake::TestTask.new do |t|
|
5
|
+
# t.libs << "test"
|
6
|
+
# end
|
7
7
|
|
8
|
-
#desc "Run test"
|
9
|
-
#task default: :test
|
8
|
+
# desc "Run test"
|
9
|
+
# task default: :test
|
10
10
|
|
11
|
-
|
11
|
+
require "rspec/core/rake_task"
|
12
12
|
|
13
|
-
|
14
|
-
task default: %w[setup copy_db_scheme copy_opts makeconfig make_migrate_script migrate acr]
|
13
|
+
RSpec::Core::RakeTask.new(:spec)
|
15
14
|
|
16
|
-
|
17
|
-
task bootstrap: %w[delete setup copy_db_scheme copy_opts makeconfig make_migrate_script migrate acr]
|
15
|
+
require "rubocop/rake_task"
|
18
16
|
|
19
|
-
|
20
|
-
task scfma: %w[setup makeconfig migrate acr]
|
21
|
-
|
22
|
-
desc "delete setup makeconfig"
|
23
|
-
task dsc: %w[delete setup makeconfig]
|
24
|
-
|
25
|
-
desc "delete setup"
|
26
|
-
task ds: %w[delete setup]
|
27
|
-
|
28
|
-
desc "setup"
|
29
|
-
task s: %w[setup]
|
30
|
-
|
31
|
-
desc "setup makeconfig"
|
32
|
-
task sc: %w[setup makeconfig]
|
33
|
-
|
34
|
-
desc "delete setup makeconfig migrate"
|
35
|
-
task dscm: %w[delete setup makeconfig migrate]
|
36
|
-
|
37
|
-
desc "setup makeconfig migrate"
|
38
|
-
task scm: %w[setup makeconfig migrate]
|
39
|
-
|
40
|
-
desc "delete setup makeconfig migrate acr"
|
41
|
-
task dscma: %w[delete setup makeconfig migrate acr]
|
42
|
-
|
43
|
-
desc "setup makeconfig migrate acr"
|
44
|
-
task scma: %w[setup makeconfig migrate acr]
|
45
|
-
|
46
|
-
desc "migrate acr"
|
47
|
-
task ma: %w[migrate acr]
|
48
|
-
|
49
|
-
desc "delete_db migrate acr"
|
50
|
-
task bma: %w[delete_db migrate acr]
|
51
|
-
|
52
|
-
desc "delete_db"
|
53
|
-
task b: %w[delete_db]
|
54
|
-
|
55
|
-
# コマンドラインで指定したクラス名を含むオプション指定用ハッシュの定義を含むRubyスクリ
|
56
|
-
# プトファイルの生成
|
57
|
-
desc "produce setting.yml, db_scheme.yml.sample and opts.rb.sample with class name Enop"
|
58
|
-
task :setup do
|
59
|
-
sh "bundle exec arxutils_sqlite3 --cmd=s --klass=Enop"
|
60
|
-
end
|
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
|
-
|
72
|
-
# DB構成情報の生成
|
73
|
-
desc "produce sqlite3.yml"
|
74
|
-
task :makeconfig do
|
75
|
-
sh "bundle exec arxutils_sqlite3 --cmd=c"
|
76
|
-
end
|
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"
|
85
|
-
task :migrate do
|
86
|
-
sh "bundle exec arxutils_sqlite3 --cmd=m"
|
87
|
-
end
|
88
|
-
|
89
|
-
desc "call ActiveRecord instance method"
|
90
|
-
task :acr do
|
91
|
-
sh "bundle exec arxutils_sqlite3 --cmd=a"
|
92
|
-
end
|
93
|
-
|
94
|
-
desc "delete configuration files adn migration scripts and db files"
|
95
|
-
task :delete do
|
96
|
-
sh "bundle exec arxutils_sqlite3 --cmd=d"
|
97
|
-
end
|
98
|
-
|
99
|
-
desc "delete db files"
|
100
|
-
task :delete_db do
|
101
|
-
sh "bundle exec arxutils_sqlite3 --cmd=b"
|
102
|
-
end
|
17
|
+
RuboCop::RakeTask.new
|
103
18
|
|
19
|
+
# task default: %i[spec rubocop]
|
104
20
|
|
21
|
+
require "arxutils_sqlite3_rake_task"
|
data/arxutils_sqlite3.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = "utility functions for ActiveRecord."
|
13
13
|
spec.homepage = "https://ykominami.github.io/arxutils_sqlite3/"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">= 2.
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
16
|
|
17
17
|
# spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
|
18
18
|
|
@@ -31,21 +31,21 @@ Gem::Specification.new do |spec|
|
|
31
31
|
|
32
32
|
spec.bindir = "exe"
|
33
33
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
34
|
-
#p spec.executables
|
34
|
+
# p spec.executables
|
35
35
|
spec.require_paths = ["lib"]
|
36
36
|
spec.add_runtime_dependency "activesupport"
|
37
37
|
# spec.add_runtime_dependency "erb"
|
38
38
|
# spec.add_runtime_dependency "activerecord", "~> 4.2"
|
39
39
|
|
40
40
|
spec.add_runtime_dependency "activerecord", "~> 6.1"
|
41
|
+
spec.add_runtime_dependency "simpleoptparse"
|
41
42
|
spec.add_runtime_dependency "sqlite3"
|
42
43
|
spec.add_runtime_dependency "ykutils"
|
43
44
|
spec.add_runtime_dependency "ykxutils"
|
44
|
-
spec.add_runtime_dependency "simpleoptparse"
|
45
45
|
# spec.add_development_dependency "bundler", "~> 2.2.10"
|
46
46
|
spec.add_development_dependency "bundler"
|
47
|
-
spec.add_development_dependency "rspec" , "~> 3.0"
|
48
47
|
spec.add_development_dependency "rake", "~> 13.0"
|
48
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
49
49
|
spec.add_development_dependency "rubocop", "~> 1.7"
|
50
50
|
spec.add_development_dependency "rubocop-rake"
|
51
51
|
spec.add_development_dependency "rubocop-rspec"
|
data/config/.gitignore
CHANGED
data/config/setting.yml
ADDED
data/exe/arxutils_sqlite3
CHANGED
@@ -10,7 +10,7 @@ config = Arxutils_Sqlite3::Config.new
|
|
10
10
|
|
11
11
|
config.require_opts_file
|
12
12
|
|
13
|
-
opts = @opts
|
13
|
+
opts = @opts || {}
|
14
14
|
|
15
15
|
acrecord = opts[:acrecord]
|
16
16
|
if acrecord
|
@@ -18,15 +18,14 @@ if acrecord
|
|
18
18
|
basename = File.basename(filename)
|
19
19
|
|
20
20
|
begin
|
21
|
-
require
|
22
|
-
rescue LoadError
|
23
|
-
#pp ex.message
|
21
|
+
require basename.to_s
|
22
|
+
rescue LoadError
|
23
|
+
# pp ex.message
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
opts[:db_dir] = Arxutils_Sqlite3::Config::DB_DIR
|
28
28
|
|
29
|
-
klass = nil
|
30
29
|
setting = config.load_setting_yaml_file
|
31
30
|
klass = setting[:klass]
|
32
31
|
|
@@ -50,7 +49,7 @@ cli = Arxutils_Sqlite3::Cli.new(config, dbconfig, env)
|
|
50
49
|
|
51
50
|
case opts["cmd"]
|
52
51
|
when "s"
|
53
|
-
#config.check_file_exist(Arxutils_Sqlite3::Config::SAMPLE_DEST_OPTS_FILE, banner, 10)
|
52
|
+
# config.check_file_exist(Arxutils_Sqlite3::Config::SAMPLE_DEST_OPTS_FILE, banner, 10)
|
54
53
|
|
55
54
|
if opts["klass"].nil? || opts["klass"].strip == ""
|
56
55
|
puts banner
|
data/lib/arxutils_sqlite3/arx.rb
CHANGED
@@ -22,7 +22,7 @@ module Arxutils_Sqlite3
|
|
22
22
|
@data = data
|
23
23
|
|
24
24
|
# スキーマ設定の:itemsの値を展開後格納するためのStructクラス
|
25
|
-
|
25
|
+
# @field ||= Struct.new("Field", :name, :type, :null)
|
26
26
|
@field ||= Struct.new(:name, :type, :null)
|
27
27
|
|
28
28
|
@data[:ary] = if @data[:items]
|
@@ -35,7 +35,7 @@ module Arxutils_Sqlite3
|
|
35
35
|
# テンプレートファイルを元にした変換結果を返す
|
36
36
|
def create
|
37
37
|
scope = Object.new
|
38
|
-
scope.instance_variable_set(:@data
|
38
|
+
scope.instance_variable_set(:@data, @data)
|
39
39
|
Ykutils::Erubyx.erubi_render_with_template_file(@fname, scope)
|
40
40
|
end
|
41
41
|
end
|
data/lib/arxutils_sqlite3/cli.rb
CHANGED
@@ -8,15 +8,15 @@ module Arxutils_Sqlite3
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def setup(klass)
|
11
|
-
p "make_config_directory"
|
11
|
+
# p "make_config_directory"
|
12
12
|
@config.make_config_directory
|
13
|
-
p "setup_db_scheme_file"
|
13
|
+
# p "setup_db_scheme_file"
|
14
14
|
@config.setup_db_scheme_file
|
15
|
-
p "setup_opts_file(#{klass})"
|
15
|
+
# p "setup_opts_file(#{klass})"
|
16
16
|
@config.setup_opts_file(klass)
|
17
|
-
p "setup_setting_yaml_file(#{klass})"
|
17
|
+
# p "setup_setting_yaml_file(#{klass})"
|
18
18
|
@config.setup_setting_yaml_file(klass)
|
19
|
-
#db_scheme_ary = nil
|
19
|
+
# db_scheme_ary = nil
|
20
20
|
end
|
21
21
|
|
22
22
|
def copy_db_scheme
|
@@ -29,23 +29,21 @@ module Arxutils_Sqlite3
|
|
29
29
|
@config.copy_opts_file
|
30
30
|
end
|
31
31
|
|
32
|
-
def makeconfig(acrecord,
|
32
|
+
def makeconfig(acrecord, _banner, _exit_code, opts)
|
33
33
|
db_scheme_ary = nil
|
34
34
|
dbconfig_path = @config.make_dbconfig_path(@dbconfig)
|
35
|
-
|
35
|
+
# @config.check_file_exist(dbconfig_path, banner, exit_code)
|
36
36
|
mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
|
37
37
|
mig.make_dbconfig(opts)
|
38
38
|
end
|
39
39
|
|
40
40
|
def setup_for_migrate(yaml_pn, acrecord, klass)
|
41
|
-
db_scheme_ary = YAML.load_file(
|
41
|
+
db_scheme_ary = YAML.load_file(yaml_pn)
|
42
42
|
dbconfig_path = @config.make_dbconfig_path(@dbconfig)
|
43
43
|
|
44
44
|
dest_dbsetup_file = @config.get_dest_dbsetup_file
|
45
45
|
@config.make_dbsetup_file(db_scheme_ary, acrecord, klass, dest_dbsetup_file)
|
46
46
|
|
47
|
-
# migrate用スクリプトの出力先ディレクトリ名
|
48
|
-
migrate_dir = @config.get_migrate_dir
|
49
47
|
# マイグレーション用スクリプトの生成、acrecordのクラス定義ファイルの生成
|
50
48
|
mig = @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, acrecord)
|
51
49
|
mig.output
|
@@ -55,7 +53,7 @@ module Arxutils_Sqlite3
|
|
55
53
|
# migrate用スクリプトの出力先ディレクトリ名
|
56
54
|
migrate_dir = @config.get_migrate_dir
|
57
55
|
|
58
|
-
|
56
|
+
Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(@config, @dbconfig, @env)
|
59
57
|
|
60
58
|
# マイグレーション実行
|
61
59
|
ActiveRecord::MigrationContext.new(migrate_dir, ActiveRecord::SchemaMigration).up
|
@@ -83,7 +81,7 @@ module Arxutils_Sqlite3
|
|
83
81
|
|
84
82
|
def rm_dbconfig
|
85
83
|
dbconfig_path = @config.make_dbconfig_path(@dbconfig)
|
86
|
-
#p dbconfig_path
|
84
|
+
# p dbconfig_path
|
87
85
|
FileUtils.rm_f(dbconfig_path)
|
88
86
|
end
|
89
87
|
end
|
@@ -4,6 +4,7 @@ module Arxutils_Sqlite3
|
|
4
4
|
##
|
5
5
|
# migrateに必要なファイルをテンプレートから作成し、migarteを実行する
|
6
6
|
class Config
|
7
|
+
EXCLUDE_FILES = %W!setting.yml!
|
7
8
|
# DB格納ディレクトリ名
|
8
9
|
DB_DIR = "db".freeze
|
9
10
|
# migrate用スクリプト格納ディレクトリ名
|
@@ -23,33 +24,36 @@ module Arxutils_Sqlite3
|
|
23
24
|
TEMPLATE_DIR = Arxutils_Sqlite3::TOP_DIR.join("template")
|
24
25
|
# リレーションテンプレートディレクトリへのパス
|
25
26
|
TEMPLATE_ACRECORD_DIR = TEMPLATE_DIR.join("acrecord")
|
26
|
-
TEMPLATE_CONFIG_DIR = TEMPLATE_DIR.join(
|
27
|
+
TEMPLATE_CONFIG_DIR = TEMPLATE_DIR.join(CONFIG_DIR)
|
27
28
|
DB_SCHEME_DIR = TEMPLATE_ACRECORD_DIR.join("db_scheme")
|
28
29
|
DB_SCHEME_FILE = DB_SCHEME_DIR.join("db_scheme.yml")
|
29
30
|
SAMPLE_DB_SCHEME_FILE = CONFIG_DIR.join("db_scheme.yml.sample")
|
30
31
|
DB_SCHEME_FILE_NAME = "db_scheme.yml".freeze
|
31
|
-
|
32
|
-
OPTS_FILE_NAME = "opts.
|
32
|
+
DB_SCHEME_FILE_NAME_B = "db_scheme".freeze
|
33
|
+
OPTS_FILE_NAME = "opts.tmpl".freeze
|
33
34
|
SAMPLE_OPTS_FILE_NAME = "opts.rb.sample".freeze
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
OPTS_FILE_NAME_B = "opts".freeze
|
36
|
+
DEST_OPTS_FILE_NAME = "opts.rb".freeze
|
37
|
+
DEST_OPTS_FILE_NAME_B = "opts".freeze
|
38
|
+
DBSETUP_FILE_NAME = "dbsetup.tmpl".freeze
|
39
|
+
DBSETUP_FILE_NAME_B = "dbsetup".freeze
|
40
|
+
DEST_DBSETUP_FILE_NAME = "dbsetup.rb".freeze
|
37
41
|
SETTING_YAML_FILE_NAME = "setting.yml".freeze
|
38
|
-
DEST_CONFIG_DIR = Pathname.new(
|
42
|
+
DEST_CONFIG_DIR = Pathname.new(CONFIG_DIR)
|
39
43
|
OPTS_FILE = DB_SCHEME_DIR.join(OPTS_FILE_NAME)
|
40
44
|
SAMPLE_OPTS_FILE = CONFIG_DIR.join(SAMPLE_OPTS_FILE_NAME)
|
41
45
|
# 変換先Dbsetupクラス定義のRubyスクリプトファイルへのパス
|
42
46
|
DBSETUP_FILE = DB_SCHEME_DIR.join(DBSETUP_FILE_NAME)
|
43
47
|
# 変換先optsファイル(Rubyスクリプトファイル)へのパス
|
44
|
-
DEST_OPTS_FILE = DEST_CONFIG_DIR.join(
|
45
|
-
|
48
|
+
DEST_OPTS_FILE = DEST_CONFIG_DIR.join(DEST_OPTS_FILE_NAME)
|
49
|
+
DEST_OPTS_FILE_B = DEST_CONFIG_DIR.join(OPTS_FILE_NAME_B)
|
46
50
|
# 変換先Dbsetupクラス定義のRubyスクリプトファイルへのパス
|
47
|
-
DEST_DBSETUP_FILE = DEST_CONFIG_DIR.join(
|
51
|
+
DEST_DBSETUP_FILE = DEST_CONFIG_DIR.join(DEST_DBSETUP_FILE_NAME)
|
48
52
|
# 変換先Dbsetupクラス定義のRubyスクリプトファイル(拡張子無し)へのパス
|
49
|
-
|
53
|
+
DEST_DBSETUP_FILE_B = DEST_CONFIG_DIR.join(DBSETUP_FILE_NAME_B)
|
50
54
|
DEST_DB_SCHEME_FILE = DEST_CONFIG_DIR.join(DB_SCHEME_FILE_NAME)
|
51
55
|
# 変換後DBスキームファイル(拡張子無し)へのパス
|
52
|
-
|
56
|
+
DEST_DB_SCHEME_FILE_B = DEST_CONFIG_DIR.join(DB_SCHEME_FILE_NAME_B)
|
53
57
|
SETTING_YAML_FILE = CONFIG_DIR.join(SETTING_YAML_FILE_NAME)
|
54
58
|
DB_PN = Pathname.new(DB_DIR)
|
55
59
|
# migrateディレクトリへのパス
|
@@ -57,51 +61,47 @@ module Arxutils_Sqlite3
|
|
57
61
|
|
58
62
|
# DB構成ファイル格納ディレクトリの作成
|
59
63
|
def make_config_directory
|
60
|
-
p "config make_config_directory"
|
64
|
+
# p "config make_config_directory"
|
61
65
|
FileUtils.mkdir_p(CONFIG_DIR)
|
62
66
|
end
|
63
67
|
|
64
68
|
# DBスキームファイルのサンプルファイルコピー
|
65
69
|
def setup_db_scheme_file
|
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,
|
70
|
+
# p "config setup_db_scheme_file"
|
71
|
+
# p "DB_SCHEME_FILE=#{DB_SCHEME_FILE}"
|
72
|
+
# p "SAMPLE_DB_SCHEME_FILE=#{SAMPLE_DB_SCHEME_FILE}"
|
73
|
+
FileUtils.cp(DB_SCHEME_FILE, SAMPLE_DB_SCHEME_FILE)
|
70
74
|
end
|
71
75
|
|
72
76
|
# DBスキームファイルが存在しなければ、サンプルファイルをDBスキームファイルとしてコピー
|
73
77
|
def copy_db_scheme_file
|
74
|
-
if
|
75
|
-
|
76
|
-
|
78
|
+
return if File.exist?(DEST_DB_SCHEME_FILE)
|
79
|
+
|
80
|
+
FileUtils.cp(SAMPLE_DB_SCHEME_FILE, DEST_DB_SCHEME_FILE)
|
77
81
|
end
|
78
82
|
|
79
83
|
# optsファイル(Rubyスクリプトファイル)のサンプルファイル書き込み
|
80
84
|
def setup_opts_file(klass)
|
81
85
|
scope = Object.new
|
82
|
-
hash = {klass: klass}
|
86
|
+
hash = { klass: klass }
|
83
87
|
result_content = Ykutils::Erubyx.erubi_render_with_template_file(OPTS_FILE, scope, hash)
|
84
|
-
File.
|
85
|
-
file.write(result_content)
|
86
|
-
}
|
88
|
+
File.write(SAMPLE_OPTS_FILE, result_content)
|
87
89
|
end
|
88
90
|
|
89
91
|
# optsファイルが存在しなければ、サンプルファイルをoptsファイルとしてコピー
|
90
92
|
def copy_opts_file
|
91
|
-
if
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
93
|
+
return if File.exist?(DEST_OPTS_FILE)
|
94
|
+
|
95
|
+
# p "exist? #{File.exist?(DEST_OPTS_FILE)}"
|
96
|
+
# p "copy SAMPLE_OPTS_FILE(#{SAMPLE_OPTS_FILE}) to DEST_OPTS_FILE(#{DEST_OPTS_FILE})"
|
97
|
+
FileUtils.cp(SAMPLE_OPTS_FILE, DEST_OPTS_FILE)
|
96
98
|
end
|
97
99
|
|
98
100
|
# setting.ymlへの出力
|
99
101
|
def setup_setting_yaml_file(klass)
|
100
|
-
hash = {
|
102
|
+
hash = { klass: klass }
|
101
103
|
content = YAML.dump(hash)
|
102
|
-
File.
|
103
|
-
file.write(content)
|
104
|
-
}
|
104
|
+
File.write(SETTING_YAML_FILE, content)
|
105
105
|
end
|
106
106
|
|
107
107
|
# DB構成ファイルの作成
|
@@ -112,13 +112,13 @@ module Arxutils_Sqlite3
|
|
112
112
|
|
113
113
|
# optsファイル(Rubyスクリプトファイル)のrequire
|
114
114
|
def require_opts_file
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
115
|
+
return unless DEST_OPTS_FILE.exist?
|
116
|
+
|
117
|
+
opts_file = File.join("./", DEST_OPTS_FILE_B.to_s)
|
118
|
+
begin
|
119
|
+
require opts_file
|
120
|
+
rescue LoadError
|
121
|
+
# pp ex.message
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -127,40 +127,38 @@ module Arxutils_Sqlite3
|
|
127
127
|
setting = {}
|
128
128
|
# settingファイル
|
129
129
|
setting_yaml_file = SETTING_YAML_FILE
|
130
|
-
if setting_yaml_file.exist?
|
131
|
-
setting = YAML.load_file( setting_yaml_file )
|
132
|
-
end
|
130
|
+
setting = YAML.load_file(setting_yaml_file) if setting_yaml_file.exist?
|
133
131
|
setting
|
134
132
|
end
|
135
133
|
|
136
134
|
# Dbsetupファイル(Rubyスクリプトファイル)のrequire
|
137
135
|
def require_dbsetup_file
|
138
|
-
dbsetup_file = File.join(".",
|
136
|
+
dbsetup_file = File.join(".", get_dest_dbsetup_file_b.to_s)
|
139
137
|
begin
|
140
138
|
require dbsetup_file
|
141
|
-
rescue LoadError
|
139
|
+
rescue LoadError
|
142
140
|
# pp ex.message
|
143
141
|
end
|
144
142
|
end
|
145
143
|
|
146
144
|
# 指定ファイルの存在確認
|
147
145
|
def check_file_exist(file_pn, banner, exit_code)
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
146
|
+
return unless file_pn.exist?
|
147
|
+
|
148
|
+
puts "#{file_pn} exists!"
|
149
|
+
puts banner
|
150
|
+
exit exit_code
|
153
151
|
end
|
154
152
|
|
155
153
|
# 指定ファイルの非存在確認
|
156
154
|
def check_file_not_exist(file_pn, banner, exit_code)
|
157
|
-
if
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
155
|
+
return if file_pn.exist?
|
156
|
+
|
157
|
+
puts "#{file_pn} does not exists!"
|
158
|
+
puts banner
|
159
|
+
exit exit_code
|
162
160
|
end
|
163
|
-
|
161
|
+
|
164
162
|
# 変換先optsファイル(Rubyスクリプトファイル)へのパス
|
165
163
|
def get_dest_opts_file
|
166
164
|
DEST_OPTS_FILE
|
@@ -175,6 +173,7 @@ module Arxutils_Sqlite3
|
|
175
173
|
def get_migrate_dir
|
176
174
|
MIGRATE_DIR
|
177
175
|
end
|
176
|
+
|
178
177
|
# コンフィグディレクトリへのパス
|
179
178
|
def get_config_dir
|
180
179
|
CONFIG_DIR
|
@@ -201,13 +200,13 @@ module Arxutils_Sqlite3
|
|
201
200
|
end
|
202
201
|
|
203
202
|
# 変換先Dbsetupクラス定義のRubyスクリプトファイル(拡張子無し)へのパス
|
204
|
-
def
|
205
|
-
|
203
|
+
def get_dest_dbsetup_file_b
|
204
|
+
DEST_DBSETUP_FILE_B
|
206
205
|
end
|
207
206
|
|
208
207
|
# 変換後DBスキームファイル名(拡張子無し)
|
209
208
|
def get_dest_db_scheme_file
|
210
|
-
|
209
|
+
DEST_DB_SCHEME_FILE_B
|
211
210
|
end
|
212
211
|
|
213
212
|
# DBログファイルの作成
|
@@ -233,14 +232,12 @@ module Arxutils_Sqlite3
|
|
233
232
|
|
234
233
|
# migrateの準備
|
235
234
|
def prepare_for_migrate(db_scheme_ary, dbconfig_dest_path, dbconfig, acrecord)
|
236
|
-
#db_dir = config.DB_DIR
|
237
|
-
db_dir = get_db_dir
|
238
235
|
# DB構成ファイルの出力先ディレクトリ
|
239
236
|
dbconfig_src_fname = "#{dbconfig}.tmpl"
|
240
237
|
# migrate用スクリプトの出力先ディレクトリ名
|
241
238
|
migrate_dir = get_migrate_dir
|
242
239
|
|
243
|
-
|
240
|
+
Migrate.new(
|
244
241
|
self,
|
245
242
|
dbconfig_dest_path,
|
246
243
|
dbconfig_src_fname,
|
@@ -254,14 +251,16 @@ module Arxutils_Sqlite3
|
|
254
251
|
src_dbsetup_file = get_src_dbsetup_file
|
255
252
|
|
256
253
|
scope = Object.new
|
257
|
-
hash0 = {module_name: acrecord[:module].join("::")}
|
258
|
-
hash = db_scheme_ary[0].merge(
|
254
|
+
hash0 = { module_name: acrecord[:module].join("::") }
|
255
|
+
hash = db_scheme_ary[0].merge(hash0)
|
259
256
|
hash["klass"] = klass
|
260
257
|
result_content = Ykutils::Erubyx.erubi_render_with_template_file(src_dbsetup_file, scope, hash)
|
261
258
|
|
262
|
-
File.
|
263
|
-
|
264
|
-
|
259
|
+
File.write(dest_dbsetup_file, result_content)
|
260
|
+
end
|
261
|
+
|
262
|
+
def exclude_file?( fname )
|
263
|
+
EXCLUDE_FILES.index( fname ) != nil
|
265
264
|
end
|
266
265
|
end
|
267
|
-
end
|
266
|
+
end
|