Remove dangling changesets

As the removed const requires us to delete filesystem repositories
directly in SQL, we need to manually remove associated changesets
that would otherwise remain broken in the database and may cause errors
when trying to access them (e.g., throught the revisions API endpoint).

This commit destroys all changesets of a filesystem repository before
destroying the repository itself.
pull/3288/head
Oliver Günther 9 years ago
parent aa0aa53808
commit 75521f7465
  1. 31
      db/migrate/20150716163704_remove_filesystem_repositories.rb

@ -30,12 +30,31 @@
# Removes all remaining Repository::Filesystem entries.
#
class RemoveFilesystemRepositories < ActiveRecord::Migration
include Migration::Utils
def up
# Circumvent Repository.where(...) since this tries to load
# the Repository::Filesystem constant and fails.
ActiveRecord::Base.connection.execute <<-SQL
DELETE FROM repositories
WHERE type = #{quote_value("Repository::Filesystem")}
SQL
ActiveRecord::Base.transaction do
# Delete any changesets belonging to filesystem repositories
ActiveRecord::Base.connection.execute <<-SQL
DELETE FROM changesets
WHERE repository_id IN (
SELECT id
FROM repositories
WHERE type = #{filesystem_type}
)
SQL
# Circumvent Repository.where(...) since this tries to load
# the Repository::Filesystem constant and fails.
ActiveRecord::Base.connection.execute <<-SQL
DELETE FROM repositories
WHERE type = #{filesystem_type}
SQL
end
end
def filesystem_type
quote_value('Repository::Filesystem')
end
end

Loading…
Cancel
Save