You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
Bug report
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 theInsert
/Update
sections of the type definitions. When using simple "automatically updatable view this works as expected.To Reproduce
We have two tables:
This view provides access to the profile and integrates information from the other table:
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:
When generating the types using
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:
System information
supabase --version
): 1.223.10The text was updated successfully, but these errors were encountered: