### Install Dependencies with npm Source: https://github.com/supabase/postgres-meta/blob/master/CONTRIBUTING.md Installs project dependencies using npm. This is a common first step for setting up a development environment. ```bash npm install ``` -------------------------------- ### Start Local Services with Docker Compose Source: https://github.com/supabase/postgres-meta/blob/master/CONTRIBUTING.md Starts the necessary services for local development using Docker Compose. This command is essential for running tests and developing against a local database. ```bash docker compose up ``` -------------------------------- ### Run Development Server and Tests Source: https://github.com/supabase/postgres-meta/blob/master/README.md These commands are used for local development and testing of the postgres-meta project. `npm run dev` starts the development server with hot-reloading. `npm run test` runs the test suite, and `npm run test -u` is used to update test snapshots after making changes. ```bash npm run dev ``` ```bash npm run test ``` ```bash npm run test -u ``` -------------------------------- ### Run Project Tests Source: https://github.com/supabase/postgres-meta/blob/master/CONTRIBUTING.md Executes the project's test suite. This command is used both for verifying changes during development and for ensuring code stability. ```bash npm run test:run ``` -------------------------------- ### Pull and Use Canary Docker Image Source: https://github.com/supabase/postgres-meta/blob/master/CONTRIBUTING.md Demonstrates how to pull a canary Docker image for testing changes that impact other services. It includes pulling the image and setting a version file. ```bash docker pull supabase/postgres-meta:canary-pr-123-abc1234 echo "canary-pr-123-abc1234" > supabase/.temp/pgmeta-version ``` -------------------------------- ### Configure Postgres Meta Environment Variables Source: https://github.com/supabase/postgres-meta/blob/master/README.md These environment variables are required to run the postgres-meta service. They define the host, port, and database connection details for both the API and the PostgreSQL database it manages. Ensure these are set correctly in your environment before running the application. ```bash PG_META_HOST="0.0.0.0" PG_META_PORT=8080 PG_META_DB_HOST="postgres" PG_META_DB_NAME="postgres" PG_META_DB_USER="postgres" PG_META_DB_PORT=5432 PG_META_DB_PASSWORD="postgres" ``` -------------------------------- ### Query API Source: https://github.com/supabase/postgres-meta/blob/master/README.md Endpoints for executing, formatting, parsing, and explaining SQL queries. ```APIDOC ## POST /query ### Description Executes a SQL query against the database. ### Method POST ### Endpoint /query ### Parameters #### Request Body - **query** (string) - Required - The SQL query to execute. - **params** (array) - Optional - Parameters for the query. ### Request Example ```json { "query": "SELECT * FROM users WHERE id = $1", "params": [1] } ``` ### Response #### Success Response (200) - **results** (array) - The results of the query. - **fields** (array) - The fields returned by the query. #### Response Example ```json { "results": [ { "id": 1, "name": "John Doe" } ], "fields": [ {"name": "id", "type": "integer"}, {"name": "name", "type": "text"} ] } ``` ## POST /format ### Description Formats a SQL query. ### Method POST ### Endpoint /format ### Parameters #### Request Body - **query** (string) - Required - The SQL query to format. ### Request Example ```json { "query": "select * from users" } ``` ### Response #### Success Response (200) - **formatted_query** (string) - The formatted SQL query. #### Response Example ```json { "formatted_query": "SELECT * FROM users" } ``` ## POST /parse ### Description Parses a SQL query into an Abstract Syntax Tree (AST). ### Method POST ### Endpoint /parse ### Parameters #### Request Body - **query** (string) - Required - The SQL query to parse. ### Request Example ```json { "query": "SELECT * FROM users" } ``` ### Response #### Success Response (200) - **ast** (object) - The AST representation of the SQL query. #### Response Example ```json { "ast": { "type": "SelectStatement", "select_list": [ { "type": "SelectExpression", "expression": { "type": "Identifier", "value": "*" } } ], "from_clause": [ { "type": "Table", "name": { "type": "Identifier", "value": "users" } } ] } } ``` ## POST /explain ### Description Explains a SQL query. ### Method POST ### Endpoint /explain ### Parameters #### Request Body - **query** (string) - Required - The SQL query to explain. ### Request Example ```json { "query": "SELECT * FROM users" } ``` ### Response #### Success Response (200) - **explanation** (string) - The explanation of the SQL query. #### Response Example ```json { "explanation": "Seq Scan on users" } ``` ``` -------------------------------- ### Tables API Source: https://github.com/supabase/postgres-meta/blob/master/README.md Endpoints for managing database tables, including listing, creating, altering, and dropping tables. ```APIDOC ## GET /tables ### Description Lists all tables. ### Method GET ### Endpoint /tables ### Parameters #### Query Parameters - **schema** (string) - Optional - Filter by schema name. ### Response #### Success Response (200) - **tables** (array) - An array of table objects. #### Response Example ```json [ { "schema": "public", "name": "users", "primary_key": ["id"] }, { "schema": "public", "name": "products", "primary_key": ["id"] } ] ``` ## POST /tables ### Description Creates a new table. ### Method POST ### Endpoint /tables ### Parameters #### Request Body - **schema** (string) - Required - The schema for the table. - **name** (string) - Required - The name of the table. - **columns** (array) - Required - An array of column definitions. - **name** (string) - Required - Column name. - **type** (string) - Required - Column type. - **is_nullable** (boolean) - Optional - Whether the column is nullable. - **primary_key** (array) - Optional - An array of column names that form the primary key. ### Request Example ```json { "schema": "public", "name": "orders", "columns": [ {"name": "id", "type": "integer", "is_nullable": false}, {"name": "user_id", "type": "integer", "is_nullable": false}, {"name": "amount", "type": "numeric", "is_nullable": false} ], "primary_key": ["id"] } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Table orders created" } ``` ## PATCH /tables ### Description Alters an existing table. ### Method PATCH ### Endpoint /tables ### Parameters #### Request Body - **schema** (string) - Required - The schema of the table. - **name** (string) - Required - The name of the table. - **new_name** (string) - Optional - The new name for the table. - **rename_columns** (array) - Optional - An array of objects to rename columns. Each object should have `name` and `new_name` properties. - **add_columns** (array) - Optional - An array of column definitions to add. - **alter_columns** (array) - Optional - An array of column definitions to alter. - **drop_columns** (array) - Optional - An array of column names to drop. ### Request Example ```json { "schema": "public", "name": "orders", "new_name": "customer_orders", "add_columns": [ {"name": "created_at", "type": "timestamp with time zone"} ] } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Table orders altered" } ``` ## DELETE /tables ### Description Drops a table. ### Method DELETE ### Endpoint /tables ### Parameters #### Request Body - **schema** (string) - Required - The schema of the table. - **name** (string) - Required - The name of the table to drop. ### Request Example ```json { "schema": "public", "name": "customer_orders" } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Table customer_orders dropped" } ``` ``` -------------------------------- ### Extensions API Source: https://github.com/supabase/postgres-meta/blob/master/README.md Endpoints for managing PostgreSQL extensions, including listing, creating, altering, and dropping extensions. ```APIDOC ## GET /extensions ### Description Lists all available extensions. ### Method GET ### Endpoint /extensions ### Response #### Success Response (200) - **extensions** (array) - An array of extension objects. #### Response Example ```json [ { "name": "uuid-ossp", "schema": "pg_catalog", "version": "1.0", "comment": "generate universally unique identifiers" } ] ``` ## POST /extensions ### Description Creates a new extension. ### Method POST ### Endpoint /extensions ### Parameters #### Request Body - **name** (string) - Required - The name of the extension to create. ### Request Example ```json { "name": "uuid-ossp" } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Extension uuid-ossp created" } ``` ## PATCH /extensions ### Description Alters an existing extension. ### Method PATCH ### Endpoint /extensions ### Parameters #### Request Body - **name** (string) - Required - The name of the extension to alter. - **version** (string) - Optional - The new version to upgrade to. ### Request Example ```json { "name": "uuid-ossp", "version": "1.1" } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Extension uuid-ossp altered to version 1.1" } ``` ## DELETE /extensions ### Description Drops an extension. ### Method DELETE ### Endpoint /extensions ### Parameters #### Request Body - **name** (string) - Required - The name of the extension to drop. ### Request Example ```json { "name": "uuid-ossp" } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Extension uuid-ossp dropped" } ``` ``` -------------------------------- ### Generate Type Definitions for Different Languages Source: https://github.com/supabase/postgres-meta/blob/master/README.md This command allows developers to generate type definitions for interacting with the postgres-meta API in various programming languages. The generation process requires the development server to be running. The command can also be configured to use a custom database connection string. ```bash npm run gen:types: ``` ```bash PG_META_DB_URL=postgresql://postgres:postgres@localhost:5432/postgres npm run gen:types: ``` -------------------------------- ### Roles API Source: https://github.com/supabase/postgres-meta/blob/master/README.md Endpoints for managing database roles, including listing, creating, altering, and dropping roles. ```APIDOC ## GET /roles ### Description Lists all database roles. ### Method GET ### Endpoint /roles ### Response #### Success Response (200) - **roles** (array) - An array of role objects. #### Response Example ```json [ { "name": "postgres", "is_superuser": true, "can_create_db": true, "can_create_role": true }, { "name": "anon", "is_superuser": false, "can_create_db": false, "can_create_role": false } ] ``` ## POST /roles ### Description Creates a new database role. ### Method POST ### Endpoint /roles ### Parameters #### Request Body - **name** (string) - Required - The name of the role. - **password** (string) - Optional - The password for the role. - **is_superuser** (boolean) - Optional - Whether the role is a superuser. - **can_create_db** (boolean) - Optional - Whether the role can create databases. - **can_create_role** (boolean) - Optional - Whether the role can create other roles. ### Request Example ```json { "name": "new_user", "password": "secure_password", "is_superuser": false } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Role new_user created" } ``` ## PATCH /roles ### Description Alters an existing role. ### Method PATCH ### Endpoint /roles ### Parameters #### Request Body - **name** (string) - Required - The name of the role to alter. - **new_name** (string) - Optional - The new name for the role. - **password** (string) - Optional - The new password for the role. - **is_superuser** (boolean) - Optional - Whether the role is a superuser. - **can_create_db** (boolean) - Optional - Whether the role can create databases. - **can_create_role** (boolean) - Optional - Whether the role can create other roles. ### Request Example ```json { "name": "new_user", "is_superuser": true } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Role new_user altered" } ``` ## DELETE /roles ### Description Drops a database role. ### Method DELETE ### Endpoint /roles ### Parameters #### Request Body - **name** (string) - Required - The name of the role to drop. ### Request Example ```json { "name": "new_user" } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Role new_user dropped" } ``` ``` -------------------------------- ### Publications API Source: https://github.com/supabase/postgres-meta/blob/master/README.md Endpoints for managing PostgreSQL publication for logical replication. ```APIDOC ## GET /publications ### Description Lists all publications. ### Method GET ### Endpoint /publications ### Response #### Success Response (200) - **publications** (array) - An array of publication objects. #### Response Example ```json [ { "name": "my_publication", "owner": "postgres", "tables": ["users", "products"] } ] ``` ## POST /publications ### Description Creates a new publication. ### Method POST ### Endpoint /publications ### Parameters #### Request Body - **name** (string) - Required - The name of the publication. - **tables** (array) - Optional - An array of table names to include in the publication. ### Request Example ```json { "name": "my_publication", "tables": ["users"] } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Publication my_publication created" } ``` ## PATCH /publications ### Description Alters an existing publication. ### Method PATCH ### Endpoint /publications ### Parameters #### Request Body - **name** (string) - Required - The name of the publication. - **add_tables** (array) - Optional - An array of table names to add. - **remove_tables** (array) - Optional - An array of table names to remove. ### Request Example ```json { "name": "my_publication", "add_tables": ["products"] } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Publication my_publication altered" } ``` ## DELETE /publications ### Description Drops a publication. ### Method DELETE ### Endpoint /publications ### Parameters #### Request Body - **name** (string) - Required - The name of the publication to drop. ### Request Example ```json { "name": "my_publication" } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Publication my_publication dropped" } ``` ``` -------------------------------- ### Functions API Source: https://github.com/supabase/postgres-meta/blob/master/README.md Endpoints for managing PostgreSQL functions, including listing, creating, altering, and dropping functions. ```APIDOC ## GET /functions ### Description Lists all functions. ### Method GET ### Endpoint /functions ### Parameters #### Query Parameters - **schema** (string) - Optional - Filter by schema name. ### Response #### Success Response (200) - **functions** (array) - An array of function objects. #### Response Example ```json [ { "schema": "public", "name": "add_numbers", "return_type": "integer", "arguments": [ {"name": "a", "type": "integer"}, {"name": "b", "type": "integer"} ] } ] ``` ## POST /functions ### Description Creates a new function. ### Method POST ### Endpoint /functions ### Parameters #### Request Body - **schema** (string) - Required - The schema for the function. - **name** (string) - Required - The name of the function. - **return_type** (string) - Required - The return type of the function. - **arguments** (array) - Optional - An array of argument objects (e.g., `[{"name": "a", "type": "integer"}]`). - **body** (string) - Required - The function body (SQL code). - **language** (string) - Optional - The language of the function (defaults to 'sql'). ### Request Example ```json { "schema": "public", "name": "add_numbers", "return_type": "integer", "arguments": [ {"name": "a", "type": "integer"}, {"name": "b", "type": "integer"} ], "body": "SELECT $1 + $2", "language": "sql" } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Function add_numbers created" } ``` ## PATCH /functions ### Description Alters an existing function. ### Method PATCH ### Endpoint /functions ### Parameters #### Request Body - **schema** (string) - Required - The schema of the function. - **name** (string) - Required - The name of the function. - **new_name** (string) - Optional - The new name for the function. - **return_type** (string) - Optional - The new return type. - **arguments** (array) - Optional - The new arguments. - **body** (string) - Optional - The new function body. - **language** (string) - Optional - The new language. ### Request Example ```json { "schema": "public", "name": "add_numbers", "new_name": "sum_integers" } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Function add_numbers altered to sum_integers" } ``` ## DELETE /functions ### Description Drops a function. ### Method DELETE ### Endpoint /functions ### Parameters #### Request Body - **schema** (string) - Required - The schema of the function. - **name** (string) - Required - The name of the function. - **arguments** (array) - Required - The arguments of the function to identify it uniquely (e.g., `[{"type": "integer"}, {"type": "integer"}]`). ### Request Example ```json { "schema": "public", "name": "add_numbers", "arguments": [ {"type": "integer"}, {"type": "integer"} ] } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Function add_numbers(integer, integer) dropped" } ``` ``` -------------------------------- ### Schemas API Source: https://github.com/supabase/postgres-meta/blob/master/README.md Endpoints for managing database schemas, including listing, creating, altering, and dropping schemas. ```APIDOC ## GET /schemas ### Description Lists all schemas. ### Method GET ### Endpoint /schemas ### Response #### Success Response (200) - **schemas** (array) - An array of schema objects. #### Response Example ```json [ { "name": "public", "owner": "postgres" }, { "name": "auth", "owner": "postgres" } ] ``` ## POST /schemas ### Description Creates a new schema. ### Method POST ### Endpoint /schemas ### Parameters #### Request Body - **name** (string) - Required - The name of the schema. - **owner** (string) - Optional - The owner of the schema. ### Request Example ```json { "name": "my_schema", "owner": "my_user" } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Schema my_schema created" } ``` ## PATCH /schemas ### Description Alters an existing schema. ### Method PATCH ### Endpoint /schemas ### Parameters #### Request Body - **name** (string) - Required - The name of the schema. - **new_name** (string) - Optional - The new name for the schema. - **owner** (string) - Optional - The new owner of the schema. ### Request Example ```json { "name": "my_schema", "new_name": "my_schema_v2" } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Schema my_schema altered to my_schema_v2" } ``` ## DELETE /schemas ### Description Drops a schema. ### Method DELETE ### Endpoint /schemas ### Parameters #### Request Body - **name** (string) - Required - The name of the schema to drop. ### Request Example ```json { "name": "my_schema_v2" } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Schema my_schema_v2 dropped" } ``` ``` -------------------------------- ### Columns API Source: https://github.com/supabase/postgres-meta/blob/master/README.md Endpoints for managing columns within tables, including listing, adding, altering, and dropping columns. ```APIDOC ## GET /columns ### Description Lists all columns in all tables. ### Method GET ### Endpoint /columns ### Parameters #### Query Parameters - **schema** (string) - Optional - Filter by schema name. ### Response #### Success Response (200) - **columns** (array) - An array of column objects. #### Response Example ```json [ { "schema": "public", "table": "users", "name": "id", "type": "integer", "default": null, "is_nullable": false, "is_identity": true } ] ``` ## POST /columns ### Description Adds a new column to a table. ### Method POST ### Endpoint /columns ### Parameters #### Request Body - **schema** (string) - Required - The schema of the table. - **table** (string) - Required - The name of the table. - **name** (string) - Required - The name of the new column. - **type** (string) - Required - The data type of the new column. - **default** (string) - Optional - The default value for the new column. - **is_nullable** (boolean) - Optional - Whether the column can be null (defaults to true). ### Request Example ```json { "schema": "public", "table": "users", "name": "email", "type": "varchar(255)", "is_nullable": true } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Column email added to table users" } ``` ## PATCH /columns ### Description Alters or renames a column. ### Method PATCH ### Endpoint /columns ### Parameters #### Request Body - **schema** (string) - Required - The schema of the table. - **table** (string) - Required - The name of the table. - **name** (string) - Required - The current name of the column. - **new_name** (string) - Optional - The new name for the column. - **type** (string) - Optional - The new data type for the column. - **default** (string) - Optional - The new default value for the column. - **is_nullable** (boolean) - Optional - Whether the column can be null. ### Request Example ```json { "schema": "public", "table": "users", "name": "email", "new_name": "email_address" } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Column email in table users renamed to email_address" } ``` ## DELETE /columns ### Description Drops a column from a table. ### Method DELETE ### Endpoint /columns ### Parameters #### Request Body - **schema** (string) - Required - The schema of the table. - **table** (string) - Required - The name of the table. - **name** (string) - Required - The name of the column to drop. ### Request Example ```json { "schema": "public", "table": "users", "name": "email_address" } ``` ### Response #### Success Response (200) - **message** (string) - Success message. #### Response Example ```json { "message": "Column email_address dropped from table users" } ``` ``` -------------------------------- ### Triggers API Source: https://github.com/supabase/postgres-meta/blob/master/README.md Endpoints for managing database triggers, including listing, creating, altering, and dropping triggers. ```APIDOC ## GET /triggers ### Description Lists all triggers. ### Method GET ### Endpoint /triggers ### Parameters #### Query Parameters - **schema** (string) - Optional - Filter by schema name. - **table** (string) - Optional - Filter by table name. ### Response #### Success Response (200) - **triggers** (array) - An array of trigger objects. #### Response Example ```json [ { "schema": "public", "table": "users", "name": "update_updated_at", "function_name": "update_timestamp", "level": "row", "timing": "before", "events": ["update"] } ] ``` ## POST /triggers ### Description Creates a new trigger. ### Method POST ### Endpoint /triggers ### Parameters #### Request Body - **schema** (string) - Required - The schema of the table. - **table** (string) - Required - The name of the table. - **name** (string) - Required - The name of the trigger. - **function_name** (string) - Required - The name of the trigger function. - **level** (string) - Optional - The trigger level ('row' or 'statement'). Defaults to 'row'. - **timing** (string) - Required - The trigger timing ('before', 'after', 'instead of'). - **events** (array) - Required - An array of trigger events ('insert', 'update', 'delete', 'truncate'). ### Request Example ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.