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

coredump: goctl model mysql ddl --src user_base.sql --dir . #3766

Open
eyjian opened this issue Dec 8, 2023 · 5 comments
Open

coredump: goctl model mysql ddl --src user_base.sql --dir . #3766

eyjian opened this issue Dec 8, 2023 · 5 comments
Assignees
Labels
area/goctl Categorizes issue or PR as related to goctl. stale

Comments

@eyjian
Copy link

eyjian commented Dec 8, 2023

goctl model mysql ddl --src user_base.sql --dir .
[convertColumns]: The column "f_stop_time" is recommended to add constraint `DEFAULT`
[convertColumns]: The column "f_create_time" is recommended to add constraint `DEFAULT`
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x156fd00]

goroutine 1 [running]:
github.com/zeromicro/go-zero/tools/goctl/model/sql/parser.checkDuplicateUniqueIndex(0xc0005dd308?, {0xc000ad0d91, 0xb})
        /root/go/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/model/sql/parser/parser.go:182 +0x340
github.com/zeromicro/go-zero/tools/goctl/model/sql/parser.Parse({0xc00031b1d0, 0x27}, {0x0, 0x0}, 0x0?)
        /root/go/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/model/sql/parser/parser.go:162 +0x5c5
github.com/zeromicro/go-zero/tools/goctl/model/sql/gen.(*defaultGenerator).genFromDDL(0x3?, {0xc00031b1d0, 0x27}, 0xd4?, 0xd4?, {0x0, 0x0})
        /root/go/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/model/sql/gen/gen.go:215 +0x9b
github.com/zeromicro/go-zero/tools/goctl/model/sql/gen.(*defaultGenerator).StartFromDDL(0x7ffddddae538?, {0xc00031b1d0?, 0xc0002409a0?}, 0xc0?, 0xfb?, {0x0?, 0x168dae0?})
        /root/go/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/model/sql/gen/gen.go:113 +0x28
github.com/zeromicro/go-zero/tools/goctl/model/sql/command.fromDDL({{0x7ffddddae524, 0xd}, {0x7ffddddae538, 0x1}, 0xc0002409a0, 0x0, 0x0, {0x0, 0x0}, 0x0, ...})
        /root/go/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/model/sql/command/command.go:256 +0x29e
github.com/zeromicro/go-zero/tools/goctl/model/sql/command.MysqlDDL(0xc000004900?, {0x1964c71?, 0x4?, 0x4?})
        /root/go/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/model/sql/command/command.go:96 +0x2e5
github.com/spf13/cobra.(*Command).execute(0xc000004900, {0xc00023dd80, 0x4, 0x4})
        /root/go/pkg/mod/github.com/spf13/[email protected]/command.go:940 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0xc00044fb00)
        /root/go/pkg/mod/github.com/spf13/[email protected]/command.go:1068 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
        /root/go/pkg/mod/github.com/spf13/[email protected]/command.go:992
github.com/zeromicro/go-zero/tools/goctl/cmd.Execute()
        /root/go/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/cmd/root.go:46 +0x6d
main.main()
        /root/go/pkg/mod/github.com/zeromicro/go-zero/tools/[email protected]/goctl.go:12 +0x4d
# cat user_base.sql 
CREATE TABLE `t_user_base` (
  `f_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `f_uname` VARCHAR(16),
  `f_phone` VARCHAR(20),
  `f_email` VARCHAR(32),
  `f_stop_time` DATETIME NOT NULL,
  `f_create_time` DATETIME NOT NULL,
  PRIMARY KEY (`f_id`),
  UNIQUE KEY (`f_phone_number`) // error field
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
@kevwan kevwan added the area/goctl Categorizes issue or PR as related to goctl. label Dec 9, 2023
@zzZZzzz888
Copy link
Contributor

Crash will not happen with below fix (the diff is on top of latest git repository)

diff --git a/tools/goctl/model/sql/parser/parser.go b/tools/goctl/model/sql/parser/parser.go
index a929d97..158a55c 100644
--- a/tools/goctl/model/sql/parser/parser.go
+++ b/tools/goctl/model/sql/parser/parser.go
@@ -149,6 +149,9 @@ func Parse(filename, database string, strict bool) ([]*Table, error) {
 
                for indexName, each := range uniqueKeyMap {
                        for _, columnName := range each {
+                               if fieldM[columnName] == nil {
+                                       return nil, fmt.Errorf("table %s: unique key with error column name[%s]", e.Name, columnName)
+                               }
                                uniqueIndex[indexName] = append(uniqueIndex[indexName], fieldM[columnName])
                        }
                }


Thanks

@kevwan
Copy link
Contributor

kevwan commented Dec 10, 2023

Would you please submit a PR?

@POABOB
Copy link
Contributor

POABOB commented Dec 10, 2023

I can tackle it.

@zzZZzzz888
Copy link
Contributor

Thanks @POABOB and @kevwan

I will submit PR tonight

Thanks

Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/goctl Categorizes issue or PR as related to goctl. stale
Projects
None yet
Development

No branches or pull requests

5 participants