schemats icon indicating copy to clipboard operation
schemats copied to clipboard

TypeError: Cannot read property 'replace' of undefined

Open pardeike opened this issue 7 years ago • 6 comments

I get the following error:

$ schemats generate -c mysql://local:local@localhost/Signing -t Logs -o Logs.ts
TypeError: Cannot read property 'replace' of undefined
    at Function.MysqlDatabase.parseMysqlEnumeration (/Users/ap/.nvm/versions/node/v8.11.3/lib/node_modules/schemats/src/schemaMysql.js:119:26)
    at /Users/ap/.nvm/versions/node/v8.11.3/lib/node_modules/schemats/src/schemaMysql.js:149:60
    at Array.forEach (<anonymous>)
    at MysqlDatabase.<anonymous> (/Users/ap/.nvm/versions/node/v8.11.3/lib/node_modules/schemats/src/schemaMysql.js:147:40)
    at step (/Users/ap/.nvm/versions/node/v8.11.3/lib/node_modules/schemats/src/schemaMysql.js:32:23)
    at Object.next (/Users/ap/.nvm/versions/node/v8.11.3/lib/node_modules/schemats/src/schemaMysql.js:13:53)
    at fulfilled (/Users/ap/.nvm/versions/node/v8.11.3/lib/node_modules/schemats/src/schemaMysql.js:4:58)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

I just installed schemats with npm install -g schemats

$ type schemats
schemats is hashed (/Users/ap/.nvm/versions/node/v8.11.3/bin/schemats)

and my table looks like this:

mysql> use Signing;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> describe Logs;
+---------+------------------------------------------------+------+-----+-------------------+----------------+
| Field   | Type                                           | Null | Key | Default           | Extra          |
+---------+------------------------------------------------+------+-----+-------------------+----------------+
| id      | int(10) unsigned                               | NO   | PRI | NULL              | auto_increment |
| tstamp  | timestamp                                      | YES  | MUL | CURRENT_TIMESTAMP |                |
| user    | char(8)                                        | YES  | MUL | NULL              |                |
| session | int(10) unsigned                               | YES  | MUL | NULL              |                |
| level   | enum('debug','info','warn','error','critical') | NO   |     | NULL              |                |
| text    | text                                           | YES  |     | NULL              |                |
+---------+------------------------------------------------+------+-----+-------------------+----------------+
6 rows in set (0.00 sec)

My database installation:

mysql> status
--------------
mysql  Ver 8.0.11 for osx10.13 on x86_64 (Homebrew)

Connection id:		23
Current database:	signing
Current user:		local@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.0.11 Homebrew
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8
Db     characterset:	utf8
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/tmp/mysql.sock
Uptime:			2 hours 38 min 35 sec

pardeike avatar Jul 16 '18 15:07 pardeike

Looks like it is related to MySql 8, It has tables & columns with an uppercase. Therefore this line:var enumValues = MysqlDatabase.parseMysqlEnumeration(enumItem.column_type); passes undefined to the parseMysqlEnumeration, it can be solved in query function that will convert all column names to lower-case

felixmosh avatar Mar 06 '19 13:03 felixmosh