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 schema synchronization for partitioned tables with PostgreSQL 12+ #6780
Conversation
@@ -1434,6 +1434,10 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner | |||
} | |||
return `("ns"."nspname" = '${schema}' AND "cl"."relname" = '${name}')`; | |||
}).join(" OR "); | |||
|
|||
const hasIsPartition = await this.hasPartitionedTables(); | |||
const isPartitionCondition = hasIsPartition ? ` AND "cl"."relispartition" = 'f'` : ""; |
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.
what if we wouldn't have hasIsPartition
check here? according to this check it looks like we do need items with "AND "cl"."relispartition" = 't' ?
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.
@pleerock the column relispartition
does not exist in PostgreSQL versions that have no support for partitioned tables (prior to version 10). This is why we need this check here.
Then, when using a version of PostgreSQL with partitioned tables, we need to ignore the partitions and only check the constraints on the "main" table ie: "relispartition" = "f"
(which are not partitions).
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.
Maybe we should rename hasPartitionedTables
to hasSupportForPartitionedTables
to make it clearer?
…ncing schema on postgresql 12+
@pleerock let me know if anything is unclear |
Looks good, thanks |
…2+ (typeorm#6780) * feat: ignore foreign keys on partitions of partitioned tables when syncing schema on postgresql 12+ * feat: consider partitionned tables as regular tables in order to keep them in sync
Hi there sorry to interrupt, this seem to be the only issue related to pg partitioning. |
Consider partitioned tables as regular tables
Typeorm currently excludes partitioned tables from schema synchronization. We could also take them into account as their behavior regarding schema modifications is the same as regular tables.
Ignore foreign keys on partitions of the partitioned tables when syncing schema on PostgreSQL 12+
When a table has foreign keys referencing a partitioned table, the
PostgresQueryRunner
will load the constraints from every partition.We need to ignore those foreign keys as they are not managed by the user.
Example:
table_A
has a foreign key constraint referencingtable_B
which is a partitioned table onkey1
andkey2
.The command
typeorm schema:log
will return this kind of list of queries to remove the FK constraints fromtable_A
.Typeorm should ignore those constraints.