Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix table_exists? in postgresql adapter to always use current search_path #1607

Merged
merged 1 commit into from Jul 12, 2011

Conversation

bradrobertson
Copy link
Contributor

modified table_exists? in the postgresql adapter to always use the current search_path unless a explicit schema is specified.

Currently one cannot load schema.rb into a new (empty) postgresql schema. create_table forces a table drop which checks table_exists? first. This returns true even though the table doesn't actually exist in the current schema. Thus a PG error is thrown when it tries to drop the nonexistent table.

@tardate
Copy link
Contributor

tardate commented Jun 10, 2011

fyi, I was working on something similar based off master, see: #1632
+1 yes I'd like to see this fixed too, as it also enables migration into independent schemas and compatibility with schema-partitioning approaches for multi-tenancy

@bradrobertson
Copy link
Contributor Author

ah good one! Ya I planned on adding a patch for master also, just haven't gotten around to it as we don't use 3.1 in production ATM.

jake3030 pushed a commit to jake3030/rails that referenced this pull request Jun 28, 2011
@bradrobertson
Copy link
Contributor Author

Can someone give me some feedback on this pull request? It's been sitting here for a month without any comments (save 1) I'm interested to know how I can improve it

@mitchlloyd
Copy link

Yes! If this were in Rails it would have saved me many hours. I had monkey patched table_exists? so that I could use Postgresql schemas and I was running into problems when I used set_table_name on a model with a schema (i.e. set_table_name 'meta.accounts'). I applied your patch and it fixed my issues with table_exists?

Would love to see this added into Rails as I have an app that makes heavy use of Postgresql schemas, a feature which is mostly unusable with an unhacked Rails install.

@bradrobertson
Copy link
Contributor Author

fyi this is what we're using in production if you need to use this patch:

gem 'rails', '3.0.8', :git => 'git://github.com/bradrobertson/rails', :branch => '3-0-stable'

@tardate
Copy link
Contributor

tardate commented Jul 8, 2011

Brad, +1 (again;-)
Note that I just realised my similar patch on 3.1 has been merged to master (covering view and schema-related improvements for the PostgreSQL adapter), suggest you see if there's anything you can scavenge from this to converge/align what's to go on 3.0 #1632

@bradrobertson
Copy link
Contributor Author

cool, thx @tardate, will take a look.
If anyone on the Rails core team can comment as to what extra work from @tardate's might make this pull request more enticing I'm all ears. I was pretty happy with the simplicity of my patch, but am definitely happy to provide more functionality if that's what people are looking for.

@spastorino
Copy link
Contributor

/cc @tenderlove

tenderlove added a commit that referenced this pull request Jul 12, 2011
fix table_exists? in postgresql adapter to always use current search_path
@tenderlove tenderlove merged commit 9a4d2b2 into rails:3-0-stable Jul 12, 2011
@spastorino
Copy link
Contributor

Was this merged in master and 3-1-stable?

@bradrobertson
Copy link
Contributor Author

3-1-stable has a different fix from @tardate. This was just for 3-0-stable

@spastorino
Copy link
Contributor

cool

@holodigm
Copy link

holodigm commented Sep 7, 2011

This issue still exists in 3-1-stable

@bradrobertson
Copy link
Contributor Author

really @tardate can you comment? I'm not on 3.1 yet

@holodigm
Copy link

holodigm commented Sep 7, 2011

I hit this on a 3.0.10 to 3.1 upgrade yesterday on a relative new multi-tenant build. Big thanks for the original fix.
#2909

@tardate
Copy link
Contributor

tardate commented Sep 11, 2011

#1632 addressed this for 3.1 but it looks like that while it's in rails/master it didn't get merged to an RC or 3.1 stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants