arxutils 0.1.31 → 0.1.35
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +0 -3
- data/arxutils.gemspec +1 -0
- data/lib/arxutils/arx.rb +9 -3
- data/lib/arxutils/arxutils.rb +0 -4
- data/lib/arxutils/dbutil/dbinit.rb +16 -11
- data/lib/arxutils/dbutil/dbmgr.rb +4 -3
- data/lib/arxutils/hier.rb +180 -0
- data/lib/arxutils/migrate.rb +63 -9
- data/lib/arxutils/misc.rb +44 -0
- data/lib/arxutils/store/storedb.rb +1 -1
- data/lib/arxutils/transactstate.rb +53 -0
- data/lib/arxutils/version.rb +1 -1
- data/lib/arxutils.rb +6 -0
- data/lib/config/mysql.tmpl +4 -4
- data/lib/config/sqlite3.tmpl +4 -4
- data/lib/template/base.tmpl +2 -2
- data/lib/template/current.tmpl +2 -4
- data/lib/template/invalid.tmpl +1 -1
- data/lib/template/relation.tmpl +3 -0
- data/lib/template/relation_count.tmpl +4 -0
- data/lib/template/relation_current.tmpl +3 -0
- data/lib/template/relation_invalid.tmpl +4 -0
- metadata +24 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0db660cdf41eaaaab3cc142711afb8186b10c06e
|
4
|
+
data.tar.gz: 20a8b02d69969d52a37cfddda3c721d0d628762d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e38ecbe696e36c4e4975fcf304beb86d49056edb6df241448232d7e8b987041f45514ece568c1449f4155fde058521c55a71e221e3de4f3d8a76bf5bd0e9f35
|
7
|
+
data.tar.gz: bc11ab615060d8d3eaff76d5e582258adf766d78cde23852403ba4c3f05ae54440c2853f047675a59c8389a802cb9b3d648ca730aea8d49200a8c117dbf16ee7
|
data/Rakefile
CHANGED
data/arxutils.gemspec
CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
+
spec.add_runtime_dependency "activesupport"
|
30
31
|
# spec.add_runtime_dependency "erb"
|
31
32
|
spec.add_runtime_dependency "activerecord"
|
32
33
|
spec.add_runtime_dependency "sqlite3"
|
data/lib/arxutils/arx.rb
CHANGED
@@ -12,18 +12,24 @@ module Arxutils
|
|
12
12
|
# :items
|
13
13
|
# フィールド名, 型, null許容 の配列
|
14
14
|
# :plural
|
15
|
+
# :relation
|
15
16
|
@data = data
|
16
17
|
|
17
18
|
@@field ||= Struct.new("Field" , :name, :type, :null )
|
18
19
|
|
19
|
-
|
20
|
+
if @data[:items]
|
21
|
+
@data[:ary] = @data[:items].map{ |x| @@field.new( *x ) }
|
22
|
+
else
|
23
|
+
@data[:ary] = []
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
27
|
def create
|
23
28
|
contents = File.open( @fname ).read
|
24
|
-
|
25
29
|
erb = ERB.new(contents)
|
26
|
-
erb.result(binding)
|
30
|
+
content = erb.result(binding)
|
31
|
+
content
|
27
32
|
end
|
33
|
+
|
28
34
|
end
|
29
35
|
end
|
data/lib/arxutils/arxutils.rb
CHANGED
@@ -7,37 +7,42 @@ require 'sqlite3'
|
|
7
7
|
module Arxutils
|
8
8
|
module Dbutil
|
9
9
|
DB_DIR = 'db'
|
10
|
-
MIGRATE_DIR = '
|
10
|
+
MIGRATE_DIR = 'migrate'
|
11
11
|
DBCONFIG_SQLITE3 = 'sqlite3'
|
12
12
|
DBCONFIG_MYSQL = 'mysql'
|
13
13
|
CONFIG_DIR = 'config'
|
14
14
|
DATABASELOG = 'database.log'
|
15
15
|
|
16
16
|
class Dbinit
|
17
|
-
attr_accessor :dbconfig_dest_path , :dbconfig_src_path , :dbconfig_src_fname , :dbconfig_dest_fname
|
17
|
+
attr_accessor :dbconfig_dest_path , :dbconfig_src_path , :dbconfig_src_fname , :dbconfig_dest_fname , :migrate_dir
|
18
18
|
|
19
|
-
def initialize(
|
20
|
-
@db_dir = db_dir
|
21
|
-
@migrate_dir = migrate_dir
|
19
|
+
def initialize( migrate_base_dir , src_config_dir , dbconfig , log_fname, forced = false )
|
20
|
+
@db_dir = dbconfig[:db_dir]
|
22
21
|
@src_config_dir = src_config_dir
|
23
22
|
@dest_config_dir = "config"
|
24
|
-
@dbconfig_dest_fname = "#{dbconfig}.yaml"
|
25
|
-
@dbconfig_src_fname = "#{dbconfig}.tmpl"
|
23
|
+
@dbconfig_dest_fname = "#{dbconfig[:kind]}.yaml"
|
24
|
+
@dbconfig_src_fname = "#{dbconfig[:kind]}.tmpl"
|
26
25
|
@dbconfig_dest_path = File.join( @dest_config_dir , @dbconfig_dest_fname)
|
27
26
|
@dbconfig_src_path = File.join(@src_config_dir , @dbconfig_src_fname)
|
28
27
|
@log_fname = log_fname
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
|
29
|
+
if @db_dir and @log_fname
|
30
|
+
@log_path = File.join( @db_dir , @log_fname )
|
31
|
+
@migrate_dir = File.join( @db_dir , migrate_base_dir )
|
32
|
+
end
|
33
|
+
FileUtils.mkdir_p( @db_dir ) if @db_dir
|
34
|
+
FileUtils.mkdir_p( @migrate_dir ) if @migrate_dir
|
32
35
|
FileUtils.mkdir_p( @dest_config_dir )
|
33
36
|
if forced
|
34
|
-
FileUtils.rm( Dir.glob( File.join( @migrate_dir , "*")))
|
37
|
+
FileUtils.rm( Dir.glob( File.join( @migrate_dir , "*"))) if @migrate_dir
|
35
38
|
FileUtils.rm( Dir.glob( File.join( @dest_config_dir , "*")))
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
39
42
|
def setup
|
43
|
+
puts ENV['ENV']
|
40
44
|
dbconfig = YAML.load( File.read( @dbconfig_dest_path ) )
|
45
|
+
puts dbconfig[ ENV['ENV'] ]
|
41
46
|
ActiveRecord::Base.establish_connection(dbconfig[ENV['ENV']])
|
42
47
|
ActiveRecord::Base.logger = Logger.new( @log_path )
|
43
48
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
|
2
3
|
require 'arxutils/dbutil/dbinit'
|
3
4
|
|
4
5
|
require 'date'
|
@@ -7,8 +8,8 @@ require 'pp'
|
|
7
8
|
module Arxutils
|
8
9
|
module Dbutil
|
9
10
|
class DbMgr
|
10
|
-
def DbMgr.init(
|
11
|
-
dbinit = Dbinit.new(
|
11
|
+
def DbMgr.init( migrate_dir , config_dir , dbconfig, log_fname, forced = false )
|
12
|
+
dbinit = Dbinit.new( migrate_dir , config_dir , dbconfig, log_fname, forced )
|
12
13
|
DbMgr.setup( dbinit )
|
13
14
|
end
|
14
15
|
|
@@ -27,7 +28,6 @@ module Arxutils
|
|
27
28
|
|
28
29
|
@@ret
|
29
30
|
end
|
30
|
-
|
31
31
|
def DbMgr.conv_string(value , encoding)
|
32
32
|
if value.class == String
|
33
33
|
if value.encodingy != encoding
|
@@ -67,3 +67,4 @@ module Arxutils
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
70
|
+
|
@@ -0,0 +1,180 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Arxutils
|
4
|
+
class HierOp
|
5
|
+
def initialize( hier_symbol , base_klass , hier_klass , current_klass )
|
6
|
+
@hier_symbol = hier_symbol
|
7
|
+
@base_klass = base_klass
|
8
|
+
@hier_klass = hier_klass
|
9
|
+
@current_klass = current_klass
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete( hier )
|
13
|
+
# 子として探す
|
14
|
+
id = nil
|
15
|
+
row_item = @base_klass.find_by( { @hier_symbol => hier } )
|
16
|
+
if row_item
|
17
|
+
id = row_item.id
|
18
|
+
delete_at( id )
|
19
|
+
end
|
20
|
+
id
|
21
|
+
end
|
22
|
+
|
23
|
+
def move( src_hier , dest_parent_hier )
|
24
|
+
# dest_parent_hierがsrc_hierの子であれば(=src_hierがdest_parent_hierの先頭からの部分文字列である)何もせずエラーを返す
|
25
|
+
escaped = Regexp.escape( src_hier )
|
26
|
+
src_re = Regexp.new( %Q!^#{escaped}! )
|
27
|
+
ret = ( src_re =~ dest_parent_hier )
|
28
|
+
# 自身の子への移動はエラーとする
|
29
|
+
if ret
|
30
|
+
return false
|
31
|
+
end
|
32
|
+
|
33
|
+
src_row_item = @base_klass.where( name: src_hier )
|
34
|
+
src_num = src_row_item.id
|
35
|
+
# srcが子である(tblでは項目を一意に指定できる)のtblでの項目を得る
|
36
|
+
src_row = @hire_klass.find_by( child_id: src_num )
|
37
|
+
|
38
|
+
dest_parent_row_item = @base_klass.find_by( name: dest_parent_hier )
|
39
|
+
unless dest_parent_row_item
|
40
|
+
dest_parent_num = register( dest_parent_hier )
|
41
|
+
else
|
42
|
+
dest_parent_num = dest_parent_row_item.id
|
43
|
+
end
|
44
|
+
dest_parent_level = get_level_by_child( dest_parent_num )
|
45
|
+
|
46
|
+
# srcの親をdest_parentにする
|
47
|
+
src_row.parent_id = dest_parent_num
|
48
|
+
|
49
|
+
# destに移動後のsrcの子のレベルを調整する
|
50
|
+
level_adjust( src_row , dest_parent_level )
|
51
|
+
# destに移動後のsrcのhierを再設定
|
52
|
+
set_hier( src_row_item , make_hier( dest_parent_row_item.name , get_name( src_row_item ) ) )
|
53
|
+
# destに移動後のsrcの子のhierを調整する
|
54
|
+
hier_adjust( src_row_item )
|
55
|
+
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
59
|
+
def register_parent( hier_ary , child_num , level )
|
60
|
+
hier_ary.pop
|
61
|
+
parent_hier_ary = hier_ary
|
62
|
+
parent_hier = parent_hier_ary.join('/')
|
63
|
+
parent_num = register( parent_hier )
|
64
|
+
hs = { parent_id: parent_num , child_id: child_num , level: level }
|
65
|
+
@hier_klass.create( hs )
|
66
|
+
end
|
67
|
+
|
68
|
+
def register( hier )
|
69
|
+
hier_ary = hier.split('/')
|
70
|
+
level = get_level_by_array( hier_ary )
|
71
|
+
|
72
|
+
# もしhier_aryがnilだけを1個持つ配列、または空文字列だけを1個もつ配列であれば、hier_nameは空文字列になる
|
73
|
+
|
74
|
+
item_row = @current_klass.find_by( {@hier_symbol => hier} )
|
75
|
+
unless item_row
|
76
|
+
# @base_klassがhierだけでcreateできる場合は(他にフィールドがnot_nullでないか)、ここに来てもよい。
|
77
|
+
# そうでなければ、SQLの制約違反が発生するため、ここに来ることを避けなければならない。
|
78
|
+
# (あらかじめここが呼ばれないようにdatabaseに登録済みにしておかなければならない。)
|
79
|
+
new_category = @base_klass.create( {@hier_symbol => hier} )
|
80
|
+
new_num = new_category.id
|
81
|
+
if level == 0
|
82
|
+
unless @hier_klass.find_by( child_id: new_num )
|
83
|
+
hs = { parent_id: new_num , child_id: new_num , level: level }
|
84
|
+
@hier_klass.create( hs )
|
85
|
+
end
|
86
|
+
else
|
87
|
+
register_parent( hier_ary , new_num, level )
|
88
|
+
end
|
89
|
+
else
|
90
|
+
new_num = item_row.org_id
|
91
|
+
if level == 0
|
92
|
+
unless @hier_klass.find_by( child_id: new_num )
|
93
|
+
hs = {parent_id: new_num , child_id: new_num , level: level}
|
94
|
+
@hier_klass.create( hs )
|
95
|
+
end
|
96
|
+
else
|
97
|
+
unless @hier_klass.find_by( child_id: new_num )
|
98
|
+
register_parent( hier_ary , new_num, level )
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
new_num
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def delete_at( num )
|
108
|
+
# 子として探す
|
109
|
+
row = @hier_klass.find_by( child_id: num )
|
110
|
+
level = row.level
|
111
|
+
parent_id = row.parent_id
|
112
|
+
row_item = @base_klass.find( num )
|
113
|
+
|
114
|
+
parent_item_row = @base_klass.find( parent_id )
|
115
|
+
parent_hier = parent_item_row.name
|
116
|
+
|
117
|
+
# 属する子を探す
|
118
|
+
child_rows = @hier_klass.where( parent_id: num )
|
119
|
+
# 属する子の階層レベルを調整する(削除するのでlevel - 1になる)
|
120
|
+
child_rows.map{ |x| level_adjust( x , level - 1 ) }
|
121
|
+
# 属する子の親を、親の親にする
|
122
|
+
child_rows.map{ |x|
|
123
|
+
x.parent_id = parent_id
|
124
|
+
}
|
125
|
+
# 属する子のhierを調整する
|
126
|
+
child_rows.map{ |x|
|
127
|
+
child_item_row = @base_klass.find( x.child_id )
|
128
|
+
name = get_name( child_item_row )
|
129
|
+
child_item_row.name = make_hier( parent_hier , name )
|
130
|
+
hier_adjust( child_item_row )
|
131
|
+
}
|
132
|
+
end
|
133
|
+
|
134
|
+
def get_level_by_array( hier_ary )
|
135
|
+
level = hier_ary.size - 1
|
136
|
+
level = 0 if level < 0
|
137
|
+
level
|
138
|
+
end
|
139
|
+
|
140
|
+
def get_name( items_row )
|
141
|
+
name = ""
|
142
|
+
if items_row
|
143
|
+
name = items_row.name.split('/').pop
|
144
|
+
end
|
145
|
+
name
|
146
|
+
end
|
147
|
+
|
148
|
+
def hier_adjust( item_row )
|
149
|
+
parent_hier = item_row.name
|
150
|
+
parent_num = item_row.id
|
151
|
+
|
152
|
+
tbl_rows = @hier_klass.where( parent_id: parent_num )
|
153
|
+
if tbl_rows.size > 0
|
154
|
+
tbl_rows.map{|x|
|
155
|
+
child_num = x.child_id
|
156
|
+
item_row = @base_klass.find( child_num )
|
157
|
+
item_row.name = make_hier( parent_hier , get_name( item_row ) )
|
158
|
+
hier_adjust( item_row )
|
159
|
+
}
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# 指定項目と、その子のlevelを調整
|
164
|
+
def level_adjust( row , parent_level )
|
165
|
+
row.level = parent_level + 1
|
166
|
+
child_rows = @hier_klass.where( parent_id: row.id )
|
167
|
+
if child_rows.size > 0
|
168
|
+
child_rows.map{ |x| level_adjust( x , row.level ) }
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def get_level_by_child( num )
|
173
|
+
@hier_klass.find_by( child_id: num ).level
|
174
|
+
end
|
175
|
+
|
176
|
+
def make_hier( parent_hier , name )
|
177
|
+
[ parent_hier , name ].join('/')
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
data/lib/arxutils/migrate.rb
CHANGED
@@ -2,37 +2,70 @@
|
|
2
2
|
require 'arxutils'
|
3
3
|
|
4
4
|
require 'fileutils'
|
5
|
+
require 'active_support'
|
5
6
|
require 'active_record'
|
7
|
+
require 'pp'
|
6
8
|
|
7
9
|
module Arxutils
|
8
10
|
class Migrate
|
9
11
|
attr_accessor :dbinit , :dbconfig_dest_path , :dbconfig_dest_fname , :dbconfig_src_path , :dbconfig_src_fname
|
10
12
|
|
11
|
-
def Migrate.migrate( data_ary ,
|
13
|
+
def Migrate.migrate( data_ary , relation_def_fpath , module_name, count_classname_downcase , count_field , dbconfig , forced )
|
12
14
|
src_config_dir = Arxutils.configdir
|
13
|
-
mig = Migrate.new(
|
14
|
-
|
15
|
+
mig = Migrate.new( Dbutil::MIGRATE_DIR , src_config_dir , dbconfig, Dbutil::DATABASELOG, forced )
|
16
|
+
# dbconfigのテンプレートは内容が固定である。convertを呼び出し、Arxのインスタンスを作成するときに、適切なdata_aryの要素を与える必要がある(ただしテンプレートへの埋め込みには用いられない
|
17
|
+
mig.make_dbconfig( dbconfig )
|
15
18
|
|
16
|
-
data_ary.reduce(0)
|
19
|
+
data_ary.reduce(0) { |next_num , x|
|
17
20
|
mig.make( next_num , x )
|
18
|
-
|
21
|
+
}
|
19
22
|
|
23
|
+
content_array = data_ary.map { |x|
|
24
|
+
mig.make_relation( x , "count", "end_count_id" )
|
25
|
+
}.select{ |x| x.size > 0 }
|
26
|
+
need_count_class_plural = content_array.reduce([]){ |s,x|
|
27
|
+
s << x[:need_count_class_plural] if x[:need_count_class_plural] != nil
|
28
|
+
s
|
29
|
+
}
|
30
|
+
if content_array.size > 0
|
31
|
+
data_count = {count_classname: "Count" ,
|
32
|
+
count_field: count_field,
|
33
|
+
need_count_class_plural: need_count_class_plural,
|
34
|
+
}
|
35
|
+
ary = content_array.collect{|x| x[:content] }.flatten
|
36
|
+
count_content = mig.convert_count_class_relation( data_count , "relation_count.tmpl" )
|
37
|
+
ary.unshift( count_content )
|
38
|
+
content_array = ary
|
39
|
+
end
|
40
|
+
File.open( relation_def_fpath , 'w' , {:encoding => Encoding::UTF_8}){ |f|
|
41
|
+
f.puts("module #{module_name}")
|
42
|
+
content_array.map{ |content|
|
43
|
+
f.puts( content )
|
44
|
+
f.puts( "\n" )
|
45
|
+
}
|
46
|
+
f.puts("end")
|
47
|
+
}
|
48
|
+
|
20
49
|
Dbutil::DbMgr.setup( mig.dbinit )
|
21
50
|
|
22
51
|
mig.migrate
|
23
52
|
end
|
24
53
|
|
25
|
-
def initialize(
|
26
|
-
@dbinit = Dbutil::Dbinit.new(
|
54
|
+
def initialize( migrate_base_dir , config_dir , dbconfig, log_fname, forced = false )
|
55
|
+
@dbinit = Dbutil::Dbinit.new( migrate_base_dir , config_dir , dbconfig, log_fname, forced )
|
27
56
|
@dbconfig_dest_path = @dbinit.dbconfig_dest_path
|
28
57
|
@dbconfig_src_path = @dbinit.dbconfig_src_path
|
29
58
|
@dbconfig_src_fname = @dbinit.dbconfig_src_fname
|
30
59
|
|
31
|
-
@migrate_dir = migrate_dir
|
60
|
+
@migrate_dir = @dbinit.migrate_dir
|
32
61
|
@src_path = Arxutils.templatedir
|
33
62
|
@src_config_path = Arxutils.configdir
|
34
63
|
end
|
35
64
|
|
65
|
+
def convert_count_class_relation( data , src_fname )
|
66
|
+
convert( data , @src_path , src_fname )
|
67
|
+
end
|
68
|
+
|
36
69
|
def convert( data , src_dir , src_fname )
|
37
70
|
arx = Arx.new( data , File.join( src_dir, src_fname ) )
|
38
71
|
arx.create
|
@@ -44,6 +77,28 @@ module Arxutils
|
|
44
77
|
f.puts( content )
|
45
78
|
}
|
46
79
|
end
|
80
|
+
|
81
|
+
def make_relation( data , count_classname_downcase , count_field )
|
82
|
+
if data[:classname_downcase] != count_classname_downcase
|
83
|
+
data[:flist].reduce( { content: [], need_count_class: nil } ){ |s, x|
|
84
|
+
case x
|
85
|
+
when "base" , "noitem"
|
86
|
+
name_base = "relation"
|
87
|
+
data[:relation] = [] unless data[:relation]
|
88
|
+
else
|
89
|
+
data[:count_classname_downcase] = count_classname_downcase
|
90
|
+
data[:count_field] = count_field
|
91
|
+
name_base = "relation_#{x}"
|
92
|
+
s[:need_count_class_plural] ||= data[:plural]
|
93
|
+
end
|
94
|
+
content = convert( data , @src_path , "#{name_base}.tmpl" )
|
95
|
+
s[:content] << content
|
96
|
+
s
|
97
|
+
}
|
98
|
+
else
|
99
|
+
{}
|
100
|
+
end
|
101
|
+
end
|
47
102
|
|
48
103
|
def make( next_num , data )
|
49
104
|
data[:flist].reduce(next_num) do |idy , x|
|
@@ -56,7 +111,6 @@ module Arxutils
|
|
56
111
|
additional = x
|
57
112
|
end
|
58
113
|
fname = File.join( @migrate_dir , sprintf("%03d_create_%s%s.rb" , idy , additional , data[:classname_downcase]) )
|
59
|
-
p fname
|
60
114
|
File.open( fname , 'w' , {:encoding => Encoding::UTF_8}){ |f|
|
61
115
|
f.puts( content )
|
62
116
|
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Arxutils
|
4
|
+
def load_file( in_file )
|
5
|
+
File.open( in_file , "r" , { :encoding => 'UTF-8' } )
|
6
|
+
end
|
7
|
+
|
8
|
+
def normalize_to_integer( *args )
|
9
|
+
args.map{ |x|
|
10
|
+
if x != nil and x !~ /^\s*$/
|
11
|
+
x.to_i
|
12
|
+
else
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_integer( model , hs )
|
19
|
+
value_hs = hs.reduce({}){ |hsx,item|
|
20
|
+
val = model.send(item[0])
|
21
|
+
if val == nil or val < item[1]
|
22
|
+
hsx[ item[0] ] = item[1]
|
23
|
+
end
|
24
|
+
hsx
|
25
|
+
}
|
26
|
+
if value_hs.size > 0
|
27
|
+
begin
|
28
|
+
model.update(value_hs)
|
29
|
+
rescue => ex
|
30
|
+
puts ex.message
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def capture_queries(&block)
|
36
|
+
queries = []
|
37
|
+
ActiveSupport::Notifications.subscribe('sql.active_record') do |_name, _start, _finish, _id, payload|
|
38
|
+
queries << payload
|
39
|
+
end
|
40
|
+
yield block
|
41
|
+
ActiveSupport::Notifications.unsubscribe('sql.active_record')
|
42
|
+
queries
|
43
|
+
end
|
44
|
+
end
|
@@ -6,7 +6,7 @@ module Arxutils
|
|
6
6
|
class StoreDb
|
7
7
|
def StoreDb.init( hs , block = nil )
|
8
8
|
ret = nil
|
9
|
-
register_time = Dbutil::DbMgr.init( hs["
|
9
|
+
register_time = Dbutil::DbMgr.init( hs["migrate_dir"] , hs["config_dir"], hs["dbconfig"] , hs["log_fname"] )
|
10
10
|
|
11
11
|
if block
|
12
12
|
ret = block.call( register_time )
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Arxutils
|
2
|
+
class TransactState
|
3
|
+
attr_accessor :ids , :state
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@ids = []
|
7
|
+
@state = :NONE
|
8
|
+
end
|
9
|
+
|
10
|
+
def add( xid )
|
11
|
+
@ids << xid if @state == :TRACE
|
12
|
+
end
|
13
|
+
|
14
|
+
def clear
|
15
|
+
@ids = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def need?
|
19
|
+
@ids.size > 0
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
class TransactStateGroup
|
25
|
+
def initialize( *names )
|
26
|
+
@state = :NONE
|
27
|
+
@inst = {}
|
28
|
+
names.map{|x| @inst[x] = TransactState.new }
|
29
|
+
end
|
30
|
+
|
31
|
+
def need?
|
32
|
+
@state != :NONE
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_all_inst_state
|
36
|
+
@inst.map{|x| x[1].state = @state }
|
37
|
+
end
|
38
|
+
|
39
|
+
def trace
|
40
|
+
@state = :TRACE
|
41
|
+
set_all_inst_state
|
42
|
+
end
|
43
|
+
|
44
|
+
def reset
|
45
|
+
@state = :NONE
|
46
|
+
set_all_inst_state
|
47
|
+
end
|
48
|
+
|
49
|
+
def method_missing(name , lang = nil)
|
50
|
+
@inst[name]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/arxutils/version.rb
CHANGED
data/lib/arxutils.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
require 'active_record'
|
1
4
|
require 'arxutils/version'
|
2
5
|
require 'arxutils/arxutils'
|
3
6
|
require 'arxutils/arx'
|
7
|
+
require 'arxutils/transactstate'
|
8
|
+
require 'arxutils/hier'
|
9
|
+
require 'arxutils/misc'
|
4
10
|
require 'arxutils/dbutil/dbinit'
|
5
11
|
require 'arxutils/dbutil/dbmgr'
|
6
12
|
require 'arxutils/store'
|
data/lib/config/mysql.tmpl
CHANGED
@@ -9,21 +9,21 @@ default_env: &default
|
|
9
9
|
host: localhost
|
10
10
|
username: root
|
11
11
|
password:
|
12
|
-
database: <%=
|
12
|
+
database: <%= @data[:dbname] %>
|
13
13
|
pool: 5
|
14
14
|
timeout: 5000
|
15
15
|
|
16
16
|
development:
|
17
17
|
<<: *default
|
18
|
-
database: <%=
|
18
|
+
database: <%= @data[:dbname] %>_developement
|
19
19
|
|
20
20
|
# Warning: The database defined as "test" will be erased and
|
21
21
|
# re-generated from your development database when you run "rake".
|
22
22
|
# Do not set this db to the same as development or production.
|
23
23
|
test:
|
24
24
|
<<: *default
|
25
|
-
database: <%=
|
25
|
+
database: <%= @data[:dbname] %>_test
|
26
26
|
|
27
27
|
production:
|
28
28
|
<<: *default
|
29
|
-
database: <%=
|
29
|
+
database: <%= @data[:dbname] %>_production
|
data/lib/config/sqlite3.tmpl
CHANGED
@@ -8,19 +8,19 @@ default_env: &default
|
|
8
8
|
adapter: sqlite3
|
9
9
|
pool: 5
|
10
10
|
timeout: 5000
|
11
|
-
database:
|
11
|
+
database: <%= @data[:db_dir] %>/sqlite3.db
|
12
12
|
|
13
13
|
development:
|
14
14
|
<<: *default
|
15
|
-
database:
|
15
|
+
database: <%= @data[:db_dir] %>/development.sqlite3
|
16
16
|
|
17
17
|
# Warning: The database defined as "test" will be erased and
|
18
18
|
# re-generated from your development database when you run "rake".
|
19
19
|
# Do not set this db to the same as development or production.
|
20
20
|
test:
|
21
21
|
<<: *default
|
22
|
-
database:
|
22
|
+
database: <%= @data[:db_dir] %>/test.sqlite3
|
23
23
|
|
24
24
|
production:
|
25
25
|
<<: *default
|
26
|
-
database:
|
26
|
+
database: <%= @data[:db_dir] %>/production.sqlite3
|
data/lib/template/base.tmpl
CHANGED
@@ -3,8 +3,8 @@ class Create<%= @data[:classname] %> < ActiveRecord::Migration
|
|
3
3
|
create_table :<%= @data[:plural] %> do |t|
|
4
4
|
<% @data[:ary].each do |x| %>
|
5
5
|
t.column :<%= x.name %>, :<%= x.type %>, :null => <%= x.null %>
|
6
|
-
<% end %>
|
7
|
-
t.
|
6
|
+
<% end %>
|
7
|
+
t.timestamps null: false
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
data/lib/template/current.tmpl
CHANGED
@@ -2,10 +2,8 @@ class CreateCurrent<%= @data[:classname_downcase] %> < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
3
3
|
execute <<-SQL
|
4
4
|
CREATE VIEW current<%= @data[:plural] %> AS SELECT id as org_id,
|
5
|
-
|
6
|
-
<%=
|
7
|
-
<% end %>
|
8
|
-
start_datetime FROM <%= @data[:plural] %> where not exists (select * from invalid<%= @data[:plural] %> where invalid<%= @data[:plural] %>.org_id = <%= @data[:plural] %>.id )
|
5
|
+
<%= @data[:ary].map{|x| x.name }.join(" , ") %>
|
6
|
+
FROM <%= @data[:plural] %> where not exists (select * from invalid<%= @data[:plural] %> where invalid<%= @data[:plural] %>.org_id = <%= @data[:plural] %>.id )
|
9
7
|
SQL
|
10
8
|
end
|
11
9
|
|
data/lib/template/invalid.tmpl
CHANGED
@@ -2,7 +2,7 @@ class CreateInvalid<%= @data[:classname_downcase] %> < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
3
3
|
create_table :invalid<%= @data[:plural] %> do |t|
|
4
4
|
t.column :org_id, :int, :null => false
|
5
|
-
t.column :
|
5
|
+
t.column :count_id, :int, :null => true
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arxutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.35
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yasuo kominami
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: activerecord
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,10 +131,13 @@ files:
|
|
117
131
|
- lib/arxutils/arxutils.rb
|
118
132
|
- lib/arxutils/dbutil/dbinit.rb
|
119
133
|
- lib/arxutils/dbutil/dbmgr.rb
|
134
|
+
- lib/arxutils/hier.rb
|
120
135
|
- lib/arxutils/migrate.rb
|
136
|
+
- lib/arxutils/misc.rb
|
121
137
|
- lib/arxutils/store.rb
|
122
138
|
- lib/arxutils/store/storecsv.rb
|
123
139
|
- lib/arxutils/store/storedb.rb
|
140
|
+
- lib/arxutils/transactstate.rb
|
124
141
|
- lib/arxutils/version.rb
|
125
142
|
- lib/config/mysql.tmpl
|
126
143
|
- lib/config/sqlite3.tmpl
|
@@ -128,6 +145,10 @@ files:
|
|
128
145
|
- lib/template/current.tmpl
|
129
146
|
- lib/template/invalid.tmpl
|
130
147
|
- lib/template/noitem.tmpl
|
148
|
+
- lib/template/relation.tmpl
|
149
|
+
- lib/template/relation_count.tmpl
|
150
|
+
- lib/template/relation_current.tmpl
|
151
|
+
- lib/template/relation_invalid.tmpl
|
131
152
|
homepage: ''
|
132
153
|
licenses: []
|
133
154
|
metadata: {}
|
@@ -147,9 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
168
|
version: '0'
|
148
169
|
requirements: []
|
149
170
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.4
|
171
|
+
rubygems_version: 2.6.4
|
151
172
|
signing_key:
|
152
173
|
specification_version: 4
|
153
174
|
summary: utility functions for ActiveRecord.
|
154
175
|
test_files: []
|
155
|
-
has_rdoc:
|