Repository: hasura/graphql-engine
File: cli/commands/migrate_create.go (Go)

Code before:
		}
		err = migrateDrv.WriteMetadata(files)
		if err != nil {
			return 0, errors.Wrap(err, "cannot write to tmp file")
		}

		for name := range files {
			err = createOptions.SetMetaUpFromFile(name)
			if err != nil {
				return 0, errors.Wrap(err, "cannot parse metadata from the server")
			}
		}
	}

	// create pure sql based migrations here
	if o.flags.Changed("up-sql") && o.flags.Changed("down-sql") {
		err = createOptions.SetSQLUp(o.upSQL)
		if err != nil {
			return 0, errors.Wrap(err, "up migration with SQL string could not be created")
		}

		err = createOptions.SetSQLDown(o.downSQL)
		if err != nil {
			return 0, errors.Wrap(err, "down migration with SQL string could not be created")
		}
	}

	if !o.flags.Changed("sql-from-file") && !o.flags.Changed("metadata-from-file") && !o.metaDataServer && !o.sqlServer && o.EC.Config.Version == cli.V1 && !(o.flags.Changed("up-sql") && o.flags.Changed("down-sql")) {
		// Set empty data for [up|down].yaml
		createOptions.MetaUp = []byte(`[]`)
		createOptions.MetaDown = []byte(`[]`)
	}

	if !o.flags.Changed("sql-from-file") && !o.flags.Changed("metadata-from-file") && !o.metaDataServer && !o.sqlServer && o.EC.Config.Version != cli.V1 && !(o.flags.Changed("up-sql") && o.flags.Changed("down-sql")) {
		// Set empty data for [up|down].sql
		createOptions.SQLUp = []byte(``)
		createOptions.SQLDown = []byte(``)
	}

	defer func() {
		if err != nil {
			createOptions.Delete()
		}
	}()
	err = createOptions.Create()
	if err != nil {
		return 0, errors.Wrap(err, "error creating migration files")
	}
	return timestamp, nil
}


Review comment (suggestion):
```suggestion
			o.EC.Logger.Warn("you are creating a down migration without an up migration")
```

Code after:
		}
		err = migrateDrv.WriteMetadata(files)
		if err != nil {
			return 0, errors.Wrap(err, "cannot write to tmp file")
		}

		for name := range files {
			err = createOptions.SetMetaUpFromFile(name)
			if err != nil {
				return 0, errors.Wrap(err, "cannot parse metadata from the server")
			}
		}
	}

	// create pure sql based migrations here
	if o.flags.Changed("up-sql") {
		err = createOptions.SetSQLUp(o.upSQL)
		if err != nil {
			return 0, errors.Wrap(err, "up migration with SQL string could not be created")
		}
	}

	if o.flags.Changed("down-sql") {
		err = createOptions.SetSQLDown(o.downSQL)
		if err != nil {
			return 0, errors.Wrap(err, "down migration with SQL string could not be created")
		}
	}

	if !o.flags.Changed("sql-from-file") && !o.flags.Changed("metadata-from-file") && !o.metaDataServer && !o.sqlServer && o.EC.Config.Version == cli.V1 && !o.flags.Changed("up-sql") && !o.flags.Changed("down-sql") {
		// Set empty data for [up|down].yaml
		createOptions.MetaUp = []byte(`[]`)
		createOptions.MetaDown = []byte(`[]`)
	}

	if !o.flags.Changed("sql-from-file") && !o.flags.Changed("metadata-from-file") && !o.metaDataServer && !o.sqlServer && o.EC.Config.Version != cli.V1 && !o.flags.Changed("up-sql") && !o.flags.Changed("down-sql") {
		// Set empty data for [up|down].sql
		createOptions.SQLUp = []byte(``)
		createOptions.SQLDown = []byte(``)
	}

	defer func() {
		if err != nil {
			createOptions.Delete()
		}
	}()
	err = createOptions.Create()
	if err != nil {
		return 0, errors.Wrap(err, "error creating migration files")
	}
	return timestamp, nil