feat: import Sea vHost single-server testing release
This commit is contained in:
commit
248badd33e
441 files changed
+63221
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
)
|
||||
|
||||
var ErrPlanInUse = errors.New("默认套餐、已被主机或历史账号引用的套餐不能删除;有未完成批量任务时请先等待任务完成")
|
||||
|
||||
func (s *Store) DeleteUnusedPlan(ctx context.Context, id uint64, confirmation string) error {
|
||||
tx, err := s.db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
var name string
|
||||
if err = tx.QueryRowContext(ctx, "SELECT name FROM plans WHERE id=? FOR UPDATE", id).Scan(&name); errors.Is(err, sql.ErrNoRows) {
|
||||
return ErrNotFound
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
if name != confirmation {
|
||||
return errors.New("请准确输入套餐名称确认删除")
|
||||
}
|
||||
var references, pending int
|
||||
if err = tx.QueryRowContext(ctx, `SELECT (SELECT COUNT(*) FROM tenants WHERE plan_id=?)+(SELECT COUNT(*) FROM projects WHERE plan_id=?),(SELECT COUNT(*) FROM admin_batches WHERE state IN ('queued','running'))`, id, id).Scan(&references, &pending); err != nil {
|
||||
return err
|
||||
}
|
||||
if id == 1 || references > 0 || pending > 0 {
|
||||
return ErrPlanInUse
|
||||
}
|
||||
if _, err = tx.ExecContext(ctx, "DELETE FROM plans WHERE id=?", id); err != nil {
|
||||
return ErrPlanInUse
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
Reference in new issue
Block a user