diff --git a/db/migrate/20230927153926_add_last_indexed_commit_to_sites.rb b/db/migrate/20230927153926_add_last_indexed_commit_to_sites.rb index 2d22cbd7..71e08f37 100644 --- a/db/migrate/20230927153926_add_last_indexed_commit_to_sites.rb +++ b/db/migrate/20230927153926_add_last_indexed_commit_to_sites.rb @@ -2,7 +2,17 @@ # Almacenar el último commit indexado class AddLastIndexedCommitToSites < ActiveRecord::Migration[6.1] - def change + def up add_column :sites, :last_indexed_commit, :string, null: true + + Site.find_each do |site| + site.update_columns(last_indexed_commit: site.repository.head_commit.oid) + rescue Rugged::Error, Rugged::OSError => e + puts "Falló #{site.name}, ignorando: #{e.message}" + end + end + + def down + remove_column :sites, :last_indexed_commit end end