Skip to main content

Getting Started

Make sure to first set up your PlanetScale developer environment. Once you’ve installed the pscale CLI, you can interact with PlanetScale and manage your databases straight from the command line.

The import command

This command imports external databases into PlanetScale Postgres. Today it supports Cloudflare D1 (SQLite) through the d1 sub-command group. For other migration paths, see the Postgres imports overview. Usage:
pscale import d1 <SUB-COMMAND> <FLAG>
Branch-scoped sub-commands take the positional form <DATABASE_NAME> [BRANCH_NAME], defaulting to the default branch. The organization comes from your pscale config (pscale org) or the --org flag.
pscale import d1 supports the human (default) and json output formats. The csv format is not supported.

Available sub-commands

Sub-commandSub-command flagsProductDescription
d1 doctorPostgresCheck that pgloader, psql, and other prerequisites are installed
d1 lint--input <FILE>PostgresAnalyze a D1 SQL export for migration issues
d1 convert-schema--input <FILE>, --output <FILE>PostgresConvert SQLite schema in a D1 export to PostgreSQL DDL
d1 start <DATABASE_NAME> [BRANCH_NAME]--input <FILE>, --dry-run, --migration-id <MIGRATION_ID>, --method <METHOD>, --dbname <NAME>, --forcePostgresStart importing a D1 export (lint + plan, then load)
d1 verify <DATABASE_NAME> [BRANCH_NAME]--migration-id <MIGRATION_ID>, --input <FILE>, --sqlite <FILE>, --dbname <NAME>PostgresVerify the import: row counts, sequences, coercion, and content checks
d1 status <DATABASE_NAME> [BRANCH_NAME]--migration-id <MIGRATION_ID>PostgresShow local migration state
d1 complete <DATABASE_NAME> [BRANCH_NAME]--migration-id <MIGRATION_ID>, --forcePostgresMark a D1 migration as complete in local state

Sub-command flag descriptions

Some of the sub-commands have additional flags unique to the sub-command. This section covers what each of those does. See the above table for which context.
Sub-command flagTypeDescriptionApplicable sub-commands
--input <FILE>stringPath to the D1 SQL export produced by wrangler d1 export (required for lint, convert-schema, and start)lint, convert-schema, start, verify
--output <FILE>stringOutput PostgreSQL schema file (default <INPUT>.postgres.sql)convert-schema
--dry-runbooleanLint and build the import plan without loading Postgres; prints a migration ID for the real runstart
--migration-id <MIGRATION_ID>stringMigration ID from a prior start --dry-run (required for verify, status, and complete)start, verify, status, complete
--method <METHOD>stringImport method: pgloader (exports ≥ 1 GB) or psql (exports < 1 GB; schema via psql, data via pgloader). Chosen automatically by export size when omittedstart
--dbname <NAME>stringDestination PostgreSQL database name (default postgres)start, verify
--sqlite <FILE>stringPath to a local SQLite file to use for source row countsverify
--forcebooleanSkip the confirmation promptstart, complete

Available flags

FlagDescription
-h, --helpView help for import command
--org <ORGANIZATION_NAME>The organization for the current user

Global flags

CommandDescription
--api-token <TOKEN>The API token to use for authenticating against the PlanetScale API.
--api-url <URL>The base URL for the PlanetScale API. Default is https://api.planetscale.com/.
--config <CONFIG_FILE>Config file. Default is $HOME/.config/planetscale/pscale.yml.
--debugEnable debug mode.
-f, --format <FORMAT>Show output in a specific format. Possible values: human (default), json.
--no-colorDisable color output.
--service-token <TOKEN>The service token for authenticating.
--service-token-id <TOKEN_ID>The service token ID for authenticating.

Need help?

Get help from the PlanetScale Support team, or join our Discord community to see how others are using PlanetScale.