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

Error on generating schema (Multiple enums with the same name) #125

Open
teachtocode opened this issue Apr 6, 2021 · 2 comments
Open

Error on generating schema (Multiple enums with the same name) #125

teachtocode opened this issue Apr 6, 2021 · 2 comments

Comments

@teachtocode
Copy link

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)

@robertpitt
Copy link

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)

@jrbakooba
Copy link

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.

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

No branches or pull requests

3 participants