cli: add check_metadata_consistency for v2 workflow migrations (#4392)

This commit is contained in:
Aravind Shankar 2020-04-22 15:52:02 +05:30 committed by GitHub
parent aca11f0944
commit 2ee6328d0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 14 deletions

View File

@ -99,6 +99,9 @@ func (m *mockDriver) SetMetadataPlugins(plugins types.MetadataPlugins) {
return
}
func (m *mockDriver) EnableCheckMetadataConsistency(enabled bool) {
}
func (m *mockDriver) GetInconsistentMetadata() (bool, []InconsistentMetadataInterface, error) {
return false, []InconsistentMetadataInterface{}, nil
}

View File

@ -38,14 +38,15 @@ var (
)
type Config struct {
MigrationsTable string
SettingsTable string
queryURL *nurl.URL
graphqlURL *nurl.URL
pgDumpURL *nurl.URL
Headers map[string]string
isCMD bool
Plugins types.MetadataPlugins
MigrationsTable string
SettingsTable string
queryURL *nurl.URL
graphqlURL *nurl.URL
pgDumpURL *nurl.URL
Headers map[string]string
isCMD bool
Plugins types.MetadataPlugins
enableCheckMetadataConsistency bool
}
type HasuraDB struct {
@ -237,15 +238,18 @@ func (h *HasuraDB) Run(migration io.Reader, fileType, fileName string) error {
if body == "" {
break
}
sqlInput := RunSQLInput{
SQL: string(body),
}
if h.config.enableCheckMetadataConsistency {
sqlInput.CheckMetadataConsistency = func() *bool { b := false; return &b }()
}
t := HasuraInterfaceQuery{
Type: "run_sql",
Args: HasuraArgs{
SQL: string(body),
},
Type: RunSQL,
Args: sqlInput,
}
h.migrationQuery.Args = append(h.migrationQuery.Args, t)
h.jsonPath[fmt.Sprintf("%d", len(h.migrationQuery.Args)-1)] = fileName
case "meta":
var t []interface{}
err := yaml.Unmarshal(migr, &t)

View File

@ -18,6 +18,10 @@ func (h *HasuraDB) SetMetadataPlugins(plugins types.MetadataPlugins) {
h.config.Plugins = plugins
}
func (h *HasuraDB) EnableCheckMetadataConsistency(enabled bool) {
h.config.enableCheckMetadataConsistency = enabled
}
func (h *HasuraDB) ExportMetadata() (map[string][]byte, error) {
query := HasuraQuery{
Type: "export_metadata",

View File

@ -857,7 +857,10 @@ func (i InconsistentMeatadataObject) GetReason() string {
}
type RunSQLInput struct {
SQL string `json:"sql" yaml:"sql"`
SQL string `json:"sql" yaml:"sql"`
Cascade bool `json:"cascade,omitempty" yaml:"cascade,omitempty"`
ReadOnly bool `json:"read_only,omitempty" yaml:"read_only,omitempty"`
CheckMetadataConsistency *bool `json:"check_metadata_consistency,omitempty" yaml:"check_metadata_consistency,omitempty"`
}
type tableConfig struct {

View File

@ -8,6 +8,8 @@ import (
type MetadataDriver interface {
SetMetadataPlugins(types.MetadataPlugins)
EnableCheckMetadataConsistency(bool)
ExportMetadata() (map[string][]byte, error)
ResetMetadata() error

View File

@ -323,6 +323,10 @@ func (m *Migrate) SetMetadataPlugins(plugins types.MetadataPlugins) {
m.databaseDrv.SetMetadataPlugins(plugins)
}
func (m *Migrate) EnableCheckMetadataConsistency(enabled bool) {
m.databaseDrv.EnableCheckMetadataConsistency(enabled)
}
func (m *Migrate) ExportMetadata() (map[string][]byte, error) {
return m.databaseDrv.ExportMetadata()
}

View File

@ -127,6 +127,9 @@ func NewMigrate(ec *cli.ExecutionContext, isCmd bool) (*Migrate, error) {
}
// Set Plugins
SetMetadataPluginsWithDir(ec, t)
if ec.Config.Version == cli.V2 {
t.EnableCheckMetadataConsistency(true)
}
return t, nil
}