mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-24 16:03:37 +03:00
e3d8a721ee
GitOrigin-RevId: f0526f9666c3986d8e3b374556859043f10dbe8d
104 lines
2.8 KiB
ReStructuredText
104 lines
2.8 KiB
ReStructuredText
.. meta::
|
|
:description: Hasura PG dump API reference
|
|
:keywords: hasura, docs, PG dump API, API reference
|
|
|
|
.. _pg_dump_api_reference:
|
|
|
|
PG Dump API Reference
|
|
=====================
|
|
|
|
.. contents:: Table of contents
|
|
:backlinks: none
|
|
:depth: 1
|
|
:local:
|
|
|
|
Introduction
|
|
------------
|
|
|
|
The PG Dump API is an admin-only endpoint that can be used to execute ``pg_dump`` on the
|
|
Postgres instance that Hasura is configured with.
|
|
|
|
The primary motive of this API is to provide convenience methods to initialise migrations from an
|
|
existing Hasura instance. But the functionality can be later expanded to do other things
|
|
such as taking a data dump etc.
|
|
|
|
Endpoint
|
|
--------
|
|
|
|
All requests are ``POST`` requests to the ``/v1alpha1/pg_dump`` endpoint.
|
|
|
|
API Spec
|
|
--------
|
|
|
|
Request
|
|
^^^^^^^
|
|
|
|
.. code-block:: http
|
|
|
|
POST /v1alpha1/pg_dump HTTP/1.1
|
|
Content-Type: application/json
|
|
X-Hasura-Role: admin
|
|
|
|
{
|
|
"opts": ["-O", "-x", "--schema-only", "--schema", "public"],
|
|
"clean_output": true
|
|
}
|
|
|
|
- ``opts``: Arguments to be passed to the ``pg_dump`` tool. Represented as array
|
|
of strings. The underlying command that is executed is:
|
|
|
|
.. code-block:: bash
|
|
|
|
pg_dump $DATABASE_URL $OPTS -f $FILENAME
|
|
|
|
- ``clean_output``: When this optional argument is set to ``true``, the output SQL from
|
|
the command is cleaned to remove the following:
|
|
|
|
- SQL front matter, like SET statements.
|
|
- ``CREATE SCHEMA public``.
|
|
- ``COMMENT ON SCHEMA public is 'standard public schema'``;
|
|
- Comments (``--``) and empty newlines.
|
|
- Postgres triggers created by Hasura for event triggers.
|
|
|
|
|
|
Sample response
|
|
^^^^^^^^^^^^^^^
|
|
|
|
.. code-block:: http
|
|
|
|
HTTP/1.1 200 OK
|
|
Content-Type: application/sql
|
|
|
|
SET check_function_bodies = false;
|
|
CREATE TABLE public.author (
|
|
id integer NOT NULL,
|
|
name text NOT NULL
|
|
);
|
|
CREATE SEQUENCE public.author_id_seq
|
|
AS integer
|
|
START WITH 1
|
|
INCREMENT BY 1
|
|
NO MINVALUE
|
|
NO MAXVALUE
|
|
CACHE 1;
|
|
ALTER SEQUENCE public.author_id_seq OWNED BY public.author.id;
|
|
ALTER TABLE ONLY public.author ALTER COLUMN id SET DEFAULT nextval('public.author_id_seq'::regclass);
|
|
|
|
Disabling PG Dump API
|
|
---------------------
|
|
|
|
Since this API can be used to dump all the Postgres data and schema, it can be
|
|
disabled, especially in production deployments.
|
|
|
|
The ``enabled-apis`` flag or the ``HASURA_GRAPHQL_ENABLED_APIS`` env var can be used to
|
|
enable/disable this API. By default, The PG DumpAPI is enabled. To disable it, you need to explicitly
|
|
state that this API is not enabled. i.e. remove it from the list of enabled APIs.
|
|
|
|
.. code-block:: bash
|
|
|
|
# enable only graphql & metadata apis, disable pgdump
|
|
--enabled-apis="graphql,metadata"
|
|
HASURA_GRAPHQL_ENABLED_APIS="graphql,metadata"
|
|
|
|
See :ref:`server_flag_reference` for info on setting the above flag/env var.
|