Fix schema creation for non-default PostgreSQL schemas#1979
Fix schema creation for non-default PostgreSQL schemas#1979Pritish053 wants to merge 5 commits intotortoise:developfrom
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
|
henadzit
left a comment
There was a problem hiding this comment.
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.
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.
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 |
|
@Pritish053 any update on this? 🙏🏻 Sorely missed feature, this 😭 |
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 EXISTSgeneration 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.