sequelize / sequelize-auto

Automatically generate bare sequelize models from your database.
2.88k stars 521 forks source link

Treat a single column, nonnull unique index as a primary key if no primary key was found #639

Open hhowe29 opened 1 year ago

hhowe29 commented 1 year ago

Don't ask how, but we have to deal with some legacy MSSQL tables that look like this:

create table foo
(
    foo_id  integer not null,
    name  varchar(50)
);

create unique index if not exists idx_foo_id
on foo (foo_id);

Modify auto-builder.ts to detect this joyous occasion and treat foo_id as a primary key. This is similar to the logic for #480 , and that block of cod would be a good insertion point for this logic. The indexes are loaded just above that.