(info DeleteInfo)
| 126 | } |
| 127 | |
| 128 | func (r *Remote) Delete(info DeleteInfo) error { |
| 129 | if len(info.Name) != 0 { |
| 130 | inUse, err := r.isDatabaseInUse(info.Name, info.Timeout) |
| 131 | if err != nil && !info.ForceDelete { |
| 132 | return fmt.Errorf("check database connections failed, err: %v", err) |
| 133 | } |
| 134 | if inUse && !info.ForceDelete { |
| 135 | return buserr.WithDetail("ErrInUsed", info.Name, nil) |
| 136 | } |
| 137 | dropSql := fmt.Sprintf("DROP DATABASE \"%s\"", info.Name) |
| 138 | if err := r.ExecSQL(dropSql, info.Timeout); err != nil && !info.ForceDelete { |
| 139 | return fmt.Errorf("drop database failed, err: %v", err) |
| 140 | } |
| 141 | } |
| 142 | dropSql := fmt.Sprintf("DROP USER \"%s\"", info.Username) |
| 143 | if err := r.ExecSQL(dropSql, info.Timeout); err != nil && !info.ForceDelete { |
| 144 | return fmt.Errorf("drop user failed, err: %v", err) |
| 145 | } |
| 146 | return nil |
| 147 | } |
| 148 | |
| 149 | func (r *Remote) isDatabaseInUse(name string, timeout uint) (bool, error) { |
| 150 | ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) |
no test coverage detected