Skip to content

Tables and schema

Every project is a Postgres database. Create tables in the dashboard (table editor or SQL editor), with migrations or through the Management API.

A new table in an exposed schema is unreadable twice over:

  1. RLS is switched on automatically for every CREATE TABLE in public (and api, if you expose it). RLS with no policy means deny all.
  2. No table grants for anon or authenticated. You grant privileges and write policies yourself. See row level security.

Functions follow the same rule: no function is executable by PUBLIC. An RPC becomes callable only after grant execute ... to authenticated (or anon).

Only public is exposed to the REST API by default. In the project’s Data API settings (PATCH /v1/projects/{ref}/config/data-api, field db_schemas) you can expose up to 50 schemas, in this form:

  • public and api;
  • core (shared data model);
  • app_<slug>, lower-case letters, digits and _, at most 40 characters after app_ (one schema per app).
{ "db_schemas": ["app_crm", "core"] }

The order matters: the first schema is the default for requests without an Accept-Profile / Content-Profile header, and a profile outside the list is refused with 406. public does not have to be in the list. Select another schema in the SDK:

const base = createClient({ url, key, db: { schema: "app_crm" } })

Base does not create the schemas or grant access to them: create them in a migration. Until then the advisor reports a warning:

Finding When
exposed_schema_missing the schema does not exist yet
exposed_schema_no_usage nobody can use it: neither anon nor authenticated for public/api, and the role app_<slug> for an app schema
app_schema_shared_with_authenticated / app_schema_shared_with_anon an app schema is open to every signed-in user, or anon holds table privileges (publish data through views)
core_shared_with_api_roles anon or authenticated hold privileges on objects in core
default_profile_not_public (info) the first schema is not public, so requests without a profile header go to it

The schemas auth, storage, realtime, base and extensions can never be exposed. An empty list is rejected.

A project that is only used from the server, or only through Edge Functions, can switch the REST API off:

PATCH /v1/projects/{ref}/config/data-api
{ "enabled": false }

The REST API and transactions then answer 404 with code data_api_disabled, and no PostgREST process runs for the project. Edge Functions, Auth, Storage and Realtime keep working. To switch it back on, send { "enabled": true } or remove the key with { "enabled": null }.

create table public.orders (
id bigint generated by default as identity primary key,
user_id uuid not null default auth.uid(),
total numeric not null,
created_at timestamptz not null default now()
);
create index on public.orders (user_id);
grant select, insert, update, delete on public.orders to authenticated;

Keep schema changes as versioned SQL files and apply them with potalab base db push or the Management API. Pick one path per project. See the CLI.

potalab base gen types turns your schema into a Database type for createClient<Database>(). Nullable columns become | null, columns with defaults are optional on insert, and identity ALWAYS and generated columns are typed never.

The dashboard Advisors page and potalab base lint report tables without RLS, unwrapped auth.uid() calls, missing indexes and more. See row level security.