Skip to content

Commit

Permalink
Revert "cli: add exclude-schema & full flags to migrate create command (
Browse files Browse the repository at this point in the history
#1564)" (#1566)

This reverts commit b4441cb.

GitOrigin-RevId: 33ddf5c
  • Loading branch information
scriptonist authored and hasura-bot committed Jun 14, 2021
1 parent 6e51864 commit c1fd8be
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 37 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
- console: add modify functionality on columns, primary keys & unique keys to MS SQL Server tables
- cli: add interactive prompt to get input when `--database-name` flag is missing
- cli: fix metadata export to avoid unnecessary empty lines in actions.graphql (#5338)
- cli: add exclude-schema & full flags to migrate create command (closes #4301) (#5713)

## v2.0.0-beta.1

Expand Down
22 changes: 1 addition & 21 deletions cli/commands/migrate_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ const migrateCreateCmdExamples = ` # Setup migration files for the first time b
# Take pg_dump from server and save it as a migration and specify the schemas to include
hasura migrate create init --sql-from-server --schema myschema1,myschema2
# Take pg_dump from server with all schemas and extensions
hasura migrate create init --from-server --full
# Take pg_dump from server by excluding certain schemas
hasura migrate create init --from-server --exclude-schema public,hdb_catalog
# Create up and down SQL migrations, providing contents as flags
hasura migrate create migration-name --up-sql "CREATE TABLE article(id serial NOT NULL, title text NOT NULL, content text NOT NULL);" --down-sql "DROP TABLE article;"
Expand Down Expand Up @@ -87,8 +81,6 @@ func newMigrateCreateCmd(ec *cli.ExecutionContext) *cobra.Command {
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")
f.StringVar(&opts.downSQL, "down-sql", "", "sql string/query that is to be used to create a down migration")
f.StringSliceVar(&opts.excludeSchema, "exclude-schema", []string{}, "take pg_dump with the --exclude-schema flag")
f.BoolVar(&opts.full, "full", false, "take pg_dump with all tables across all schemas without the --schema option")

migrateCreateCmd.MarkFlagFilename("sql-from-file")
migrateCreateCmd.MarkFlagFilename("metadata-from-file")
Expand All @@ -111,11 +103,7 @@ type migrateCreateOptions struct {
schemaNames []string
upSQL string
downSQL string
excludeSchema []string
full bool

Source cli.Source

}

func (o *migrateCreateOptions) run() (version int64, err error) {
Expand All @@ -129,14 +117,6 @@ func (o *migrateCreateOptions) run() (version int64, err error) {
}
}

if len(o.excludeSchema) != 0 && !o.fromServer {
return 0, errors.New("exclude-schema flag has to be used along with from-server")
}

if o.full && !o.fromServer {
return 0, errors.New("full flag has to be used along with from-server")
}

if o.flags.Changed("metadata-from-file") && o.EC.Config.Version != cli.V1 {
return 0, errors.New("metadata-from-file flag can be set only with config version 1")
}
Expand Down Expand Up @@ -177,7 +157,7 @@ func (o *migrateCreateOptions) run() (version int64, err error) {
}
}
if o.sqlServer {
data, err := migrateDrv.ExportSchemaDump(o.schemaNames, o.Source.Name, o.Source.Kind, o.excludeSchema, o.full)
data, err := migrateDrv.ExportSchemaDump(o.schemaNames, o.Source.Name, o.Source.Kind)
if err != nil {
return 0, errors.Wrap(err, "cannot fetch schema dump")
}
Expand Down
2 changes: 1 addition & 1 deletion cli/migrate/database/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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, excludeSchema []string, full bool) ([]byte, error) {
func (m *mockDriver) ExportSchemaDump(schemaName []string, sourceName string, sourceKind hasura.SourceKind) ([]byte, error) {
return nil, nil
}

Expand Down
14 changes: 3 additions & 11 deletions cli/migrate/database/hasuradb/schema_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,12 @@ import (
"github.com/hasura/graphql-engine/cli/internal/hasura"
)

// ExportSchemaDump calls pg_dump to help initialize the first set of migrations
func (h *HasuraDB) ExportSchemaDump(schemaNames []string, sourceName string, sourceKind hasura.SourceKind, excludeSchema []string, full bool) ([]byte, error) {
func (h *HasuraDB) ExportSchemaDump(schemaNames []string, sourceName string, sourceKind hasura.SourceKind) ([]byte, error) {
switch sourceKind {
case hasura.SourceKindPG:
opts := []string{"-O", "-x", "--schema-only"}
if len(excludeSchema) != 0 {
for _, s := range excludeSchema {
opts = append(opts, "--exclude-schema", s)
}
}
if !full && len(excludeSchema) != 0 {
for _, s := range schemaNames {
opts = append(opts, "--schema", s)
}
for _, s := range schemaNames {
opts = append(opts, "--schema", s)
}
query := SchemaDump{
Opts: opts,
Expand Down
2 changes: 1 addition & 1 deletion cli/migrate/database/schema_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package database
import "github.com/hasura/graphql-engine/cli/internal/hasura"

type SchemaDriver interface {
ExportSchemaDump(schemaName []string, sourceName string, sourceKind hasura.SourceKind, excludeSchema []string, full bool) ([]byte, error)
ExportSchemaDump(schemaName []string, sourceName string, sourceKind hasura.SourceKind) ([]byte, error)
}
4 changes: 2 additions & 2 deletions cli/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ func (m *Migrate) GetUnappliedMigrations(version uint64) []uint64 {
return m.sourceDrv.GetUnappliedMigrations(version)
}

func (m *Migrate) ExportSchemaDump(schemName []string, sourceName string, sourceKind hasura.SourceKind, excludeSchema []string, full bool) ([]byte, error) {
return m.databaseDrv.ExportSchemaDump(schemName, sourceName, sourceKind, excludeSchema, full)
func (m *Migrate) ExportSchemaDump(schemName []string, sourceName string, sourceKind hasura.SourceKind) ([]byte, error) {
return m.databaseDrv.ExportSchemaDump(schemName, sourceName, sourceKind)
}

func (m *Migrate) RemoveVersions(versions []uint64) error {
Expand Down

0 comments on commit c1fd8be

Please sign in to comment.