mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 08:02:15 +03:00
cli: add check_metadata_consistency for v2 workflow migrations (#4392)
This commit is contained in:
parent
aca11f0944
commit
2ee6328d0d
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
|
@ -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 {
|
||||
|
@ -8,6 +8,8 @@ import (
|
||||
type MetadataDriver interface {
|
||||
SetMetadataPlugins(types.MetadataPlugins)
|
||||
|
||||
EnableCheckMetadataConsistency(bool)
|
||||
|
||||
ExportMetadata() (map[string][]byte, error)
|
||||
|
||||
ResetMetadata() error
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user