Skip to content

TS schema gen not deterministic in SetofOptions #1008

@gwax

Description

@gwax

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When sorting grouped functions for schema generation, postgres-meta does not sort function definitions by SetofOptions, which leads to unstable schema generation.

To Reproduce

  1. Create multiple join functions that take different table type as arguments but return the same set of table row. In other words, define join functions for B -> A, C -> A, D -> A
  2. Run typegen
  3. dump database
  4. supabase db reset
  5. restore database
  6. typegen <- doesn't always change but also doesn't always stay the same

Expected behavior

schema generation should be deterministic and stable, regardless of function return type

Screenshots

System information

  • OS: macOS or Linux
  • Browser (if applies) [e.g. chrome, safari]
  • Version of supabase-js: [e.g. 6.0.2]
  • Version of Node.js: 22.14.0
  • "supabase": "^2.54.11"

Additional context

The problem is this sort right here: https://github.com/supabase/postgres-meta/blob/master/src/server/templates/typescript.ts#L685

This line gives different loop results because sourceTable isn't part of the sort behavior above: https://github.com/supabase/postgres-meta/blob/master/src/server/templates/typescript.ts#L256

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions