> ## Documentation Index
> Fetch the complete documentation index at: https://synthbrew.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Import PostgreSQL schema SQL

> Export PostgreSQL schema SQL and import it into Synthbrew as a draft schema.

Use this flow when you already have PostgreSQL schema SQL and want Synthbrew to turn it into a schema draft without relying on AI.

## What SQL input works best

The SQL importer is designed for PostgreSQL schema DDL, especially:

* `pg_dump --schema-only` exports
* Schema export/download files from hosted PostgreSQL providers
* Hand-written PostgreSQL `CREATE TABLE`, `ALTER TABLE`, `CREATE TYPE ... AS ENUM`, and `CREATE INDEX` statements

The importer does not execute SQL. It parses supported PostgreSQL schema statements and maps them into a Synthbrew schema draft.

## Export schema SQL with `pg_dump`

If you already have a PostgreSQL connection string, the most reliable option is a schema-only export:

```bash theme={null}
pg_dump \
  --schema-only \
  --no-owner \
  --no-privileges \
  "$DATABASE_URL" > schema.sql
```

This produces a SQL file focused on schema structure instead of data.

## Other ways to get a SQL file

* Many hosted PostgreSQL providers let you export or download schema SQL from their dashboard.
* If you manage migrations in your app repo, you can often copy the final migration SQL or concatenate the schema migrations into one file.
* If you already have a local `.sql` schema dump, you can upload it directly in Synthbrew.

## Import the SQL in Synthbrew

1. Open **Schemas** in your project.
2. Choose **Import from SQL file**.
3. Upload one `.sql` file or paste PostgreSQL schema SQL into the editor.
4. Add a schema name and optional description.
5. Load the preview, review warnings, and choose the schemas or tables you want.
6. Open the draft in the editor and make any final adjustments before saving the schema.

## What gets imported

Synthbrew aims to map the same kinds of things it can infer from the connection-string import flow:

* Tables
* Columns and common PostgreSQL scalar types
* Enums created with `CREATE TYPE ... AS ENUM`
* Primary keys and unique constraints
* Foreign keys that fit the current Synthbrew schema model
* Simple indexes

It also applies the existing field-type and generator heuristics used by the connection-string importer.

## What gets ignored or downgraded to warnings

Some PostgreSQL objects are not represented directly in the current Synthbrew schema model. The importer keeps going, but shows warnings for items like:

* Views and materialized views
* Comments
* Grants and privilege statements
* Session/config statements
* Functions, triggers, and policies
* Extensions
* Sequences and other objects outside the current schema contract
* Unsupported or lossy constraint/index shapes

If a warning appears, open the draft in the editor and review the affected entity or field before saving.

## Troubleshooting

### `SQL is required`

The SQL textarea is empty. Upload a `.sql` file or paste PostgreSQL schema SQL before loading the preview.

### `No importable tables found in SQL`

The file likely contains comments, grants, or other statements but no supported `CREATE TABLE` definitions. Re-export with a schema-focused SQL dump or check that the file includes table definitions.

### Preview fails with a parse error

The importer expects PostgreSQL syntax. Re-export the file from PostgreSQL or adjust non-PostgreSQL syntax before trying again.
