lib/knj/knjdb/revision.rb in knjrbfw-0.0.9 vs lib/knj/knjdb/revision.rb in knjrbfw-0.0.10
- old
+ new
@@ -42,15 +42,22 @@
#Check for normal bugs and raise apropiate error.
raise "'schema' argument was not a Hash." if !schema.is_a?(Hash)
raise "':return_keys' is not 'symbols' - Knjdbrevision will not work without it." if db.opts[:return_keys] != "symbols"
raise "No tables given." if !schema.has_key?("tables")
+ #Cache tables to avoid constant reloading.
+ tables = db.tables.list
+
schema["tables"].each do |table_name, table_data|
begin
begin
- table_obj = db.tables[table_name.to_sym]
+ table_obj = db.tables[table_name]
+ #Cache indexes- and column-objects to avoid constant reloading.
+ cols = table_obj.columns
+ indexes = table_obj.indexes
+
if table_data["columns"]
first_col = true
table_data["columns"].each do |col_data|
begin
col_obj = table_obj.column(col_data["name"])
@@ -213,10 +220,10 @@
index_obj.drop
end
end
- self.rows_init("table" => table_obj, "rows" => table_data["rows"]) if table_data["rows"]
+ self.rows_init("table" => table_obj, "rows" => table_data["rows"]) if table_data and table_data["rows"]
rescue Knj::Errors::NotFound => e
if table_data["renames"]
table_data["renames"].each do |table_name_rename|
begin
table_rename = db.tables[table_name_rename]
\ No newline at end of file