Skip to content

feat(postgrest)!: carry primary keys and relation columns on PostgrestTable and emit them from typegen - #1858

Merged
spydon merged 0 commit into
mainfrom
lukasklingsbo/sdk-1895-table-primary-keys-and-relations
Sep 18, 2026
Merged

spydon merged 0 commit into
mainfrom
lukasklingsbo/sdk-1895-table-primary-keys-and-relations

Conversation

@spydon

@spydon spydon commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Stacked on #1857. Tracked in SDK-1895, part of RFC: Pluggable offline support for the client SDKs.

What

PostgrestTable only knew its name and row converter. supabase_typegen introspected primary keys but its metadata parser dropped them, and the generated relation constants carried only the embed name. Anything that identifies or joins rows on the client (an offline store, a local evaluator for embedded selects, the typed .stream() primary key) had to be told what the schema already knows.

postgrest

  • PostgrestTable(name, rowFromJson, {required primaryKey, relations = const []}). primaryKey is the list of typed key columns, empty for a view or a keyless table. relations lists the table's relations.
  • PostgrestRelation<Row, Target> sealed base with name, columns (on this table), referencedTable and referencedColumns (on the target, paired by index). PostgrestToOneRelation and PostgrestToManyRelation extend it and require all of them.
  • Embedded column expressions keep the relation they were projected through instead of only its name.

supabase_typegen

  • The parser reads primaryKeys into TableDescription.primaryKey, in key order and per schema.
  • The generator emits primaryKey: and relations: on every table definition and columns:, referencedTable: and referencedColumns: on every relation constant, referencing the column constants of both namespace classes. Member identifiers are now claimed once per table up front so cross-table references resolve to the same sanitized names. Goldens regenerated.

Breaking changes

PostgrestTable, PostgrestToOneRelation and PostgrestToManyRelation have required named parameters. All are @experimental on the v3 line; hand-written definitions in the repository's tests were updated.

Tests

  • postgrest_embedded_relation_test.dart: relations expose the columns of both sides, projected columns keep their relation.
  • generator_metadata_parser_test.dart: primary keys parsed in key order, views have none, composite keys keep their order, other schemas are ignored.
  • dart_generator_test.dart: table definitions list primary key and relations, relation constants carry their columns, a view has an empty key, a sanitized key column keeps its constant.
  • Existing typed suites updated for the new constructors and still green; compliance validate, drift and symbol checks pass locally.

@coderabbitai

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@spydon
spydon merged commit d4b7bec into main Sep 18, 2026
@spydon
spydon force-pushed the lukasklingsbo/sdk-1886-typed-table-executor-and-client-plugins branch from fd180d5 to 0917c3f Compare September 18, 2026 15:15
@spydon
spydon deleted the lukasklingsbo/sdk-1895-table-primary-keys-and-relations branch September 18, 2026 15:15
@spydon
spydon force-pushed the lukasklingsbo/sdk-1895-table-primary-keys-and-relations branch from 398d45e to d4b7bec Compare September 18, 2026 15:15
@spydon
spydon changed the base branch from lukasklingsbo/sdk-1886-typed-table-executor-and-client-plugins to main September 18, 2026 15:15
@spydon
spydon restored the lukasklingsbo/sdk-1895-table-primary-keys-and-relations branch September 18, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant