Clear changesets and changes with raw sql when deleting a repository (#1627).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1666 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
0eba42423a
commit
fc07ba2a99
|
@ -17,9 +17,13 @@
|
||||||
|
|
||||||
class Repository < ActiveRecord::Base
|
class Repository < ActiveRecord::Base
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
has_many :changesets, :dependent => :destroy, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
|
has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
|
||||||
has_many :changes, :through => :changesets
|
has_many :changes, :through => :changesets
|
||||||
|
|
||||||
|
# Raw SQL to delete changesets and changes in the database
|
||||||
|
# has_many :changesets, :dependent => :destroy is too slow for big repositories
|
||||||
|
before_destroy :clear_changesets
|
||||||
|
|
||||||
# Checks if the SCM is enabled when creating a repository
|
# Checks if the SCM is enabled when creating a repository
|
||||||
validate_on_create { |r| r.errors.add(:type, :activerecord_error_invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) }
|
validate_on_create { |r| r.errors.add(:type, :activerecord_error_invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) }
|
||||||
|
|
||||||
|
@ -127,4 +131,9 @@ class Repository < ActiveRecord::Base
|
||||||
root_url.strip!
|
root_url.strip!
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def clear_changesets
|
||||||
|
connection.delete("DELETE FROM changes WHERE changes.changeset_id IN (SELECT changesets.id FROM changesets WHERE changesets.repository_id = #{id})")
|
||||||
|
connection.delete("DELETE FROM changesets WHERE changesets.repository_id = #{id}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,6 +45,16 @@ class RepositoryTest < Test::Unit::TestCase
|
||||||
assert_equal repository, project.repository
|
assert_equal repository, project.repository
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_destroy
|
||||||
|
changesets = Changeset.count(:all, :conditions => "repository_id = 10")
|
||||||
|
changes = Change.count(:all, :conditions => "repository_id = 10", :include => :changeset)
|
||||||
|
assert_difference 'Changeset.count', -changesets do
|
||||||
|
assert_difference 'Change.count', -changes do
|
||||||
|
Repository.find(10).destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_should_not_create_with_disabled_scm
|
def test_should_not_create_with_disabled_scm
|
||||||
# disable Subversion
|
# disable Subversion
|
||||||
Setting.enabled_scm = ['Darcs', 'Git']
|
Setting.enabled_scm = ['Darcs', 'Git']
|
||||||
|
|
Loading…
Reference in New Issue