Browse files

Namespace indexes when copying databases in some cases

If copying from a database without a global index namespace (e.g.
MySQL) to a database with a global index namespace (e.g. PostgreSQL),
the previous copying could break if you had indexes with the same
name in both tables.  To work around this, prepend the table name
to the index name when copying.

Note that if the index name exactly matches Sequel's default name,
it will not do any additional namespacing.
  • Loading branch information...
1 parent 452cb31 commit 7f2f6e0daa3285ee3b649808c052bef0ca5f01dc @jeremyevans committed May 31, 2012
Showing with 3 additions and 1 deletion.
  1. +3 −1 bin/sequel
View
4 bin/sequel
@@ -162,10 +162,12 @@ begin
start_time = Time.now
TO_DB = connect_proc[db2]
same_db = DB.database_type==TO_DB.database_type
+ index_opts = {:same_db=>same_db}
+ index_opts[:index_names] = :namespace if !DB.global_index_namespace? && TO_DB.global_index_namespace?
puts "Databases connections successful"
schema_migration = eval(DB.dump_schema_migration(:indexes=>false, :same_db=>same_db))
- index_migration = eval(DB.dump_indexes_migration(:same_db=>same_db))
+ index_migration = eval(DB.dump_indexes_migration(index_opts))
fk_migration = eval(DB.dump_foreign_key_migration(:same_db=>same_db))
puts "Migrations dumped successfully"

0 comments on commit 7f2f6e0

Please sign in to comment.