模型与数据库对比差异时,数据库环境中 datetime(3) 字段的长度无法解析

Viewed 37

软件中识别出数据库的字段配置:image.png

数据库DDL的配置:image.png

什么数据库

1 Answers

修改MySQL的字段查询元数据模板如下图所示:

e0499245-7636-4714-a21b-85626ab35398.png

使用下方的模板替换即可:

SELECT
    table_schema as schema_name,
    table_name AS tbl_def_key,
    ordinal_position as order_value,
    column_name AS def_key,
    column_comment AS def_name,
    '' AS intro,
    column_type,
    data_type AS db_data_type,
    IF(data_type = column_type or data_type = 'decimal' or data_type = 'datetime', IF(data_type = 'decimal' or data_type = 'datetime', CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(COLUMN_TYPE, '(', -1), ',', 1) AS UNSIGNED), NULL),character_maximum_length) AS data_len,
    IF(data_type = column_type or data_type = 'decimal', IF(data_type = 'decimal', CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(COLUMN_TYPE, ',', -1), ')', 1) AS UNSIGNED), NULL), numeric_scale ) AS num_scale,
    IF(column_key = 'PRI', 1, 0 ) AS primary_key,
    IF(is_nullable = 'YES', 0, 1 ) AS not_null,
    IF(extra = 'AUTO_INCREMENT', 1, 0 ) AS auto_increment,
    column_default AS default_value
FROM
    information_schema.COLUMNS
WHERE
    table_schema in (:schemaName)
  and CONCAT(table_schema, '.', table_name) in (:sysTableNames)
ORDER BY
    table_schema ASC,
    table_name ASC,
    ordinal_position ASC