diff --git a/cli/migrate/database/driver_test.go b/cli/migrate/database/driver_test.go index ecdf5292e98..069bf742084 100644 --- a/cli/migrate/database/driver_test.go +++ b/cli/migrate/database/driver_test.go @@ -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 } diff --git a/cli/migrate/database/hasuradb/hasuradb.go b/cli/migrate/database/hasuradb/hasuradb.go index 841bdb37415..df72cd9eb13 100644 --- a/cli/migrate/database/hasuradb/hasuradb.go +++ b/cli/migrate/database/hasuradb/hasuradb.go @@ -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) diff --git a/cli/migrate/database/hasuradb/metadata.go b/cli/migrate/database/hasuradb/metadata.go index fa38334702e..0b7d92b3ecf 100644 --- a/cli/migrate/database/hasuradb/metadata.go +++ b/cli/migrate/database/hasuradb/metadata.go @@ -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", diff --git a/cli/migrate/database/hasuradb/types.go b/cli/migrate/database/hasuradb/types.go index 3d5052e3b59..08886b661ab 100644 --- a/cli/migrate/database/hasuradb/types.go +++ b/cli/migrate/database/hasuradb/types.go @@ -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 { diff --git a/cli/migrate/database/metadata.go b/cli/migrate/database/metadata.go index 7d52a0fc3ad..ca7fb2006dc 100644 --- a/cli/migrate/database/metadata.go +++ b/cli/migrate/database/metadata.go @@ -8,6 +8,8 @@ import ( type MetadataDriver interface { SetMetadataPlugins(types.MetadataPlugins) + EnableCheckMetadataConsistency(bool) + ExportMetadata() (map[string][]byte, error) ResetMetadata() error diff --git a/cli/migrate/migrate.go b/cli/migrate/migrate.go index 090afe0fbab..aa99f5a63c0 100644 --- a/cli/migrate/migrate.go +++ b/cli/migrate/migrate.go @@ -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() } diff --git a/cli/migrate/util.go b/cli/migrate/util.go index b3b27056e33..9aaba418062 100644 --- a/cli/migrate/util.go +++ b/cli/migrate/util.go @@ -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 }