// AddMigrationAttempt adds an "attempt" field to migration documents
// which are missing one.
19509
func AddMigrationAttempt(pool *StatePool) error {
	st := pool.SystemState()
	coll, closer := st.db().GetRawCollection(migrationsC)
	defer closer()

	query := coll.Find(bson.M{"attempt": bson.M{"$exists": false}})
	query = query.Select(bson.M{"_id": 1})
	iter := query.Iter()
	defer iter.Close()
	var ops []txn.Op
	var doc bson.M
	for iter.Next(&doc) {
		id := doc["_id"]
		attempt, err := extractMigrationAttempt(id)
		if err != nil {
			upgradesLogger.Warningf("%s (skipping)", err)
			continue
		}

		ops = append(ops, txn.Op{
			C:      migrationsC,
			Id:     id,
			Assert: txn.DocExists,
			Update: bson.D{{"$set", bson.D{{"attempt", attempt}}}},
		})
	}
	if err := iter.Close(); err != nil {
		return errors.Annotate(err, "iterating migrations")
	}

	return errors.Trace(st.runRawTransaction(ops))
}
331182
func (c *GetConfigSetsCall) IncludeLastImportAttempt(includeLastImportAttempt bool) *GetConfigSetsCall {
	c.urlParams_.Set("include_last_import_attempt", fmt.Sprint(includeLastImportAttempt))
	return c
}
406081
func (md *MDServerDisk) StartImplicitTeamMigration(
	ctx context.Context, id tlf.ID) (err error) {
	panic("StartImplicitTeamMigration called on *MDServerDisk")
}
653246
func MarkMigrationAsComplete(db *bolt.DB, id string) error {
	if err := db.Update(func(tx *bolt.Tx) error {
		now := time.Now().UTC().Format(time.RFC3339)
		return tx.Bucket(SchemaVersionBucket).Put([]byte(id), []byte(now))
	}); err != nil {
		return err
	}

	return nil
}
406105
func (t Term) InsertAt(args ...interface{}) Term {
	return constructMethodTerm(t, "InsertAt", p.Term_INSERT_AT, args, map[string]interface{}{})
}
1269326
func ApplyMigrations(database Database, migrationsFolder string) error {
	// Initialize migrations table, if it does not exist yet
	if err := database.CreateMigrationsTable(); err != nil {
		return err
	}

	// Scan migration file names in migrations folder
	d, err := os.Open(migrationsFolder)
	if err != nil {
		return err
	}
	dir, err := d.Readdir(-1)
	if err != nil {
		return err
	}

	// Run migrations
	sqlFiles := make([]string, 0)
	for _, f := range dir {
		ext := filepath.Ext(f.Name())
		if ".sql" == ext || ".cql" == ext {
			sqlFiles = append(sqlFiles, f.Name())
		}
	}
	sort.Strings(sqlFiles)
	for _, filename := range sqlFiles {
		// if exists in migrations table, leave it
		// else execute sql
		migrated, err := database.HasMigrated(filename)
		if err != nil {
			return err
		}
		fullpath := filepath.Join(migrationsFolder, filename)
		if migrated {
			fmt.Println("Already migrated", fullpath)
			continue
		}
		b, err := ioutil.ReadFile(fullpath)
		if err != nil {
			return err
		}
		migration := string(b)
		if len(migration) == 0 {
			fmt.Println("Skipping empty file", fullpath)
			continue // empty file
		}
		err = database.Migrate(filename, migration)
		if err != nil {
			return err
		}
		fmt.Println("Migrated", fullpath)
	}

	return nil
}
1320584
func (r *Rewriter) refsToMigrate() ([]*git.Ref, error) {
	var refs []*git.Ref
	var err error

	if root, ok := r.db.Root(); ok {
		refs, err = git.AllRefsIn(root)
	} else {
		refs, err = git.AllRefs()
	}

	if err != nil {
		return nil, err
	}

	var local []*git.Ref
	for _, ref := range refs {
		if ref.Type == git.RefTypeRemoteBranch {
			continue
		}

		local = append(local, ref)
	}

	return local, nil
}
865770
func (s *IdentityService) AddUserLoginAttempt(user string, attempt services.LoginAttempt, ttl time.Duration) error {
	if err := attempt.Check(); err != nil {
		return trace.Wrap(err)
	}
	value, err := json.Marshal(attempt)
	if err != nil {
		return trace.Wrap(err)
	}
	item := backend.Item{
		Key:     backend.Key(webPrefix, usersPrefix, user, attemptsPrefix, uuid.New()),
		Value:   value,
		Expires: backend.Expiry(s.Clock(), ttl),
	}
	_, err = s.Put(context.TODO(), item)
	return trace.Wrap(err)
}
1096823
func (s *ModifyReplicationTaskInput) SetMigrationType(v string) *ModifyReplicationTaskInput {
	s.MigrationType = &v
	return s
}
521240
func (g *Generator) AddImport(importPath GoImportPath) GoPackageName {
	g.addedImports[importPath] = true
	return g.GoPackageName(importPath)
}
1336974
func (c *Connection) MigrateReset(path string) error {
	oncer.Deprecate(0, "pop.Connection#MigrateReset", "Use pop.FileMigrator#Reset instead.")

	mig, err := NewFileMigrator(path, c)
	if err != nil {
		return errors.WithStack(err)
	}
	return mig.Reset()
}
920796
func (_m *FacadeInterface) AddServiceTemplate(ctx datastore.Context, serviceTemplate servicetemplate.ServiceTemplate, reloadLogstashConfig bool) (string, error) {
	ret := _m.Called(ctx, serviceTemplate, reloadLogstashConfig)

	var r0 string
	if rf, ok := ret.Get(0).(func(datastore.Context, servicetemplate.ServiceTemplate, bool) string); ok {
		r0 = rf(ctx, serviceTemplate, reloadLogstashConfig)
	} else {
		r0 = ret.Get(0).(string)
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(datastore.Context, servicetemplate.ServiceTemplate, bool) error); ok {
		r1 = rf(ctx, serviceTemplate, reloadLogstashConfig)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
96794
func (dm *DjangoMigration) Insert(db XODB) error {
	var err error

	// if already exist, bail
	if dm._exists {
		return errors.New("insert failed: already exists")
	}

	// sql insert query, primary key provided by sequence
	const sqlstr = `INSERT INTO public.django_migrations (` +
		`app, name, applied` +
		`) VALUES (` +
		`$1, $2, $3` +
		`) RETURNING id`

	// run query
	XOLog(sqlstr, dm.App, dm.Name, dm.Applied)
	err = db.QueryRow(sqlstr, dm.App, dm.Name, dm.Applied).Scan(&dm.ID)
	if err != nil {
		return err
	}

	// set existence
	dm._exists = true

	return nil
}
527253
func addImportsForInterfaceMethods(imports importMap, it reflect.Type) {
	// Handle each method.
	for i := 0; i < it.NumMethod(); i++ {
		m := it.Method(i)
		addImportsForType(imports, m.Type)
	}
}
625030
func (md *MDServerMemory) StartImplicitTeamMigration(
	ctx context.Context, id tlf.ID) (err error) {
	md.lock.Lock()
	defer md.lock.Unlock()
	md.iTeamMigrationLocks[id] = true
	return nil
}
564729
func MakeAttempt(c context.Context, aid *dm.Attempt_ID) *Attempt {
	now := clock.Now(c).UTC()
	return &Attempt{
		ID:       *aid,
		Created:  now,
		Modified: now,
	}
}
938390
func ShortAttempt() RetryStrategy {
	return RetryStrategy{
		Count:          10,
		Break:          50 * time.Millisecond,
		BreakIncrement: 0,
		Timeout:        5 * time.Second,
	}
}