Skip to content

Commit 430da28

Browse files
Ravi Teja KNTSclaude
authored andcommitted
Add the page model schema (expand release)
Additive migrations only: page indexability, meaningful page dates, new catalog content columns kept in sync with the legacy ones, and the course and lesson tables. The deployed app keeps working; the app that reads the new columns ships in a later release. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent ebc9c42 commit 430da28

9 files changed

Lines changed: 1161 additions & 0 deletions
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
begin;
2+
set local lock_timeout = '10s';
3+
-- Release A retains the counters used by the deployed readers and writers.
4+
-- These definitions keep explicit old-writer increments and automatic increments equivalent.
5+
create or replace function public.prepare_stack127_tool_page_update()
6+
returns trigger
7+
language plpgsql
8+
set search_path = pg_catalog
9+
as $$
10+
begin
11+
if (new.title, new.intro_markdown, new.usage_markdown, new.content_markdown)
12+
is distinct from
13+
(old.title, old.intro_markdown, old.usage_markdown, old.content_markdown) then
14+
new.content_revision = old.content_revision + 1;
15+
elsif new.content_revision <> old.content_revision then
16+
raise exception 'content_revision changes only with title or Markdown content';
17+
end if;
18+
19+
if new.tool_version is distinct from old.tool_version then
20+
new.tool_version_updated_at = now();
21+
elsif new.tool_version_updated_at <> old.tool_version_updated_at then
22+
raise exception 'tool_version_updated_at changes only with tool_version';
23+
end if;
24+
25+
return new;
26+
end;
27+
$$;
28+
29+
create or replace function public.prepare_stack127_directory_page_update()
30+
returns trigger language plpgsql set search_path=pg_catalog as $$
31+
begin
32+
if (new.title,new.intro_markdown,new.content_markdown) is distinct from (old.title,old.intro_markdown,old.content_markdown) then
33+
new.content_revision=old.content_revision+1;
34+
elsif new.content_revision<>old.content_revision then
35+
raise exception 'content_revision changes only with title or Markdown content';
36+
end if;
37+
return new;
38+
end;
39+
$$;
40+
notify pgrst, 'reload schema';
41+
commit;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Publication controls access; indexability controls search engines.
2+
begin;
3+
set local lock_timeout = '10s';
4+
set local statement_timeout = '120s';
5+
6+
alter table public.stack127_pages
7+
add column is_indexable boolean not null default true;
8+
9+
comment on column public.stack127_pages.is_indexable is
10+
'Published pages with false stay public but send noindex, omit JSON-LD, and stay out of the sitemap.';
11+
12+
-- The page-change trigger compares the whole row, including this new column.
13+
notify pgrst, 'reload schema';
14+
commit;

‎supabase/migrations/20261006105817_meaningful_page_dates.sql‎

Lines changed: 395 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
begin;
2+
set local lock_timeout = '10s';
3+
create or replace function public.stack127_touch_directory_records()
4+
returns trigger language plpgsql security invoker set search_path = pg_catalog as $$
5+
declare
6+
changed jsonb[];
7+
value jsonb;
8+
owner_slug text;
9+
section_id text;
10+
slugs text[] := '{}';
11+
entities text[] := '{}';
12+
entity_slugs text[] := '{}';
13+
idx integer;
14+
begin
15+
if tg_op = 'INSERT' then
16+
execute format('select array_agg(value) from (select public.stack127_directory_record_value(%L,to_jsonb(r)) value from new_rows r) records where value is not null',tg_table_name) into changed;
17+
elsif tg_op = 'DELETE' then
18+
execute format('select array_agg(value) from (select public.stack127_directory_record_value(%L,to_jsonb(r)) value from old_rows r) records where value is not null',tg_table_name) into changed;
19+
else
20+
execute format('with before as (select public.stack127_directory_record_value(%L,to_jsonb(r)) value from old_rows r),
21+
after as (select public.stack127_directory_record_value(%L,to_jsonb(r)) value from new_rows r),
22+
changes as ((select value from before except select value from after) union (select value from after except select value from before))
23+
select array_agg(value) from changes where value is not null',tg_table_name,tg_table_name) into changed;
24+
end if;
25+
if changed is null then return null; end if;
26+
foreach value in array changed loop
27+
case tg_table_name
28+
when 'platform_fee_sections','platform_fee_entries' then
29+
section_id := case when tg_table_name='platform_fee_sections' then value->>'id' else value->>'section_id' end;
30+
if tg_table_name='platform_fee_sections' then
31+
owner_slug := public.stack127_platform_fee_group_slug(value->>'group_name');
32+
else
33+
select public.stack127_platform_fee_group_slug(group_name) into owner_slug from public.platform_fee_sections where id=section_id;
34+
end if;
35+
slugs := slugs || array['platform-fees','platform-fees/' || owner_slug];
36+
entities := array_append(entities,'platform_fees'); entity_slugs := array_append(entity_slugs,section_id);
37+
when 'ad_networks','ad_network_publisher_relationships','ad_network_publishers' then
38+
if tg_table_name <> 'ad_network_publishers' or exists (
39+
select 1 from public.ad_network_publisher_relationships rel where rel.publisher_id=(value->>'id')::bigint and rel.status='confirmed'
40+
) then slugs := array_append(slugs,'ad-networks'); end if;
41+
if tg_table_name='ad_networks' then
42+
owner_slug := value->>'slug';
43+
slugs := array_append(slugs,'ad-networks/' || owner_slug);
44+
entities := array_append(entities,'ad_networks'); entity_slugs := array_append(entity_slugs,owner_slug);
45+
else
46+
for owner_slug in
47+
select network.slug from public.ad_networks network where
48+
(tg_table_name='ad_network_publisher_relationships' and network.id=(value->>'ad_network_id')::bigint) or
49+
(tg_table_name='ad_network_publishers' and exists(select 1 from public.ad_network_publisher_relationships rel
50+
where rel.ad_network_id=network.id and rel.publisher_id=(value->>'id')::bigint and rel.status='confirmed'))
51+
loop
52+
slugs := array_append(slugs,'ad-networks/' || owner_slug);
53+
entities := array_append(entities,'ad_networks'); entity_slugs := array_append(entity_slugs,owner_slug);
54+
end loop;
55+
end if;
56+
when 'launch_directories' then
57+
slugs := array_append(slugs,'launch-directories');
58+
entities := array_append(entities,'launch_directories'); entity_slugs := array_append(entity_slugs,'launch-directories');
59+
when 'terminal_apps' then
60+
slugs := array_append(slugs,'cli-apps');
61+
entities := array_append(entities,'cli_apps'); entity_slugs := array_append(entity_slugs,'cli-apps');
62+
when 'github_projects' then
63+
if exists(select 1 from public.self_host_apps app where app.github_project_id=(value->>'id')::uuid and app.published and app.self_hosting_status='self_hostable') then
64+
slugs := array_append(slugs,'self-host-apps');
65+
entities := array_append(entities,'self_host_catalog'); entity_slugs := array_append(entity_slugs,'all');
66+
end if;
67+
if exists(select 1 from public.terminal_apps app where app.github_project_id=(value->>'id')::uuid and app.published) then
68+
slugs := array_append(slugs,'cli-apps');
69+
entities := array_append(entities,'cli_apps'); entity_slugs := array_append(entity_slugs,'cli-apps');
70+
end if;
71+
when 'self_host_app_categories' then
72+
if exists(select 1 from public.self_host_app_category_links link join public.self_host_apps app on app.id=link.app_id
73+
where link.category_id=(value->>'id')::uuid and app.published and app.self_hosting_status='self_hostable') then
74+
slugs := array_append(slugs,'self-host-apps');
75+
entities := array_append(entities,'self_host_catalog'); entity_slugs := array_append(entity_slugs,'all');
76+
end if;
77+
else
78+
if tg_table_name='self_host_apps' then owner_slug := value->>'slug';
79+
else
80+
select app.slug into owner_slug from public.self_host_apps app where app.id=(value->>'app_id')::uuid
81+
and app.published and app.self_hosting_status='self_hostable';
82+
end if;
83+
if owner_slug is not null then
84+
slugs := slugs || array['self-host-apps','self-host-apps/' || owner_slug];
85+
entities := array_append(entities,'self_host_app'); entity_slugs := array_append(entity_slugs,owner_slug);
86+
end if;
87+
end case;
88+
end loop;
89+
for owner_slug in select distinct unnest(slugs) order by 1 loop
90+
perform public.stack127_touch_page(owner_slug,tg_table_name);
91+
end loop;
92+
for idx in select distinct on (entities[n],entity_slugs[n]) n from generate_subscripts(entities,1) n loop
93+
perform public.stack127_enqueue_revalidation(entities[idx],entity_slugs[idx],tg_table_name);
94+
end loop;
95+
return null;
96+
end;
97+
$$;
98+
commit;
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
begin;
2+
set local lock_timeout = '10s';
3+
create or replace function public.stack127_touch_directory_records()
4+
returns trigger language plpgsql security invoker set search_path = pg_catalog as $$
5+
declare
6+
changed jsonb[];
7+
value jsonb;
8+
owner_slug text;
9+
section_id text;
10+
slugs text[] := '{}';
11+
entities text[] := '{}';
12+
entity_slugs text[] := '{}';
13+
idx integer;
14+
begin
15+
if tg_op = 'INSERT' then
16+
execute format('select array_agg(value) from (select public.stack127_directory_record_value(%L,to_jsonb(r)) value from new_rows r) records where value is not null',tg_table_name) into changed;
17+
elsif tg_op = 'DELETE' then
18+
execute format('select array_agg(value) from (select public.stack127_directory_record_value(%L,to_jsonb(r)) value from old_rows r) records where value is not null',tg_table_name) into changed;
19+
else
20+
execute format('with before as (select public.stack127_directory_record_value(%L,to_jsonb(r)) value from old_rows r),
21+
after as (select public.stack127_directory_record_value(%L,to_jsonb(r)) value from new_rows r),
22+
changes as ((select value from before except select value from after) union (select value from after except select value from before))
23+
select array_agg(value) from changes where value is not null',tg_table_name,tg_table_name) into changed;
24+
end if;
25+
if changed is null then return null; end if;
26+
foreach value in array changed loop
27+
case tg_table_name
28+
when 'platform_fee_sections','platform_fee_entries' then
29+
section_id := case when tg_table_name='platform_fee_sections' then value->>'id' else value->>'section_id' end;
30+
if tg_table_name='platform_fee_sections' then
31+
owner_slug := public.stack127_platform_fee_group_slug(value->>'group_name');
32+
else
33+
select public.stack127_platform_fee_group_slug(group_name) into owner_slug from public.platform_fee_sections where id=section_id;
34+
end if;
35+
slugs := slugs || array['platform-fees','platform-fees/' || owner_slug];
36+
entities := array_append(entities,'platform_fees'); entity_slugs := array_append(entity_slugs,section_id);
37+
when 'ad_networks','ad_network_publisher_relationships','ad_network_publishers' then
38+
if tg_table_name <> 'ad_network_publishers' or exists (
39+
select 1 from public.ad_network_publisher_relationships rel where rel.publisher_id=(value->>'id')::bigint and rel.status='confirmed'
40+
) then slugs := array_append(slugs,'ad-networks'); end if;
41+
if tg_table_name='ad_networks' then
42+
owner_slug := value->>'slug';
43+
slugs := array_append(slugs,'ad-networks/' || owner_slug);
44+
entities := array_append(entities,'ad_networks'); entity_slugs := array_append(entity_slugs,owner_slug);
45+
else
46+
for owner_slug in
47+
select network.slug from public.ad_networks network where
48+
(tg_table_name='ad_network_publisher_relationships' and network.id=(value->>'ad_network_id')::bigint) or
49+
(tg_table_name='ad_network_publishers' and exists(select 1 from public.ad_network_publisher_relationships rel
50+
where rel.ad_network_id=network.id and rel.publisher_id=(value->>'id')::bigint and rel.status='confirmed'))
51+
loop
52+
slugs := array_append(slugs,'ad-networks/' || owner_slug);
53+
entities := array_append(entities,'ad_networks'); entity_slugs := array_append(entity_slugs,owner_slug);
54+
end loop;
55+
end if;
56+
when 'launch_directories' then
57+
slugs := array_append(slugs,'launch-directories');
58+
entities := array_append(entities,'launch_directories'); entity_slugs := array_append(entity_slugs,'launch-directories');
59+
when 'terminal_apps' then
60+
slugs := array_append(slugs,'cli-apps');
61+
entities := array_append(entities,'cli_apps'); entity_slugs := array_append(entity_slugs,'cli-apps');
62+
when 'github_projects' then
63+
if exists(select 1 from public.self_host_apps app where app.github_project_id=(value->>'id')::uuid and app.published and app.self_hosting_status='self_hostable') then
64+
slugs := array_append(slugs,'self-host-apps');
65+
slugs := slugs || coalesce((select array_agg('self-host-apps/' || app.slug) from public.self_host_apps app
66+
where app.published and app.self_hosting_status='self_hostable' and (
67+
(tg_table_name='github_projects' and app.github_project_id=(value->>'id')::uuid) or
68+
(tg_table_name='self_host_app_categories' and exists(select 1 from public.self_host_app_category_links link
69+
where link.app_id=app.id and link.category_id=(value->>'id')::uuid))
70+
)), '{}'::text[]);
71+
entities := array_append(entities,'self_host_catalog'); entity_slugs := array_append(entity_slugs,'all');
72+
end if;
73+
if exists(select 1 from public.terminal_apps app where app.github_project_id=(value->>'id')::uuid and app.published) then
74+
slugs := array_append(slugs,'cli-apps');
75+
entities := array_append(entities,'cli_apps'); entity_slugs := array_append(entity_slugs,'cli-apps');
76+
end if;
77+
when 'self_host_app_categories' then
78+
if exists(select 1 from public.self_host_app_category_links link join public.self_host_apps app on app.id=link.app_id
79+
where link.category_id=(value->>'id')::uuid and app.published and app.self_hosting_status='self_hostable') then
80+
slugs := array_append(slugs,'self-host-apps');
81+
slugs := slugs || coalesce((select array_agg('self-host-apps/' || app.slug) from public.self_host_apps app
82+
where app.published and app.self_hosting_status='self_hostable' and (
83+
(tg_table_name='github_projects' and app.github_project_id=(value->>'id')::uuid) or
84+
(tg_table_name='self_host_app_categories' and exists(select 1 from public.self_host_app_category_links link
85+
where link.app_id=app.id and link.category_id=(value->>'id')::uuid))
86+
)), '{}'::text[]);
87+
entities := array_append(entities,'self_host_catalog'); entity_slugs := array_append(entity_slugs,'all');
88+
end if;
89+
else
90+
if tg_table_name='self_host_apps' then owner_slug := value->>'slug';
91+
else
92+
select app.slug into owner_slug from public.self_host_apps app where app.id=(value->>'app_id')::uuid
93+
and app.published and app.self_hosting_status='self_hostable';
94+
end if;
95+
if owner_slug is not null then
96+
slugs := slugs || array['self-host-apps','self-host-apps/' || owner_slug];
97+
entities := array_append(entities,'self_host_app'); entity_slugs := array_append(entity_slugs,owner_slug);
98+
end if;
99+
end case;
100+
end loop;
101+
for owner_slug in select distinct unnest(slugs) order by 1 loop
102+
perform public.stack127_touch_page(owner_slug,tg_table_name);
103+
end loop;
104+
for idx in select distinct on (entities[n],entity_slugs[n]) n from generate_subscripts(entities,1) n loop
105+
perform public.stack127_enqueue_revalidation(entities[idx],entity_slugs[idx],tg_table_name);
106+
end loop;
107+
return null;
108+
end;
109+
$$;
110+
111+
-- The license directory combines code facts with counts from published apps.
112+
create function public.stack127_touch_directory_license_counts()
113+
returns trigger language plpgsql security invoker set search_path = pg_catalog as $$
114+
declare before_counts jsonb := '[]'; after_counts jsonb := '[]';
115+
begin
116+
if tg_op <> 'INSERT' then
117+
select coalesce(jsonb_agg(to_jsonb(counts) order by license,license_spdx_id),'[]') into before_counts
118+
from (select license,license_spdx_id,count(*) count from old_rows
119+
where published and self_hosting_status='self_hostable' group by license,license_spdx_id) counts;
120+
end if;
121+
if tg_op <> 'DELETE' then
122+
select coalesce(jsonb_agg(to_jsonb(counts) order by license,license_spdx_id),'[]') into after_counts
123+
from (select license,license_spdx_id,count(*) count from new_rows
124+
where published and self_hosting_status='self_hostable' group by license,license_spdx_id) counts;
125+
end if;
126+
if before_counts is distinct from after_counts then
127+
perform public.stack127_touch_page('software-licenses-for-self-hosting','license_app_counts');
128+
end if;
129+
return null;
130+
end;
131+
$$;
132+
revoke all on function public.stack127_touch_directory_license_counts() from public, anon, authenticated;
133+
grant execute on function public.stack127_touch_directory_license_counts() to service_role;
134+
create trigger stack127_touch_license_counts_insert after insert on public.self_host_apps
135+
referencing new table as new_rows for each statement execute function public.stack127_touch_directory_license_counts();
136+
create trigger stack127_touch_license_counts_update after update on public.self_host_apps
137+
referencing old table as old_rows new table as new_rows for each statement execute function public.stack127_touch_directory_license_counts();
138+
create trigger stack127_touch_license_counts_delete after delete on public.self_host_apps
139+
referencing old table as old_rows for each statement execute function public.stack127_touch_directory_license_counts();
140+
commit;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
begin;
2+
set local lock_timeout = '10s';
3+
-- Retired or renamed child routes still change their registered ancestors.
4+
create or replace function public.stack127_touch_page(p_slug text, p_reason text)
5+
returns void language plpgsql security invoker set search_path = pg_catalog as $$
6+
declare target record;
7+
begin
8+
if p_reason is null or btrim(p_reason) = '' then raise exception 'A page change reason is required'; end if;
9+
for target in
10+
select page.slug from public.stack127_pages page
11+
where page.slug = p_slug or (
12+
page.page_family = 'directory' and left(p_slug, length(page.slug) + 1) = page.slug || '/'
13+
) order by page.slug
14+
loop
15+
update public.stack127_pages set updated_at = case when is_published then now() else null end
16+
where slug = target.slug and updated_at is distinct from case when is_published then now() else null end;
17+
perform public.stack127_enqueue_revalidation('page', target.slug, p_reason);
18+
end loop;
19+
end;
20+
$$;
21+
22+
create function public.stack127_touch_directory_registry()
23+
returns trigger language plpgsql security invoker set search_path = pg_catalog as $$
24+
begin
25+
if tg_op='UPDATE' and (to_jsonb(new)-array['published_at','updated_at','row_updated_at'])
26+
is not distinct from (to_jsonb(old)-array['published_at','updated_at','row_updated_at']) then return null; end if;
27+
if tg_op<>'INSERT' and old.page_family='directory' then
28+
perform public.stack127_touch_page(old.slug,'directory_registry');
29+
end if;
30+
if tg_op<>'DELETE' and new.page_family='directory' then
31+
perform public.stack127_touch_page(new.slug,'directory_registry');
32+
end if;
33+
return null;
34+
end;
35+
$$;
36+
revoke all on function public.stack127_touch_directory_registry() from public, anon, authenticated;
37+
grant execute on function public.stack127_touch_directory_registry() to service_role;
38+
create trigger stack127_touch_directory_registry
39+
after insert or update or delete on public.stack127_pages
40+
for each row execute function public.stack127_touch_directory_registry();
41+
commit;

0 commit comments

Comments
 (0)