irm_yaml_db 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -1
- data/VERSION +1 -1
- data/irm_yaml_db.gemspec +1 -1
- data/lib/serialization_helper.rb +4 -1
- data/lib/yaml_db.rb +13 -1
- metadata +1 -1
data/README.markdown
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/irm_yaml_db.gemspec
CHANGED
data/lib/serialization_helper.rb
CHANGED
@@ -52,6 +52,9 @@ module SerializationHelper
|
|
52
52
|
end
|
53
53
|
|
54
54
|
class Load
|
55
|
+
GREEN = "\e[32m"
|
56
|
+
CLEAR = "\e[0m"
|
57
|
+
|
55
58
|
def self.load(io, truncate = true)
|
56
59
|
ActiveRecord::Base.connection.transaction do
|
57
60
|
load_documents(io, truncate)
|
@@ -82,7 +85,7 @@ module SerializationHelper
|
|
82
85
|
columns = column_names.map{|cn| ActiveRecord::Base.connection.columns(table).detect{|c| c.name == cn}}
|
83
86
|
quoted_column_names = column_names.map { |column| ActiveRecord::Base.connection.quote_column_name(column) }.join(',')
|
84
87
|
quoted_table_name = SerializationHelper::Utils.quote_table(table)
|
85
|
-
puts "Synch #{table}'s data
|
88
|
+
puts "#{GREEN}Synch #{table}'s data......#{CLEAR}"
|
86
89
|
records.each do |record|
|
87
90
|
quoted_values = record.zip(columns).map{|c| ActiveRecord::Base.connection.quote(c.first, c.last)}.join(',')
|
88
91
|
|
data/lib/yaml_db.rb
CHANGED
@@ -59,14 +59,26 @@ module YamlDb
|
|
59
59
|
class Load < SerializationHelper::Load
|
60
60
|
def self.load_documents(io, truncate = true)
|
61
61
|
YAML.load_documents(io) do |ydoc|
|
62
|
+
not_exists_tables = []
|
62
63
|
ydoc.keys.each do |table_name|
|
63
64
|
next if ydoc[table_name].nil?
|
64
65
|
if ActiveRecord::Base.connection.table_exists?(table_name)
|
65
66
|
load_table(table_name, ydoc[table_name], truncate)
|
66
67
|
else
|
67
|
-
|
68
|
+
not_exists_tables << table_name
|
68
69
|
end
|
69
70
|
end
|
71
|
+
if not_exists_tables.any?
|
72
|
+
red_color = "\e[31m"
|
73
|
+
default_color = "\e[0m"
|
74
|
+
#CLEAR = "\e[0m"
|
75
|
+
#BOLD = "\e[1m"
|
76
|
+
#RED = "\e[31m"
|
77
|
+
#GREEN = "\e[32m"
|
78
|
+
#YELLOW = "\e[33m"
|
79
|
+
#BLUE = "\e[34m"
|
80
|
+
puts "#{red_color}Synch data field because tables: #{not_exists_tables.join(",")} are not exists #{default_color}"
|
81
|
+
end
|
70
82
|
end
|
71
83
|
end
|
72
84
|
end
|