summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEtienne Massip <etienne.massip@gmail.com>2011-12-03 12:12:53 +0000
committerEtienne Massip <etienne.massip@gmail.com>2011-12-03 12:12:53 +0000
commit39ae7b66f86aacb5bca381abaeeb9aa6b43bfb7d (patch)
tree462a4c4862ead5463891a918d69a56a606dde18d
parent7e62d02abbbac03c0ba95fb7475ab98e3c78f0dd (diff)
downloadredmine-39ae7b66f86aacb5bca381abaeeb9aa6b43bfb7d.tar.gz
redmine-39ae7b66f86aacb5bca381abaeeb9aa6b43bfb7d.zip
Enforced unicity of relations between 2 issues with a database index (#9685).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8041 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--db/migrate/20111201201315_add_unique_index_to_issue_relations.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/db/migrate/20111201201315_add_unique_index_to_issue_relations.rb b/db/migrate/20111201201315_add_unique_index_to_issue_relations.rb
new file mode 100644
index 000000000..2ee9adb03
--- /dev/null
+++ b/db/migrate/20111201201315_add_unique_index_to_issue_relations.rb
@@ -0,0 +1,16 @@
+class AddUniqueIndexToIssueRelations < ActiveRecord::Migration
+ def self.up
+
+ # Remove duplicates
+ IssueRelation.connection.select_values("SELECT r.id FROM #{IssueRelation.table_name} r" +
+ " WHERE r.id > (SELECT min(r1.id) FROM #{IssueRelation.table_name} r1 WHERE r1.issue_from_id = r.issue_from_id AND r1.issue_to_id = r.issue_to_id)").each do |i|
+ IssueRelation.delete_all(["id = ?", i])
+ end
+
+ add_index :issue_relations, [:issue_from_id, :issue_to_id], :unique => true
+ end
+
+ def self.down
+ remove_index :issue_relations, :column => [:issue_from_id, :issue_to_id]
+ end
+end