postgrest-docs icon indicating copy to clipboard operation
postgrest-docs copied to clipboard

Recommend using views for abstraction, but don't enforce it from the beginning

Open steve-chavez opened this issue 3 years ago • 0 comments

Currently on https://postgrest.org/en/latest/schema_structure.html#schema-isolation

It is recommended that you don’t expose tables on your API schema. Instead expose views and stored procedures which insulate the internal details from the outside world.

We recommend wrapping all tables in views from the get-go, however that has a considerable maintenance impact(more db objects) specially at the beginning of a project. There's nothing wrong in doing:

-- moving a table to a private schema and replacing it by a view
BEGIN;
ALTER TABLE api.projects SET SCHEMA private;
CREATE VIEW api.projects AS SELECT * FROM private.projects;
END;

At later stages of the project if some abstraction is needed.

Most real world cases have a combination of tables and views.

steve-chavez avatar May 04 '22 23:05 steve-chavez