func validateOneAdminLeftInOrg(orgId int64, sess *xorm.Session) error { // validate that there is an admin user left res, err := sess.Query("SELECT 1 from org_user WHERE org_id=? and role='Admin'", orgId) if err != nil { return err } if len(res) == 0 { return m.ErrLastOrgAdmin } return err }
func (mg *Migrator) exec(m Migration, sess *xorm.Session) error { mg.Logger.Info("Executing migration", "id", m.Id()) condition := m.GetCondition() if condition != nil { sql, args := condition.Sql(mg.dialect) results, err := sess.Query(sql, args...) if err != nil || len(results) == 0 { mg.Logger.Info("Skipping migration condition not fulfilled", "id", m.Id()) return sess.Rollback() } } _, err := sess.Exec(m.Sql(mg.dialect)) if err != nil { mg.Logger.Error("Executing migration failed", "id", m.Id(), "error", err) return err } return nil }