[Ovirt-devel] [PATCH 3/3] enhance migrations in order to use the new system. It should be backward compatible with existing database, since it uses the same fk name & index.

Mohammed Morsi mmorsi at redhat.com
Wed Oct 14 19:19:04 UTC 2009


Michel Loiseleur wrote:
> diff --git a/src/db/migrate/027_fix_uniqueness_constraints_in_bondings_nics.rb b/src/db/migrate/027_fix_uniqueness_constraints_in_bondings_nics.rb
> index 5f58c5c..e2c638c 100644
> --- a/src/db/migrate/027_fix_uniqueness_constraints_in_bondings_nics.rb
> +++ b/src/db/migrate/027_fix_uniqueness_constraints_in_bondings_nics.rb
> @@ -1,8 +1,18 @@
>  
>  class FixUniquenessConstraintsInBondingsNics < ActiveRecord::Migration
>    def self.up
> +    # Mysql 5.* forces foreign key to have an index, for performance reason.
> +    # One cannot remove an index before drop foreign key on it.
> +    remove_foreign_key :bondings_nics, :name => 'fk_bondings_nics_bonding'
> +    remove_foreign_key :bondings_nics, :name => 'fk_bondings_nics_nic'
> +
>      remove_index :bondings_nics, [:bonding_id, :nic_id]
>      add_index :bondings_nics, :nic_id, :unique => true
> +
> +    # it can be re-added afterwards, without any problem
> +    add_foreign_key :bondings_nics, :bondings,
> +                    :name => 'fk_bondings_nics_bonding'
> +    add_foreign_key :bondings_nics, :nics, :name => 'fk_bondings_nics_nic'
>    end
>  
>    def self.down
> @@ -10,4 +20,3 @@ class FixUniquenessConstraintsInBondingsNics < ActiveRecord::Migration
>      add_index :bondings_nics, [:bonding_id, :nic_id], :unique => true
>    end
>  end
> -
>   
I ran into an issue with this migration, #27, when running "rake
db:migrate" against a new "ovirt_development" postgres database, created
via the instructions in config/database.yml

The error I got was:

   1.
      ==  FixUniquenessConstraintsInBondingsNics: migrating
      =========================
   2.
      -- remove_foreign_key(:bondings_nics,
      {:name=>"fk_bondings_nics_bonding"})
   3.
      rake aborted!
   4.
      An error has occurred, this and all later migrations canceled:
   5.
       
   6.
      PGError: ERROR:  syntax error at or near "FOREIGN"
   7.
      LINE 1: ALTER TABLE "bondings_nics" DROP FOREIGN KEY
      "fk_bondings_ni...
   8.
                                               ^
   9.
      : ALTER TABLE "bondings_nics" DROP FOREIGN KEY
      "fk_bondings_nics_bonding"




Rake stops at this point, so I'm not sure if any other migrations are
broken. Does this work when trying it against postgres locally?

  -Mo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/ovirt-devel/attachments/20091014/72f0ca27/attachment.htm>


More information about the ovirt-devel mailing list