tinbase 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,4 +10,4 @@
10
10
  * enforced here — this path is for local-dev/preview only.
11
11
  */
12
12
  export declare const MINIMAL_BOOTSTRAP_SQL = "\ncreate schema if not exists auth;\ncreate schema if not exists storage;\ncreate schema if not exists supabase_migrations;\n\ncreate table if not exists auth.users (\n id uuid primary key default gen_random_uuid(),\n aud text default 'authenticated',\n role text default 'authenticated',\n email text unique,\n encrypted_password text,\n email_confirmed_at timestamptz,\n last_sign_in_at timestamptz,\n raw_app_meta_data jsonb default '{}'::jsonb,\n raw_user_meta_data jsonb default '{}'::jsonb,\n is_super_admin boolean default false,\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n phone text unique,\n phone_confirmed_at timestamptz,\n banned_until timestamptz,\n deleted_at timestamptz,\n is_anonymous boolean default false\n);\n\ncreate table if not exists auth.refresh_tokens (\n id bigserial primary key,\n token text unique not null,\n user_id uuid not null,\n parent text,\n session_id uuid,\n revoked boolean default false,\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate table if not exists auth.one_time_tokens (\n id uuid primary key default gen_random_uuid(),\n user_id uuid,\n email text not null,\n token_type text not null,\n token text not null,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ncreate table if not exists auth.identities (\n id uuid primary key default gen_random_uuid(),\n user_id uuid not null,\n provider text not null,\n provider_id text not null,\n identity_data jsonb default '{}'::jsonb,\n last_sign_in_at timestamptz default now(),\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n unique (provider, provider_id)\n);\n\ncreate table if not exists auth.flow_state (\n id uuid primary key default gen_random_uuid(),\n provider text not null,\n provider_state text not null unique,\n redirect_to text,\n code_challenge text,\n code_challenge_method text,\n auth_code text unique,\n user_id uuid,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ncreate table if not exists auth.mfa_factors (\n id uuid primary key default gen_random_uuid(),\n user_id uuid not null,\n friendly_name text,\n factor_type text not null default 'totp',\n status text not null default 'unverified',\n secret text,\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate table if not exists auth.mfa_challenges (\n id uuid primary key default gen_random_uuid(),\n factor_id uuid not null,\n verified_at timestamptz,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ncreate table if not exists storage.buckets (\n id text primary key,\n name text not null unique,\n owner uuid,\n public boolean default false,\n file_size_limit bigint,\n allowed_mime_types text[],\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate table if not exists storage.objects (\n id uuid primary key default gen_random_uuid(),\n bucket_id text not null,\n name text not null,\n owner uuid,\n version text,\n metadata jsonb default '{}'::jsonb,\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n last_accessed_at timestamptz default now(),\n unique (bucket_id, name)\n);\n\ncreate table if not exists supabase_migrations.schema_migrations (\n version text primary key,\n name text,\n statements text[],\n applied_at timestamptz default now()\n);\n\ncreate table if not exists supabase_migrations.seed_files (\n path text primary key,\n hash text,\n applied_at timestamptz default now()\n);\n";
13
- export declare const BOOTSTRAP_SQL = "\n-- \u2500\u2500 Extensions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n-- Supabase enables these by default and migrations lean on them\n-- (uuid_generate_v4(), crypt(), citext, pg_trgm, \u2026). Each is created into the\n-- 'extensions' schema like hosted Supabase; any not available in this engine\n-- build is skipped rather than aborting the whole bootstrap.\ncreate schema if not exists extensions;\ndo $$\ndeclare ext text;\nbegin\n foreach ext in array array['uuid-ossp','pgcrypto','citext','pg_trgm','ltree','hstore','fuzzystrmatch'] loop\n begin\n execute format('create extension if not exists %I with schema extensions', ext);\n exception when others then\n -- extension not bundled in this engine build; continue\n end;\n end loop;\nend $$;\n\n-- uuid-ossp isn't in every Postgres build (it needs an external UUID lib at\n-- build time \u2014 e.g. the theseus Linux binaries omit it). uuid_generate_v4() is\n-- the single most-used function from it, so shim it onto core gen_random_uuid()\n-- (also a v4 UUID) whenever the real extension isn't present, so migrations\n-- that call it work identically on every engine and platform.\ndo $$\nbegin\n if not exists (\n select 1 from pg_proc p join pg_namespace n on n.oid = p.pronamespace\n where p.proname = 'uuid_generate_v4' and n.nspname in ('public', 'extensions')\n ) then\n create function extensions.uuid_generate_v4() returns uuid\n language sql volatile as 'select gen_random_uuid()';\n end if;\nend $$;\n\n-- Make extension functions resolvable unqualified (uuid_generate_v4(), \u2026) on\n-- the current session (migrations run here) and for future connections.\ndo $$\nbegin\n execute 'alter database ' || quote_ident(current_database()) ||\n ' set search_path to \"$user\", public, extensions';\nexception when others then\n -- some engines disallow altering the current database; session SET below still applies\nend $$;\nset search_path to \"$user\", public, extensions;\n\n-- \u2500\u2500 Roles \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ndo $$\nbegin\n if not exists (select from pg_roles where rolname = 'anon') then\n create role anon nologin noinherit;\n end if;\n if not exists (select from pg_roles where rolname = 'authenticated') then\n create role authenticated nologin noinherit;\n end if;\n if not exists (select from pg_roles where rolname = 'service_role') then\n create role service_role nologin noinherit bypassrls;\n end if;\nend $$;\n\ngrant usage on schema extensions to anon, authenticated, service_role;\nalter role anon set search_path to \"$user\", public, extensions;\nalter role authenticated set search_path to \"$user\", public, extensions;\nalter role service_role set search_path to \"$user\", public, extensions;\n\ngrant usage on schema public to anon, authenticated, service_role;\ngrant all on all tables in schema public to anon, authenticated, service_role;\ngrant all on all sequences in schema public to anon, authenticated, service_role;\ngrant execute on all functions in schema public to anon, authenticated, service_role;\n\nalter default privileges in schema public\n grant all on tables to anon, authenticated, service_role;\nalter default privileges in schema public\n grant all on sequences to anon, authenticated, service_role;\nalter default privileges in schema public\n grant execute on functions to anon, authenticated, service_role;\n\n-- \u2500\u2500 Auth schema (GoTrue-compatible subset) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists auth;\n\ncreate table if not exists auth.users (\n id uuid primary key default gen_random_uuid(),\n aud text default 'authenticated',\n role text default 'authenticated',\n email text unique,\n encrypted_password text,\n email_confirmed_at timestamptz,\n invited_at timestamptz,\n confirmation_token text,\n recovery_token text,\n last_sign_in_at timestamptz,\n raw_app_meta_data jsonb default '{}'::jsonb,\n raw_user_meta_data jsonb default '{}'::jsonb,\n is_super_admin boolean default false,\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n phone text unique,\n phone_confirmed_at timestamptz,\n banned_until timestamptz,\n deleted_at timestamptz,\n is_anonymous boolean default false\n);\n\ncreate table if not exists auth.refresh_tokens (\n id bigint generated by default as identity primary key,\n token text unique not null,\n user_id uuid not null references auth.users(id) on delete cascade,\n parent text,\n session_id uuid,\n revoked boolean default false,\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate index if not exists refresh_tokens_user_id_idx on auth.refresh_tokens(user_id);\n\ncreate table if not exists auth.one_time_tokens (\n id uuid primary key default gen_random_uuid(),\n user_id uuid references auth.users(id) on delete cascade,\n email text not null,\n token_type text not null, -- otp | magiclink | recovery\n token text not null,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ncreate table if not exists auth.identities (\n id uuid primary key default gen_random_uuid(),\n user_id uuid not null references auth.users(id) on delete cascade,\n provider text not null,\n provider_id text not null,\n identity_data jsonb default '{}'::jsonb,\n last_sign_in_at timestamptz default now(),\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n unique (provider, provider_id)\n);\n\n-- OAuth / PKCE flow state, bridging /authorize \u2192 provider \u2192 /callback \u2192 exchange\ncreate table if not exists auth.flow_state (\n id uuid primary key default gen_random_uuid(),\n provider text not null,\n provider_state text not null unique,\n redirect_to text,\n code_challenge text,\n code_challenge_method text,\n auth_code text unique,\n user_id uuid references auth.users(id) on delete cascade,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ncreate table if not exists auth.mfa_factors (\n id uuid primary key default gen_random_uuid(),\n user_id uuid not null references auth.users(id) on delete cascade,\n friendly_name text,\n factor_type text not null default 'totp',\n status text not null default 'unverified', -- unverified | verified\n secret text,\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate table if not exists auth.mfa_challenges (\n id uuid primary key default gen_random_uuid(),\n factor_id uuid not null references auth.mfa_factors(id) on delete cascade,\n verified_at timestamptz,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ngrant usage on schema auth to anon, authenticated, service_role;\n\ncreate or replace function auth.jwt() returns jsonb\nlanguage sql stable as $$\n select coalesce(\n nullif(current_setting('request.jwt.claims', true), ''),\n '{}'\n )::jsonb\n$$;\n\ncreate or replace function auth.uid() returns uuid\nlanguage sql stable as $$\n select nullif(auth.jwt() ->> 'sub', '')::uuid\n$$;\n\ncreate or replace function auth.role() returns text\nlanguage sql stable as $$\n select coalesce(auth.jwt() ->> 'role', 'anon')\n$$;\n\ncreate or replace function auth.email() returns text\nlanguage sql stable as $$\n select auth.jwt() ->> 'email'\n$$;\n\ngrant execute on function auth.jwt(), auth.uid(), auth.role(), auth.email()\n to anon, authenticated, service_role;\n\n-- \u2500\u2500 Storage schema (storage-api-compatible subset) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists storage;\n\ncreate table if not exists storage.buckets (\n id text primary key,\n name text not null unique,\n owner uuid,\n public boolean default false,\n file_size_limit bigint,\n allowed_mime_types text[],\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate table if not exists storage.objects (\n id uuid primary key default gen_random_uuid(),\n bucket_id text not null references storage.buckets(id),\n name text not null,\n owner uuid,\n version text,\n metadata jsonb default '{}'::jsonb,\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n last_accessed_at timestamptz default now(),\n unique (bucket_id, name)\n);\n\ncreate index if not exists objects_bucket_name_idx on storage.objects(bucket_id, name);\n\ngrant usage on schema storage to anon, authenticated, service_role;\ngrant select on storage.buckets to anon, authenticated, service_role;\ngrant all on storage.buckets to service_role;\ngrant all on storage.objects to anon, authenticated, service_role;\n\ncreate or replace function storage.foldername(name text) returns text[]\nlanguage sql immutable as $$\n select (string_to_array(name, '/'))[1 : array_length(string_to_array(name, '/'), 1) - 1]\n$$;\n\ncreate or replace function storage.filename(name text) returns text\nlanguage sql immutable as $$\n select (string_to_array(name, '/'))[array_length(string_to_array(name, '/'), 1)]\n$$;\n\ncreate or replace function storage.extension(name text) returns text\nlanguage sql immutable as $$\n select reverse(split_part(reverse(storage.filename(name)), '.', 1))\n$$;\n\nalter table storage.objects enable row level security;\n\n-- Dev-friendly default policies. Replace them in your migrations to lock down.\ndo $$\nbegin\n if not exists (select from pg_policies where schemaname = 'storage' and tablename = 'objects' and policyname = 'tinbase_authenticated_all') then\n create policy tinbase_authenticated_all on storage.objects\n for all to authenticated using (true) with check (true);\n end if;\n if not exists (select from pg_policies where schemaname = 'storage' and tablename = 'objects' and policyname = 'tinbase_public_read') then\n create policy tinbase_public_read on storage.objects\n for select to anon\n using (bucket_id in (select id from storage.buckets where public));\n end if;\nend $$;\n\n-- \u2500\u2500 Migration bookkeeping (same table the Supabase CLI uses) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists supabase_migrations;\n\ncreate table if not exists supabase_migrations.schema_migrations (\n version text primary key,\n name text,\n statements text[],\n applied_at timestamptz default now()\n);\n\ncreate table if not exists supabase_migrations.seed_files (\n path text primary key,\n hash text,\n applied_at timestamptz default now()\n);\n\n-- \u2500\u2500 Realtime CDC plumbing \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists tinbase;\n\ncreate or replace function tinbase.cdc_notify() returns trigger\nlanguage plpgsql security definer as $$\ndeclare\n payload text;\nbegin\n payload := json_build_object(\n 'schema', TG_TABLE_SCHEMA,\n 'table', TG_TABLE_NAME,\n 'type', TG_OP,\n 'commit_timestamp', to_char(now() at time zone 'utc', 'YYYY-MM-DD\"T\"HH24:MI:SS.MS\"Z\"'),\n 'record', case when TG_OP in ('INSERT', 'UPDATE') then row_to_json(NEW) else null end,\n 'old_record', case when TG_OP in ('UPDATE', 'DELETE') then row_to_json(OLD) else null end\n )::text;\n -- pg_notify payloads are capped at ~8kB; degrade like Supabase does.\n if octet_length(payload) > 7500 then\n payload := json_build_object(\n 'schema', TG_TABLE_SCHEMA,\n 'table', TG_TABLE_NAME,\n 'type', TG_OP,\n 'commit_timestamp', to_char(now() at time zone 'utc', 'YYYY-MM-DD\"T\"HH24:MI:SS.MS\"Z\"'),\n 'record', null,\n 'old_record', null,\n 'errors', json_build_array('Payload too large')\n )::text;\n end if;\n perform pg_notify('tinbase_cdc', payload);\n return coalesce(NEW, OLD);\nend $$;\n\n-- \u2500\u2500 Realtime Authorization + broadcast-from-database \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n-- Mirrors Supabase Realtime: developers write RLS policies on\n-- realtime.messages using realtime.topic(); a SELECT policy grants a private\n-- channel's subscribers the right to *receive*, an INSERT policy the right to\n-- *broadcast*. realtime.send() lets the database push a broadcast to a topic.\ncreate schema if not exists realtime;\n\ncreate table if not exists realtime.messages (\n id uuid not null default gen_random_uuid(),\n topic text not null,\n extension text not null,\n event text,\n payload jsonb,\n private boolean default false,\n inserted_at timestamptz not null default now(),\n updated_at timestamptz not null default now(),\n primary key (id)\n);\nalter table realtime.messages enable row level security;\n\ngrant usage on schema realtime to anon, authenticated, service_role;\ngrant all on realtime.messages to anon, authenticated, service_role;\n\n-- the topic currently being authorized/broadcast (set per operation)\ncreate or replace function realtime.topic() returns text\n language sql stable as $$ select nullif(current_setting('realtime.topic', true), '') $$;\n\n-- push a broadcast message to all subscribers of <topic> from SQL / triggers.\n-- Delivered over the websocket by the in-process realtime engine, which listens\n-- on the 'tinbase_realtime_broadcast' channel.\ncreate or replace function realtime.send(payload jsonb, event text, topic text, private boolean default true)\n returns void language plpgsql security definer as $$\nbegin\n perform pg_notify(\n 'tinbase_realtime_broadcast',\n json_build_object('topic', topic, 'event', event, 'payload', payload, 'private', private)::text\n );\nexception when others then\n -- never let a notify failure abort the caller's transaction\n null;\nend $$;\n\ngrant execute on function realtime.topic() to anon, authenticated, service_role;\ngrant execute on function realtime.send(jsonb, text, text, boolean) to anon, authenticated, service_role;\n";
13
+ export declare const BOOTSTRAP_SQL = "\n-- \u2500\u2500 Extensions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n-- Supabase enables these by default and migrations lean on them\n-- (uuid_generate_v4(), crypt(), citext, pg_trgm, \u2026). Each is created into the\n-- 'extensions' schema like hosted Supabase; any not available in this engine\n-- build is skipped rather than aborting the whole bootstrap.\ncreate schema if not exists extensions;\ndo $$\ndeclare ext text;\nbegin\n foreach ext in array array['uuid-ossp','pgcrypto','citext','pg_trgm','ltree','hstore','fuzzystrmatch'] loop\n begin\n execute format('create extension if not exists %I with schema extensions', ext);\n exception when others then\n -- extension not bundled in this engine build; continue\n end;\n end loop;\nend $$;\n\n-- uuid-ossp isn't in every Postgres build (it needs an external UUID lib at\n-- build time \u2014 e.g. the theseus Linux binaries omit it). uuid_generate_v4() is\n-- the single most-used function from it, so shim it onto core gen_random_uuid()\n-- (also a v4 UUID) whenever the real extension isn't present, so migrations\n-- that call it work identically on every engine and platform.\ndo $$\nbegin\n if not exists (\n select 1 from pg_proc p join pg_namespace n on n.oid = p.pronamespace\n where p.proname = 'uuid_generate_v4' and n.nspname in ('public', 'extensions')\n ) then\n create function extensions.uuid_generate_v4() returns uuid\n language sql volatile as 'select gen_random_uuid()';\n end if;\nend $$;\n\n-- Make extension functions resolvable unqualified (uuid_generate_v4(), \u2026) on\n-- the current session (migrations run here) and for future connections.\ndo $$\nbegin\n execute 'alter database ' || quote_ident(current_database()) ||\n ' set search_path to \"$user\", public, extensions';\nexception when others then\n -- some engines disallow altering the current database; session SET below still applies\nend $$;\nset search_path to \"$user\", public, extensions;\n\n-- \u2500\u2500 Roles \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ndo $$\nbegin\n if not exists (select from pg_roles where rolname = 'anon') then\n create role anon nologin noinherit;\n end if;\n if not exists (select from pg_roles where rolname = 'authenticated') then\n create role authenticated nologin noinherit;\n end if;\n if not exists (select from pg_roles where rolname = 'service_role') then\n create role service_role nologin noinherit bypassrls;\n end if;\nend $$;\n\ngrant usage on schema extensions to anon, authenticated, service_role;\nalter role anon set search_path to \"$user\", public, extensions;\nalter role authenticated set search_path to \"$user\", public, extensions;\nalter role service_role set search_path to \"$user\", public, extensions;\n\ngrant usage on schema public to anon, authenticated, service_role;\ngrant all on all tables in schema public to anon, authenticated, service_role;\ngrant all on all sequences in schema public to anon, authenticated, service_role;\ngrant execute on all functions in schema public to anon, authenticated, service_role;\n\nalter default privileges in schema public\n grant all on tables to anon, authenticated, service_role;\nalter default privileges in schema public\n grant all on sequences to anon, authenticated, service_role;\nalter default privileges in schema public\n grant execute on functions to anon, authenticated, service_role;\n\n-- \u2500\u2500 Auth schema (GoTrue-compatible subset) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists auth;\n\ncreate table if not exists auth.users (\n instance_id uuid default '00000000-0000-0000-0000-000000000000',\n id uuid primary key default gen_random_uuid(),\n aud text default 'authenticated',\n role text default 'authenticated',\n email text unique,\n encrypted_password text,\n email_confirmed_at timestamptz,\n invited_at timestamptz,\n confirmation_token text default '',\n confirmation_sent_at timestamptz,\n recovery_token text default '',\n recovery_sent_at timestamptz,\n email_change_token_new text default '',\n email_change text default '',\n email_change_sent_at timestamptz,\n email_change_token_current text default '',\n email_change_confirm_status smallint default 0,\n last_sign_in_at timestamptz,\n raw_app_meta_data jsonb default '{}'::jsonb,\n raw_user_meta_data jsonb default '{}'::jsonb,\n is_super_admin boolean default false,\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n phone text unique,\n phone_confirmed_at timestamptz,\n phone_change text default '',\n phone_change_token text default '',\n phone_change_sent_at timestamptz,\n reauthentication_token text default '',\n reauthentication_sent_at timestamptz,\n banned_until timestamptz,\n deleted_at timestamptz,\n is_anonymous boolean default false\n);\n\ncreate table if not exists auth.refresh_tokens (\n id bigint generated by default as identity primary key,\n token text unique not null,\n user_id uuid not null references auth.users(id) on delete cascade,\n parent text,\n session_id uuid,\n revoked boolean default false,\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate index if not exists refresh_tokens_user_id_idx on auth.refresh_tokens(user_id);\n\ncreate table if not exists auth.one_time_tokens (\n id uuid primary key default gen_random_uuid(),\n user_id uuid references auth.users(id) on delete cascade,\n email text not null,\n token_type text not null, -- otp | magiclink | recovery\n token text not null,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ncreate table if not exists auth.identities (\n id uuid primary key default gen_random_uuid(),\n user_id uuid not null references auth.users(id) on delete cascade,\n provider text not null,\n provider_id text not null,\n identity_data jsonb default '{}'::jsonb,\n last_sign_in_at timestamptz default now(),\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n unique (provider, provider_id)\n);\n\n-- OAuth / PKCE flow state, bridging /authorize \u2192 provider \u2192 /callback \u2192 exchange\ncreate table if not exists auth.flow_state (\n id uuid primary key default gen_random_uuid(),\n provider text not null,\n provider_state text not null unique,\n redirect_to text,\n code_challenge text,\n code_challenge_method text,\n auth_code text unique,\n user_id uuid references auth.users(id) on delete cascade,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ncreate table if not exists auth.mfa_factors (\n id uuid primary key default gen_random_uuid(),\n user_id uuid not null references auth.users(id) on delete cascade,\n friendly_name text,\n factor_type text not null default 'totp',\n status text not null default 'unverified', -- unverified | verified\n secret text,\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate table if not exists auth.mfa_challenges (\n id uuid primary key default gen_random_uuid(),\n factor_id uuid not null references auth.mfa_factors(id) on delete cascade,\n verified_at timestamptz,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ngrant usage on schema auth to anon, authenticated, service_role;\n\ncreate or replace function auth.jwt() returns jsonb\nlanguage sql stable as $$\n select coalesce(\n nullif(current_setting('request.jwt.claims', true), ''),\n '{}'\n )::jsonb\n$$;\n\ncreate or replace function auth.uid() returns uuid\nlanguage sql stable as $$\n select nullif(auth.jwt() ->> 'sub', '')::uuid\n$$;\n\ncreate or replace function auth.role() returns text\nlanguage sql stable as $$\n select coalesce(auth.jwt() ->> 'role', 'anon')\n$$;\n\ncreate or replace function auth.email() returns text\nlanguage sql stable as $$\n select auth.jwt() ->> 'email'\n$$;\n\ngrant execute on function auth.jwt(), auth.uid(), auth.role(), auth.email()\n to anon, authenticated, service_role;\n\n-- \u2500\u2500 Storage schema (storage-api-compatible subset) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists storage;\n\ncreate table if not exists storage.buckets (\n id text primary key,\n name text not null unique,\n owner uuid,\n public boolean default false,\n file_size_limit bigint,\n allowed_mime_types text[],\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate table if not exists storage.objects (\n id uuid primary key default gen_random_uuid(),\n bucket_id text not null references storage.buckets(id),\n name text not null,\n owner uuid,\n version text,\n metadata jsonb default '{}'::jsonb,\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n last_accessed_at timestamptz default now(),\n unique (bucket_id, name)\n);\n\ncreate index if not exists objects_bucket_name_idx on storage.objects(bucket_id, name);\n\ngrant usage on schema storage to anon, authenticated, service_role;\ngrant select on storage.buckets to anon, authenticated, service_role;\ngrant all on storage.buckets to service_role;\ngrant all on storage.objects to anon, authenticated, service_role;\n\ncreate or replace function storage.foldername(name text) returns text[]\nlanguage sql immutable as $$\n select (string_to_array(name, '/'))[1 : array_length(string_to_array(name, '/'), 1) - 1]\n$$;\n\ncreate or replace function storage.filename(name text) returns text\nlanguage sql immutable as $$\n select (string_to_array(name, '/'))[array_length(string_to_array(name, '/'), 1)]\n$$;\n\ncreate or replace function storage.extension(name text) returns text\nlanguage sql immutable as $$\n select reverse(split_part(reverse(storage.filename(name)), '.', 1))\n$$;\n\nalter table storage.objects enable row level security;\n\n-- Dev-friendly default policies. Replace them in your migrations to lock down.\ndo $$\nbegin\n if not exists (select from pg_policies where schemaname = 'storage' and tablename = 'objects' and policyname = 'tinbase_authenticated_all') then\n create policy tinbase_authenticated_all on storage.objects\n for all to authenticated using (true) with check (true);\n end if;\n if not exists (select from pg_policies where schemaname = 'storage' and tablename = 'objects' and policyname = 'tinbase_public_read') then\n create policy tinbase_public_read on storage.objects\n for select to anon\n using (bucket_id in (select id from storage.buckets where public));\n end if;\nend $$;\n\n-- \u2500\u2500 Migration bookkeeping (same table the Supabase CLI uses) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists supabase_migrations;\n\ncreate table if not exists supabase_migrations.schema_migrations (\n version text primary key,\n name text,\n statements text[],\n applied_at timestamptz default now()\n);\n\ncreate table if not exists supabase_migrations.seed_files (\n path text primary key,\n hash text,\n applied_at timestamptz default now()\n);\n\n-- \u2500\u2500 Realtime CDC plumbing \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists tinbase;\n\ncreate or replace function tinbase.cdc_notify() returns trigger\nlanguage plpgsql security definer as $$\ndeclare\n payload text;\nbegin\n payload := json_build_object(\n 'schema', TG_TABLE_SCHEMA,\n 'table', TG_TABLE_NAME,\n 'type', TG_OP,\n 'commit_timestamp', to_char(now() at time zone 'utc', 'YYYY-MM-DD\"T\"HH24:MI:SS.MS\"Z\"'),\n 'record', case when TG_OP in ('INSERT', 'UPDATE') then row_to_json(NEW) else null end,\n 'old_record', case when TG_OP in ('UPDATE', 'DELETE') then row_to_json(OLD) else null end\n )::text;\n -- pg_notify payloads are capped at ~8kB; degrade like Supabase does.\n if octet_length(payload) > 7500 then\n payload := json_build_object(\n 'schema', TG_TABLE_SCHEMA,\n 'table', TG_TABLE_NAME,\n 'type', TG_OP,\n 'commit_timestamp', to_char(now() at time zone 'utc', 'YYYY-MM-DD\"T\"HH24:MI:SS.MS\"Z\"'),\n 'record', null,\n 'old_record', null,\n 'errors', json_build_array('Payload too large')\n )::text;\n end if;\n perform pg_notify('tinbase_cdc', payload);\n return coalesce(NEW, OLD);\nend $$;\n\n-- \u2500\u2500 Realtime Authorization + broadcast-from-database \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n-- Mirrors Supabase Realtime: developers write RLS policies on\n-- realtime.messages using realtime.topic(); a SELECT policy grants a private\n-- channel's subscribers the right to *receive*, an INSERT policy the right to\n-- *broadcast*. realtime.send() lets the database push a broadcast to a topic.\ncreate schema if not exists realtime;\n\ncreate table if not exists realtime.messages (\n id uuid not null default gen_random_uuid(),\n topic text not null,\n extension text not null,\n event text,\n payload jsonb,\n private boolean default false,\n inserted_at timestamptz not null default now(),\n updated_at timestamptz not null default now(),\n primary key (id)\n);\nalter table realtime.messages enable row level security;\n\ngrant usage on schema realtime to anon, authenticated, service_role;\ngrant all on realtime.messages to anon, authenticated, service_role;\n\n-- the topic currently being authorized/broadcast (set per operation)\ncreate or replace function realtime.topic() returns text\n language sql stable as $$ select nullif(current_setting('realtime.topic', true), '') $$;\n\n-- push a broadcast message to all subscribers of <topic> from SQL / triggers.\n-- Delivered over the websocket by the in-process realtime engine, which listens\n-- on the 'tinbase_realtime_broadcast' channel.\ncreate or replace function realtime.send(payload jsonb, event text, topic text, private boolean default true)\n returns void language plpgsql security definer as $$\nbegin\n perform pg_notify(\n 'tinbase_realtime_broadcast',\n json_build_object('topic', topic, 'event', event, 'payload', payload, 'private', private)::text\n );\nexception when others then\n -- never let a notify failure abort the caller's transaction\n null;\nend $$;\n\ngrant execute on function realtime.topic() to anon, authenticated, service_role;\ngrant execute on function realtime.send(jsonb, text, text, boolean) to anon, authenticated, service_role;\n";
@@ -217,6 +217,7 @@ alter default privileges in schema public
217
217
  create schema if not exists auth;
218
218
 
219
219
  create table if not exists auth.users (
220
+ instance_id uuid default '00000000-0000-0000-0000-000000000000',
220
221
  id uuid primary key default gen_random_uuid(),
221
222
  aud text default 'authenticated',
222
223
  role text default 'authenticated',
@@ -224,8 +225,15 @@ create table if not exists auth.users (
224
225
  encrypted_password text,
225
226
  email_confirmed_at timestamptz,
226
227
  invited_at timestamptz,
227
- confirmation_token text,
228
- recovery_token text,
228
+ confirmation_token text default '',
229
+ confirmation_sent_at timestamptz,
230
+ recovery_token text default '',
231
+ recovery_sent_at timestamptz,
232
+ email_change_token_new text default '',
233
+ email_change text default '',
234
+ email_change_sent_at timestamptz,
235
+ email_change_token_current text default '',
236
+ email_change_confirm_status smallint default 0,
229
237
  last_sign_in_at timestamptz,
230
238
  raw_app_meta_data jsonb default '{}'::jsonb,
231
239
  raw_user_meta_data jsonb default '{}'::jsonb,
@@ -234,6 +242,11 @@ create table if not exists auth.users (
234
242
  updated_at timestamptz default now(),
235
243
  phone text unique,
236
244
  phone_confirmed_at timestamptz,
245
+ phone_change text default '',
246
+ phone_change_token text default '',
247
+ phone_change_sent_at timestamptz,
248
+ reauthentication_token text default '',
249
+ reauthentication_sent_at timestamptz,
237
250
  banned_until timestamptz,
238
251
  deleted_at timestamptz,
239
252
  is_anonymous boolean default false
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/db/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8HpC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoW5B,CAAA"}
1
+ {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/db/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8HpC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiX5B,CAAA"}
@@ -1,5 +1,10 @@
1
1
  import { BOOTSTRAP_SQL, MINIMAL_BOOTSTRAP_SQL } from './bootstrap.js';
2
- import { PGMQ_SQL, CRON_SQL } from './emulated.js';
2
+ import { PGMQ_SQL, CRON_SQL, NET_SQL, EXT_COMPAT_SQL, VAULT_SQL } from './emulated.js';
3
+ import { rewriteMigrationSql } from './sql-compat.js';
4
+ // tinbase's default session search_path (matches bootstrap + Supabase's, with
5
+ // the extensions schema on the path). Reset to this before each migration so a
6
+ // migration's own `SET search_path` can't leak across our single connection.
7
+ const DEFAULT_SEARCH_PATH_SQL = `set search_path to "$user", public, extensions`;
3
8
  import { createPgliteEngine } from './pglite-engine.js';
4
9
  export class Database {
5
10
  engine;
@@ -21,10 +26,13 @@ export class Database {
21
26
  }
22
27
  else {
23
28
  await engine.exec(BOOTSTRAP_SQL);
24
- // emulated extensions (pgmq queues, cron) — pure SQL, so pgmq.*/cron.* work
25
- // with no C extension on either engine
29
+ // emulated extensions (pgmq queues, cron, pg_net) — pure SQL, so
30
+ // pgmq.*/cron.*/net.* work with no C extension on either engine
26
31
  await engine.exec(PGMQ_SQL);
27
32
  await engine.exec(CRON_SQL);
33
+ await engine.exec(NET_SQL);
34
+ await engine.exec(EXT_COMPAT_SQL);
35
+ await engine.exec(VAULT_SQL);
28
36
  }
29
37
  return new Database(engine);
30
38
  }
@@ -57,7 +65,13 @@ export class Database {
57
65
  if (seen.rows.length > 0)
58
66
  continue;
59
67
  await this.engine.transaction(async (tx) => {
60
- await tx.exec(m.sql);
68
+ // The Supabase CLI applies each migration on a fresh connection, so a
69
+ // top-level `SET search_path TO ''` in one file never leaks to the next.
70
+ // tinbase runs every migration on one connection, so reset to the
71
+ // default first — otherwise a hardened migration's search_path change
72
+ // breaks unqualified calls (e.g. gen_random_bytes) in later files.
73
+ await tx.exec(DEFAULT_SEARCH_PATH_SQL);
74
+ await tx.exec(rewriteMigrationSql(m.sql));
61
75
  await tx.query(`insert into supabase_migrations.schema_migrations (version, name, statements)
62
76
  values ($1, $2, $3)`, [version, m.name, [m.sql]]);
63
77
  });
@@ -68,15 +82,20 @@ export class Database {
68
82
  const seen = await this.engine.query(`select 1 from supabase_migrations.seed_files where path = 'supabase/seed.sql' and hash = $1`, [hash]);
69
83
  if (seen.rows.length === 0) {
70
84
  await this.engine.transaction(async (tx) => {
71
- await tx.exec(seedSql);
85
+ await tx.exec(DEFAULT_SEARCH_PATH_SQL);
86
+ await tx.exec(rewriteMigrationSql(seedSql));
72
87
  await tx.query(`insert into supabase_migrations.seed_files (path, hash) values ('supabase/seed.sql', $1)
73
88
  on conflict (path) do update set hash = excluded.hash, applied_at = now()`, [hash]);
74
89
  });
75
90
  applied.push('seed.sql');
76
91
  }
77
92
  }
78
- if (applied.length > 0)
93
+ if (applied.length > 0) {
94
+ // a migration/seed may have left the session search_path at '' — restore
95
+ // the default so runtime queries resolve extension functions unqualified
96
+ await this.engine.exec(DEFAULT_SEARCH_PATH_SQL);
79
97
  this.invalidateSchemaCache();
98
+ }
80
99
  return applied;
81
100
  }
82
101
  async listAppliedMigrations() {
@@ -1 +1 @@
1
- {"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/db/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA;QAC7D,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;QAC5C,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;IAClD,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;IAC9D,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAA;AAC1C,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAA;AAC3C,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,IAAY;IACnC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;IACpF,OAAO,CAAC,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACzF,CAAC"}
@@ -8,5 +8,8 @@
8
8
  * `pgmq.send(...)`, `pgmq.read(...)`, `select cron.schedule(...)` etc. behave
9
9
  * the same from the client's and a migration's point of view.
10
10
  */
11
- export declare const PGMQ_SQL = "\ncreate schema if not exists pgmq;\ngrant usage on schema pgmq to anon, authenticated, service_role;\n\ndo $$ begin\n if not exists (select 1 from pg_type t join pg_namespace n on n.oid = t.typnamespace\n where t.typname = 'message_record' and n.nspname = 'pgmq') then\n create type pgmq.message_record as (\n msg_id bigint, read_ct integer, enqueued_at timestamptz, vt timestamptz, message jsonb\n );\n end if;\nend $$;\n\ncreate or replace function pgmq.create(queue_name text) returns void language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\nbegin\n execute format('create table if not exists pgmq.%I (\n msg_id bigint generated always as identity primary key,\n read_ct integer not null default 0,\n enqueued_at timestamptz not null default now(),\n vt timestamptz not null default now(),\n message jsonb)', 'q_' || queue_name);\n execute format('create table if not exists pgmq.%I (\n msg_id bigint primary key, read_ct integer not null default 0,\n enqueued_at timestamptz not null, archived_at timestamptz not null default now(),\n vt timestamptz, message jsonb)', 'a_' || queue_name);\nend $pgmq$;\n\ncreate or replace function pgmq.send(queue_name text, msg jsonb, delay integer default 0)\nreturns bigint language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\ndeclare id bigint;\nbegin\n perform pgmq.create(queue_name);\n execute format('insert into pgmq.%I (vt, message) values (now() + make_interval(secs => $1), $2) returning msg_id', 'q_' || queue_name)\n into id using delay, msg;\n return id;\nend $pgmq$;\n\ncreate or replace function pgmq.read(queue_name text, vt integer, qty integer)\nreturns setof pgmq.message_record language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\nbegin\n return query execute format($fmt$\n with cte as (\n select msg_id from pgmq.%I where vt <= now() order by msg_id limit $1 for update skip locked\n )\n update pgmq.%I m set vt = now() + make_interval(secs => $2), read_ct = read_ct + 1\n from cte where m.msg_id = cte.msg_id\n returning m.msg_id, m.read_ct, m.enqueued_at, m.vt, m.message\n $fmt$, 'q_' || queue_name, 'q_' || queue_name) using qty, vt;\nend $pgmq$;\n\ncreate or replace function pgmq.pop(queue_name text)\nreturns setof pgmq.message_record language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\nbegin\n return query execute format($fmt$\n with cte as (select msg_id from pgmq.%I where vt <= now() order by msg_id limit 1 for update skip locked)\n delete from pgmq.%I m using cte where m.msg_id = cte.msg_id\n returning m.msg_id, m.read_ct, m.enqueued_at, m.vt, m.message\n $fmt$, 'q_' || queue_name, 'q_' || queue_name);\nend $pgmq$;\n\ncreate or replace function pgmq.delete(queue_name text, msg_id bigint)\nreturns boolean language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\ndeclare n integer;\nbegin\n execute format('delete from pgmq.%I where msg_id = $1', 'q_' || queue_name) using msg_id;\n get diagnostics n = row_count;\n return n > 0;\nend $pgmq$;\n\ncreate or replace function pgmq.archive(queue_name text, msg_id bigint)\nreturns boolean language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\ndeclare n integer;\nbegin\n execute format($fmt$\n with del as (delete from pgmq.%I where msg_id = $1 returning *)\n insert into pgmq.%I (msg_id, read_ct, enqueued_at, vt, message)\n select msg_id, read_ct, enqueued_at, vt, message from del\n $fmt$, 'q_' || queue_name, 'a_' || queue_name) using msg_id;\n get diagnostics n = row_count;\n return n > 0;\nend $pgmq$;\n\ngrant execute on all functions in schema pgmq to anon, authenticated, service_role;\n";
11
+ export declare const PGMQ_SQL = "\ncreate schema if not exists pgmq;\ngrant usage on schema pgmq to anon, authenticated, service_role;\n\ndo $$ begin\n if not exists (select 1 from pg_type t join pg_namespace n on n.oid = t.typnamespace\n where t.typname = 'message_record' and n.nspname = 'pgmq') then\n create type pgmq.message_record as (\n msg_id bigint, read_ct integer, enqueued_at timestamptz, vt timestamptz, message jsonb\n );\n end if;\nend $$;\n\ncreate or replace function pgmq.create(queue_name text) returns void language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\nbegin\n execute format('create table if not exists pgmq.%I (\n msg_id bigint generated always as identity primary key,\n read_ct integer not null default 0,\n enqueued_at timestamptz not null default now(),\n vt timestamptz not null default now(),\n message jsonb)', 'q_' || queue_name);\n execute format('create table if not exists pgmq.%I (\n msg_id bigint primary key, read_ct integer not null default 0,\n enqueued_at timestamptz not null, archived_at timestamptz not null default now(),\n vt timestamptz, message jsonb)', 'a_' || queue_name);\nend $pgmq$;\n\ncreate or replace function pgmq.send(queue_name text, msg jsonb, delay integer default 0)\nreturns bigint language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\ndeclare id bigint;\nbegin\n perform pgmq.create(queue_name);\n execute format('insert into pgmq.%I (vt, message) values (now() + make_interval(secs => $1), $2) returning msg_id', 'q_' || queue_name)\n into id using delay, msg;\n return id;\nend $pgmq$;\n\ncreate or replace function pgmq.read(queue_name text, vt integer, qty integer)\nreturns setof pgmq.message_record language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\nbegin\n return query execute format($fmt$\n with cte as (\n select msg_id from pgmq.%I where vt <= now() order by msg_id limit $1 for update skip locked\n )\n update pgmq.%I m set vt = now() + make_interval(secs => $2), read_ct = read_ct + 1\n from cte where m.msg_id = cte.msg_id\n returning m.msg_id, m.read_ct, m.enqueued_at, m.vt, m.message\n $fmt$, 'q_' || queue_name, 'q_' || queue_name) using qty, vt;\nend $pgmq$;\n\ncreate or replace function pgmq.pop(queue_name text)\nreturns setof pgmq.message_record language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\nbegin\n return query execute format($fmt$\n with cte as (select msg_id from pgmq.%I where vt <= now() order by msg_id limit 1 for update skip locked)\n delete from pgmq.%I m using cte where m.msg_id = cte.msg_id\n returning m.msg_id, m.read_ct, m.enqueued_at, m.vt, m.message\n $fmt$, 'q_' || queue_name, 'q_' || queue_name);\nend $pgmq$;\n\ncreate or replace function pgmq.delete(queue_name text, msg_id bigint)\nreturns boolean language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\ndeclare n integer;\nbegin\n execute format('delete from pgmq.%I where msg_id = $1', 'q_' || queue_name) using msg_id;\n get diagnostics n = row_count;\n return n > 0;\nend $pgmq$;\n\ncreate or replace function pgmq.archive(queue_name text, msg_id bigint)\nreturns boolean language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\ndeclare n integer;\nbegin\n execute format($fmt$\n with del as (delete from pgmq.%I where msg_id = $1 returning *)\n insert into pgmq.%I (msg_id, read_ct, enqueued_at, vt, message)\n select msg_id, read_ct, enqueued_at, vt, message from del\n $fmt$, 'q_' || queue_name, 'a_' || queue_name) using msg_id;\n get diagnostics n = row_count;\n return n > 0;\nend $pgmq$;\n\ncreate or replace function pgmq.drop_queue(queue_name text) returns boolean language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\nbegin\n execute format('drop table if exists pgmq.%I', 'q_' || queue_name);\n execute format('drop table if exists pgmq.%I', 'a_' || queue_name);\n return true;\nend $pgmq$;\n\ncreate or replace function pgmq.purge_queue(queue_name text) returns bigint language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\ndeclare n bigint;\nbegin\n execute format('delete from pgmq.%I', 'q_' || queue_name);\n get diagnostics n = row_count;\n return n;\nend $pgmq$;\n\ncreate or replace function pgmq.list_queues()\nreturns table(queue_name text, is_partitioned boolean, is_unlogged boolean, created_at timestamptz)\nlanguage sql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\n select substring(tablename from 3), false, false, now()\n from pg_tables where schemaname = 'pgmq' and left(tablename, 2) = 'q_';\n$pgmq$;\n\ngrant execute on all functions in schema pgmq to anon, authenticated, service_role;\n";
12
12
  export declare const CRON_SQL = "\ncreate schema if not exists cron;\ngrant usage on schema cron to service_role, authenticated;\n\ncreate table if not exists cron.job (\n jobid bigint generated always as identity primary key,\n schedule text not null,\n command text not null,\n jobname text unique,\n active boolean not null default true,\n created_at timestamptz not null default now()\n);\n\ncreate table if not exists cron.job_run_details (\n runid bigint generated always as identity primary key,\n jobid bigint,\n command text,\n status text,\n return_message text,\n start_time timestamptz,\n end_time timestamptz\n);\n\ncreate or replace function cron.schedule(job_name text, schedule text, command text)\nreturns bigint language plpgsql security definer set search_path = cron, pg_catalog, public as $cron$\ndeclare id bigint;\nbegin\n insert into cron.job (jobname, schedule, command) values (job_name, schedule, command)\n on conflict (jobname) do update set schedule = excluded.schedule, command = excluded.command, active = true\n returning jobid into id;\n return id;\nend $cron$;\n\ncreate or replace function cron.schedule(schedule text, command text)\nreturns bigint language plpgsql security definer set search_path = cron, pg_catalog, public as $cron$\nbegin\n return cron.schedule('job_' || floor(extract(epoch from clock_timestamp()) * 1000)::bigint::text, schedule, command);\nend $cron$;\n\ncreate or replace function cron.unschedule(job_name text)\nreturns boolean language plpgsql security definer set search_path = cron, pg_catalog, public as $cron$\ndeclare n integer;\nbegin\n delete from cron.job where jobname = job_name;\n get diagnostics n = row_count;\n return n > 0;\nend $cron$;\n\ncreate or replace function cron.unschedule(job_id bigint)\nreturns boolean language plpgsql security definer set search_path = cron, pg_catalog, public as $cron$\ndeclare n integer;\nbegin\n delete from cron.job where jobid = job_id;\n get diagnostics n = row_count;\n return n > 0;\nend $cron$;\n\ngrant execute on function cron.schedule(text,text,text), cron.schedule(text,text), cron.unschedule(text), cron.unschedule(bigint) to service_role, authenticated;\n";
13
+ export declare const NET_SQL = "\ncreate schema if not exists net;\ngrant usage on schema net to service_role, authenticated;\n\ncreate table if not exists net.http_request_queue (\n id bigint generated always as identity primary key,\n method text not null,\n url text not null,\n headers jsonb not null default '{}'::jsonb,\n body text,\n timeout_milliseconds int not null default 5000,\n created timestamptz not null default now()\n);\n\ncreate table if not exists net._http_response (\n id bigint primary key,\n status_code int,\n content_type text,\n headers jsonb,\n content text,\n timed_out boolean,\n error_msg text,\n created timestamptz not null default now()\n);\ngrant select on net._http_response to service_role, authenticated;\n\n-- fold a jsonb param object into the URL as a query string (pg_net semantics)\ncreate or replace function net._merge_params(url text, params jsonb)\nreturns text language sql immutable as $net$\n select case\n when params is null or params = '{}'::jsonb then url\n else url || (case when position('?' in url) > 0 then '&' else '?' end) ||\n (select string_agg(key || '=' || (value #>> '{}'), '&') from jsonb_each(params))\n end;\n$net$;\n\ncreate or replace function net.http_get(url text, params jsonb default '{}'::jsonb, headers jsonb default '{}'::jsonb, timeout_milliseconds int default 5000)\nreturns bigint language plpgsql security definer set search_path = net, pg_catalog, public as $net$\ndeclare req_id bigint;\nbegin\n insert into net.http_request_queue (method, url, headers, body, timeout_milliseconds)\n values ('GET', net._merge_params(url, params), coalesce(headers, '{}'::jsonb), null, timeout_milliseconds)\n returning id into req_id;\n return req_id;\nend $net$;\n\ncreate or replace function net.http_post(url text, body jsonb default '{}'::jsonb, params jsonb default '{}'::jsonb, headers jsonb default '{}'::jsonb, timeout_milliseconds int default 5000)\nreturns bigint language plpgsql security definer set search_path = net, pg_catalog, public as $net$\ndeclare req_id bigint; hdrs jsonb;\nbegin\n hdrs := coalesce(headers, '{}'::jsonb);\n -- default the content type to JSON, matching pg_net, unless the caller set one\n if not (hdrs ? 'Content-Type' or hdrs ? 'content-type') then\n hdrs := hdrs || jsonb_build_object('Content-Type', 'application/json');\n end if;\n insert into net.http_request_queue (method, url, headers, body, timeout_milliseconds)\n values ('POST', net._merge_params(url, params), hdrs, body::text, timeout_milliseconds)\n returning id into req_id;\n return req_id;\nend $net$;\n\ncreate or replace function net.http_delete(url text, params jsonb default '{}'::jsonb, headers jsonb default '{}'::jsonb, timeout_milliseconds int default 5000)\nreturns bigint language plpgsql security definer set search_path = net, pg_catalog, public as $net$\ndeclare req_id bigint;\nbegin\n insert into net.http_request_queue (method, url, headers, body, timeout_milliseconds)\n values ('DELETE', net._merge_params(url, params), coalesce(headers, '{}'::jsonb), null, timeout_milliseconds)\n returning id into req_id;\n return req_id;\nend $net$;\n\ngrant execute on function net.http_get(text,jsonb,jsonb,int), net.http_post(text,jsonb,jsonb,jsonb,int), net.http_delete(text,jsonb,jsonb,int) to service_role, authenticated;\n";
14
+ export declare const EXT_COMPAT_SQL = "\ncreate schema if not exists extensions;\ndo $ensure_moddatetime$\nbegin\n if not exists (\n select 1 from pg_proc p join pg_namespace n on n.oid = p.pronamespace\n where n.nspname = 'extensions' and p.proname = 'moddatetime'\n ) then\n execute $fn$\n create function extensions.moddatetime() returns trigger language plpgsql as $mod$\n begin\n if TG_NARGS >= 1 then\n NEW := jsonb_populate_record(NEW, jsonb_build_object(TG_ARGV[0], now()));\n end if;\n return NEW;\n end\n $mod$\n $fn$;\n end if;\nend\n$ensure_moddatetime$;\n";
15
+ export declare const VAULT_SQL = "\ncreate schema if not exists vault;\ngrant usage on schema vault to service_role;\n\ncreate table if not exists vault.secrets (\n id uuid primary key default gen_random_uuid(),\n name text unique,\n description text not null default '',\n secret text not null,\n key_id uuid,\n nonce bytea,\n created_at timestamptz not null default now(),\n updated_at timestamptz not null default now()\n);\ngrant select, insert, update, delete on vault.secrets to service_role;\n\ncreate or replace view vault.decrypted_secrets as\n select id, name, description, secret, secret as decrypted_secret, key_id, nonce, created_at, updated_at\n from vault.secrets;\ngrant select on vault.decrypted_secrets to service_role;\n\ncreate or replace function vault.create_secret(new_secret text, new_name text default null, new_description text default '', new_key_id uuid default null)\nreturns uuid language plpgsql security definer set search_path = vault, pg_catalog, public as $vault$\ndeclare rec_id uuid;\nbegin\n insert into vault.secrets (name, description, secret, key_id)\n values (new_name, coalesce(new_description, ''), new_secret, new_key_id)\n returning id into rec_id;\n return rec_id;\nend $vault$;\n\ncreate or replace function vault.update_secret(secret_id uuid, new_secret text default null, new_name text default null, new_description text default null, new_key_id uuid default null)\nreturns void language plpgsql security definer set search_path = vault, pg_catalog, public as $vault$\nbegin\n update vault.secrets set\n secret = coalesce(new_secret, secret),\n name = coalesce(new_name, name),\n description = coalesce(new_description, description),\n key_id = coalesce(new_key_id, key_id),\n updated_at = now()\n where id = secret_id;\nend $vault$;\n\ngrant execute on function vault.create_secret(text,text,text,uuid), vault.update_secret(uuid,text,text,text,uuid) to service_role;\n";
@@ -91,6 +91,28 @@ begin
91
91
  return n > 0;
92
92
  end $pgmq$;
93
93
 
94
+ create or replace function pgmq.drop_queue(queue_name text) returns boolean language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$
95
+ begin
96
+ execute format('drop table if exists pgmq.%I', 'q_' || queue_name);
97
+ execute format('drop table if exists pgmq.%I', 'a_' || queue_name);
98
+ return true;
99
+ end $pgmq$;
100
+
101
+ create or replace function pgmq.purge_queue(queue_name text) returns bigint language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$
102
+ declare n bigint;
103
+ begin
104
+ execute format('delete from pgmq.%I', 'q_' || queue_name);
105
+ get diagnostics n = row_count;
106
+ return n;
107
+ end $pgmq$;
108
+
109
+ create or replace function pgmq.list_queues()
110
+ returns table(queue_name text, is_partitioned boolean, is_unlogged boolean, created_at timestamptz)
111
+ language sql security definer set search_path = pgmq, pg_catalog, public as $pgmq$
112
+ select substring(tablename from 3), false, false, now()
113
+ from pg_tables where schemaname = 'pgmq' and left(tablename, 2) = 'q_';
114
+ $pgmq$;
115
+
94
116
  grant execute on all functions in schema pgmq to anon, authenticated, service_role;
95
117
  `;
96
118
  // ── cron (scheduled jobs) ────────────────────────────────────────────────────
@@ -153,4 +175,161 @@ end $cron$;
153
175
 
154
176
  grant execute on function cron.schedule(text,text,text), cron.schedule(text,text), cron.unschedule(text), cron.unschedule(bigint) to service_role, authenticated;
155
177
  `;
178
+ // pg_net emulation — the `net.http_get/post/delete` SQL surface. The functions
179
+ // only enqueue into net.http_request_queue; the in-process NetService
180
+ // (src/net/service.ts) performs the HTTP and records the reply in
181
+ // net._http_response, exactly like pg_net's background worker. This lets the
182
+ // common Supabase pattern — a cron job that calls net.http_post to hit an Edge
183
+ // Function — run unchanged, with no C extension on either engine.
184
+ export const NET_SQL = `
185
+ create schema if not exists net;
186
+ grant usage on schema net to service_role, authenticated;
187
+
188
+ create table if not exists net.http_request_queue (
189
+ id bigint generated always as identity primary key,
190
+ method text not null,
191
+ url text not null,
192
+ headers jsonb not null default '{}'::jsonb,
193
+ body text,
194
+ timeout_milliseconds int not null default 5000,
195
+ created timestamptz not null default now()
196
+ );
197
+
198
+ create table if not exists net._http_response (
199
+ id bigint primary key,
200
+ status_code int,
201
+ content_type text,
202
+ headers jsonb,
203
+ content text,
204
+ timed_out boolean,
205
+ error_msg text,
206
+ created timestamptz not null default now()
207
+ );
208
+ grant select on net._http_response to service_role, authenticated;
209
+
210
+ -- fold a jsonb param object into the URL as a query string (pg_net semantics)
211
+ create or replace function net._merge_params(url text, params jsonb)
212
+ returns text language sql immutable as $net$
213
+ select case
214
+ when params is null or params = '{}'::jsonb then url
215
+ else url || (case when position('?' in url) > 0 then '&' else '?' end) ||
216
+ (select string_agg(key || '=' || (value #>> '{}'), '&') from jsonb_each(params))
217
+ end;
218
+ $net$;
219
+
220
+ create or replace function net.http_get(url text, params jsonb default '{}'::jsonb, headers jsonb default '{}'::jsonb, timeout_milliseconds int default 5000)
221
+ returns bigint language plpgsql security definer set search_path = net, pg_catalog, public as $net$
222
+ declare req_id bigint;
223
+ begin
224
+ insert into net.http_request_queue (method, url, headers, body, timeout_milliseconds)
225
+ values ('GET', net._merge_params(url, params), coalesce(headers, '{}'::jsonb), null, timeout_milliseconds)
226
+ returning id into req_id;
227
+ return req_id;
228
+ end $net$;
229
+
230
+ create or replace function net.http_post(url text, body jsonb default '{}'::jsonb, params jsonb default '{}'::jsonb, headers jsonb default '{}'::jsonb, timeout_milliseconds int default 5000)
231
+ returns bigint language plpgsql security definer set search_path = net, pg_catalog, public as $net$
232
+ declare req_id bigint; hdrs jsonb;
233
+ begin
234
+ hdrs := coalesce(headers, '{}'::jsonb);
235
+ -- default the content type to JSON, matching pg_net, unless the caller set one
236
+ if not (hdrs ? 'Content-Type' or hdrs ? 'content-type') then
237
+ hdrs := hdrs || jsonb_build_object('Content-Type', 'application/json');
238
+ end if;
239
+ insert into net.http_request_queue (method, url, headers, body, timeout_milliseconds)
240
+ values ('POST', net._merge_params(url, params), hdrs, body::text, timeout_milliseconds)
241
+ returning id into req_id;
242
+ return req_id;
243
+ end $net$;
244
+
245
+ create or replace function net.http_delete(url text, params jsonb default '{}'::jsonb, headers jsonb default '{}'::jsonb, timeout_milliseconds int default 5000)
246
+ returns bigint language plpgsql security definer set search_path = net, pg_catalog, public as $net$
247
+ declare req_id bigint;
248
+ begin
249
+ insert into net.http_request_queue (method, url, headers, body, timeout_milliseconds)
250
+ values ('DELETE', net._merge_params(url, params), coalesce(headers, '{}'::jsonb), null, timeout_milliseconds)
251
+ returning id into req_id;
252
+ return req_id;
253
+ end $net$;
254
+
255
+ grant execute on function net.http_get(text,jsonb,jsonb,int), net.http_post(text,jsonb,jsonb,jsonb,int), net.http_delete(text,jsonb,jsonb,int) to service_role, authenticated;
256
+ `;
257
+ // Small pure-SQL stand-ins for contrib extensions Supabase migrations lean on
258
+ // but which aren't in the PGlite / native builds. `moddatetime` (a BEFORE
259
+ // UPDATE trigger that stamps a timestamp column) is the common one — projects
260
+ // attach it as the updated_at trigger. Created only if absent, so a real
261
+ // extension (where present) still wins.
262
+ export const EXT_COMPAT_SQL = `
263
+ create schema if not exists extensions;
264
+ do $ensure_moddatetime$
265
+ begin
266
+ if not exists (
267
+ select 1 from pg_proc p join pg_namespace n on n.oid = p.pronamespace
268
+ where n.nspname = 'extensions' and p.proname = 'moddatetime'
269
+ ) then
270
+ execute $fn$
271
+ create function extensions.moddatetime() returns trigger language plpgsql as $mod$
272
+ begin
273
+ if TG_NARGS >= 1 then
274
+ NEW := jsonb_populate_record(NEW, jsonb_build_object(TG_ARGV[0], now()));
275
+ end if;
276
+ return NEW;
277
+ end
278
+ $mod$
279
+ $fn$;
280
+ end if;
281
+ end
282
+ $ensure_moddatetime$;
283
+ `;
284
+ // Supabase Vault emulation. Real Vault (supabase_vault + pgsodium) encrypts
285
+ // secrets at rest; we can't ship those C extensions, so this is a dev-only
286
+ // plaintext stand-in with the same surface: vault.secrets, the
287
+ // vault.decrypted_secrets view, and vault.create_secret / update_secret. Enough
288
+ // for migrations and app code that store/read secrets by name to work locally.
289
+ // NOT for production — secrets are stored in cleartext.
290
+ export const VAULT_SQL = `
291
+ create schema if not exists vault;
292
+ grant usage on schema vault to service_role;
293
+
294
+ create table if not exists vault.secrets (
295
+ id uuid primary key default gen_random_uuid(),
296
+ name text unique,
297
+ description text not null default '',
298
+ secret text not null,
299
+ key_id uuid,
300
+ nonce bytea,
301
+ created_at timestamptz not null default now(),
302
+ updated_at timestamptz not null default now()
303
+ );
304
+ grant select, insert, update, delete on vault.secrets to service_role;
305
+
306
+ create or replace view vault.decrypted_secrets as
307
+ select id, name, description, secret, secret as decrypted_secret, key_id, nonce, created_at, updated_at
308
+ from vault.secrets;
309
+ grant select on vault.decrypted_secrets to service_role;
310
+
311
+ create or replace function vault.create_secret(new_secret text, new_name text default null, new_description text default '', new_key_id uuid default null)
312
+ returns uuid language plpgsql security definer set search_path = vault, pg_catalog, public as $vault$
313
+ declare rec_id uuid;
314
+ begin
315
+ insert into vault.secrets (name, description, secret, key_id)
316
+ values (new_name, coalesce(new_description, ''), new_secret, new_key_id)
317
+ returning id into rec_id;
318
+ return rec_id;
319
+ end $vault$;
320
+
321
+ create or replace function vault.update_secret(secret_id uuid, new_secret text default null, new_name text default null, new_description text default null, new_key_id uuid default null)
322
+ returns void language plpgsql security definer set search_path = vault, pg_catalog, public as $vault$
323
+ begin
324
+ update vault.secrets set
325
+ secret = coalesce(new_secret, secret),
326
+ name = coalesce(new_name, name),
327
+ description = coalesce(new_description, description),
328
+ key_id = coalesce(new_key_id, key_id),
329
+ updated_at = now()
330
+ where id = secret_id;
331
+ end $vault$;
332
+
333
+ grant execute on function vault.create_secret(text,text,text,uuid), vault.update_secret(uuid,text,text,text,uuid) to service_role;
334
+ `;
156
335
  //# sourceMappingURL=emulated.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"emulated.js","sourceRoot":"","sources":["../../src/db/emulated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmFvB,CAAA;AAED,gFAAgF;AAChF,MAAM,CAAC,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DvB,CAAA"}
1
+ {"version":3,"file":"emulated.js","sourceRoot":"","sources":["../../src/db/emulated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyGvB,CAAA;AAED,gFAAgF;AAChF,MAAM,CAAC,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DvB,CAAA;AAED,+EAA+E;AAC/E,sEAAsE;AACtE,kEAAkE;AAClE,6EAA6E;AAC7E,+EAA+E;AAC/E,kEAAkE;AAClE,MAAM,CAAC,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwEtB,CAAA;AAED,8EAA8E;AAC9E,0EAA0E;AAC1E,8EAA8E;AAC9E,yEAAyE;AACzE,wCAAwC;AACxC,MAAM,CAAC,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;CAqB7B,CAAA;AAED,4EAA4E;AAC5E,2EAA2E;AAC3E,+DAA+D;AAC/D,gFAAgF;AAChF,+EAA+E;AAC/E,wDAAwD;AACxD,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4CxB,CAAA"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Compatibility rewrites for user migration / seed SQL.
3
+ *
4
+ * tinbase can't install C extensions (pg_cron, pg_net, http, supabase_vault,
5
+ * hypopg, …) into the PGlite or embedded-native Postgres build, and several of
6
+ * them are emulated in pure SQL instead (cron, pg_net, pgmq — see
7
+ * db/emulated.ts). A real Supabase project's first migration typically runs a
8
+ * batch of `CREATE EXTENSION` statements; on stock Postgres a missing one
9
+ * aborts the whole migration with `extension "…" is not available`.
10
+ *
11
+ * `tolerateExtensionStatements` wraps every *top-level* CREATE/DROP EXTENSION
12
+ * statement in a `DO … EXCEPTION WHEN OTHERS` block (the same trick the
13
+ * bootstrap uses for its own extension list), so an unavailable extension is
14
+ * skipped with a NOTICE rather than aborting the migration. Extensions the
15
+ * engine does bundle are still created normally, and the emulated schemas
16
+ * created at bootstrap remain in place.
17
+ *
18
+ * It also strips `CONCURRENTLY` from index statements: tinbase applies each
19
+ * migration inside a transaction (for atomicity + rollback), and
20
+ * `CREATE/DROP INDEX CONCURRENTLY` / `REINDEX … CONCURRENTLY` are illegal in a
21
+ * transaction block. On a single-connection local dev database CONCURRENTLY
22
+ * buys nothing over a plain index, so we drop the keyword — the resulting index
23
+ * is identical.
24
+ *
25
+ * The scan is quote/comment-aware so it never touches these keywords when they
26
+ * appear inside a dollar-quoted function body, a string literal, or a comment.
27
+ */
28
+ /**
29
+ * Rewrite user migration / seed SQL for the local engine: make CREATE/DROP
30
+ * EXTENSION tolerant, and strip CONCURRENTLY from index statements.
31
+ */
32
+ export declare function rewriteMigrationSql(sql: string): string;