drawdb-io / drawdb-io/drawdb

[BUG] PostgreSQL Import fails with Syntax Error on valid pg_dump files

Open
#852 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
39.5k
Forks
3.2k
Avg merge
10h 46m
Merged PRs (30d)
16

Description

----------------------------------------------------------------------------------------------------------------------------
#PR - #852 (Bug fixing)

----------------------------------------------------------------------------------------------------------------------------

**Describe the bug**
When importing a SQL script generated by pg_dump (PostgreSQL), the application fails to generate the diagram and displays a "Syntax Error" message. This happens even for valid SQL files because the parser (node-sql-parser) crashes when it encounters standard PostgreSQL dump artefacts like comments (--), configuration commands (SET statement_timeout...), or extensions (CREATE EXTENSION).

**To Reproduce**
Steps to reproduce the behaviour:

1. Generate a dump file from a PostgreSQL database using pg_dump (or use a SQL file containing SET commands or comments).
2. Open DrawDB and click File > Import SQL.
3. Paste the SQL content or upload the file.
4. See error: "Syntax Error due to token..." (or generally failing to load).

**Expected behaviour**
The application should successfully parse the DDL statements (CREATE TABLE, ALTER TABLE) to generate the diagram, while ignoring non-structural metadata like comments or session variable configurations.

**Desktop (please complete the following information):**
- OS: macOS / Windows / Linux (Platform Independent)
- Browser Chrome / Firefox / Safari

**Additional context**
The issue stems from the strictness of the node-sql-parser library. It does not support specific pg_dump meta-commands. A fix involves sanitising the SQL input to strip these artefacts before parsing. I have prepared a PR for this.

Contributor guide

Open the contributing guide

Research direction

Start at DrawDB's File > Import SQL flow and the node-sql-parser invocation described in the issue. Reproduce with a pg_dump file containing comments, SET commands, or CREATE EXTENSION, then verify that CREATE TABLE and ALTER TABLE statements still generate a diagram while the non-structural artefacts are ignored.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, postgresql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.