exe/arxutils_sqlite3 in arxutils_sqlite3-0.1.44 vs exe/arxutils_sqlite3 in arxutils_sqlite3-0.1.45
- old
+ new
@@ -4,41 +4,33 @@
require "simpleoptparse"
require "pp"
require "ykutils"
require "ykxutils"
-if File.exist?(Arxutils_Sqlite3::DEST_OPTS_FILE)
- opts_file = File.join("./" , Arxutils_Sqlite3::DEST_OPTS_FILE_2.to_s)
- begin
- require opts_file
- rescue LoadError => ex
- pp ex.message
- end
-end
+config = Arxutils_Sqlite3::Config.new
+config.require_opts_file
+
begin
require "dbrelation"
rescue LoadError => ex
pp ex.message
end
+
+klass = nil
+setting = config.load_setting_yaml_file
+klass = setting[:klass]
+
# DBセットアップクラス
-if File.exist?(Arxutils_Sqlite3::DEST_DBSETUP_FILE)
- dbsetup_file = File.join("./" , Arxutils_Sqlite3::DEST_DBSETUP_FILE_2.to_s)
- begin
- require dbsetup_file
- rescue LoadError => ex
- pp ex.message
- end
-end
+config.require_dbsetup_file
banner = "Usage: bundle exec ruby exe/makemigrate --cmd=(s|c|m|i|d) -y yaml_file --klass=class"
opts = @opts ? @opts : {}
+opts["dbconfig"] = Arxutils_Sqlite3::Config::DBCONFIG_SQLITE3
-opts["dbconfig"] = Arxutils_Sqlite3::Dbutil::DBCONFIG_SQLITE3
-
Simpleoptparse::Simpleoptparse.parse(ARGV, opts, banner, Arxutils_Sqlite3::VERSION, nil) do |parser|
parser.on("--cmd X", %w[s c m i d]) { |x| opts["cmd"] = x }
parser.on("-y yaml_file", "--yaml yaml_file") { |x| opts["yaml"] = x }
parser.on("--klass klass") { |x| opts["klass"] = x }
end
@@ -46,95 +38,72 @@
env = ENV.fetch("ENV", nil)
env ||= "production"
case opts["cmd"]
when "s"
- FileUtils.cp(Arxutils_Sqlite3::DB_SCHEME_FILE, Arxutils_Sqlite3::Dbutil::CONFIG_DIR )
+ config.check_file_exist(Arxutils_Sqlite3::Config::DEST_OPTS_FILE, banner, 10)
+
if opts["klass"].nil? || opts["klass"].strip == ""
puts banner
- exit 10
+ exit 20
end
-
- scope = Object.new
- hash = {klass: opts["klass"]}
- result_content = Ykutils::Erubyx.erubi_render_with_template_file(Arxutils_Sqlite3::OPTS_FILE, scope, hash)
-
- File.open(Arxutils_Sqlite3::DEST_OPTS_FILE, "w"){|file|
- file.write(result_content)
- }
+ klass = opts["klass"]
+ config.make_config_directory
+ config.setup_db_scheme_file
+ config.setup_opts_file(klass)
+ config.setup_setting_yaml_file(klass)
db_scheme_ary = nil
when "c"
db_scheme_ary = nil
- db_dir = Arxutils_Sqlite3::Dbutil::DB_DIR
- config_dir = Arxutils_Sqlite3::Dbutil::CONFIG_DIR
- # DB構成ファイル名
- dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, opts["dbconfig"])
-
- mig = Arxutils_Sqlite3::Util.prepare_for_migrate(env, db_scheme_ary, db_dir, dbconfig_path, opts)
+ dbconfig = opts["dbconfig"]
+ replation = opts["replation"]
+ dbconfig_path = config.make_dbconfig_path(dbconfig)
+ config.check_file_exist(dbconfig_path, banner, 30)
+ mig = config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, replation)
mig.make_dbconfig(opts)
when "m"
- if opts["yaml"].nil? || opts["yaml"].strip == ""
+ yaml_fname = opts["yaml"]
+ relation = opts[:relation]
+ dbconfig = opts["dbconfig"]
+
+ if yaml_fname.nil? || yaml_fname.strip == ""
puts banner
- exit 20
+ exit 40
end
+ yaml_pn = Pathname.new(yaml_fname)
+ config.check_file_not_exist(yaml_pn, banner, 55)
+ db_scheme_ary = YAML.load_file( yaml_pn )
- opts["migrate_cmd"] = "migrate"
- db_scheme_ary = YAML.load_file( opts["yaml"] )
+ dest_dbsetup_file = config.get_dest_dbsetup_file
+ config.check_file_exist(dest_dbsetup_file, banner, 50)
- scope = Object.new
+ config.make_dbsetup_file(db_scheme_ary, relation, klass, dest_dbsetup_file)
- hash0 = {module_name: opts[:relation][:module].join("::")}
- hash = db_scheme_ary[0].merge( hash0 )
- result_content = Ykutils::Erubyx.erubi_render_with_template_file(Arxutils_Sqlite3::DBSETUP_FILE, scope, hash)
+ connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(config, dbconfig, env)
- File.open(Arxutils_Sqlite3::DEST_DBSETUP_FILE, "w"){|file|
- file.write(result_content)
- }
- db_dir = Arxutils_Sqlite3::Dbutil::DB_DIR
+ # マイグレーション用スクリプトの生成、relationのクラス定義ファイルの生成
+ mig = config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, relation)
+ mig.output
- config_dir = Arxutils_Sqlite3::Dbutil::CONFIG_DIR
- # DB構成ファイル名
- dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, opts["dbconfig"])
- # DBログファイルへのパス
- log_path = Arxutils_Sqlite3::Util.make_log_path(db_dir, opts["dbconfig"])
- mig = Arxutils_Sqlite3::Util.prepare_for_migrate(env, db_scheme_ary, db_dir, dbconfig_path, opts)
- mig.process
- dbconnect = Arxutils_Sqlite3::Dbutil::Dbconnect.new(
- dbconfig_path,
- env,
- log_path
- )
- connect_time = dbconnect.connect
- #p "connect_time=#{connect_time}"
+ # マイグレーション実行
ActiveRecord::MigrationContext.new(mig.migrate_dir, ActiveRecord::SchemaMigration).up
when "i"
- #db_scheme_ary = YAML.load_file( opts["yaml"] )
- db_scheme_ary = nil
- db_dir = Arxutils_Sqlite3::Dbutil::DB_DIR
-
- config_dir = Arxutils_Sqlite3::Dbutil::CONFIG_DIR
- # DB構成ファイルへのパス
- dbconfig_dest_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, opts["dbconfig"])
- # DBログファイルへのパス
- log_path = Arxutils_Sqlite3::Util.make_log_path(db_dir, opts["dbconfig"])
- dbconnect = Arxutils_Sqlite3::Dbutil::Dbconnect.new(
- dbconfig_dest_path,
- env,
- log_path
- )
- connect_time = dbconnect.connect
-
+ dbconfig = opts["dbconfig"]
+ connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(config, dbconfig, env)
Dbsetup.new(connect_time)
when "d"
db_scheme_ary = nil
- mig = Arxutils_Sqlite3::Util.repare_for_migrate(env, db_scheme_ary, opts)
+ dbconfig = opts["dbconfig"]
+ replation = opts["replation"]
+
+ config_dir = config.get_config_dir
+ dbconfig_path = Arxutils_Sqlite3::Util.make_dbconfig_path(config_dir, dbconfig)
+ mig = config.prepare_for_migrate(db_scheme_ary, dbconfig_path, dbconfig, replation)
mig.delete_migrate_config_and_db
else
puts "Invalid command(#{opts["cmd"]}) specified!!"
end
-#
-