holistics / dbml

Database Markup Language (DBML), designed to define and document database structures
https://dbml.org
Apache License 2.0
2.91k stars 171 forks source link

Cannot read property 'indexes' of undefined #118

Open divya-kr opened 4 years ago

divya-kr commented 4 years ago

I have used the postgres structure.sql file generated using rake command. I ended up removing lot of stuffs from file to make below command run to get my dbml. Ended up removing all default values which had '::' in it. Then all ALTER SEQUENCE statements, data type double precision, varying[], etc.

sql2dbml db/structure.sql --postgres -o out.dbml

But for sure we would like to see indexes also getting documented on dbdocs.io, but unfortunately it throws error from the line index definition starts.

ex:CREATE UNIQUE INDEX admin_user_sitting_assignments_auid_sid ON public.admin_user_sitting_assignments USING btree (admin_user_id, sitting_id);

`SyntaxError: You have a syntax error at "structure.sql". at /usr/local/lib/node_modules/@dbml/cli/lib/cli/utils.js:55:13 at Array.forEach () at generate (/usr/local/lib/node_modules/@dbml/cli/lib/cli/utils.js:48:14) at importHandler (/usr/local/lib/node_modules/@dbml/cli/lib/cli/import.js:40:27) at Object.sql2dbml (/usr/local/lib/node_modules/@dbml/cli/lib/cli/index.js:38:23) at Object. (/usr/local/lib/node_modules/@dbml/cli/bin/sql2dbml.js:4:19) at Module._compile (internal/modules/cjs/loader.js:1201:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10) at Module.load (internal/modules/cjs/loader.js:1050:32) at Function.Module._load (internal/modules/cjs/loader.js:938:14)

ROOT_ERROR: TypeError: Cannot read property 'indexes' of undefined at /usr/local/lib/node_modules/@dbml/cli/node_modules/@dbml/core/lib/parse/postgresParser.js:8:94 at Array.forEach () at peg$c0 (/usr/local/lib/node_modules/@dbml/cli/node_modules/@dbml/core/lib/parse/postgresParser.js:5:4391) at peg$parseparser (/usr/local/lib/node_modules/@dbml/cli/node_modules/@dbml/core/lib/parse/postgresParser.js:33:6989) at Object.peg$parse [as parse] (/usr/local/lib/node_modules/@dbml/cli/node_modules/@dbml/core/lib/parse/postgresParser.js:41:143) at Function.parsePostgresToJSON (/usr/local/lib/node_modules/@dbml/cli/node_modules/@dbml/core/lib/parse/Parser.js:51:41) at Function.parse (/usr/local/lib/node_modules/@dbml/cli/node_modules/@dbml/core/lib/parse/Parser.js:79:32) at Object._import [as import] (/usr/local/lib/node_modules/@dbml/cli/node_modules/@dbml/core/lib/import/index.js:15:37) at /usr/local/lib/node_modules/@dbml/cli/lib/cli/import.js:40:68 at /usr/local/lib/node_modules/@dbml/cli/lib/cli/utils.js:52:23`

Any leads here?

phuongduyphan commented 4 years ago

Hi @divya-kr,

This could be because the referred table public.admin_user_sitting_assignments is not declared yet or it is declared after the CREATE UNIQUE INDEX statement. We will make the error message clearer in the next released patch.

If the error still occurs, could you send us your schema at dbdiagram@holistics.io so we could inspect the issue further?