Beispiel #1
0
func GetSchemaFromDb(b *bolt.DB) Schema {

	// first version
	v := First
	err := b.View(func(t *bolt.Tx) error {
		b := t.Bucket(AboutBucket)
		if b == nil {
			return nil
		}

		v = VersionFromString(string(b.Get([]byte("about"))))
		return nil
	})
	if err != nil {
		return Schemas[0]
	}

	// find the oldest valid schema
	for _, s := range Schemas {

		// best case, exact match
		if s.Version == v {
			return s
		}

		// as soon as we find an older version, this is the one
		if !s.Version.Greater(v) {
			return s
		}
	}

	return Schemas[0]
}