Typegen is not respecting unique table constraint
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- postgresql, typescript
- Domain
- databases
Research direction
Reproduce the schema with customers, addresses, and orders, then run npx supabase gen types typescript --local > types/supabase.ts and inspect the generated relationship types. Trace the type-generation entry point used by that command and verify that the unique addresses.customer_id relationship is emitted as an object while orders remains an array.
Written by the indexing model from the issue text.
Description
Describe the bug
I have three tables. One main table customers and two linked tables addresses and orders. They both are linked to the customers table's id column, but the addresses table has a unique constraint on customer_id relation column. The problem is that the generated types assumes that both table relations are one to many.
To Reproduce
Steps to reproduce the behavior:
- Start a new project and create three tables. Reference one main table from the two others, one with a unique constraint and one without.
- Generate types using
npx supabase gen types typescript --local > types/supabase.ts - Use
const supabase = createClient<Database>()and queryconst { data } = supabase .from("customers") .select("*, orders (id), addresses (id)").single() - see that the type of
data.ordersanddata.addressesare both an array of objects.
Expected behavior
The types to respect the unique constraint and be an object and not an array of objects.
Desktop
- OS: Mac OS 13.4.1
- Version of CLI: v1.93.0
- Version of supabase-js: v2.33.2
- Version of Node.js: v16.14.2
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 223
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from supabase/postgres-meta
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
supabase/postgres-meta#1150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
supabase/postgres-meta#1147 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
supabase/postgres-meta#1146 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
supabase/postgres-meta#1143 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
supabase/postgres-meta#1142 ·
All issues in supabase/postgres-meta
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·