lib/knj/knjdb/revision.rb in knjrbfw-0.0.23 vs lib/knj/knjdb/revision.rb in knjrbfw-0.0.24

- old
+ new

@@ -3,10 +3,11 @@ @args = args end #This method checks if certain rows are present in a table based on a hash. def rows_init(args) + db = args["db"] table = args["table"] args["rows"].each do |row_data| if row_data["find_by"] find_by = row_data["find_by"] @@ -35,11 +36,10 @@ #This initializes a database-structure and content based on a schema-hash. def init_db(args) schema = args["schema"] db = args["db"] - @db = db #Check for normal bugs and raise apropiate error. raise "'schema' argument was not a Hash: '#{schema.class.name}'." 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") @@ -48,10 +48,11 @@ tables = db.tables.list schema["tables"].each do |table_name, table_data| begin begin + raise Knj::Errors::NotFound if !tables.key?(table_name) table_obj = db.tables[table_name] #Cache indexes- and column-objects to avoid constant reloading. cols = table_obj.columns indexes = table_obj.indexes @@ -222,15 +223,16 @@ index_obj.drop end end - self.rows_init("table" => table_obj, "rows" => table_data["rows"]) if table_data and table_data["rows"] + self.rows_init("db" => db, "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 + raise Knj::Errors::NotFound if !tables.key?(table_name) table_rename = db.tables[table_name_rename] table_rename.rename(table_name) raise Knj::Errors::Retry rescue Knj::Errors::NotFound next @@ -270,7 +272,12 @@ rescue Knj::Errors::NotFound => e next end end end + + + #Free cache. + tables.clear + tables = nil end end \ No newline at end of file