drawdb-io / drawdb

Free, simple, and intuitive online database design tool and SQL generator.
https://drawdb.app
MIT License
12.11k stars 856 forks source link

Relationships are not always imported correctly from source #8

Closed jamaa closed 2 months ago

jamaa commented 2 months ago

When importing the following SQL, the relationships between the tables are not imported:

CREATE TABLE `Pattern` (
    `Id`    INT NOT NULL AUTO_INCREMENT,
    `Description`   VARCHAR(255),
    `IsFlexible`    BOOLEAN DEFAULT (FALSE),
    `IsInterpolated`    BOOLEAN NOT NULL DEFAULT (FALSE),
    `PatternType`   INT NOT NULL,
    `ScenarioId`    INT NOT NULL,
    CONSTRAINT `PK_Pattern` PRIMARY KEY(`Id`)
);
CREATE TABLE `PatternDateValue` (
    `PatternId` INT NOT NULL,
    `Date`  DATETIME NOT NULL,
    `Value` DOUBLE,
    CONSTRAINT `PK_PatternDateValue` PRIMARY KEY(`PatternId`,`Date`),
    CONSTRAINT `FK_PatternDateValue_Pattern_PatternId` FOREIGN KEY(`PatternId`) REFERENCES `Pattern`(`Id`) ON DELETE CASCADE
);
CREATE TABLE `PatternNumberValue` (
    `PatternId` INT NOT NULL,
    `Number`    SMALLINT NOT NULL,
    `Value` DOUBLE,
    CONSTRAINT `PK_PatternNumberValue` PRIMARY KEY(`PatternId`,`Number`),
    CONSTRAINT `FK_PatternNumberValue_Pattern_PatternId` FOREIGN KEY(`PatternId`) REFERENCES `Pattern`(`Id`) ON DELETE CASCADE
);

Other relationships work as expected though. I can't figure out why some work and some don't.

Here is one that is imported correctly:

CREATE TABLE `ScenarioGroup` (
    `Id`    INT NOT NULL AUTO_INCREMENT,
    `Description`   VARCHAR(255),
    `Name`  VARCHAR(255),
    `DateCreated`   DATETIME NOT NULL,
    CONSTRAINT `PK_ScenarioGroup` PRIMARY KEY(`Id`)
);
CREATE TABLE `Scenario` (
    `Id`    INT NOT NULL AUTO_INCREMENT,
    `ScenarioGroupId`   INT NOT NULL,
    `DateCreated`   DATETIME NOT NULL,
    `Name`  VARCHAR(255),
    `Description`   VARCHAR(255),
    `ActiveSimulationId`    INT DEFAULT (0),
    `IsUpdateActive`    BOOLEAN DEFAULT (TRUE),
    `OperationalInfo`   VARCHAR(255),
    CONSTRAINT `PK_Scenario` PRIMARY KEY(`Id`),
    CONSTRAINT `FK_Scenario_ScenarioGroup_ScenarioGroupId` FOREIGN KEY(`ScenarioGroupId`) REFERENCES `ScenarioGroup`(`Id`) ON DELETE CASCADE
);