From 87f883b7932940941dd174fe92c4712a7c7e4d92 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Sat, 11 Apr 2020 17:40:33 -0500 Subject: [PATCH] Add multiple schemas feature --- api.rst | 34 ++++++++++++++++++++++++++++++++++ configuration.rst | 14 +++++++++++++- releases/upcoming.rst | 9 ++++++--- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/api.rst b/api.rst index 88b4134dc..9d06e45c8 100644 --- a/api.rst +++ b/api.rst @@ -1371,6 +1371,8 @@ You can get raw output from a ``text`` column by using ``Accept: text/plain``. This follows the same rules as :ref:`binary_output`. +.. _open-api: + OpenAPI Support =============== @@ -1406,6 +1408,38 @@ You can use a tool like `Swagger UI `_ to create The OpenAPI information can go out of date as the schema changes under a running server. To learn how to refresh the cache see :ref:`schema_reloading`. +.. _multiple-schemas: + +Switching Schemas +================= + +You can switch schemas at runtime with the ``Accept-Profile`` and ``Content-Profile`` headers. You can only switch to a schema that is included in :ref:`db-schema`. +This is useful for **api versioning** and **schema-based multitenancy**. + +The schema to be used can be selected through the ``Accept-Profile`` header for GET or HEAD: + +.. code-block:: http + + GET /items HTTP/1.1 + Accept-Profile: tenant2 + +If you don't specify the ``Accept-Profile`` header, the first schema on :ref:`db-schema` will be used. + +For POST, PATCH, PUT, DELETE you can use the ``Content-Profile`` header for selecting the schema: + +.. code-block:: http + + POST /items HTTP/1.1 + Content-Profile: tenant2 + + {...} + +You can also select the schema for :ref:`s_procs` and :ref:`open-api`. + +.. note:: + + These headers are based on the nascent "Content Negotiation by Profile" spec: https://www.w3.org/TR/dx-prof-conneg + HTTP Logic ========== diff --git a/configuration.rst b/configuration.rst index fe9b9f7f2..35d93d308 100644 --- a/configuration.rst +++ b/configuration.rst @@ -75,7 +75,19 @@ db-schema The database schema to expose to REST clients. Tables, views and stored procedures in this schema will get API endpoints. - This schema gets added to the `search_path `_ of every request. + The chosen schema gets added to the `search_path `_ of every request. Example: + + .. code:: bash + + db-schema = "api" + + You can also specify a list of schemas that can be used for **schema-based multitenancy** and **api versioning** by :ref:`multiple-schemas`. Example: + + .. code:: bash + + db-schema = "tenant1, tenant2" + ##or + ##db-schema = "v1, v2" .. _db-anon-role: diff --git a/releases/upcoming.rst b/releases/upcoming.rst index d896b201b..5fa71b0f2 100644 --- a/releases/upcoming.rst +++ b/releases/upcoming.rst @@ -10,11 +10,14 @@ These are changes yet unreleased. If you'd like to try them out before a new off Added ----- -* Support for the :ref:`on_conflict ` query parameter to UPSERT based on a unique constraint. - |br| -- `@ykst `_ +* Support for :ref:`multiple-schemas` at runtime. + |br| -- `@steve-chavez `_, `@mahmoudkassem `_ * Support for :ref:`planned_count` and :ref:`estimated_count`. - |br| -- `@steve-chavez `_ + |br| -- `@steve-chavez `_, `@LorenzHenk `_ + +* Support for the :ref:`on_conflict ` query parameter to UPSERT based on a unique constraint. + |br| -- `@ykst `_ * Support for :ref:`Resource Embedding Disambiguation `. |br| -- `@steve-chavez `_