diff options
Diffstat (limited to 'lib/puppet/rails')
-rw-r--r-- | lib/puppet/rails/database/002_remove_duplicated_index_on_all_tables.rb | 17 | ||||
-rw-r--r-- | lib/puppet/rails/database/schema.rb | 8 |
2 files changed, 17 insertions, 8 deletions
diff --git a/lib/puppet/rails/database/002_remove_duplicated_index_on_all_tables.rb b/lib/puppet/rails/database/002_remove_duplicated_index_on_all_tables.rb new file mode 100644 index 000000000..3873a13e2 --- /dev/null +++ b/lib/puppet/rails/database/002_remove_duplicated_index_on_all_tables.rb @@ -0,0 +1,17 @@ +class RemoveDuplicatedIndexOnAllTables < ActiveRecord::Migration + def self.up + ActiveRecord::Base.connection.tables.each do |t| + if ActiveRecord::Base.connection.indexes(t).collect {|c| c.columns}.include?("id") + remove_index t.to_s, :id + end + end + end + + def self.down + ActiveRecord::Base.connection.tables.each do |t| + unless ActiveRecord::Base.connection.indexes(t).collect {|c| c.columns}.include?("id") + add_index t.to_s, :id, :integer => true + end + end + end +end diff --git a/lib/puppet/rails/database/schema.rb b/lib/puppet/rails/database/schema.rb index d11d91aa5..f3ad2c11e 100644 --- a/lib/puppet/rails/database/schema.rb +++ b/lib/puppet/rails/database/schema.rb @@ -16,7 +16,6 @@ class Puppet::Rails::Schema t.column :updated_at, :datetime t.column :created_at, :datetime end - add_index :resources, :id, :integer => true add_index :resources, :host_id, :integer => true add_index :resources, :source_file_id, :integer => true @@ -34,7 +33,6 @@ class Puppet::Rails::Schema t.column :updated_at, :datetime t.column :created_at, :datetime end - add_index :source_files, :id, :integer => true add_index :source_files, :filename create_table :resource_tags do |t| @@ -43,7 +41,6 @@ class Puppet::Rails::Schema t.column :updated_at, :datetime t.column :created_at, :datetime end - add_index :resource_tags, :id, :integer => true add_index :resource_tags, :resource_id, :integer => true add_index :resource_tags, :puppet_tag_id, :integer => true @@ -65,7 +62,6 @@ class Puppet::Rails::Schema t.column :source_file_id, :integer t.column :created_at, :datetime end - add_index :hosts, :id, :integer => true add_index :hosts, :source_file_id, :integer => true add_index :hosts, :name @@ -74,7 +70,6 @@ class Puppet::Rails::Schema t.column :updated_at, :datetime t.column :created_at, :datetime end - add_index :fact_names, :id, :integer => true add_index :fact_names, :name create_table :fact_values do |t| @@ -84,7 +79,6 @@ class Puppet::Rails::Schema t.column :updated_at, :datetime t.column :created_at, :datetime end - add_index :fact_values, :id, :integer => true add_index :fact_values, :fact_name_id, :integer => true add_index :fact_values, :host_id, :integer => true @@ -96,7 +90,6 @@ class Puppet::Rails::Schema t.column :updated_at, :datetime t.column :created_at, :datetime end - add_index :param_values, :id, :integer => true add_index :param_values, :param_name_id, :integer => true add_index :param_values, :resource_id, :integer => true @@ -105,7 +98,6 @@ class Puppet::Rails::Schema t.column :updated_at, :datetime t.column :created_at, :datetime end - add_index :param_names, :id, :integer => true add_index :param_names, :name end end |