From a69f47ccf415bd55d814cd644acde7e883b8cfbf Mon Sep 17 00:00:00 2001 From: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com> Date: Wed, 3 Jun 2020 15:25:47 +0530 Subject: [PATCH 1/3] install manifests: update all install manifests to enable dev mode by default (close #4599) (#4716) --- CHANGELOG.md | 1 + install-manifests/azure-container-with-pg/azuredeploy.json | 3 ++- install-manifests/azure-container/azuredeploy.json | 3 ++- install-manifests/docker-compose-https/docker-compose.yaml | 6 ++++-- .../docker-compose-pgadmin/docker-compose.yaml | 3 +++ .../docker-compose-postgis/docker-compose.yaml | 5 ++++- install-manifests/docker-compose/docker-compose.yaml | 3 +++ install-manifests/docker-run/docker-run.sh | 1 + install-manifests/google-cloud-k8s-sql/deployment.yaml | 4 ++++ install-manifests/kubernetes/deployment.yaml | 4 ++++ 10 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08d064a927da9..2d8ef9bb80f8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,7 @@ Read more about the session argument for computed fields in the [docs](https://h - docs: update troubleshooting section with reference on debugging errors (close #4052) (#4825) - docs: add page for procuring custom docker images and binaries (#4828) - docs: add content on how to secure action handlers and other actions docs improvements (#4743) +- install manifests: update all install manifests to enable dev mode by default (close #4599) (#4716) ## `v1.2.0` diff --git a/install-manifests/azure-container-with-pg/azuredeploy.json b/install-manifests/azure-container-with-pg/azuredeploy.json index 1abfbb601964f..7bf79ab456dc1 100644 --- a/install-manifests/azure-container-with-pg/azuredeploy.json +++ b/install-manifests/azure-container-with-pg/azuredeploy.json @@ -181,7 +181,8 @@ "serve", "--server-port", "80", - "--enable-console" + "--enable-console", + "--dev-mode" ], "resources": { "requests": { diff --git a/install-manifests/azure-container/azuredeploy.json b/install-manifests/azure-container/azuredeploy.json index 6d79f57ac6412..45ab24989df8b 100644 --- a/install-manifests/azure-container/azuredeploy.json +++ b/install-manifests/azure-container/azuredeploy.json @@ -90,7 +90,8 @@ "serve", "--server-port", "80", - "--enable-console" + "--enable-console", + "--dev-mode" ], "resources": { "requests": { diff --git a/install-manifests/docker-compose-https/docker-compose.yaml b/install-manifests/docker-compose-https/docker-compose.yaml index 6755ea725f09f..6d8120ff55000 100644 --- a/install-manifests/docker-compose-https/docker-compose.yaml +++ b/install-manifests/docker-compose-https/docker-compose.yaml @@ -15,9 +15,11 @@ services: environment: # database url to connect HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres - # enable the console served by server + ## enable the console served by server HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set "false" to disable console - ## uncomment next line to set an admin secret key + ## enable debugging mode. It is recommended to disable this in production + HASURA_GRAPHQL_DEV_MODE: "true" + ## uncomment next line to set an admin secret # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey command: - graphql-engine diff --git a/install-manifests/docker-compose-pgadmin/docker-compose.yaml b/install-manifests/docker-compose-pgadmin/docker-compose.yaml index f5bbf8dca53af..2ee723b07675a 100644 --- a/install-manifests/docker-compose-pgadmin/docker-compose.yaml +++ b/install-manifests/docker-compose-pgadmin/docker-compose.yaml @@ -27,7 +27,10 @@ services: restart: always environment: HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres + ## enable the console served by server HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console + ## enable debugging mode. It is recommended to disable this in production + HASURA_GRAPHQL_DEV_MODE: "true" ## uncomment next line to set an admin secret # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey volumes: diff --git a/install-manifests/docker-compose-postgis/docker-compose.yaml b/install-manifests/docker-compose-postgis/docker-compose.yaml index 629c887596225..61c330be44482 100644 --- a/install-manifests/docker-compose-postgis/docker-compose.yaml +++ b/install-manifests/docker-compose-postgis/docker-compose.yaml @@ -16,8 +16,11 @@ services: restart: always environment: HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres + ## enable the console served by server HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console - ## uncomment next line to set the admin secret key + ## enable debugging mode. It is recommended to disable this in production + HASURA_GRAPHQL_DEV_MODE: "true" + ## uncomment next line to set an admin secret # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey volumes: db_data: diff --git a/install-manifests/docker-compose/docker-compose.yaml b/install-manifests/docker-compose/docker-compose.yaml index 4e9ec68c691a7..41f3b69afbe79 100644 --- a/install-manifests/docker-compose/docker-compose.yaml +++ b/install-manifests/docker-compose/docker-compose.yaml @@ -16,7 +16,10 @@ services: restart: always environment: HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres + ## enable the console served by server HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console + ## enable debugging mode. It is recommended to disable this in production + HASURA_GRAPHQL_DEV_MODE: "true" HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log ## uncomment next line to set an admin secret # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey diff --git a/install-manifests/docker-run/docker-run.sh b/install-manifests/docker-run/docker-run.sh index 7e47385b0f428..33176842cd2eb 100755 --- a/install-manifests/docker-run/docker-run.sh +++ b/install-manifests/docker-run/docker-run.sh @@ -2,4 +2,5 @@ docker run -d -p 8080:8080 \ -e HASURA_GRAPHQL_DATABASE_URL=postgres://username:password@hostname:port/dbname \ -e HASURA_GRAPHQL_ENABLE_CONSOLE=true \ + -e HASURA_GRAPHQL_DEV_MODE=true \ hasura/graphql-engine:v1.2.2 diff --git a/install-manifests/google-cloud-k8s-sql/deployment.yaml b/install-manifests/google-cloud-k8s-sql/deployment.yaml index 1262609c0e998..3699f769db990 100644 --- a/install-manifests/google-cloud-k8s-sql/deployment.yaml +++ b/install-manifests/google-cloud-k8s-sql/deployment.yaml @@ -32,8 +32,12 @@ spec: - serve env: # [START Hasura config variables] + ## enable the console served by server - name: HASURA_GRAPHQL_ENABLE_CONSOLE value: "true" + ## enable debugging mode. It is recommended to disable this in production + - name: HASURA_GRAPHQL_DEV_MODE + value: "true" # [END Hasura config variables] - name: POSTGRES_DB_HOST value: 127.0.0.1:5432 diff --git a/install-manifests/kubernetes/deployment.yaml b/install-manifests/kubernetes/deployment.yaml index dc47f457c0630..16a39618ed519 100644 --- a/install-manifests/kubernetes/deployment.yaml +++ b/install-manifests/kubernetes/deployment.yaml @@ -24,8 +24,12 @@ spec: env: - name: HASURA_GRAPHQL_DATABASE_URL value: postgres://username:password@hostname:port/dbname + ## enable the console served by server - name: HASURA_GRAPHQL_ENABLE_CONSOLE value: "true" + ## enable debugging mode. It is recommended to disable this in production + - name: HASURA_GRAPHQL_DEV_MODE + value: "true" ports: - containerPort: 8080 protocol: TCP From d9cc67679026c78b1722afc645f573a3df57f791 Mon Sep 17 00:00:00 2001 From: Ashish Rao Date: Wed, 3 Jun 2020 16:49:36 +0530 Subject: [PATCH 2/3] cli: add --dry-run flag to migrate apply command (close #3128) (#3499) --- CHANGELOG.md | 3 +- cli/commands/migrate_apply.go | 14 +++++- cli/commands/migrate_squash.go | 2 +- cli/commands/migrate_status.go | 6 ++- cli/migrate/migrate.go | 85 +++++++++++++++++++++++++++++++--- 5 files changed, 97 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d8ef9bb80f8e..a8bb2d7747936 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,8 @@ Read more about the session argument for computed fields in the [docs](https://h - cli: list all available commands in root command help (fix #4623) (#4628) - cli: fix bug with squashing event triggers (close #4883) - cli: add support for skipping execution while generating migrations through the migrate REST API +- cli: add dry run flag in hasura migrate apply command (fix #3128) (#3499) +- cli: load assets from server when HASURA_GRAPHQL_CONSOLE_ASSETS_DIR is set (close #3382) - docs: add section on actions vs. remote schemas to actions documentation (#4284) - docs: fix wrong info about excluding scheme in CORS config (#4685) - docs: add single object mutations docs (close #4622) (#4625) @@ -291,7 +293,6 @@ For example, see [here](https://hasura.io/docs/1.0/graphql/manual/api-reference/ - server: fix recreating action's permissions (close #4377) - server: make the graceful shutdown logic customizable (graceful shutdown on the SIGTERM signal continues to be the default) - docs: add reference docs for CLI (clsoe #4327) (#4408) -- cli: load assets from server when HASURA_GRAPHQL_CONSOLE_ASSETS_DIR is set (close #3382) ## `v1.2.0-beta.4` diff --git a/cli/commands/migrate_apply.go b/cli/commands/migrate_apply.go index e4096d1c24385..74387ffe69001 100644 --- a/cli/commands/migrate_apply.go +++ b/cli/commands/migrate_apply.go @@ -61,7 +61,12 @@ func newMigrateApplyCmd(ec *cli.ExecutionContext) *cobra.Command { return ec.Validate() }, RunE: func(cmd *cobra.Command, args []string) error { - opts.EC.Spin("Applying migrations...") + if opts.dryRun && opts.SkipExecution { + return errors.New("both --skip-execution and --dry-run flags cannot be used together") + } + if !opts.dryRun { + opts.EC.Spin("Applying migrations...") + } err := opts.Run() opts.EC.Spinner.Stop() if err != nil { @@ -78,7 +83,9 @@ func newMigrateApplyCmd(ec *cli.ExecutionContext) *cobra.Command { } return errors.Wrap(err, "apply failed") } - opts.EC.Logger.Info("migrations applied") + if !opts.dryRun { + opts.EC.Logger.Info("migrations applied") + } return nil }, } @@ -93,6 +100,7 @@ func newMigrateApplyCmd(ec *cli.ExecutionContext) *cobra.Command { f.BoolVar(&opts.SkipExecution, "skip-execution", false, "skip executing the migration action, but mark them as applied") f.StringVar(&opts.MigrationType, "type", "up", "type of migration (up, down) to be used with version flag") + f.BoolVar(&opts.dryRun, "dry-run", false, "print the names of migrations which are going to be applied") return migrateApplyCmd } @@ -106,6 +114,7 @@ type MigrateApplyOptions struct { // version up to which migration chain has to be applied GotoVersion string SkipExecution bool + dryRun bool } func (o *MigrateApplyOptions) Run() error { @@ -119,6 +128,7 @@ func (o *MigrateApplyOptions) Run() error { return err } migrateDrv.SkipExecution = o.SkipExecution + migrateDrv.DryRun = o.dryRun return ExecuteMigration(migrationType, migrateDrv, step) } diff --git a/cli/commands/migrate_squash.go b/cli/commands/migrate_squash.go index 1891d898070cf..8e4e598675359 100644 --- a/cli/commands/migrate_squash.go +++ b/cli/commands/migrate_squash.go @@ -3,6 +3,7 @@ package commands import ( "bytes" "fmt" + "github.com/hasura/graphql-engine/cli/util" "strconv" "strings" "text/tabwriter" @@ -10,7 +11,6 @@ import ( "github.com/hasura/graphql-engine/cli/migrate" "github.com/hasura/graphql-engine/cli" - "github.com/hasura/graphql-engine/cli/util" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" diff --git a/cli/commands/migrate_status.go b/cli/commands/migrate_status.go index b6a110b2f271d..7953c45050c61 100644 --- a/cli/commands/migrate_status.go +++ b/cli/commands/migrate_status.go @@ -3,11 +3,13 @@ package commands import ( "bytes" "fmt" + "os" "text/tabwriter" + "github.com/hasura/graphql-engine/cli/util" + "github.com/hasura/graphql-engine/cli" "github.com/hasura/graphql-engine/cli/migrate" - "github.com/hasura/graphql-engine/cli/util" "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -33,7 +35,7 @@ func newMigrateStatusCmd(ec *cli.ExecutionContext) *cobra.Command { return err } buf := printStatus(status) - fmt.Println(buf.String()) + fmt.Fprintf(os.Stdout, "%s", buf) return nil }, } diff --git a/cli/migrate/migrate.go b/cli/migrate/migrate.go index 2b913c0b151dd..94cbf395244fb 100644 --- a/cli/migrate/migrate.go +++ b/cli/migrate/migrate.go @@ -13,8 +13,11 @@ import ( "io" "os" "sync" + "text/tabwriter" "time" + "github.com/hasura/graphql-engine/cli/util" + "github.com/hasura/graphql-engine/cli/metadata/types" "github.com/hasura/graphql-engine/cli/migrate/database" "github.com/hasura/graphql-engine/cli/migrate/source" @@ -99,6 +102,7 @@ type Migrate struct { status *Status SkipExecution bool + DryRun bool } // New returns a new Migrate instance from a source URL and a database URL. @@ -538,8 +542,11 @@ func (m *Migrate) Migrate(version uint64, direction string) error { ret := make(chan interface{}, m.PrefetchMigrations) go m.read(version, direction, ret) - - return m.unlockErr(m.runMigrations(ret)) + if m.DryRun { + return m.unlockErr(m.runDryRun(ret)) + } else { + return m.unlockErr(m.runMigrations(ret)) + } } func (m *Migrate) QueryWithVersion(version uint64, data io.ReadCloser, skipExecution bool) error { @@ -600,7 +607,11 @@ func (m *Migrate) Steps(n int64) error { go m.readDown(-n, ret) } - return m.unlockErr(m.runMigrations(ret)) + if m.DryRun { + return m.unlockErr(m.runDryRun(ret)) + } else { + return m.unlockErr(m.runMigrations(ret)) + } } // Up looks at the currently active migration version @@ -632,7 +643,11 @@ func (m *Migrate) Up() error { go m.readUp(-1, ret) - return m.unlockErr(m.runMigrations(ret)) + if m.DryRun { + return m.unlockErr(m.runDryRun(ret)) + } else { + return m.unlockErr(m.runMigrations(ret)) + } } // Down looks at the currently active migration version @@ -663,7 +678,11 @@ func (m *Migrate) Down() error { ret := make(chan interface{}, m.PrefetchMigrations) go m.readDown(-1, ret) - return m.unlockErr(m.runMigrations(ret)) + if m.DryRun { + return m.unlockErr(m.runDryRun(ret)) + } else { + return m.unlockErr(m.runMigrations(ret)) + } } func (m *Migrate) squashUp(version uint64, ret chan<- interface{}) { @@ -1188,6 +1207,32 @@ func (m *Migrate) runMigrations(ret <-chan interface{}) error { return nil } +func (m *Migrate) runDryRun(ret <-chan interface{}) error { + migrations := make([]*Migration, 0) + var lastInsertVersion int64 + for r := range ret { + if m.stop() { + return nil + } + + switch r.(type) { + case error: + return r.(error) + case *Migration: + migr := r.(*Migration) + if migr.Body != nil { + version := int64(migr.Version) + if version != lastInsertVersion { + migrations = append(migrations, migr) + lastInsertVersion = version + } + } + } + } + fmt.Fprintf(os.Stdout, "%s", printDryRunStatus(migrations)) + return nil +} + func (m *Migrate) squashMigrations(retUp <-chan interface{}, retDown <-chan interface{}, dataUp chan<- interface{}, dataDown chan<- interface{}, versions chan<- int64) error { var latestVersion int64 go func() { @@ -1582,8 +1627,11 @@ func (m *Migrate) GotoVersion(gotoVersion int64) error { go m.readDownFromVersion(currVersion, gotoVersion, ret) } - return m.unlockErr(m.runMigrations(ret)) - + if m.DryRun { + return m.unlockErr(m.runDryRun(ret)) + } else { + return m.unlockErr(m.runMigrations(ret)) + } } // readUpFromVersion reads up migrations from `from` limitted by `limit`. (is a modified version of readUp) @@ -1771,3 +1819,26 @@ func (m *Migrate) readDownFromVersion(from int64, to int64, ret chan<- interface noOfAppliedMigrations++ } } + +func printDryRunStatus(migrations []*Migration) *bytes.Buffer { + out := new(tabwriter.Writer) + buf := &bytes.Buffer{} + out.Init(buf, 0, 8, 2, ' ', 0) + w := util.NewPrefixWriter(out) + w.Write(util.LEVEL_0, "VERSION\tTYPE\tNAME\n") + for _, migration := range migrations { + var direction string + if int64(migration.Version) == migration.TargetVersion { + direction = "up" + } else { + direction = "down" + } + w.Write(util.LEVEL_0, "%d\t%s\t%s\n", + migration.Version, + direction, + migration.Identifier, + ) + } + out.Flush() + return buf +} From 7e2d6370ce6ce18255958309d0d71a674437e2c0 Mon Sep 17 00:00:00 2001 From: George Kormaris Date: Wed, 3 Jun 2020 17:01:04 +0100 Subject: [PATCH 3/3] Fix typo in error message (#4923) "confilct" to "conflict" Co-authored-by: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com> --- server/src-lib/Hasura/RQL/DDL/Schema/Cache.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src-lib/Hasura/RQL/DDL/Schema/Cache.hs b/server/src-lib/Hasura/RQL/DDL/Schema/Cache.hs index 6e9a8b750425a..43f43876a5ec1 100644 --- a/server/src-lib/Hasura/RQL/DDL/Schema/Cache.hs +++ b/server/src-lib/Hasura/RQL/DDL/Schema/Cache.hs @@ -79,7 +79,7 @@ mergeCustomTypes gCtxMap remoteSchemaCtx customTypesState = do (_, _) -> True unless (null conflictingCustomTypes) $ throw400 InvalidCustomTypes $ - "following custom types confilct with the " <> + "following custom types conflict with the " <> "autogenerated hasura types or from remote schemas: " <> showNames conflictingCustomTypes