Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'replace' of undefined #97

Open
pardeike opened this issue Jul 16, 2018 · 1 comment · May be fixed by #123
Open

TypeError: Cannot read property 'replace' of undefined #97

pardeike opened this issue Jul 16, 2018 · 1 comment · May be fixed by #123

Comments

@pardeike
Copy link

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
chaffeqa added a commit to chaffeqa/schemats that referenced this issue Aug 20, 2018
The issue was `enumItem` looks like:

```
RowDataPacket {
  COLUMN_NAME: 'gameType',
  COLUMN_TYPE: 'enum(\'BRACKET\',\'PICKEM\')',
  DATA_TYPE: 'enum' }
```

I'm sure there is a nicer + tested solution, but unfortunately I don't have the time to submit that, sorry!
@felixmosh
Copy link

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

@maranomynet maranomynet linked a pull request Jan 14, 2021 that will close this issue
maranomynet added a commit to maranomynet/mysql-schema-ts that referenced this issue Jan 14, 2021
Fixes a column-name issue that seems to affect mysql@8

See description/info here: SweetIQ/schemats#97
nettofarah pushed a commit to nettofarah/mysql-schema-ts that referenced this issue Feb 20, 2021
Fixes a column-name issue that seems to affect mysql@8

See description/info here: SweetIQ/schemats#97
nettofarah added a commit to nettofarah/mysql-schema-ts that referenced this issue Sep 8, 2021
)

* Rename selected columns to guarantee correct case

Fixes a column-name issue that seems to affect mysql@8

See description/info here: SweetIQ/schemats#97

* fix: Assume that a "auto_increment"-ing non-nullable column "hasDefault"

This makes sure that primary key "id" fields are flagged as optional 
for inserts.

Co-authored-by: Netto Farah <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants