Error on generating schema (Multiple enums with the same name)
teachtocode opened this issue · 2 comments
Hi , when i try to execute the command i am getting error
command :
schemats generate -c mysql://root:root@localhost:8889/labourindia -t kc_blogs -o osms.ts
Error: Multiple enums with the same name and contradicting types were found: status: ["1","0"] and ["0","1"]
at /usr/local/lib/node_modules/schemats/src/schemaMysql.js:153:39
at Array.forEach ()
at MysqlDatabase. (/usr/local/lib/node_modules/schemats/src/schemaMysql.js:147:40)
at step (/usr/local/lib/node_modules/schemats/src/schemaMysql.js:32:23)
at Object.next (/usr/local/lib/node_modules/schemats/src/schemaMysql.js:13:53)
at fulfilled (/usr/local/lib/node_modules/schemats/src/schemaMysql.js:4:58)
Seeing the same issue here:
Error: Multiple enums with the same name and contradicting types were found: type: ["REQUEST","RESPONSE"] and ["INTERNAL","EXTERNAL"]
at /Users/rpitt-mbp/.npm/_npx/29285/lib/node_modules/schemats/src/schemaMysql.js:153:39
at Array.forEach (<anonymous>)
at MysqlDatabase.<anonymous> (/Users/rpitt-mbp/.npm/_npx/29285/lib/node_modules/schemats/src/schemaMysql.js:147:40)
at step (/Users/rpitt-mbp/.npm/_npx/29285/lib/node_modules/schemats/src/schemaMysql.js:32:23)
at Object.next (/Users/rpitt-mbp/.npm/_npx/29285/lib/node_modules/schemats/src/schemaMysql.js:13:53)
at fulfilled (/Users/rpitt-mbp/.npm/_npx/29285/lib/node_modules/schemats/src/schemaMysql.js:4:58)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
I am encountering the same error. The reason is that one or more different tables have the same enum column names, in my case it was 'type'. Here is the query you can run to determine the culprits:
SELECT
col.table_schema AS database_name,
col.table_name,
col.ordinal_position AS column_id,
col.column_name,
col.data_type,
TRIM(
LEADING 'enum'
FROM
col.column_type
) AS enum_values
FROM
information_schema.columns col
JOIN information_schema.tables tab ON tab.table_schema = col.table_schema
AND tab.table_name = col.table_name
AND tab.table_type = 'BASE TABLE'
WHERE
col.data_type IN ('enum')
AND col.table_schema NOT IN (
'information_schema',
'sys',
'performance_schema',
'mysql'
)
AND col.table_schema = 'your-database-name'
ORDER BY
col.column_name,
col.table_schema,
col.table_name;
I am going to try to rename my columns since there's not that many of them, and this is something we try to do anyways in this project (thing_status
instead of just status
for clarity). What's weird was this is the command I was running:
bash> schemats generate -c mysql://root@localhost/db-name -t users -o users.ts
Which I would think would only scan the table I specified which doesn't have one of the offending columns, but I guess not.