Postgres schema to ERD: a prompt-to-DDL workflow
Raltey does not read a live Postgres database. It takes a description of the schema, or manual edits on the database schema canvas, and produces an ERD you can review. The export panel then generates PostgreSQL DDL, Prisma, Drizzle, TypeScript, Zod, Go, or Python. The workflow is prompt to diagram to code, with a human review in the middle.
If you want live introspection, ChartDB or dbdiagram.io may fit better. If you want a visual design surface with code exports, keep reading.
The type mapping
Raltey's SQL export maps canvas field types to Postgres types. This is the actual mapping in the generator:
| Canvas type | Postgres type |
|---|---|
| int | INTEGER |
| float | FLOAT |
| double | DOUBLE PRECISION |
| bigint | BIGINT |
| text | TEXT |
| varchar | VARCHAR(255) |
| blob | BYTEA |
| json | JSON |
| jsonb | JSONB |
| boolean | BOOLEAN |
| date | DATE |
| time | TIME |
| timestamp | TIMESTAMP |
Auto-increment integer fields become SERIAL, and auto-increment bigint fields become BIGSERIAL.
A prompt that produces a reviewable schema
The agent does better with explicit relations and nullability. A useful prompt:
Design a Postgres schema for a project management app. Tables: users, workspaces, workspace_members, projects, tasks, comments. A workspace has many members. A project belongs to a workspace. A task belongs to a project. A comment belongs to a task. Every table has an id, created_at, and updated_at. Add the foreign keys and make the nullable fields explicit.
You get a set of table nodes on the database schema canvas. Each table has typed columns, primary keys, and foreign keys. Relations are drawn between the tables.
Review the diagram before the code
Check these on the canvas:
- Primary keys. Every table should have one.
- Foreign keys. The direction should match the application. A comment belongs to a task, not the other way around.
- Nullability. A nullable foreign key is a different design from a required one.
- Timestamps.
created_atandupdated_atshould exist where the application expects them. - Naming. Table and column names should match the conventions your team uses in code.
The export is only as good as the diagram. A wrong relation becomes a wrong constraint.
What the SQL looks like
Raltey emits quoted identifiers and separate foreign key statements:
CREATE TABLE "tasks" (
"id" SERIAL PRIMARY KEY,
"project_id" INTEGER NOT NULL,
"title" TEXT NOT NULL,
"status" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP NOT NULL
);
-- Foreign Keys
ALTER TABLE "tasks" ADD CONSTRAINT "fk_tasks_project_id" FOREIGN KEY ("project_id") REFERENCES "projects" ("id");
The generator does not add indexes, check constraints, or defaults beyond the fields on the canvas. Add those in your migration layer.
What to do with the output
Do not run generated DDL directly against production. Use it as a draft:
- Copy the DDL or download the
.sqlfile. - Diff it against your existing schema.
- Add indexes and constraints your application needs.
- Put it through your migration tool.
- Review the migration with someone who owns the data.
For a new project, the DDL is a fast starting point. For an existing project, the diff is the useful artifact.
Prisma, Drizzle, and typed models
The same canvas exports to more than SQL:
- Prisma: a
schema.prismawith the postgresql provider andDATABASE_URL. - Drizzle: a TypeScript schema file.
- TypeScript: types for an API or frontend.
- Zod: runtime validation schemas.
- Go: structs for a Go service.
- Python: models for a Python service.
The schema canvas is the single source. The export format changes for the consumer.
What Raltey does not do
- No live database connection.
- No MySQL, SQL Server, or SQLite DDL.
- No DBML import or export.
- No automatic migration generation.
- No schema diff against a live database.
Those are deliberate limits for now. The tool is a design canvas with code exports, not a database IDE.
A short checklist before export
- All tables have primary keys.
- All relations have the correct direction.
- Foreign key fields use the right integer type.
- Nullable fields are intentional.
- Timestamps and soft-delete fields are present.
- The naming matches your codebase.
- You saved a named version before the change.
FAQ
Can Raltey connect to my Postgres database?
No. There is no live database introspection. Raltey generates the ERD from your description or manual edits, not from a database connection.
Does the SQL export include foreign keys?
Yes. Foreign keys are emitted as ALTER TABLE statements after the CREATE TABLE statements.
How are Postgres types mapped?
Integer maps to INTEGER, float to FLOAT, double to DOUBLE PRECISION, bigint to BIGINT, text to TEXT, varchar to VARCHAR(255), blob to BYTEA, json to JSON, jsonb to JSONB, boolean to BOOLEAN, date to DATE, time to TIME, and timestamp to TIMESTAMP.
Does Raltey generate migrations?
No. It generates schema code. You still need a migration tool and a review step.
Start a database schema project or read the database schema guide.
