L-Mario564 / drizzle-dbml-generator

Generate DBML markup from your schema defined with Drizzle ORM.
MIT License
160 stars 8 forks source link

Error generating DBML: SyntaxError: "undefined" is not valid JSON #12

Closed LargatSeif closed 5 months ago

LargatSeif commented 5 months ago

hey , first of all thanks for this great lib πŸ™πŸ»

i've encountered this issue when launching the script FYI : tried with ts-node and tsx but without success.

{"level":50,"time":1717200292667,"pid":*****,"hostname":"********","msg":"πŸ”΄  Error generating DBML"}
Error generating DBML: SyntaxError: "undefined" is not valid JSON
    at JSON.parse (<anonymous>)
    at <anonymous> (******/node_modules/.pnpm/drizzle-orm@0.31.0_@libsql+client@0.6.1_bufferutil@4.0.8_utf-8-validate@6.0.3__@neondatabase+_cm6mdk32q54q32ryyx46rir3wq/node_modules/src/pg-core/indexes.ts:122:27)
    at Array.map (<anonymous>)
    at IndexBuilderOn.on (******/node_modules/.pnpm/drizzle-orm@0.31.0_@libsql+client@0.6.1_bufferutil@4.0.8_utf-8-validate@6.0.3__@neondatabase+_cm6mdk32q54q32ryyx46rir3wq/node_modules/src/pg-core/indexes.ts:116:12)
    at PgTable.<anonymous> (******/src/lib/secure/db/schema/activities.ts:20:59)
    at PgGenerator.generateTable (******/node_modules/.pnpm/drizzle-dbml-generator@0.6.1_@libsql+client@0.6.1_bufferutil@4.0.8_utf-8-validate@6.0.3__@neo_diado5yhhvrhexhjdbgb7czlxa/node_modules/drizzle-dbml-generator/dist/index.cjs:178:67)
    at PgGenerator.generate (******/node_modules/.pnpm/drizzle-dbml-generator@0.6.1_@libsql+client@0.6.1_bufferutil@4.0.8_utf-8-validate@6.0.3__@neo_diado5yhhvrhexhjdbgb7czlxa/node_modules/drizzle-dbml-generator/dist/index.cjs:286:35)
    at pgGenerate (******/node_modules/.pnpm/drizzle-dbml-generator@0.6.1_@libsql+client@0.6.1_bufferutil@4.0.8_utf-8-validate@6.0.3__@neo_diado5yhhvrhexhjdbgb7czlxa/node_modules/drizzle-dbml-generator/dist/index.cjs:330:68)
    at <anonymous> (******/src/lib/secure/db/dbml.ts:9:2)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)

and here is my little script :

import { pgGenerate } from 'drizzle-dbml-generator'; 
import { logger } from '../logger';
import * as schema from './schema/';

logger.debug('🟒  Generating DBML');
console.log('Generating DBML...');
console.log(Object.keys(schema));
try{
    pgGenerate({
        schema,
        out: './docs/schema.dbml',
        relational: true
    });
    logger.info('🟒  DBML generated');
} catch (e) {
    logger.error('πŸ”΄  Error generating DBML');
    console.error('Error generating DBML:', e);
    process.exit(1);
}
rorz commented 5 months ago

It's related to https://github.com/drizzle-team/drizzle-orm/releases/tag/0.31.0 I think.

Drizzle changed the way they treat Postgres indexes, and I think the underlying generator in drizzle-dbml-generator barfs with the "old" index API input.

I will look at this and provide an update if I get around to it...

rorz commented 5 months ago

This should fix it: https://github.com/L-Mario564/drizzle-dbml-generator/pull/13

Β―\_(ツ)_/Β― (Works on my machine anyway 😁)