xelixdev / django-pgviews-redux

Fork of django-postgres that focuses on maintaining and improving support for Postgres SQL Views.
The Unlicense
64 stars 15 forks source link

Improved PostgreSQL Schema Handling #28

Closed likeon closed 5 months ago

likeon commented 1 year ago

The recommended method for positioning a view in a PostgreSQL schema other than 'public' is by using the 'db_table' attribute within the 'Meta' class: db_table = 'my_custom_schema.preferredcustomer'.

Nevertheless, this method does not function effectively and can cause complex ORM queries to fail with an error. You can find more in-depth discussions about this issue in the following StackOverflow threads:

The topics above recommend specifying schema like that: db_table = 'schema\".\"tablename'. Although this approach works well with Django in the scenarios I tested, it is hacky and leads to failure in view creation when using django-pgviews-redux.

This pull request aims to address the problem by altering the SQL queries generated by the package to exclude schema specification unless explicitly defined. As a result, the search_path connection option is prioritized, enabling the creation of views in the anticipated schemas.

likeon commented 1 year ago

Glad you are open about accepting the contribution!

Sure, I'll update the README. Tests, however, I am not sure how to go about as it might require an additional database declaration in test project settings. Let me think a bit about it.

Thank you.

likeon commented 1 year ago

Unfortunately I don't have time to continue working on this one. Apologies for the noise. Feel free to close it.

mikicz commented 1 year ago

Thanks for letting me know - I might add the tests and update README, if I find the time