db-schema-visualizer icon indicating copy to clipboard operation
db-schema-visualizer copied to clipboard

A GIST type of index in a *.dbml prevents a diagram generation

Open Andygol opened this issue 10 months ago • 5 comments

Describe the bug

A *.dbml file containing a gist index prevents a diagram generation.

Re: https://dbml.dbdiagram.io/docs#index-settings

To Reproduce Steps to reproduce the behavior:

  1. Install latest @dbml/cli (v.3.9.5)

     npm install -g @dbml/cli
    
  2. Generate *.dbml from DB where GIST type of index is used

    db2dbml postgres 'postgresql://openstreetmap:pass@localhost:5432/openstreetmap' -o osmdb.dbml
    
  3. Inspect your *.dbml files to identify any instances of the gist keyword. Additionally, attempt to visualize the Entity-Relationship Diagram (ERD) based on this information.

     Table "acls" {
       "id" int8 [pk, not null, increment]
       "address" inet
       "k" varchar [not null]
       "v" varchar
       "domain" varchar
       "mx" varchar
    
       Indexes {
         k [type: btree, name: "acls_k_idx"]
         address [type: gist, name: "index_acls_on_address"]
         domain [type: btree, name: "index_acls_on_domain"]
         mx [type: btree, name: "index_acls_on_mx"]
       }
     }
    
  4. See error

    SyntaxError: Expected btree, comment, hash, or whitespace but "g" found.

    If you replace gist -> hash (for example) VSCode plugin displays diagram as expected.

Expected behavior I hope that with using up-to-date version of @dbml/core(https://www.npmjs.com/package/@dbml/core) the issue would be eliminated.

https://github.com/BOCOVO/db-schema-visualizer/blob/297ac2f4d2b959a924d0fc3ca79c3c2c67e088bf/packages/dbml-to-json-table-schema/package.json#L11

https://github.com/BOCOVO/db-schema-visualizer/blob/297ac2f4d2b959a924d0fc3ca79c3c2c67e088bf/packages/shared/package.json#L7

Andygol avatar Jan 24 '25 08:01 Andygol

Additionally, it is possible to convert *.sql files according to the following link: https://dbml.dbdiagram.io/cli#convert—a-sql-file-to-dbml

The OSM DB *.sql file can be found here: https://github.com/openstreetmap/openstreetmap-website/raw/refs/heads/master/db/structure.sql

Andygol avatar Jan 24 '25 09:01 Andygol

Hello @Andygol !

Thank you for giving those detail on the issue. I appreciate it. I'll try the suggestion and if it works I will ship a release.

BOCOVO avatar Feb 11 '25 22:02 BOCOVO

Additionally, it is possible to convert *.sql files according to the following link: https://dbml.dbdiagram.io/cli#convert—a-sql-file-to-dbml

The OSM DB *.sql file can be found here: https://github.com/openstreetmap/openstreetmap-website/raw/refs/heads/master/db/structure.sql

But I don't really understand this point.

BOCOVO avatar Feb 11 '25 22:02 BOCOVO

The OSM DB *.sql file can be found here: https://github.com/openstreetmap/openstreetmap-website/raw/refs/heads/master/db/structure.sql

☝ you may use this structure.sql to test how GIST type is processed

Andygol avatar Feb 14 '25 07:02 Andygol

Oh ! I understand now. You are suggesting me to convert that SQL to DBML and that it may help me in my investigation.

BOCOVO avatar Feb 14 '25 07:02 BOCOVO