postgresql_adapter schema patch

Hi all

I recently started using postgres more and using schemas in postgres to keep the number of databases under control.

When using schemas in a database and using rails, if two tables have the same name, the output of rake db:schema:dump is incorrect

Recreating a failing environment, have a database railstest with public, dev and test schemas:

$>rails test $>cd test $>vi database.yml development:   adapter: postgresql   database: railstest   schema_search_path: dev   encoding: utf8   username: railstest   password: test   host: localhost

# Warning: The database defined as 'test' will be erased and # re-generated from your development database when you run 'rake'. # Do not set this db to the same as development or production. test:   adapter: postgresql   database: railstest   schema_search_path: test   encoding: utf8   username: railstest   password: test   host: localhost production:   adapter: postgresql   database: railstest   encoding: utf8   username: railstest   password: test   host: localhost $>rake db:sessions:create $>rake db:migrate $>rake db:schema:dump

The schema generated a this point is incorrect (look at the add_index lines): # This file is autogenerated. Instead of editing this file, please use the # migrations feature of ActiveRecord to incrementally modify your database, and # then regenerate this schema definition.

ActiveRecord::Schema.define(:version => 1) do

  create_table "sessions", :force => true do |t|     t.column "session_id", :string     t.column "data", :text     t.column "updated_at", :datetime   end

  add_index "sessions", ["session_id", "session_id"], :name => "index_sessions_on_session_id"   add_index "sessions", ["updated_at", "updated_at"], :name => "index_sessions_on_updated_at"

end

I tracked this down to postgresqk_adapter.rb in the index method, it does not differenciate between schemas.

I have a small patch that corrects the problem for me, once the patch is applied, my schema.rb looks like : # This file is autogenerated. Instead of editing this file, please use the # migrations feature of ActiveRecord to incrementally modify your database, and # then regenerate this schema definition.

ActiveRecord::Schema.define(:version => 1) do

  create_table "sessions", :force => true do |t|     t.column "session_id", :string     t.column "data", :text     t.column "updated_at", :datetime   end

  add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"   add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"

end

However I have no idea how to write a failing test for this ... :confused: The patch is attached (both fulltext and tar.gzipped in case) to this email. I hope someone with more experience will pick it up and get it in.

It applies cleanly against both activerecord-1.15.3/lib/active_record/connection_adapters/postgresql_adapter.rb and http://svn.rubyonrails.org/rails/trunk/activerecord/lib/active_record/connection_adapter/postgresql_adapter.rb rev 6891 (which is the last modified rev for this file as I am writing this email)

jean

postgresql_adapter.patch (1.11 KB)

postgresql_adapter.patch.tar.gz (584 Bytes)

Great troubleshooting. Please create a ticket and attach your patch at http://dev.rubyonrails.org. See test/schema_test_postgresql.rb for an example of testing with multiple schemas.

jeremy

Here it comes : http://dev.rubyonrails.org/ticket/8659 Complete with its test case which fails before and passes after the patch

jean