nodejh / sequelize-automate

Automatically generate bare sequelize models from your database.
MIT License
116 stars 22 forks source link

Can't generate classes for mssql DB #18

Open lampsbr opened 4 years ago

lampsbr commented 4 years ago

Hi, can I get support for this package here? =]

I'm trying to generate the sequelize models for my mssql databases, but in some point the script gives me an error message and doesn't save any file. How can I fix this?

First I type $ sequelize-automate -t js -h myhost -d mydbname -u user -p mypassword -P 1433 -e mssql

Then it calls Executing (default): SELECT c.COLUMN_NAME AS 'Name', for every table,

Then it tries calling an object that "does not exist". Maybe I don't have permission to see this object. Here's the error message:

DatabaseError [SequelizeDatabaseError]: The object '[subgrupo_principal]' does not exist in database 'mydbname' or is invalid for this operation. at Query.formatError (/usr/lib/node_modules/sequelize-automate/node_modules/sequelize/lib/dialects/mssql/query.js:314:12) at Request.userCallback (/usr/lib/node_modules/sequelize-automate/node_modules/sequelize/lib/dialects/mssql/query.js:74:23) at Request.callback (/usr/lib/node_modules/tedious/lib/request.js:56:14) at Connection.endOfMessageMarkerReceived (/usr/lib/node_modules/tedious/lib/connection.js:2416:20) at Connection.dispatchEvent (/usr/lib/node_modules/tedious/lib/connection.js:1297:15) at Parser.<anonymous> (/usr/lib/node_modules/tedious/lib/connection.js:1112:14) at Parser.emit (events.js:310:20) at Parser.<anonymous> (/usr/lib/node_modules/tedious/lib/token/token-stream-parser.js:37:14) at Parser.emit (events.js:310:20) at addChunk (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:298:12) at readableAddChunk (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:280:11) at Parser.Readable.push (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:241:10) at Parser.Transform.push (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:139:32) at Parser.afterTransform (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:88:10) at Parser._transform (/usr/lib/node_modules/tedious/lib/token/stream-parser.js:88:14) at Parser.Transform._read (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:177:10) at Parser.Transform._write (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:164:83) at doWrite (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:409:139) at writeOrBuffer (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:398:5) at Parser.Writable.write (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:307:11) at Parser.addEndOfMessageMarker (/usr/lib/node_modules/tedious/lib/token/token-stream-parser.js:55:24) at Connection.message (/usr/lib/node_modules/tedious/lib/connection.js:2405:32) { parent: RequestError: The object '[subgrupo_principal]' does not exist in database 'mydbname' or is invalid for this operation. at Parser.<anonymous> (/usr/lib/node_modules/tedious/lib/connection.js:879:27) at Parser.emit (events.js:310:20) at Parser.<anonymous> (/usr/lib/node_modules/tedious/lib/token/token-stream-parser.js:37:14) at Parser.emit (events.js:310:20) at addChunk (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:298:12) at readableAddChunk (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:280:11) at Parser.Readable.push (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:241:10) at Parser.Transform.push (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:139:32) at doneParsing (/usr/lib/node_modules/tedious/lib/token/stream-parser.js:122:14) at /usr/lib/node_modules/tedious/lib/token/infoerror-token-parser.js:48:5 at /usr/lib/node_modules/tedious/lib/token/infoerror-token-parser.js:21:19 at /usr/lib/node_modules/tedious/lib/token/stream-parser.js:221:7 at Parser.awaitData (/usr/lib/node_modules/tedious/lib/token/stream-parser.js:145:7) at Parser.readUInt32LE (/usr/lib/node_modules/tedious/lib/token/stream-parser.js:218:10) at /usr/lib/node_modules/tedious/lib/token/infoerror-token-parser.js:20:90 at /usr/lib/node_modules/tedious/lib/token/stream-parser.js:379:9 at /usr/lib/node_modules/tedious/lib/token/stream-parser.js:371:7 at Parser.awaitData (/usr/lib/node_modules/tedious/lib/token/stream-parser.js:145:7) at Parser.readBuffer (/usr/lib/node_modules/tedious/lib/token/stream-parser.js:368:10) at /usr/lib/node_modules/tedious/lib/token/stream-parser.js:378:12 at /usr/lib/node_modules/tedious/lib/token/stream-parser.js:165:7 at Parser.awaitData (/usr/lib/node_modules/tedious/lib/token/stream-parser.js:145:7) { code: 'EREQUEST', number: 15009, state: 1, class: 16, serverName: 'myhost', procName: 'sp_helpindex', lineNumber: 41, sql: "EXEC sys.sp_helpindex @objname = N'[subgrupo_principal]';", parameters: undefined }, original: RequestError: The object '[subgrupo_principal]' does not exist in database 'mydbname' or is invalid for this operation. at Parser.<anonymous> (/usr/lib/node_modules/tedious/lib/connection.js:879:27) at Parser.emit (events.js:310:20) at Parser.<anonymous> (/usr/lib/node_modules/tedious/lib/token/token-stream-parser.js:37:14) at Parser.emit (events.js:310:20) at addChunk (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:298:12) at readableAddChunk (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:280:11) at Parser.Readable.push (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:241:10) at Parser.Transform.push (/usr/lib/node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:139:32) at doneParsing (/usr/lib/node_modules/tedious/lib/token/stream-parser.js:122:14) at /usr/lib/node_modules/tedious/lib/token/infoerror-token-parser.js:48:5 at /usr/lib/node_modules/tedious/lib/token/infoerror-token-parser.js:21:19 at /usr/lib/node_modules/tedious/lib/token/stream-parser.js:221:7 at Parser.awaitData (/usr/lib/node_modules/tedious/lib/token/stream-parser.js:145:7) at Parser.readUInt32LE (/usr/lib/node_modules/tedious/lib/token/stream-parser.js:218:10) at /usr/lib/node_modules/tedious/lib/token/infoerror-token-parser.js:20:90 at /usr/lib/node_modules/tedious/lib/token/stream-parser.js:379:9 at /usr/lib/node_modules/tedious/lib/token/stream-parser.js:371:7 at Parser.awaitData (/usr/lib/node_modules/tedious/lib/token/stream-parser.js:145:7) at Parser.readBuffer (/usr/lib/node_modules/tedious/lib/token/stream-parser.js:368:10) at /usr/lib/node_modules/tedious/lib/token/stream-parser.js:378:12 at /usr/lib/node_modules/tedious/lib/token/stream-parser.js:165:7 at Parser.awaitData (/usr/lib/node_modules/tedious/lib/token/stream-parser.js:145:7) { code: 'EREQUEST', number: 15009, state: 1, class: 16, serverName: 'myhost', procName: 'sp_helpindex', lineNumber: 41, sql: "EXEC sys.sp_helpindex @objname = N'[subgrupo_principal]';", parameters: undefined }, sql: "EXEC sys.sp_helpindex @objname = N'[subgrupo_principal]';", parameters: undefined }

After this, it stil print some lines like Executing (default): EXEC sys.sp_helpindex @objname = N'[aviso]';

Then it ends, does not tell me if everything went ok, and leaves me with a still empty models directory. =(

osmanraifgunes commented 4 years ago

https://github.com/sequelize/sequelize/issues/11948

osmanraifgunes commented 4 years ago

Temporary solution :

Delete table_schema = 'public' from node_modules\sequelize\lib\dialects\postgres\query-generator.js line 118

and

Delete AND c.table_schema = ${this.escape(schema)} from node_modules\sequelize\lib\dialects\postgres\query-generator.js line 144

Generate database model. And undo code changes in this file.