mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
489835eb36
- modified the `dry-run` flag of metadata apply command. - added new flag `o` which takes "json" or "yaml" as parameters for metadata apply command. - added new flag `o` which takes "json" or "yaml" as parameters for metadata export command. It outputs the metadata from server to stdout in form of json or yaml and won't change the project's metadata. - added deprecation warnings for `--from-file` flag - added info message for describing change of behavior of `--dry-run` flag - v3 metadata objects like `rest_endpoints` was also added to list of metadata objects in config v2 (fix) - the order in which metadata objects are appended to metadata objects list matter when using `--dry-run` flag, refactored this order to match server metadata. - `metadata apply` command can now accept json/yaml metadata from io pipe - config v3 `metadata apply` didn't show any information to user when applied metadata is inconsistent, this is addressed. - removed `github.com/ghodss/yaml` dependency from repo - version metadata object was added twice during intialization (fix) Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com> GitOrigin-RevId: 2316f519eb40645efd86ffee2a85d3c90543ec17
80 lines
2.4 KiB
Go
80 lines
2.4 KiB
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/hasura/graphql-engine/cli/internal/testutil"
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
. "github.com/onsi/gomega/gexec"
|
|
)
|
|
|
|
var _ = Describe("seed_apply", func() {
|
|
|
|
var dirName string
|
|
var session *Session
|
|
var teardown func()
|
|
BeforeEach(func() {
|
|
dirName = testutil.RandDirName()
|
|
hgeEndPort, teardownHGE := testutil.StartHasura(GinkgoT(), testutil.HasuraVersion)
|
|
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
|
|
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
|
Args: []string{"init", dirName},
|
|
})
|
|
editEndpointInConfig(filepath.Join(dirName, defaultConfigFilename), hgeEndpoint)
|
|
|
|
teardown = func() {
|
|
session.Kill()
|
|
os.RemoveAll(dirName)
|
|
teardownHGE()
|
|
}
|
|
})
|
|
|
|
AfterEach(func() {
|
|
teardown()
|
|
})
|
|
|
|
Context("seed apply test", func() {
|
|
upSql := `CREATE TABLE "public"."table1" ("id" serial NOT NULL, PRIMARY KEY ("id") );`
|
|
|
|
data := `INSERT INTO public.table1 (id) VALUES (1);
|
|
INSERT INTO public.table1 (id) VALUES (2);
|
|
INSERT INTO public.table1 (id) VALUES (3);
|
|
INSERT INTO public.table1 (id) VALUES (4);`
|
|
|
|
downSql := `DROP TABLE "public"."table1";`
|
|
|
|
It("should apply the seed file inside seed/default ", func() {
|
|
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
|
Args: []string{"migrate", "create", "table1", "--up-sql", upSql, "--down-sql", downSql, "--database-name", "default"},
|
|
WorkingDirectory: dirName,
|
|
})
|
|
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
|
Args: []string{"migrate", "apply", "--database-name", "default"},
|
|
WorkingDirectory: dirName,
|
|
})
|
|
err := os.Mkdir(filepath.Join(filepath.Join(dirName, "seeds"), "default"), 0755)
|
|
|
|
if err != nil {
|
|
fmt.Println(err, "error creating default directory in seeds")
|
|
}
|
|
filePointer, err := os.Create(filepath.Join(filepath.Join(filepath.Join(dirName, "seeds"), "default"), "table_seed.sql"))
|
|
if err != nil {
|
|
fmt.Println(err, "not able to create table_seed.sql file")
|
|
}
|
|
_, err = filePointer.WriteString(data)
|
|
if err != nil {
|
|
fmt.Println(err, "not able to write into table_seed.sql file")
|
|
}
|
|
session = testutil.Hasura(testutil.CmdOpts{
|
|
Args: []string{"seed", "apply", "--file", "table_seed.sql", "--database-name", "default"},
|
|
WorkingDirectory: dirName,
|
|
})
|
|
Eventually(session, 60*60).Should(Exit(0))
|
|
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring("Seeds planted"))
|
|
})
|
|
})
|
|
})
|