Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions proposals/catalog-snapshot-size-2277/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Inactive Catalog snapshot size proposal (#2277)

Outside migrations; no runtime grants or activation. Requires Database main7708e337 plus original DB1253f2c849 accepted four-file bundle (composition tree4a611d840e1e04d2b6f7d5a50e7789c4940d3b07). The original Catalog migration and restored history remain untouched.

Replace only save_context_catalog_case in disposable fixtures. Dedicated SQLSTATE22001 / CATALOG_SNAPSHOT_TOO_LARGE follows exact replay and precedes mutation, checking incomingJSONB and final server-revision snapshot against the existing1MiB cap. Preserve original fingerprint, actor/owner access, CAS, tableCHECK, arbitrary JSON values and existing grants.

The fixture reuses the accepted four-file bootstrap and applies this proposal last. API tests read exact owning Git bytes; no SQL business logic is copied into API. Any future approved migration/release composition is a separate gate. Keep this PR draft and unmerged; no apply/dryrun/hosted preview or grants are authorized.
19 changes: 19 additions & 0 deletions proposals/catalog-snapshot-size-2277/fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Reuse the accepted four-file synthetic bundle setup for paired API size tests."""
import pathlib
import test_release_cases as base
ROOT = pathlib.Path(__file__).resolve().parents[2]
def apply(cls, name):
cls.sql((ROOT / 'supabase/migrations' / name).read_text())
def setup_catalog_size_fixture(cls):
base.ReleaseCases.setUpClass.__func__(cls)
cls.sql('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";')
cls.sql('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO anon,authenticated,service_role; ALTER DEFAULT PRIVILEGES REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT EXECUTE ON FUNCTIONS TO service_role;')
for n in ['20260630210000_create_email_send_log.sql','20260630211500_finalize_email_send_log.sql']:apply(cls,n)
cls.sql("INSERT INTO public.email_send_log(id,status,raw_body) VALUES('00000000-0000-4000-8000-000000000001','rejected','synthetic pre-migration row');")
for n in ['20261022120000_context_catalog_cases.sql','20261106120000_email_send_log_reason.sql','20261110010000_ingestion_catalog.sql','20261110010100_ingestion_catalog_page_budget.sql']:apply(cls,n)

class CatalogSizeFixture(base.ReleaseCases):
@classmethod
def setUpClass(cls):
setup_catalog_size_fixture(cls)
cls.sql((ROOT / "proposals/catalog-snapshot-size-2277/proposal.sql").read_text())
43 changes: 43 additions & 0 deletions proposals/catalog-snapshot-size-2277/proposal.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- INACTIVE disposable-fixture proposal. Not a migration or deployment authorization.
-- Requires the exact accepted DB125 four-file bundle. No runtime grants.
begin;
create or replace function public.save_context_catalog_case(p_actor uuid,p_owner uuid,p_case uuid,p_expected_revision integer,p_key text,p_snapshot jsonb)
returns jsonb language plpgsql set search_path='' as $$
declare current_case public.context_catalog_cases; saved public.context_catalog_case_revisions; digest text; next_revision integer; stored_snapshot jsonb;
begin
perform public.authorize_context_case_actor(p_actor,p_owner);
if p_case is null or p_expected_revision is null or p_expected_revision<0 or p_key is null or p_key !~ '^[A-Za-z0-9._:-]{1,128}$'
then raise exception 'Invalid catalog case request' using errcode='22023'; end if;
-- Fingerprint covers the exact input revision and artifact; replay does not create another revision.
digest:=encode(sha256(convert_to(jsonb_build_object('case',p_case,'revision',p_expected_revision,'snapshot',p_snapshot)::text,'UTF8')),'hex');
perform pg_advisory_xact_lock(hashtextextended(p_owner::text||':catalog-key:'||p_key,0));
select * into saved from public.context_catalog_case_revisions where owner_id=p_owner and idempotency_key=p_key;
if saved.case_id is not null then
if saved.actor_id<>p_actor or saved.input_fingerprint<>digest then raise exception 'Catalog key reused for different input' using errcode='22023'; end if;
return public.read_context_catalog_case(p_actor,p_owner,saved.case_id,saved.revision);
end if;
-- Replay above remains valid; this signal is owned only by Catalog save size checks.
if octet_length(p_snapshot::text)>1048576 then
raise exception 'CATALOG_SNAPSHOT_TOO_LARGE' using errcode='22001';
end if;
perform public.validate_context_catalog_snapshot(p_owner,p_case,p_expected_revision,p_snapshot);
perform pg_advisory_xact_lock(hashtextextended(p_case::text||':catalog-case',0));
select * into current_case from public.context_catalog_cases where id=p_case for update;
if current_case.id is not null and current_case.owner_id<>p_owner then raise exception 'Catalog case unavailable' using errcode='42501'; end if;
if coalesce(current_case.revision,0)<>p_expected_revision then raise exception 'Catalog revision conflict' using errcode='40001'; end if;
next_revision:=p_expected_revision+1;
stored_snapshot:=jsonb_set(p_snapshot,'{revision}',to_jsonb(next_revision));
if octet_length(stored_snapshot::text)>1048576 then
raise exception 'CATALOG_SNAPSHOT_TOO_LARGE' using errcode='22001';
end if;
if current_case.id is null then
insert into public.context_catalog_cases(id,owner_id,created_by,revision) values(p_case,p_owner,p_actor,next_revision);
else
update public.context_catalog_cases set revision=next_revision,updated_at=clock_timestamp() where id=p_case and owner_id=p_owner;
end if;
insert into public.context_catalog_case_revisions(case_id,owner_id,revision,actor_id,idempotency_key,input_fingerprint,snapshot)
values(p_case,p_owner,next_revision,p_actor,p_key,digest,stored_snapshot);
return public.read_context_catalog_case(p_actor,p_owner,p_case,next_revision);
end $$;

commit;
Loading