### Install dependencies and start the application Source: https://planetscale.com/docs/vitess/tutorials/planetscale-serverless-driver-node-example Install the project dependencies using npm and then start the Express API server. ```bash npm install npm start ``` -------------------------------- ### Clone the Go Example Repository Source: https://planetscale.com/docs/vitess/tutorials/connect-go-app Clone the provided Go example repository to your local machine to start building your application. ```bash git clone https://github.com/planetscale/golang-example-gin.git ``` -------------------------------- ### Run Discovery Tool Setup Script Source: https://planetscale.com/docs/postgres/imports/discovery-tool Execute the setup script to verify Python version, create a virtual environment, and install dependencies. ```bash ./setup.sh ``` -------------------------------- ### Install MCP Server for Cursor Source: https://planetscale.com/docs/cli/mcp Example of installing the MCP server specifically for the Cursor IDE. The output confirms successful configuration. ```bash pscale mcp install --target cursor ``` -------------------------------- ### Start Migration Script Source: https://planetscale.com/docs/vitess/imports/postgres-mysql-planetscale-migration-guide After the setup is completed and the schema is ready, run the `start.sh` script using the same identifier provided during the preparation phase to begin the actual data migration. ```bash sh start.sh --identifier "$IDENTIFIER" ``` -------------------------------- ### Complete WebSocket Connection Example Source: https://planetscale.com/docs/postgres/connecting/neon-serverless-driver This example demonstrates a full setup for connecting to a database using WebSocket mode. It includes importing necessary modules, configuring Neon, creating a connection pool, executing a query, and closing the pool. Ensure `neonConfig.webSocketConstructor` is set if not using a native WebSocket global. ```typescript import ws from "ws"; import { Pool, neonConfig } from "@neondatabase/serverless"; neonConfig.webSocketConstructor = ws; // These MUST be set for PlanetScale Postgres connections neonConfig.pipelineConnect = false; neonConfig.wsProxy = (host, port) => `${host}/v2?address=${host}:${port}`; const pool = new Pool({ connectionString: process.env.DATABASE_URL }); const posts = await pool.query("SELECT * FROM posts WHERE id = $1", [postId]); pool.end(); ``` -------------------------------- ### Clone PHP Starter App Source: https://planetscale.com/docs/vitess/tutorials/connect-php-app Clone the PlanetScale PHP example application to get started. ```bash git clone https://github.com/planetscale/php-example.git ``` -------------------------------- ### Create .env File Source: https://planetscale.com/docs/vitess/tutorials/connect-nextjs-app Rename the example environment file to .env to start configuring your application's settings. ```sh mv .env.example .env ``` -------------------------------- ### Example Output: No Webhooks Found Source: https://planetscale.com/docs/cli/webhook This is an example of the output when no webhooks are configured for the specified database. ```bash No webhooks exist in database . ``` -------------------------------- ### Install Dependencies Source: https://planetscale.com/docs/vitess/tutorials/connect-nextjs-app Navigate into the cloned directory and install the necessary project dependencies using npm. ```sh cd nextjs-starter npm install ``` -------------------------------- ### Install PlanetScale Singer Tap Source: https://planetscale.com/docs/vitess/integrations/stitch Install the PlanetScale Singer tap using Homebrew. ```bash brew install planetscale/tap/ps-singer-tap ``` -------------------------------- ### Install PlanetScale HTTP Tap Source: https://planetscale.com/docs/vitess/integrations/stitch Install the PlanetScale HTTP tap using Homebrew. ```bash brew install planetscale/tap/ps-http-tap ``` -------------------------------- ### Install Prisma CLI Source: https://planetscale.com/docs/postgres/tutorials/planetscale-postgres-prisma Install the Prisma CLI using npm. This is the first step in setting up Prisma in your application. ```bash npm install prisma ``` -------------------------------- ### Install PHP Dependencies Source: https://planetscale.com/docs/vitess/tutorials/connect-php-app Navigate into the cloned directory and install the application's dependencies using Composer. ```bash cd php-example composer install ``` -------------------------------- ### Example Sync Output Source: https://planetscale.com/docs/vitess/integrations/stitch This is an example of the output you might see during a PlanetScale to Stitch sync process. ```bash PlanetScale Tap : INFO : Syncing records for PlanetScale database : import-on-scaler PlanetScale Tap : INFO : syncing rows from stream "departments" from shard "-" PlanetScale Tap : INFO : [departments shard : -] peeking to see if there's any new rows PlanetScale Tap : INFO : new rows found, syncing rows for 1m0s PlanetScale Tap : INFO : [departments shard : -] syncing rows with cursor [shard:"-" keyspace:"import-on-scaler"] PlanetScale Tap : INFO : Syncing with cursor position : [], using last known PK : false, stop cursor is : [MySQL56/e42292e8-e28f-11ec-9c5b-d680f5d655b3:1-705,e4e20f06-e28f-11ec-8d20-8e7ac09cb64c:1-26,eba743a8-e28f-11ec-9227-62aa711d33c6:1-20] PlanetScale Tap : INFO : [departments shard : -] Continuing with cursor after server timeout PlanetScale Tap : INFO : [departments shard : -] peeking to see if there's any new rows HTTP Tap : INFO : flushing [20] messages for stream "departments" PlanetScale Tap : INFO : [departments shard : -] no new rows found, exiting HTTP Tap : INFO : Server response status : "OK", message : "Batch accepted" HTTP Tap : INFO : flushing [1] messages for stream "departments" HTTP Tap : INFO : Server response status : "OK", message : "Batch accepted" HTTP Tap : INFO : saving state to path : state/state-1656850746251.json ``` -------------------------------- ### Main Application Setup in Go Source: https://planetscale.com/docs/vitess/tutorials/connect-go-app Initializes the application by loading environment variables, establishing a database connection, and setting up the Gin router with defined API routes. ```go func main() { // Load in the ".env" file err := godotenv.Load() if err != nil { log.Fatal("failed to load env", err) } // Open a connection to the database db, err = sql.Open("mysql", os.Getenv("DSN")) if err != nil { log.Fatal("failed to open db connection", err) } // Build router & define routes router := gin.Default() router.GET("/products", GetProducts) router.GET("/products/:productId", GetSingleProduct) router.POST("/products", CreateProduct) router.PUT("/products/:productId", UpdateProduct) router.DELETE("/products/:productId", DeleteProduct) // Run the router router.Run() } ``` -------------------------------- ### Quickstart: Initialize and Add PlanetScale Database Source: https://planetscale.com/docs/connect/stripe-projects Initialize Stripe Projects, add a PlanetScale database (Postgres or MySQL), and sync credentials to a local .env file. Ensure you are in your app directory before running these commands. ```bash # Enter into your app directory cd my-app # Initialize a new Stripe project stripe projects init # Add a PlanetScale Postgres database stripe projects add planetscale/postgresql # Or add a PlanetScale MySQL database stripe projects add planetscale/mysql # Sync credentials to your local .env file stripe projects env --sync ``` -------------------------------- ### Signup Command Example Output Source: https://planetscale.com/docs/cli/signup This is an example of the interactive prompts and successful signup confirmation message you will see when using the 'pscale signup' command. The password must meet specific complexity requirements. ```bash pscale signup You are registering a new PlanetScale account. ? What is your e-mail? me@example.com ? Please type your password ****************** ? Please confirm your password ****************** You've successfully signed up for PlanetScale! Please check your email for a confirmation link and then get started with `pscale auth login`. ``` -------------------------------- ### Start Grafana Service on macOS Source: https://planetscale.com/docs/vitess/guides/prometheus-metrics-grafana Starts the Grafana service after installation on macOS using Homebrew. This allows Grafana to run in the background. ```bash $ brew services start grafana ``` -------------------------------- ### Copy .env.example to .env Source: https://planetscale.com/docs/vitess/tutorials/nextjs-planetscale-netlify-template Create a local environment file by copying the example configuration. This file will store your local database credentials and application settings. ```bash cp .env.example .env ``` -------------------------------- ### Example PlanetScale Sequence Next Values (Initial) Source: https://planetscale.com/docs/postgres/imports/aurora An example output showing the next values for sequences on a new PlanetScale database, typically starting at 0. This highlights the discrepancy with the source database. ```sql schemaname | sequencename | next_value ------------+------------------+------------ public | users_id_seq | 0 public | posts_id_seq | 0 public | followers_id_seq | 0 ``` -------------------------------- ### Start Go Application Source: https://planetscale.com/docs/vitess/tutorials/connect-go-gorm-app Run this command to start your Go application. Ensure you are in the project's root directory. ```bash go run . ``` -------------------------------- ### Make a cURL Request Source: https://planetscale.com/docs/api/reference/oauth Example of making a GET request to retrieve organizations using an access token for authentication. ```curl curl --request GET 'https://api.planetscale.com/v1/organizations' \ --header 'Authorization: Bearer ' ``` -------------------------------- ### cURL Example for API Request Source: https://planetscale.com/docs/api/reference/service-tokens This cURL command demonstrates how to make a GET request to the /v1/organizations endpoint using a service token for authentication. ```curl curl --request GET 'https://api.planetscale.com/v1/organizations' \ --header 'Authorization: :' ``` -------------------------------- ### Page-based Pagination Example Source: https://planetscale.com/docs/api/reference/pagination Demonstrates how to use page-based pagination by requesting the first page with 50 items per page for a list organizations GET request. ```APIDOC ## GET /v1/organizations ### Description Fetches a list of organizations with support for pagination. ### Method GET ### Endpoint /v1/organizations ### Query Parameters - **page** (integer) - Optional - The page number to retrieve. - **per_page** (integer) - Optional - The number of items to return per page. Defaults to 25, with a maximum of 100. ### Request Example ```curl curl --request GET \ --url 'https://api.planetscale.com/v1/organizations?page=1&per_page=50' \ --header 'Authorization: TOKEN_ID:TOKEN_SECRET' \ --header 'accept: application/json' ``` ### Response #### Success Response (200) - **data** (array) - A list of organization objects. - **pagination** (object) - Contains pagination information. - **page** (integer) - The current page number. - **per_page** (integer) - The number of items per page. - **total_pages** (integer) - The total number of pages available. ``` -------------------------------- ### Install Discovery Tool with Pipx (All Providers) Source: https://planetscale.com/docs/postgres/imports/discovery-tool Install the discovery tool using pipx with support for all available provider integrations. ```bash pipx install -e ".[all]" ``` -------------------------------- ### Example Output: Webhooks Found Source: https://planetscale.com/docs/cli/webhook This is an example of the output when webhooks are configured for the specified database, showing details like ID, URL, events, and status. ```bash ID URL EVENTS ENABLED CREATED AT UPDATED AT -------------- ------------------------------------- ------------------------------- --------- ------------ ------------ abc123xyz https://example.com/webhook branch.ready, branch.sleeping Yes 2 days ago 1 day ago ``` -------------------------------- ### Apply Query Hints with pg_hint_plan Source: https://planetscale.com/docs/postgres/extensions/pg_hint_plan This SQL query demonstrates how to use hints with pg_hint_plan to guide the query planner. Hints are specified in a special comment block starting with /*+. ```sql /*+ SeqScan(t1) IndexScan(t2 t2_pkey) */ SELECT * FROM table1 t1 JOIN table2 t2 ON t1.id = t2.id; ``` -------------------------------- ### Signup Command with Flags Source: https://planetscale.com/docs/cli/signup This demonstrates the general usage of the signup command with a placeholder for flags. Refer to the global flags section for available options. ```bash pscale signup ``` -------------------------------- ### Branch Start Maintenance Event Source: https://planetscale.com/docs/api/webhook-events This event is triggered before maintenance begins on a production branch. It is available for both Vitess and Postgres databases, with specific behaviors outlined for each. The response body is identical to a 200 response from the Get a branch API endpoint. ```APIDOC ## branch.start_maintenance Event ### Description This webhook notifies you right before maintenance for your production branch is about to start. It is available for both Vitess and Postgres databases, with different behaviors. ### Event `branch.start_maintenance` ### Response Body The response body is the same as a 200 response from the [Get a branch](/api/reference/get_branch) API endpoint. ### Request Example ```json { "timestamp": 1698252879, "event": "branch.start_maintenance", "organization": "myorg", "database": "example_database", "resource": { "id": "q9x7ylb3hcmx", "type": "Branch", "name": "main", "cluster_architecture": "x86_64", "cluster_name": "PS_20_AWS_X86", "cluster_display_name": "PS-20", "cluster_iops": null, "restore_checklist_completed_at": null, "schema_last_updated_at": "2025-09-17T20:49:14.983Z", "state": "ready", "created_at": "2025-07-15T12:38:22.664Z", "updated_at": "2025-09-24T21:00:35.717Z", "actor": { "id": "u2dr4sbhz6ag", "type": "User", "display_name": "Mike Coutermarsh", "avatar_url": "https://www.gravatar.com/avatar/236f8e1435745283319e2bcfeed75072?d=https%3A%2F%2Fapp.planetscale.com%2Fgravatar-fallback.png&s=64" }, "restored_from_branch": null, "frozen": true, "safe_migrations": false, "default": true, "enabling_vectors": false, "metal": false, "production": true, "ready": true, "stale_schema": false, "parent_branch": null, "private_edge_connectivity": false, "replicas": 2, "read_only_reason": null, "read_only_at": null, "minimum_storage_bytes": 21474836480, "maximum_storage_bytes": 3324304687104, "storage_autoscaling": true, "storage_shrinking": true, "storage_type": "gp3", "storage_iops": 4000, "storage_throughput_mibs": 300, "has_replicas": true, "has_read_only_replicas": false, "has_roles": true, "region": { "id": "ri0pbcmdkjsh", "type": "Region", "provider": "AWS", "enabled": true, "public_ip_addresses": [ "18.117.23.127", "3.131.243.164", "3.132.168.252", "3.131.252.213", "3.132.182.173", "3.15.49.114", "3.209.149.66", "3.215.97.46", "34.193.111.15" ], "display_name": "AWS us-east-2", "location": "Ohio", "slug": "aws-us-east-2", "current_default": false }, "kind": "postgresql" } } ``` ``` -------------------------------- ### Clone Go Starter App Source: https://planetscale.com/docs/vitess/tutorials/connect-go-gorm-app Clone the provided Go starter application repository to begin. This application is designed to display a list of products from the database. ```bash git clone https://github.com/planetscale/golang-example.git ``` -------------------------------- ### Install Dependencies Source: https://planetscale.com/docs/vitess/tutorials/nextjs-planetscale-netlify-template Installs the necessary project dependencies using Yarn. Ensure you have Yarn installed globally. ```bash yarn install ``` -------------------------------- ### Verify Homebrew Installation Source: https://planetscale.com/docs/cli/planetscale-environment-setup Check if Homebrew is installed on your macOS system. If not, follow the provided link to install it. ```bash brew -v ``` -------------------------------- ### Create .env File Source: https://planetscale.com/docs/vitess/tutorials/connect-go-gorm-app Copy the example environment file to create a new .env file. This file will store your database connection details. ```bash cp .env.example .env ``` -------------------------------- ### Install a Postgres Extension Source: https://planetscale.com/docs/postgres/extensions Use the CREATE EXTENSION command to install an extension. The IF NOT EXISTS clause prevents errors if the extension is already installed. ```sql CREATE EXTENSION IF NOT EXISTS pgcrypto; ``` -------------------------------- ### Run the Go Application Source: https://planetscale.com/docs/vitess/tutorials/connect-go-app Install project dependencies and run the Go application using the go run command. Ensure your .env file is correctly configured. ```bash go mod tidy go run . ``` -------------------------------- ### Install Grafana on macOS using Homebrew Source: https://planetscale.com/docs/vitess/guides/prometheus-metrics-grafana Installs Grafana using the Homebrew package manager on macOS. Ensure Homebrew is installed before running this command. ```bash $ brew install grafana ``` -------------------------------- ### Install pg_stat_statements Extension Source: https://planetscale.com/docs/postgres/extensions/pg_stat_statements Install the pg_stat_statements extension in your PostgreSQL database after enabling it via the dashboard. Use IF NOT EXISTS to prevent errors if it's already installed. ```sql CREATE EXTENSION IF NOT EXISTS pg_stat_statements; ``` -------------------------------- ### Configure Discovery Tool Credentials Source: https://planetscale.com/docs/postgres/imports/discovery-tool Copy the sample configuration file to 'config.yaml' and edit it with your database and cloud provider credentials. Minimum configuration requires database connection details. ```bash cp sample-config.yaml config.yaml ``` -------------------------------- ### Install PlanetScale CLI via Homebrew Source: https://planetscale.com/docs/cli/planetscale-environment-setup Install the PlanetScale CLI using Homebrew on macOS. This command adds the PlanetScale tap and installs the pscale package. ```bash brew install planetscale/tap/pscale ``` -------------------------------- ### Install Discovery Tool with pipx (MySQL, AWS, GCP Support) Source: https://planetscale.com/docs/vitess/imports/discovery-tool Install the discovery tool using pipx, including support for MySQL, AWS, and GCP. ```bash pipx install -e ".[mysql,aws,gcp]" ``` -------------------------------- ### Install pg_cron Extension Source: https://planetscale.com/docs/postgres/extensions/pg_cron Install the pg_cron extension in your PostgreSQL database after enabling it via the PlanetScale Dashboard. Use IF NOT EXISTS to prevent errors if the extension is already installed. ```sql CREATE EXTENSION IF NOT EXISTS pg_cron; ``` -------------------------------- ### Install PlanetScale CLI and Clients via Scoop Source: https://planetscale.com/docs/cli/planetscale-environment-setup Add the PlanetScale scoop bucket and install the pscale, MySQL, and PostgreSQL clients on Windows. ```bash scoop bucket add pscale https://github.com/planetscale/scoop-bucket.git scoop install pscale mysql postgresql ``` -------------------------------- ### Install TimescaleDB Extension Source: https://planetscale.com/docs/postgres/extensions/timescaledb Use this SQL command to install the TimescaleDB extension after enabling it in the PlanetScale dashboard. The `IF NOT EXISTS` clause prevents errors if the extension is already installed. ```sql CREATE EXTENSION IF NOT EXISTS timescaledb; ``` -------------------------------- ### Initialize Prisma in Application Source: https://planetscale.com/docs/postgres/tutorials/planetscale-postgres-prisma Run this command to set up Prisma within your project directory. It generates necessary configuration files. ```bash npx prisma init ```