Skip to content

Commit

Permalink
Merge branch 'master' into feature/console-analyze-subs
Browse files Browse the repository at this point in the history
  • Loading branch information
kolharsam authored Jun 4, 2020
2 parents c7458fb + 7e2d637 commit aa11a54
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 19 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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)
Expand All @@ -95,6 +97,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`

Expand Down Expand Up @@ -291,7 +294,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`

Expand Down
14 changes: 12 additions & 2 deletions cli/commands/migrate_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
},
}
Expand All @@ -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
}

Expand All @@ -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 {
Expand All @@ -119,6 +128,7 @@ func (o *MigrateApplyOptions) Run() error {
return err
}
migrateDrv.SkipExecution = o.SkipExecution
migrateDrv.DryRun = o.dryRun

return ExecuteMigration(migrationType, migrateDrv, step)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/migrate_squash.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package commands
import (
"bytes"
"fmt"
"github.com/hasura/graphql-engine/cli/util"
"strconv"
"strings"
"text/tabwriter"

"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"
Expand Down
6 changes: 4 additions & 2 deletions cli/commands/migrate_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
},
}
Expand Down
85 changes: 78 additions & 7 deletions cli/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{}) {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion install-manifests/azure-container-with-pg/azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@
"serve",
"--server-port",
"80",
"--enable-console"
"--enable-console",
"--dev-mode"
],
"resources": {
"requests": {
Expand Down
3 changes: 2 additions & 1 deletion install-manifests/azure-container/azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
"serve",
"--server-port",
"80",
"--enable-console"
"--enable-console",
"--dev-mode"
],
"resources": {
"requests": {
Expand Down
6 changes: 4 additions & 2 deletions install-manifests/docker-compose-https/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions install-manifests/docker-compose-pgadmin/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion install-manifests/docker-compose-postgis/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
3 changes: 3 additions & 0 deletions install-manifests/docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions install-manifests/docker-run/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions install-manifests/google-cloud-k8s-sql/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions install-manifests/kubernetes/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/src-lib/Hasura/RQL/DDL/Schema/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit aa11a54

Please sign in to comment.