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 ... :/
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-core-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---