Skip to content

goctl model mysql datasource fails to identify NULL correctly in MariaDB #5384

@leetpy

Description

@leetpy

Describe the bug
When using goctl model mysql datasource to generate database models, the tool determines if a field's default value is NULL by checking COLUMN_DEFAULT. However, this logic encounters issues when running against MariaDB.

To Reproduce
Steps to reproduce the behavior, if applicable:

  1. test sql
CREATE DATABASE testnull;
USE testnull;

CREATE TABLE `test_table` (
 `test_null` VARCHAR(10) DEFAULT 'NULL',
 `name` VARCHAR(10) DEFAULT 'aaa',
 `age` int DEFAULT 10,
 `deleted_at` datetime(3) DEFAULT NULL
);

SELECT 
 c.COLUMN_NAME,
 c.DATA_TYPE,
 c.COLUMN_TYPE,
 c.EXTRA,
 c.COLUMN_COMMENT,
 c.COLUMN_DEFAULT,
 c.IS_NULLABLE,
 c.ORDINAL_POSITION 
FROM INFORMATION_SCHEMA.COLUMNS c 
WHERE c.TABLE_SCHEMA = 'testnull' 
AND c.TABLE_NAME = 'test_table';
  1. The error is
    In mariadb-11.4 I get the flllowing content
    Image

In MySQL-9.6.0 I get the flllowing content
Image

Expected behavior

The code check isDefaultNull with COLUMN_DEFAULT , but in mariadb, we get a null string.

https://github.com/zeromicro/go-zero/blob/master/tools/goctl/model/sql/parser/parser.go#L355

Environments (please complete the following information):

  • OS: Linux
  • goctl version 1.9.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions