kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.44k stars 267 forks source link

Postgres Introspection getTables() misses partition tables #1033

Closed HeikoOsigus closed 3 months ago

HeikoOsigus commented 3 months ago

The getTables() method in src/dialect/postgres/postgres-introspector.ts does not consider partitioned tables.

The SQL checks for relkind = 'r' or relkind ='v', regular table or view. Partition tables have relkind = 'p'. See postgres documentation https://www.postgresql.org/docs/current/catalog-pg-class.html

Suggested change, add check for relkind = 'p' e.g.:

.where((eb) =>
        eb.or([eb('c.relkind', '=', 'r'), eb('c.relkind', '=', 'v'),eb('c.relkind','=','p']),
      )