sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Fixes to table inheritance

Open dbhoot opened this issue 1 year ago • 1 comments

Previously

Fixes #3024

There are two main fixes in this PR

  • Any alterations to a parent table never propagated to the children. This is because the columns of the parent table(s) were only added on table create.

  • Not null overrides on child tables were not applied correctly. This is because there was a shared column reference between the parent and child tables. When any override for any child table existed, it was applied to the shared reference, which actually affected (incorrectly) other tables.

Now

  • Changes to a parent table are propagated to the child tables
  • Child tables have their own copy of the column definition. Overriding on a single table only affects the column definition on the table which it was declared. Parent / Sibling tables are no longer affected.

How does this work?

When a child table inherits from a parent, we now update the parent table to have references to the child table. When we apply an alter statement to the parent, we also recursively traverse the children and apply the same alteration to the children.

dbhoot avatar Apr 25 '24 09:04 dbhoot

hi @kyleconroy -- is there any hope of this change getting reviewed / merged? Are there concerns about it the implementation or anything? I know the core maintainers are busy so I'd like to do what I can to help.

dbhoot avatar Oct 17 '24 03:10 dbhoot

Hello @kyleconroy , It would be great if this could get reviewed because we really need this functionality.

ShadowBr0ther avatar Jan 20 '25 19:01 ShadowBr0ther