-
-
Notifications
You must be signed in to change notification settings - Fork 438
Fix schema creation for non-default PostgreSQL schemas #1979
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
base: develop
Are you sure you want to change the base?
Fix schema creation for non-default PostgreSQL schemas #1979
Conversation
Resolves issue tortoise#1671 where Tortoise ORM failed to generate tables for non-default schemas. Changes: - Modified BaseSchemaGenerator to use schema-qualified table names in CREATE TABLE statements when schema is specified - Added automatic CREATE SCHEMA generation for PostgreSQL backends - Updated template strings to properly handle qualified table names - Fixed M2M table creation to work with schemas - Added tests for schema creation functionality
cba5f4c
to
5c35bc7
Compare
Can anyone approve this for the workflow ? @henadzit |
CodSpeed Performance ReportMerging #1979 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution!
Looks like your IDE reformatted a few file, and this makes it hard to review the PR. Can you please rollback the formatting changes?
- Add `no_key` parameter to `queryset.select_for_update`. | ||
- `F()` supports referencing JSONField attributes, e.g. `F("json_field__custom_field__nested_id")` (#1960) | ||
|
||
Fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.25.1 has been already released, you need to add 0.25.2 (unreleased)
and put your changes there.
# Get qualified table name for FK reference if related model has schema | ||
qualified_related_table_name = self._get_qualified_table_name( | ||
reference.related_model | ||
).strip('"') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you remove the leading and trailing "
but leave them in the middle around .
?
Hi! What the progress on this MR? |
Will pick this up on the weekend |
Sure |
Fix PostgreSQL schema creation for non-default schemas
Summary
Fixes #1671 by implementing automatic PostgreSQL schema creation and schema-qualified SQL generation.
Previously, Tortoise ORM would fail when trying to generate tables in non-default PostgreSQL schemas because:
This PR resolves both issues, enabling seamless use of custom PostgreSQL schemas.
Key Changes
Core Implementation
CREATE SCHEMA IF NOT EXISTS
generation for PostgreSQL"schema"."table"
)Files Modified
tortoise/backends/base/schema_generator.py
- Added schema qualification methodstortoise/backends/base_postgres/schema_generator.py
- PostgreSQL schema creation logictests/schema/test_schema_creation.py
- Comprehensive test coverageCHANGELOG.rst
- Added entry for the fixBefore vs After
Before (fails):
After (works):
Testing
Checklist
Impact: Fully backward compatible - no breaking changes for existing code.