Class: Arxutils::Migrate
- Inherits:
-
Object
- Object
- Arxutils::Migrate
- Defined in:
- lib/arxutils/migrate.rb
Overview
migrateに必要なファイルをテンプレートから作成し、migarteを実行する
Defined Under Namespace
Classes: Migratex
Constant Summary collapse
- FILENAME_COUNTER_STEP =
migrate用スクリプトファイル名の先頭の番号の間隔
10
Class Method Summary collapse
-
.migrate(db_dir, src_config_dir, log_fname, migrate_dir, env, db_scheme_ary, dbconfig, opts) ⇒ Object
migrateに必要なファイルをテンプレートから作成し、migarteを実行する.
Class Method Details
.migrate(db_dir, src_config_dir, log_fname, migrate_dir, env, db_scheme_ary, dbconfig, opts) ⇒ Object
migrateに必要なファイルをテンプレートから作成し、migarteを実行する
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/arxutils/migrate.rb', line 18 def self.migrate( db_dir , src_config_dir , log_fname, migrate_dir, env, db_scheme_ary , dbconfig , opts ) log_file_name = sprintf("%s-%s" , dbconfig.to_s , log_fname ) mig = Migratex.new( db_dir , migrate_dir , src_config_dir , dbconfig, env, log_file_name, opts ) # DB構成情報の生成 # dbconfigのテンプレートは内容が固定である。 if( opts["makeconfig"] ) mig.make_dbconfig( opts ) return end # スキーマ設定配列から、migrate用のスクリプトを作成する db_scheme_ary.map{ |x| mig.make_script_group(x) }.flatten(1).each_with_index{|data , index| idy = (index + 1) * FILENAME_COUNTER_STEP mig.output_script( idy , *data ) } # スキーマ設定配列から、relationのmigrate用のスクリプトの内容(ハッシュ形式)の配列を作成する content_array = db_scheme_ary.map { |x| mig.make_relation( x , "count" ) }.select{ |x| x.size > 0 } # 複数形のクラス名を集める need_count_class_plural = content_array.select{ |x| x[:need_count_class_plural] != nil }.map{ |x| x[:need_count_class_plural] } # relationのmigrateが必要であれば、それをテンプレートファイルから作成して、スクリプトの内容として追加する if content_array.find{|x| x != nil} data_count = {count_classname: "Count" , need_count_class_plural: need_count_class_plural, } ary = content_array.collect{|x| x[:content] }.flatten count_content = mig.convert_count_class_relation( data_count , "relation_count.tmpl" ) ary.unshift( count_content ) content_array = ary end # relationのスクリプトを作成 mig.output_relation_script( content_array , opts[:relation] ) # データベース接続とログ設定 ::Arxutils::Dbutil::DbMgr.setup( mig.dbinit ) # migrateを実行する mig.migrate end |