mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 08:02:15 +03:00
cli: avoid exporting hasura-specific schemas during hasura init
fixes https://github.com/hasura/graphql-engine/issues/8352 PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4178 Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com> GitOrigin-RevId: eff7067c34932435207eff794f9435356b55b666
This commit is contained in:
parent
f0c04279be
commit
0016d3cad5
@ -10,6 +10,7 @@
|
||||
- server: Don't drop nested typed null fields in actions (fix #8237)
|
||||
- server: fixes remote relationships on actions (fix #8399)
|
||||
- console: add remote database relationships for views
|
||||
- cli: avoid exporting hasura-specific schemas during hasura init (#8352)
|
||||
- cli: fix performance regression in `migrate status` command (fix #8398)
|
||||
|
||||
## v2.5.1
|
||||
|
@ -82,7 +82,7 @@ test-e2e:
|
||||
ifndef HAS_GINKGO
|
||||
cd ~ && go get github.com/onsi/ginkgo/ginkgo && cd -
|
||||
endif
|
||||
cd commands && ginkgo -p -v -failFast
|
||||
cd commands && ginkgo -p -v -failFast $(ARGS)
|
||||
|
||||
test-all: test integration_tests_config_v2 integration_tests_config_v3 test-e2e
|
||||
# clean the output directory
|
||||
|
@ -729,7 +729,10 @@ func (ec *ExecutionContext) Validate() error {
|
||||
ec.HasMetadataV3 = true
|
||||
}
|
||||
if ec.Config.Version >= V3 && !ec.HasMetadataV3 {
|
||||
return fmt.Errorf("config v3 can only be used with servers having metadata version >= 3")
|
||||
return fmt.Errorf(`config v3 can only be used with servers having metadata version >= 3
|
||||
You could fix this problem by taking one of the following actions:
|
||||
1. Upgrade your Hasura server to a newer version (>= v2.0.0) ie upgrade to a version which supports metadata v3
|
||||
2. Force CLI to use an older config version via the --version <VERSION> flag`)
|
||||
}
|
||||
|
||||
ec.APIClient = &hasura.Client{
|
||||
|
@ -381,8 +381,7 @@ func (a *failedValidatingEndpointAction) Execute(ctx fsm.EventContext) eventType
|
||||
context := ctx.(*initCtx)
|
||||
context.logger.Debug(failedValidatingEndpoint)
|
||||
if context.err != nil {
|
||||
context.logger.Debug(context.err)
|
||||
context.logger.Infoln("validating endpoint failed, server not reachable")
|
||||
context.logger.Errorf("validating server failed: %v", context.err)
|
||||
}
|
||||
return gotoEndstate
|
||||
}
|
||||
@ -427,9 +426,10 @@ type creatingMigrationAction struct{}
|
||||
func (a *creatingMigrationAction) Execute(ctx fsm.EventContext) eventType {
|
||||
context := ctx.(*initCtx)
|
||||
opts := migrateCreateOptions{
|
||||
EC: context.ec,
|
||||
name: "init",
|
||||
fromServer: true,
|
||||
EC: context.ec,
|
||||
name: "init",
|
||||
fromServer: true,
|
||||
excludeSchemas: []string{"hdb_catalog", "hdb_views"},
|
||||
}
|
||||
context.logger.Debug(creatingMigration)
|
||||
if err := context.ec.Validate(); err != nil {
|
||||
|
@ -98,6 +98,10 @@ var _ = Describe("hasura init --endpoint (config v3)", func() {
|
||||
fileInfos, err := os.ReadDir(filepath.Join(projectDirectory, "migrations", sourceName))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(len(fileInfos)).Should(BeEquivalentTo(1))
|
||||
upMigrationsContent, err := ioutil.ReadFile(filepath.Join(projectDirectory, "migrations", sourceName, fileInfos[0].Name(), "up.sql"))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(upMigrationsContent).ShouldNot(ContainSubstring("hdb_catalog"))
|
||||
Expect(upMigrationsContent).ShouldNot(ContainSubstring("hdb_views"))
|
||||
})
|
||||
|
||||
})
|
||||
@ -185,6 +189,10 @@ var _ = Describe("hasura init --endpoint (config v2)", func() {
|
||||
fileInfos, err := os.ReadDir(filepath.Join(projectDirectory, "migrations"))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(len(fileInfos)).Should(BeEquivalentTo(1))
|
||||
upMigrationsContent, err := ioutil.ReadFile(filepath.Join(projectDirectory, "migrations", fileInfos[0].Name(), "up.sql"))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(string(upMigrationsContent)).ShouldNot(ContainSubstring("hdb_catalog"))
|
||||
Expect(string(upMigrationsContent)).ShouldNot(ContainSubstring("hdb_views"))
|
||||
})
|
||||
|
||||
})
|
||||
|
@ -102,7 +102,7 @@ func newMigrateCreateCmd(ec *cli.ExecutionContext) *cobra.Command {
|
||||
f.BoolVar(&opts.fromServer, "from-server", false, "take pg_dump of schema (default: public) and Hasura metadata from the server")
|
||||
f.StringVar(&opts.sqlFile, "sql-from-file", "", "path to an SQL file which contains the SQL statements")
|
||||
f.BoolVar(&opts.sqlServer, "sql-from-server", false, "take pg_dump from the server (default: public) and save it as a migration")
|
||||
f.StringSliceVar(&opts.schemaNames, "schema", []string{"public"}, "name of Postgres schema to export as a migration. provide multiple schemas with a comma separated list e.g. --schema public,user")
|
||||
f.StringSliceVar(&opts.includeSchemas, "schema", []string{"public"}, "name of Postgres schema to export as a migration. provide multiple schemas with a comma separated list e.g. --schema public,user")
|
||||
f.StringVar(&opts.metaDataFile, "metadata-from-file", "", "path to a hasura metadata file to be used for up actions")
|
||||
f.BoolVar(&opts.metaDataServer, "metadata-from-server", false, "take metadata from the server and write it as an up migration file")
|
||||
f.StringVar(&opts.upSQL, "up-sql", "", "sql string/query that is to be used to create an up migration")
|
||||
@ -133,7 +133,8 @@ type migrateCreateOptions struct {
|
||||
sqlServer bool
|
||||
metaDataFile string
|
||||
metaDataServer bool
|
||||
schemaNames []string
|
||||
includeSchemas []string
|
||||
excludeSchemas []string
|
||||
upSQL string
|
||||
upSQLChanged bool
|
||||
downSQLChanged bool
|
||||
@ -167,7 +168,7 @@ func (o *migrateCreateOptions) run() (version int64, err error) {
|
||||
}
|
||||
}
|
||||
if o.sqlServer {
|
||||
data, err := migrateDrv.ExportSchemaDump(o.schemaNames, o.Source.Name, o.Source.Kind)
|
||||
data, err := migrateDrv.ExportSchemaDump(o.includeSchemas, o.excludeSchemas, o.Source.Name, o.Source.Kind)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("cannot fetch schema dump: %w", err)
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ func (m *mockDriver) Squash(list *CustomList, ret chan<- interface{}) {
|
||||
func (m *mockDriver) EnableCheckMetadataConsistency(enabled bool) {
|
||||
}
|
||||
|
||||
func (m *mockDriver) ExportSchemaDump(schemaName []string, sourceName string, sourceKind hasura.SourceKind) ([]byte, error) {
|
||||
func (m *mockDriver) ExportSchemaDump(includeSchemas []string, excludeSchemas []string, sourceName string, sourceKind hasura.SourceKind) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
@ -7,13 +7,16 @@ import (
|
||||
"github.com/hasura/graphql-engine/cli/v2/internal/hasura"
|
||||
)
|
||||
|
||||
func (h *HasuraDB) ExportSchemaDump(schemaNames []string, sourceName string, sourceKind hasura.SourceKind) ([]byte, error) {
|
||||
func (h *HasuraDB) ExportSchemaDump(includeSchemas []string, excludeSchemas []string, sourceName string, sourceKind hasura.SourceKind) ([]byte, error) {
|
||||
switch sourceKind {
|
||||
case hasura.SourceKindPG:
|
||||
opts := []string{"-O", "-x", "--schema-only"}
|
||||
for _, s := range schemaNames {
|
||||
for _, s := range includeSchemas {
|
||||
opts = append(opts, "--schema", s)
|
||||
}
|
||||
for _, s := range excludeSchemas {
|
||||
opts = append(opts, "--exclude-schema", s)
|
||||
}
|
||||
query := hasura.PGDumpRequest{
|
||||
Opts: opts,
|
||||
CleanOutput: true,
|
||||
|
@ -3,5 +3,5 @@ package database
|
||||
import "github.com/hasura/graphql-engine/cli/v2/internal/hasura"
|
||||
|
||||
type SchemaDriver interface {
|
||||
ExportSchemaDump(schemaName []string, sourceName string, sourceKind hasura.SourceKind) ([]byte, error)
|
||||
ExportSchemaDump(includeSchemas []string, excludeSchemas []string, sourceName string, sourceKind hasura.SourceKind) ([]byte, error)
|
||||
}
|
||||
|
@ -393,8 +393,8 @@ func (m *Migrate) GetUnappliedMigrations(version uint64) []uint64 {
|
||||
return m.sourceDrv.GetUnappliedMigrations(version)
|
||||
}
|
||||
|
||||
func (m *Migrate) ExportSchemaDump(schemName []string, sourceName string, sourceKind hasura.SourceKind) ([]byte, error) {
|
||||
return m.databaseDrv.ExportSchemaDump(schemName, sourceName, sourceKind)
|
||||
func (m *Migrate) ExportSchemaDump(includeSchemas []string, excludeSchemas []string, sourceName string, sourceKind hasura.SourceKind) ([]byte, error) {
|
||||
return m.databaseDrv.ExportSchemaDump(includeSchemas, excludeSchemas, sourceName, sourceKind)
|
||||
}
|
||||
|
||||
func (m *Migrate) RemoveVersions(versions []uint64) error {
|
||||
|
Loading…
Reference in New Issue
Block a user