ariga / entimport

A tool for generating Ent schema from SQL schema
Apache License 2.0
174 stars 49 forks source link

ent cant generate from incorrect edge (mismatch field types) #38

Closed kitchendcardiff closed 2 years ago

kitchendcardiff commented 2 years ago

ent generates an error trying to parse the generated schema from the ddl below. The provided error is: "mismatch field type between edge field "username" and id of type "User" (string != int32)"

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL,
  `token` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`),
  UNIQUE KEY `token` (`token`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8;

CREATE TABLE `programme_uploads` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL,
  `upload_time` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `username` (`username`),
  KEY `upload_time_index` (`upload_time`),
  CONSTRAINT `programme_uploads_ibfk_1` FOREIGN KEY (`username`) REFERENCES `users` (`username`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8;

I think it might be missing the foreign key reference in the generation?

giautm commented 2 years ago

Hey @kitchendcardiff, thank you for your time on the issue.

Ent currently doesn't support FK with the destination isn't a PK.

Can you migrate your database to create the column programme_uploads.user_id that reference to users.id?

kitchendcardiff commented 2 years ago

Unfortunately Its a legacy db I can't change the structure on, but I appreciate the reply and confirmation.