Skip to content

Commit 8e190df

Browse files
committed
fix(typegen): include partitioned tables types to types introspection
1 parent f8471a3 commit 8e190df

File tree

3 files changed

+624
-1
lines changed

3 files changed

+624
-1
lines changed

src/lib/sql/types.sql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ from
4747
t.typrelid = 0
4848
or (
4949
select
50-
c.relkind ${props.includeTableTypes ? `in ('c', 'r', 'v', 'm')` : `= 'c'`}
50+
c.relkind ${props.includeTableTypes ? `in ('c', 'r', 'v', 'm', 'p')` : `= 'c'`}
5151
from
5252
pg_class c
5353
where

test/db/00-init.sql

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,39 @@ ROWS 1
429429
AS $$
430430
SELECT * FROM public.todos WHERE todos."user-id" = user_row.id LIMIT 1;
431431
$$;
432+
433+
-- Function that return the created_ago computed field
434+
CREATE OR REPLACE FUNCTION "public"."created_ago" ("public"."users_audit") RETURNS numeric LANGUAGE "sql"
435+
SET
436+
"search_path" TO '' AS $_$
437+
SELECT ROUND(EXTRACT(EPOCH FROM (NOW() - $1.created_at)));
438+
$_$;
439+
440+
-- Create a partitioned table for testing computed fields on partitioned tables
441+
CREATE TABLE public.events (
442+
id bigint generated by default as identity,
443+
created_at timestamptz default now(),
444+
event_type text,
445+
data jsonb,
446+
primary key (id, created_at)
447+
) partition by range (created_at);
448+
449+
-- Create partitions for the events table
450+
CREATE TABLE public.events_2024 PARTITION OF public.events
451+
FOR VALUES FROM ('2024-01-01') TO ('2025-01-01');
452+
453+
CREATE TABLE public.events_2025 PARTITION OF public.events
454+
FOR VALUES FROM ('2025-01-01') TO ('2026-01-01');
455+
456+
-- Insert some test data
457+
INSERT INTO public.events (created_at, event_type, data)
458+
VALUES
459+
('2024-06-15', 'login', '{"user": "alice"}'),
460+
('2025-03-20', 'logout', '{"user": "bob"}');
461+
462+
-- Function that returns computed field for partitioned table
463+
CREATE OR REPLACE FUNCTION "public"."days_since_event" ("public"."events") RETURNS numeric LANGUAGE "sql"
464+
SET
465+
"search_path" TO '' AS $_$
466+
SELECT ROUND(EXTRACT(EPOCH FROM (NOW() - $1.created_at)) / 86400);
467+
$_$;

0 commit comments

Comments
 (0)