drawio icon indicating copy to clipboard operation
drawio copied to clipboard

Having multiple primary keys causes a parsing issue when converting SQL to an ER-Diagram

Open pica4500 opened this issue 2 years ago • 1 comments

Preflight Checklist

  • [x] I agree to follow the Code of Conduct that this project adheres to.
  • [x] I have searched the issue tracker for a feature request that matches the one I want to file, without success.

You must agree to search and the code of conduct. You must fill in this entire template. If you delete part/all or miss parts out your issue will be closed.

If you are technical, you should reporting bugs along the lines of https://marker.io/blog/how-to-write-bug-report. If you are not technical, we will make allowances, please try to make an effort to understand the process.

Describe the bug In the example below, when converting SQL to ER-Diagram, the primary key cannot be parsed.

CREATE TABLE Persons (
    ID int NOT NULL,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Age int,
    PRIMARY KEY (ID, LastName)
);

To Reproduce Steps to reproduce the behavior:

  1. Go to '+'
  2. Click on 'Advanced'
  3. Scroll down to 'SQL'
  4. copy and paste below code and generate
CREATE TABLE Persons (
    ID int NOT NULL,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Age int,
    PRIMARY KEY (ID, LastName)
);
  1. See draw.io cannot parse ID, LastName as a primary key image

Expected behavior ER Diagram should check ID, LastName column as PK

Screenshots

image

draw.io version (In the Help->About menu of the draw.io editor):

  • draw.io version 21.6.6

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Firefox
  • Browser Version 120.0.1

Smartphone (please complete the following information):

  • Only checked in desktop

I tested the problem in incognito/private mode with all browser extensions switched off, write "yes" below:

  • yes

Additional context draw.io docs says it supports MySQL (https://www.drawio.com/doc/faq/sql-plugin)

In MySQL docs, you can also check, this kind of multiple primary keys are supported. (https://dev.mysql.com/doc/refman/8.0/en/partitioning-limitations-partitioning-keys-unique-keys.html)

I guess, you have to check below code. If input has PRIMARY KEY (ID, LastName) then, below code will push "ID, LastName" string into primaryKeyList and this string will not match with any columns i guess.

var primaryKey = name.replace('PRIMARY KEY (', '').replace(')', '');

https://github.com/jgraph/drawio/blob/1d6d5d06716665a80767c51781bd2aa344ff8a9d/src/main/webapp/plugins/sql.js#L454

pica4500 avatar Jan 17 '24 23:01 pica4500

@pica4500 I have a pr #4122 for the sql plugin that you have to install yourself manually (one file change) for improvements on the sql import parsing into uml diagram for draw.io.

Note on https://www.drawio.com/doc/faq/sql-plugin that this plugin is not maintained by core drawio developers, and they are closed contributions hence won't merge my pr with the improvements. This plugin should be used as-is, as an unsupported example for developers.

lastlink avatar Jan 28 '24 03:01 lastlink

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. See the FAQ for more information.

github-actions[bot] avatar Aug 03 '24 11:08 github-actions[bot]