2021-02-15 18:14:00 +03:00
|
|
|
package version
|
|
|
|
|
|
|
|
import (
|
2021-02-17 07:20:19 +03:00
|
|
|
"path/filepath"
|
|
|
|
|
2021-07-23 12:49:44 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/metadataobject"
|
2021-06-18 20:38:29 +03:00
|
|
|
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2"
|
2021-02-15 18:14:00 +03:00
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
2021-02-17 07:20:19 +03:00
|
|
|
type V3MetadataV2ConfigVersion struct {
|
2021-02-15 18:14:00 +03:00
|
|
|
*VersionConfig
|
|
|
|
}
|
|
|
|
|
2021-07-23 12:49:44 +03:00
|
|
|
func (a *V3MetadataV2ConfigVersion) Build(metadata *yaml.MapSlice) metadataobject.ErrParsingMetadataObject {
|
2021-02-15 18:14:00 +03:00
|
|
|
item := yaml.MapItem{
|
|
|
|
Key: "version",
|
|
|
|
// Force version 2
|
|
|
|
Value: 2,
|
|
|
|
}
|
|
|
|
*metadata = append(*metadata, item)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-17 07:20:19 +03:00
|
|
|
func NewV3MetadataVersion(ec *cli.ExecutionContext, baseDir string) *V3MetadataV2ConfigVersion {
|
2021-02-15 18:14:00 +03:00
|
|
|
ec.Version.GetServerFeatureFlags()
|
2021-02-17 07:20:19 +03:00
|
|
|
return &V3MetadataV2ConfigVersion{
|
2021-02-15 18:14:00 +03:00
|
|
|
&VersionConfig{
|
|
|
|
MetadataDir: baseDir,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2021-07-23 12:49:44 +03:00
|
|
|
func (a *V3MetadataV2ConfigVersion) Export(_ yaml.MapSlice) (map[string][]byte, metadataobject.ErrParsingMetadataObject) {
|
2021-02-17 07:20:19 +03:00
|
|
|
v := Version{
|
|
|
|
// during a v3 metadata export forcefully write metadata v2
|
|
|
|
Version: 2,
|
|
|
|
}
|
|
|
|
data, err := yaml.Marshal(v)
|
|
|
|
if err != nil {
|
2021-07-23 12:49:44 +03:00
|
|
|
return nil, a.error(err)
|
2021-02-17 07:20:19 +03:00
|
|
|
}
|
|
|
|
return map[string][]byte{
|
2021-07-23 12:49:44 +03:00
|
|
|
filepath.ToSlash(filepath.Join(a.MetadataDir, a.Filename())): data,
|
2021-02-17 07:20:19 +03:00
|
|
|
}, nil
|
|
|
|
}
|