Ejemplo n.º 1
0
func (s *mySQLStore) GetFeatureByName(name string) (*models.Feature, error) {
	feature := new(models.Feature)

	query := sq.Select("*").From("feature").Where(sq.Eq{"name": name})

	sql, args, err := query.ToSql()
	if err != nil {
		return nil, err
	}

	log.Debug(sql)

	if err := meddler.QueryRow(s.db, feature, sql, args...); err != nil {
		return nil, err
	}

	envs, err := s.ListEnvironments()
	if err != nil {
		return nil, err
	}

	if len(envs) == 0 {
		return feature, nil
	}

	feature.Status = make(map[string]bool)
	envNames := make(map[int64]string)
	for _, env := range envs {
		feature.Status[env.Name] = false
		envNames[env.ID] = env.Name
	}

	status, err := s.listStatusByFeatureID(feature.ID)
	if err != nil {
		return nil, err
	}

	for _, st := range status {
		name := envNames[st.EnvironmentID]
		if name == "" {
			continue
		}

		feature.Status[name] = st.Enabled
	}

	return feature, nil
}
Ejemplo n.º 2
0
func (s *mySQLStore) CreateFeature(feature *models.Feature) error {
	feature.CreatedAt = time.Now()

	if err := meddler.Insert(s.db, "feature", feature); err != nil {
		return err
	}

	// update the feature to create all the status
	return s.UpdateFeature(feature)
}