Permalink
Browse files

Do not create redundant unique indexes for key properties

  • Loading branch information...
1 parent 96b22b4 commit 57e1c2875c67a81dd945e15b5cbe0784203e876c @dkubb dkubb committed May 25, 2010
Showing with 7 additions and 3 deletions.
  1. +7 −3 lib/dm-migrations/adapters/dm-do-adapter.rb
@@ -154,6 +154,7 @@ def drop_table_statement(model)
def create_index_statements(model)
name = self.name
table_name = model.storage_name(name)
+
indexes(model).map do |index_name, fields|
<<-SQL.compress_lines
CREATE INDEX #{quote_name("index_#{table_name}_#{index_name}")} ON
@@ -164,9 +165,12 @@ def create_index_statements(model)
# @api private
def create_unique_index_statements(model)
- name = self.name
- table_name = model.storage_name(name)
- unique_indexes(model).map do |index_name, fields|
+ name = self.name
+ table_name = model.storage_name(name)
+ key = model.key(name).map { |property| property.field }
+ unique_indexes = unique_indexes(model).reject { |index_name, fields| fields == key }
+
+ unique_indexes.map do |index_name, fields|
<<-SQL.compress_lines
CREATE UNIQUE INDEX #{quote_name("unique_#{table_name}_#{index_name}")} ON
#{quote_name(table_name)} (#{fields.map { |field| quote_name(field) }.join(', ')})

0 comments on commit 57e1c28

Please sign in to comment.