(ctx context.Context, req dto.MysqlDBCreate)
| 100 | } |
| 101 | |
| 102 | func (u *MysqlService) Create(ctx context.Context, req dto.MysqlDBCreate) (*model.DatabaseMysql, error) { |
| 103 | if cmd.CheckIllegal(req.Name, req.Username, req.Password, req.Format, req.Collation, req.Permission) { |
| 104 | return nil, buserr.New("ErrCmdIllegal") |
| 105 | } |
| 106 | |
| 107 | mysql, _ := mysqlRepo.Get(repo.WithByName(req.Name), mysqlRepo.WithByMysqlName(req.Database), repo.WithByFrom(req.From)) |
| 108 | if mysql.ID != 0 { |
| 109 | return nil, buserr.New("ErrRecordExist") |
| 110 | } |
| 111 | |
| 112 | var createItem model.DatabaseMysql |
| 113 | if err := copier.Copy(&createItem, &req); err != nil { |
| 114 | return nil, buserr.WithDetail("ErrStructTransform", err.Error(), nil) |
| 115 | } |
| 116 | |
| 117 | if req.From == "local" && req.Username == "root" { |
| 118 | return nil, errors.New("cannot set root as user name") |
| 119 | } |
| 120 | |
| 121 | cli, version, err := LoadMysqlClientByFrom(req.Database) |
| 122 | if err != nil { |
| 123 | return nil, err |
| 124 | } |
| 125 | createItem.MysqlName = req.Database |
| 126 | defer cli.Close() |
| 127 | if err := cli.Create(client.CreateInfo{ |
| 128 | Name: req.Name, |
| 129 | Format: req.Format, |
| 130 | Collation: req.Collation, |
| 131 | Username: req.Username, |
| 132 | Password: req.Password, |
| 133 | Permission: req.Permission, |
| 134 | Version: version, |
| 135 | Timeout: 300, |
| 136 | }); err != nil { |
| 137 | return nil, err |
| 138 | } |
| 139 | |
| 140 | global.LOG.Infof("create database %s successful!", req.Name) |
| 141 | if err := mysqlRepo.Create(ctx, &createItem); err != nil { |
| 142 | return nil, err |
| 143 | } |
| 144 | return &createItem, nil |
| 145 | } |
| 146 | |
| 147 | func (u *MysqlService) BindUser(req dto.BindUser) error { |
| 148 | if cmd.CheckIllegal(req.Username, req.Password, req.Permission) { |
nothing calls this directly
no test coverage detected