MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / Delete

Method Delete

agent/utils/postgresql/client/remote.go:128–147  ·  view source on GitHub ↗
(info DeleteInfo)

Source from the content-addressed store, hash-verified

126}
127
128func (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
149func (r *Remote) isDatabaseInUse(name string, timeout uint) (bool, error) {
150 ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)

Callers 1

CreateUserMethod · 0.95

Calls 2

isDatabaseInUseMethod · 0.95
ExecSQLMethod · 0.95

Tested by

no test coverage detected