Blackdread / sql-to-jdl

Tool to translate SQL databases to JDL format of jHipster (Created due to existing databases to be generated with jHipster and build angular-java web)
MIT License
179 stars 81 forks source link

In relation, project generate relation unique key instead primary. #164

Closed sheryarshirazi closed 1 year ago

sheryarshirazi commented 1 year ago

consider sql this SQL

CREATE TABLE cars (
    car_number int(11) NOT NULL,
    model varchar(255) NOT NULL,
        UNIQUE (model),
    PRIMARY KEY (car_number)
);

CREATE TABLE excise (
    chassis_number int(11) NOT NULL,
        vehicle int(11) NOT NULL,
    PRIMARY KEY (chassis_number),
        CONSTRAINT FK_of_excise_with_cars
        FOREIGN KEY (vehicle) REFERENCES cars (car_number)
);

excise table connect with cars table by vehicle and car_number respectively but generated JDL model has connect both entities with Excise.vehical to Cars.model. It should link with car_number instead model see JDL below

entity Cars(cars) {
    carNumber Integer required,
    model String required unique maxlength(255)
}
entity Excise(excise) {
    chassisNumber Integer required
}

relationship ManyToOne {
    Excise{vehicle(model) required} to Cars{excise}
}

why do it always prefer UNIQUE over primary key?

Blackdread commented 1 year ago

The logic seems correct and expected. I do not really understand the English you wrote, can you rephrase and fix typos?

JDL is using surrogate keys, I am not in favor of that but that's how the project works.

sheryarshirazi commented 1 year ago

@Blackdread corrected but I think you already explain the reason

Blackdread commented 1 year ago

I close this ticket, the logic is correct, and the (model) means that it use that data to be displayed in the dropdown in UI. Read JDL documentation for that