[supabase gen] complex Views with triggers missing Insert/Update definitions
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 65/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- postgresql, typescript
Research direction
Start by reproducing the schema and trigger from the issue, then run supabase gen types --lang typescript and inspect the generated public.Views.Profile definition. Trace the type-generation entry point for view metadata and add coverage for trigger-backed views. Done means the generated Profile type includes the expected Insert and Update sections without regressing automatically updatable views.
Written by the indexing model from the issue text.
Description
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
supabase gen types does not properly handle the case that a complex view uses triggers to write information back through the view. It does not produce the Insert/ Update sections of the type definitions. When using simple "automatically updatable view this works as expected.
To Reproduce
We have two tables:
CREATE TABLE IF NOT EXISTS private.profile_type (
id int2 NOT NULL PRIMARY KEY,
name text NOT NULL,
);
CREATE TABLE IF NOT EXISTS private.profile (
id uuid REFERENCES auth.users NOT NULL primary key,
username text unique,
profile_type_id int2 REFERENCES private.profile_type(id),
);
This view provides access to the profile and integrates information from the other table:
CREATE OR REPLACE VIEW public."Profile" ("id", "username", "profileType")
WITH (security_invoker)
AS SELECT p.id, username, pt.name
FROM private.profile AS p
JOIN private.profile_type AS pt ON p.profile_type_id = pt.id;
This view is not an "automatically updatable view". In order to write back to the profile table, we are attaching a trigger to the view that handles the INSERT and UPDATE statements:
CREATE OR REPLACE FUNCTION public.profile_view_v1_row()
RETURNS TRIGGER
AS $$
BEGIN
IF TG_OP = 'INSERT' THEN
-- omitted code
ELSE -- 'UPDATE'
-- omitted code
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
CREATE OR REPLACE TRIGGER profile_view_v1_row
INSTEAD OF INSERT OR UPDATE ON public."Profile"
FOR EACH ROW
EXECUTE FUNCTION public.profile_view_v1_row();
When generating the types using
supabase gen types --lang typescript
it does not include the sections for Insert and Update in the public->Views->Profile part of the generated types (see below)
Expected behavior
The expected type definition should look like this:
...
public: {
Tables: {
[_ in never]: never
}
Views: {
Profile: {
Row: {
id: string | null
profileType: string | null
username: string | null
}
--> These parts are missing and should be generated
Insert: {
id?: string | null
profileType?: string | null
username?: string | null
}
Update: {
id?: string | null
profileType?: string | null
username?: string | null
}
<--
...
}
System information
- OS: macOS
- supabase cli version (
supabase --version): 1.223.10
- 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 ·