<< | Index | >>
Goal/Estimate/Evaluation:
Note
suspend
Experiment
migel> Migel::Model::Product.find_by_pharmacode('2126923').article_name -> CONTAM Vaginaltampon 26mm regular migel> Migel::Model::Product.find_by_pharmacode('2126923').delete -> CONTAM Vaginaltampon 26mm regular migel> Migel::Model::Product.find_by_pharmacode('2126923').article_name -> undefined method `article_name' for nil:NilClass migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').delete -> Stück migel> Migel::Model::Product.find_by_pharmacode('2126975').article_name -> CONTAM Vaginaltampon 33mm extra 5 Stk migel> Migel::Model::Product.find_by_pharmacode('2126975').migelid.class -> NilClass
Note
Problem
Experiment
def delete products.each do |product| product.delete end super end
Restore
masa@masa ~/ywesee/migel_dev $ sudo -u postgres dropdb migel; sudo -u postgres createdb -E UTF8 -T template0 migel masa@masa ~/ywesee/migel_dev $ cat migel_database_with_fullindex_tables_backup.20110913.sql |psql -U postgres migel
Note
Run
migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').delete
Result
migel> Migel::Model::Product.find_by_pharmacode('2998899') -> CONTRELLE Starterpack G1 G2 G3 ass 3 Stk migel> Migel::Model::Product.find_by_pharmacode('2998899').migelid.class -> NilClass migel> Migel::Model::Product.find_by_pharmacode('2126981') -> CONTAM Vaginaltampon Probierset ass 3 Stk migel> Migel::Model::Product.find_by_pharmacode('2126981').migelid.class -> NilClass
Experiment
def delete products.each do |product| p product.odba_id p product.pharmacode product.delete end p products.length #super end
Run
migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').delete
Log
9919 "2126917" 9921 "2126975" 9923 "2760086" 9925 "2760100" 4
migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').products.map{|pr| pr.pharmacode.to_s}.join(",") -> 2126923,2126981,2760092,2998899
Note
Experiment
migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').products.map{|pr| pr.pharmacode.to_s}.join(",") -> 2126917,2126923,2126975,2126981,2760086,2760092,2760100,2998899
Note
Experiment
def delete while product = products.shift p product.odba_id p product.pharmacode product.delete end p products.length #super end
Run
migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').products.map{|pr| pr.pharmacode.to_s}.join(",") -> 2126917,2126923,2126975,2126981,2760086,2760092,2760100,2998899 migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').delete -> migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').products.map{|pr| pr.pharmacode.to_s}.join(",") -> migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').products.length -> 0
Log
9919 "2126917" 9920 "2126923" 9921 "2126975" 9922 "2126981" 9923 "2760086" 9924 "2760092" 9925 "2760100" 9926 "2998899" 0
Note
IMPORTANT
Experiment
def delete while predicate = self.class.predicates.shift predicate.execute(:delete, self) end self end
Run
migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').products.map{|pr| pr.pharmacode.to_s}.join(",") -> 2126917,2126923,2126975,2126981,2760086,2760092,2760100,2998899 migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').delete
Result
Experiment
def cascade(action, next_level) if(next_level.is_a?(Array)) if action == :delete while element = next_level.shift cascade(action, element) end else next_level.each { |element| cascade(action, element) } end else next_level.send(action) if(next_level.respond_to?(action)) end end
Run
migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').products.map{|pr| pr.pharmacode.to_s}.join(",") -> 2126917,2126923,2126975,2126981,2760086,2760092,2760100,2998899 migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').delete -> Stück migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').products.map{|pr| pr.pharmacode.to_s}.join(",") -> undefined method `products' for nil:NilClass migel>
Result
Note
Algorithm (Design)
Experiment
def update(path, language) # update Group, Subgroup, Migelid data from a csv file CSV.readlines(path)[1..-1].each do |row| id = row.at(13).to_s.split('.') if(id.empty?) id = row.at(4).to_s.split('.') else id[-1].replace(id[-1][0,1]) end unless id.empty? group = update_group(id, row, language) subgroup = update_subgroup(id, group, row, language) migel_code_list.delete(group.migel_code) migel_code_list.delete(subgroup.migel_code) if(id.size > 2) migelid = update_migelid(id, subgroup, row, language) migel_code_list.delete(migelid.migel_code) end end end # delete not updated list migel_code_list.each do |migel_code| case migel_code.length when 2 Migel::Model::Group.find_by_migel_code(migel_code).delete when 5 Migel::Model::Subgroup.find_by_migel_code(migel_code).delete else Migel::Model::Migelid.find_by_migel_code(migel_code).delete end end end
def code_list(index_table_name, output_filename = nil) list = ODBA.cache.index_keys(index_table_name) if output_filename File.open(output_filename, 'w') do |out| out.print list.join("\n"), "\n" end end list end def migel_code_list(output_filename = nil) @migel_code_list ||= begin index_table_name = 'migel_model_migelid_migel_code' code_list(index_table_name, output_filename) end end
def import_all_products_from_csv(file_name = 'migel_products_de.csv', lang = 'de', estimate = false) .. update_product(migelid, record, lang)pharmacode_list.delete(line[1])
end puts "updating: " + estimate_time(start_time, total, count) if estimate end .. # delete processpharmacode_list.each do |pharmacode|
Migel::Model::Product.find_by_pharmacode(pharmacode).delete
end
Restore
masa@masa ~/ywesee/migel_dev $ sudo -u postgres dropdb migel; sudo -u postgres createdb -E UTF8 -T template0 migel masa@masa ~/ywesee/migel_dev $ bin/migeld
Run
migel> Migel::Util::Importer.new.update('data/csv/migel_de.csv','de') -> migel> Migel::Util::Importer.new.update('data/csv/migel_fr.csv','fr') -> migel> init_fulltext_index_tables -> migel> Migel::Util::Importer.new.update('test.csv','de') -> 15.30.50.00.1
Result
migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').class -> NilClass
Note
Restore
masa@masa ~/ywesee/migel_dev $ sudo -u postgres dropdb migel; sudo -u postgres createdb -E UTF8 -T template0 migel masa@masa ~/ywesee/migel_dev $ cat migel_database_backup.20110913.sql |psql -U postgres migel masa@masa ~/ywesee/migel_dev $ bin/migeld
Run
migel> Migel::Util::Importer.new.import_all_products_from_csv('test.csv', 'de', true)
Result
migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').class -> Migel::Model::Migelid migel> Migel::Model::Migelid.find_by_migel_code('15.30.50.00.1').name.de -> Wegwerf-Scheidenpessar
Note