func (st *State) migrationFromQuery(query mongo.Query) (ModelMigration, error) { var doc modelMigDoc err := query.One(&doc) if err == mgo.ErrNotFound { return nil, errors.NotFoundf("migration") } else if err != nil { return nil, errors.Annotate(err, "migration lookup failed") } statusColl, closer := st.getCollection(migrationsStatusC) defer closer() var statusDoc modelMigStatusDoc err = statusColl.FindId(doc.Id).One(&statusDoc) if err == mgo.ErrNotFound { return nil, errors.NotFoundf("migration status") } else if err != nil { return nil, errors.Annotate(err, "migration status lookup failed") } return &modelMigration{ doc: doc, statusDoc: statusDoc, st: st, }, nil }
func (m *Model) refresh(query mongo.Query) error { err := query.One(&m.doc) if err == mgo.ErrNotFound { return errors.NotFoundf("model") } return err }