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

Enhancement: Inspectdb adds data types and exception handling. Models can also be generated if there are types that cannot be handled. #187

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

ProgrammerPlus1998
Copy link

@ProgrammerPlus1998 ProgrammerPlus1998 commented Aug 11, 2021

  1. Inspectdb adds DECIMAL, DOUBLE, CHAR, TIME data type matching;
    inspectdb增加 DECIMALDOUBLECHARTIME 数据类型匹配;

  2. Add exception handling to avoid manually creating the entire model because specific data types are not supported.
    添加异常处理,避免因为不支持特定的数据类型,手动创建整个模型。

xiechen and others added 2 commits August 11, 2021 17:36
1. Inspectdb adds DECIMAL, DOUBLE, CHAR, TIME data type matching;
2. Add exception handling, avoid the need to manually create the entire table because a certain data type is not supported.
increase:
1. Inspectdb adds DECIMAL, DOUBLE, CHAR, TIME data type matching;
2. Add exception handling, avoid the need to manually create the entire table because a certain data type is not supported.
@ProgrammerPlus1998 ProgrammerPlus1998 changed the title increase Enhancement: Inspectdb adds data types and exception handling. Models can also be generated if there are types that cannot be handled. Aug 11, 2021
@long2ice
Copy link
Member

可以加个单元测试

@long2ice
Copy link
Member

另外,更新一下changlog,感谢贡献!

@ProgrammerPlus1998
Copy link
Author

这块的测试之前的部分是写在哪里?

@long2ice
Copy link
Member

之前好像没有,你可以加个,然后在本地执行make style ci保证通过持续集成检测

@ProgrammerPlus1998
Copy link
Author

我一写业务的后端,让我写个测试,一时间不知道该从何下手,先下班了,明天再琢磨。🚀

@long2ice
Copy link
Member

你可以参考其他的

@ProgrammerPlus1998
Copy link
Author

我用show create table {table} 出来的结果
CREATE TABLE index_third_alternative (
id int unsigned NOT NULL AUTO_INCREMENT,
value smallint NOT NULL DEFAULT '0',
value_classification varchar(11) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT 'greed, fear',
timestamp int NOT NULL DEFAULT '0' COMMENT '平台的时间',
PRIMARY KEY (id),
UNIQUE KEY uk_alternative_timestamp (timestamp)
) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

模型创建出来的结果:
class Index_Third_Alternative(Model):
id = fields.IntField(pk=True, )
value = fields.SmallIntField()
value_classification = fields.CharField(max_length=11, null=True, )
collate = The UTF8MB4_UNICODE_CI data type type is not currently supported, please add it manually.
timestamp = fields.IntField(unique=True, description='平台的时间', )

这个模型是改完之后的效果,但是不影响代码的理解,这个 collate 并没有出现在我的数据库字段当中,为什么创建模型的时候却展示出来了,思索了半天没有找到产生这个问题的原因。

@long2ice
Copy link
Member

long2ice commented Aug 12, 2021

是解析错误吗

@ProgrammerPlus1998
Copy link
Author

我刚才查出来来,是一个bug

@ProgrammerPlus1998
Copy link
Author

这是传进去的建表语句
CREATE TABLE keyword_tags (
id int NOT NULL AUTO_INCREMENT,
tag varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
type varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
unique_key varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
comment varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (id),
KEY ix_keyword_tags_type (type)
) ENGINE=InnoDB AUTO_INCREMENT=4218 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

@ProgrammerPlus1998
Copy link
Author

这是ddlparse.py716行 ret = self._DDL_PARSE_EXPR.parseString(self._ddl) 解析出来的结果
[['id', [['int']], '', ['NOT NULL', 'AUTO_INCREMENT']],
['tag', [['varchar'], '64'], '', ['utf8mb4']],
['COLLATE', [['utf8mb4_bin']], '', ['DEFAULT NULL']],
['type', [['varchar'], '32'], '', []],
['COLLATE', [['utf8mb4_unicode_ci']], '', ['NOT NULL']],
['unique_key', [['varchar'], '32'], '', []],
['COLLATE', [['utf8mb4_unicode_ci']], '', ['NOT NULL']],
['comment', [['varchar'], '128'], '', []],
['COLLATE', [['utf8mb4_unicode_ci']], '', ['NOT NULL']],
['PRIMARY KEY', ['id']]]

@long2ice
Copy link
Member

那是第三库的问题了,有点尴尬

@ProgrammerPlus1998
Copy link
Author

简单的办法是在inspectdb里头做判断,跳过名字为collate且数据类型为UTF8MB4_UNICOID_CI的,但是不知道会不会误伤。

@ProgrammerPlus1998
Copy link
Author

大佬想办法吧,我去干活了

@long2ice
Copy link
Member

暂时要么解决该问题,要么重构,有一些想法,但是暂时没动力去弄

@waketzheng
Copy link
Contributor

Please fix conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants