// By setting various fields of api.Operation, Alter can be used to do the
// following:
//
// 1. Modify the schema.
//
// 2. Drop a predicate.
//
// 3. Drop the database.
517816
func (d *Dgraph) Alter(ctx context.Context, op *api.Operation) error {
	dc := d.anyClient()

	ctx = d.getContext(ctx)
	_, err := dc.Alter(ctx, op)

	if isJwtExpired(err) {
		err = d.retryLogin(ctx)
		if err != nil {
			return err
		}
		ctx = d.getContext(ctx)
		_, err = dc.Alter(ctx, op)
	}

	return err
}
300469
func CreateChangefeedTable(db gorm.DB) error {
	query := db.AutoMigrate(&SQLChange{})
	return query.Error
}
627294
func Schema(extra environschema.Fields) (environschema.Fields, error) {
	fields := make(environschema.Fields)
	for name, field := range configSchema {
		if controller.ControllerOnlyAttribute(name) {
			return nil, errors.Errorf("config field %q clashes with controller config", name)
		}
		fields[name] = field
	}
	for name, field := range extra {
		if controller.ControllerOnlyAttribute(name) {
			return nil, errors.Errorf("config field %q clashes with controller config", name)
		}
		if _, ok := fields[name]; ok {
			return nil, errors.Errorf("config field %q clashes with global config", name)
		}
		fields[name] = field
	}
	return fields, nil
}
765559
func (agent *ActionAgent) PreflightSchema(ctx context.Context, changes []string) ([]*tabletmanagerdatapb.SchemaChangeResult, error) {
	if err := agent.lock(ctx); err != nil {
		return nil, err
	}
	defer agent.unlock()

	// get the db name from the tablet
	dbName := topoproto.TabletDbName(agent.Tablet())

	// and preflight the change
	return agent.MysqlDaemon.PreflightSchemaChange(dbName, changes)
}
1214951
func RemoveAppName(db *mgo.Database) (err error) {
	Topics := db.C(topicsCollection)

	change, err := Topics.UpdateAll(
		bson.M{},
		bson.M{
			"$unset": bson.M{
				"app_name": "",
			},
		},
	)
	handle_errors(err)
	fmt.Println("Updated", change.Updated, "documents in `", topicsCollection, "` collection")
	return
}
377641
func (fmd *FakeMysqlDaemon) ApplySchemaChange(dbName string, change *tmutils.SchemaChange) (*tabletmanagerdatapb.SchemaChangeResult, error) {
	if fmd.ApplySchemaChangeResult == nil {
		return nil, fmt.Errorf("no apply schema defined")
	}
	return fmd.ApplySchemaChangeResult, nil
}
135242
func Change(schema interface{}, changes ...map[string]interface{}) *Changeset {
	ch := &Changeset{}
	ch.changes = make(map[string]interface{})
	ch.values, ch.types, _ = mapSchema(schema)

	if len(changes) > 0 {
		ch.changes = changes[0]
	} else {
		ch.changes = make(map[string]interface{})
	}

	return ch
}
271713
func (db *Database) Delete(id string, rev string) (string, error) {
	url, err := buildUrl(db.dbName, id)
	if err != nil {
		return "", err
	}
	var headers = make(map[string]string)
	headers["Accept"] = "application/json"
	headers["If-Match"] = rev
	resp, err := db.connection.request("DELETE", url, nil, headers, db.auth)
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()
	return getRevInfo(resp)
}
843997
func (api *DatabaseAPI) SetFilterBy(key string, value interface{}) {
	api.filterBy(key, value, false)
}
923328
func (exclude ExcludeConstraint) Modify(table *aspect.TableElem) error {
	// There must be at least one clause
	if len(exclude.clauses) == 0 {
		return fmt.Errorf(
			"postgres: an EXCLUDE constraint must contain at least one clause",
		)
	}

	// All excluded elements must exist in the given table
	for _, clause := range exclude.clauses {
		_, exists := table.C[clause.Name]
		if !exists {
			return fmt.Errorf(
				"No column with the name '%s' exists in the table '%s'. Is it declared after the PrimaryKey declaration?",
				clause.Name, table.Name(),
			)
		}
	}

	table.AddCreatable(exclude)
	return nil
}
1207117
func (c *CodebaseController) Edit(ctx *app.EditCodebaseContext) error {
	listWorkspacesContext := app.ListWorkspacesCodebaseContext{ctx.Context, ctx.ResponseData, ctx.RequestData, ctx.CodebaseID}
	return c.ListWorkspaces(&listWorkspacesContext)
}
1026229
func (db *DB) AddQuery(query string, expectedResult *sqltypes.Result) *ExpectedResult {
	if len(expectedResult.Rows) > 0 && len(expectedResult.Fields) == 0 {
		panic(fmt.Errorf("please add Fields to this Result so it's valid: %v", query))
	}
	resultCopy := &sqltypes.Result{}
	*resultCopy = *expectedResult
	db.mu.Lock()
	defer db.mu.Unlock()
	key := strings.ToLower(query)
	r := &ExpectedResult{resultCopy, nil}
	db.data[key] = r
	db.queryCalled[key] = 0
	return r
}
508954
func (s *service) Edit(reqDTO rest.RequestDTO) (resDTO rest.ResponseDTO, error *servicehelper.Error) {
	entity, err := s.repo.FindByPublicId(reqDTO.PublicId)
	if err != nil {
		return rest.ResponseDTO{}, &servicehelper.Error{Detail: errors.New("no result found"), Code: servicehelper.NotFound}
	}

	entity.FirstName = reqDTO.FirstName
	entity.LastName = reqDTO.LastName
	entity.ProfilePictureUrl = reqDTO.ProfilePictureUrl
	birthday, err := time.Parse("2006-01-02", reqDTO.Birthday)
	if err != nil {
		return rest.ResponseDTO{}, &servicehelper.Error{Detail: errors.New("birthday is malformed"), Code: servicehelper.BadRequest}
	}
	entity.Birthday = &birthday

	if err := s.repo.Update(entity); err != nil {
		return rest.ResponseDTO{}, &servicehelper.Error{
			Detail:  errors.New("could not update profile"),
			Message: "We could not update the profile, please contact us or try again later",
			Code:    servicehelper.UnexpectedError}
	}
	return createDTOFromEntity(entity)
}
479410
func (client *Client) PreflightSchema(ctx context.Context, tablet *topodatapb.Tablet, changes []string) ([]*tabletmanagerdatapb.SchemaChangeResult, error) {
	cc, c, err := client.dial(tablet)
	if err != nil {
		return nil, err
	}
	defer cc.Close()

	response, err := c.PreflightSchema(ctx, &tabletmanagerdatapb.PreflightSchemaRequest{
		Changes: changes,
	})
	if err != nil {
		return nil, err
	}

	return response.ChangeResults, nil
}
190713
func (db *DB) Rename(oldName, newName string) error {
	db.schemaLock.Lock()
	defer db.schemaLock.Unlock()
	if _, exists := db.cols[oldName]; !exists {
		return fmt.Errorf("Collection %s does not exist", oldName)
	} else if _, exists := db.cols[newName]; exists {
		return fmt.Errorf("Collection %s already exists", newName)
	} else if err := db.cols[oldName].close(); err != nil {
		return err
	} else if err := os.Rename(path.Join(db.path, oldName), path.Join(db.path, newName)); err != nil {
		return err
	} else if db.cols[newName], err = OpenCol(db, newName); err != nil {
		return err
	}
	delete(db.cols, oldName)
	return nil
}
294054
func (db *Database) Put(key []byte, value []byte) error {
	return db.db.Put(key, value, nil)
}
97665
func (pk PrimaryKeyArray) Modify(table *TableElem) error {
	// Confirm that all columns in the primary key exists
	for _, name := range pk {
		_, exists := table.C[name]
		if !exists {
			return fmt.Errorf(
				"No column with the name '%s' exists in the table '%s'. Is it declared after the PrimaryKey declaration?",
				name, table.Name(),
			)
		}
		// TODO Set the attributes of the column type?
	}
	// If all columns exist, set the primary key
	table.pk = pk

	// Add the pk to the create array
	table.creates = append(table.creates, pk)

	return nil
}