Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI can't generate entity if enum value starts with a number #1172

Closed
SPeeSimon opened this issue Oct 29, 2022 · 3 comments · Fixed by #1211
Closed

CLI can't generate entity if enum value starts with a number #1172

SPeeSimon opened this issue Oct 29, 2022 · 3 comments · Fixed by #1211
Assignees

Comments

@SPeeSimon
Copy link

Description

Unable to generate an entity when an enum value starts with a number (basically when it is an invalid enum value).
I am trying to generate entities from an existing database (more precise: a wikipedia schema).

The cli fails to create to generate the source for some tables. The DDL for one of the failing table is:

CREATE TABLE `image` (
  `img_name` varbinary(255) NOT NULL DEFAULT '',
  `img_size` int(8) unsigned NOT NULL DEFAULT '0',
  `img_width` int(5) NOT NULL DEFAULT '0',
  `img_height` int(5) NOT NULL DEFAULT '0',
  `img_metadata` mediumblob NOT NULL,
  `img_bits` int(3) NOT NULL DEFAULT '0',
  `img_media_type` enum('UNKNOWN','BITMAP','DRAWING','AUDIO','VIDEO','MULTIMEDIA','OFFICE','TEXT','EXECUTABLE','ARCHIVE','3D') DEFAULT NULL,
  `img_major_mime` enum('unknown','application','audio','image','text','video','message','model','multipart','chemical') NOT NULL DEFAULT 'unknown',
  `img_minor_mime` varbinary(100) NOT NULL DEFAULT 'unknown',
  `img_description_id` bigint(20) unsigned NOT NULL,
  `img_actor` bigint(20) unsigned NOT NULL,
  `img_timestamp` binary(14) NOT NULL,
  `img_sha1` varbinary(32) NOT NULL DEFAULT '',
  PRIMARY KEY (`img_name`),
  KEY `img_size` (`img_size`),
  KEY `img_timestamp` (`img_timestamp`),
  KEY `img_media_mime` (`img_media_type`,`img_major_mime`,`img_minor_mime`),
  KEY `img_actor_timestamp` (`img_actor`,`img_timestamp`),
  KEY `img_sha1` (`img_sha1`(10))
) ENGINE=InnoDB DEFAULT CHARSET=binary ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8

Steps to Reproduce

  1. Create database tables (I used https://gerrit.wikimedia.org/g/mediawiki/core/%2B/HEAD/maintenance/tables-generated.sql)
  2. Generate entities: sea-orm-cli generate entity --tables image

Expected Behavior

What I don't expect is a "panicked" message, but rather:

  • Entity is created with the enum value altered and inform the user of the update
  • Entity is created with the invalid enum value and inform the user of the error
  • Entity is created, but the invalid enum value is skipped or commented out and inform the user of the error
  • The user has the option to choose which action to do

Actual Behavior

thread 'main' panicked at '"3d" is not a valid Ident', C:.cargo\registry\src\github.com-1ecc6299db9ec823\proc-macro2-1.0.47\src\fallback.rs:756:9

Reproduces How Often

allways

Versions

sea-orm-cli 0.10.1
mysql

Additional Information

The problem also applies for the tables: filearchive, image, imagelinks, oldimage, uploadstash

@tyt2y3
Copy link
Member

tyt2y3 commented Oct 30, 2022

Interesting, should not be a difficult fix

Ref: #588 (comment)

@Yuubari
Copy link

Yuubari commented Nov 1, 2022

This happens for PostgreSQL as welll; indeed with the MediaWiki schema:

CREATE TYPE mediawiki.media_type AS ENUM (
    'UNKNOWN',
    'BITMAP',
    'DRAWING',
    'AUDIO',
    'VIDEO',
    'MULTIMEDIA',
    'OFFICE',
    'TEXT',
    'EXECUTABLE',
    'ARCHIVE',
    '3D'
);

@billy1624
Copy link
Member

Hey @SPeeSimon @Yuubari, sorry for the delay. Please check #1211 for the fix :)

@billy1624 billy1624 moved this from Triage to Done in SeaQL Dev Tracker Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants