diff --git a/.github/workflows/ci-dgraph-core-upgrade-tests.yml b/.github/workflows/ci-dgraph-core-upgrade-tests.yml index a8df8d9222c..6cb2464143f 100644 --- a/.github/workflows/ci-dgraph-core-upgrade-tests.yml +++ b/.github/workflows/ci-dgraph-core-upgrade-tests.yml @@ -45,15 +45,13 @@ jobs: #!/bin/bash # go env settings export GOPATH=~/go - export DGRAPH_UPGRADE_MAIN_ONLY=true # move the binary cp dgraph/dgraph ~/go/bin/dgraph # run the core upgrade tests - go test -tags=upgrade \ - github.com/hypermodeinc/dgraph/v24/ee/acl \ - github.com/hypermodeinc/dgraph/v24/worker \ - github.com/hypermodeinc/dgraph/v24/query \ - -v -timeout=120m -failfast + go test -v -timeout=120m -failfast -tags=upgrade \ + github.com/hypermodeinc/dgraph/v24/ee/acl \ + github.com/hypermodeinc/dgraph/v24/worker \ + github.com/hypermodeinc/dgraph/v24/query # clean up docker containers after test execution go clean -testcache # sleep diff --git a/.github/workflows/ci-dgraph-fuzz.yml b/.github/workflows/ci-dgraph-fuzz.yml index 211cc7e7551..fcd0c98ec2f 100644 --- a/.github/workflows/ci-dgraph-fuzz.yml +++ b/.github/workflows/ci-dgraph-fuzz.yml @@ -36,4 +36,4 @@ jobs: #!/bin/bash # go env settings export GOPATH=~/go - go test ./dql -fuzz="Fuzz" -fuzztime="300s" -fuzzminimizetime="120s" + go test -v ./dql -fuzz="Fuzz" -fuzztime="300s" -fuzzminimizetime="120s" diff --git a/.github/workflows/ci-dgraph-oss-build.yml b/.github/workflows/ci-dgraph-oss-build.yml index 54177242bd4..93904d1385b 100644 --- a/.github/workflows/ci-dgraph-oss-build.yml +++ b/.github/workflows/ci-dgraph-oss-build.yml @@ -41,4 +41,4 @@ jobs: # move the binary cp dgraph/dgraph ~/go/bin/dgraph # run OSS unit tests - go test -timeout=60m -failfast -tags=oss -count=1 ./... + go test -v -timeout=60m -failfast -tags=oss -count=1 ./... diff --git a/.github/workflows/ci-dgraph-system-upgrade-tests.yml b/.github/workflows/ci-dgraph-system-upgrade-tests.yml index d88ef19a4ad..2c53d18ca64 100644 --- a/.github/workflows/ci-dgraph-system-upgrade-tests.yml +++ b/.github/workflows/ci-dgraph-system-upgrade-tests.yml @@ -45,15 +45,14 @@ jobs: #!/bin/bash # go env settings export GOPATH=~/go - export DGRAPH_UPGRADE_MAIN_ONLY=true # move the binary cp dgraph/dgraph ~/go/bin/dgraph # run the sytem upgrade tests - go test -tags=upgrade github.com/hypermodeinc/dgraph/v24/systest/mutations-and-queries \ - github.com/hypermodeinc/dgraph/v24/systest/plugin \ - github.com/hypermodeinc/dgraph/v24/systest/license \ - github.com/hypermodeinc/dgraph/v24/systest/multi-tenancy \ - -v -timeout=120m -failfast + go test -v -timeout=120m -failfast -tags=upgrade \ + github.com/hypermodeinc/dgraph/v24/systest/mutations-and-queries \ + github.com/hypermodeinc/dgraph/v24/systest/plugin \ + github.com/hypermodeinc/dgraph/v24/systest/license \ + github.com/hypermodeinc/dgraph/v24/systest/multi-tenancy # clean up docker containers after test execution go clean -testcache # sleep diff --git a/.github/workflows/ci-dgraph-upgrade-fixed-versions-tests.yml b/.github/workflows/ci-dgraph-upgrade-fixed-versions-tests.yml index d25ec215159..91e5b87f4fb 100644 --- a/.github/workflows/ci-dgraph-upgrade-fixed-versions-tests.yml +++ b/.github/workflows/ci-dgraph-upgrade-fixed-versions-tests.yml @@ -31,6 +31,7 @@ jobs: #!/bin/bash # go env settings export GOPATH=~/go + export DGRAPH_UPGRADE_MAIN_ONLY=false # move the binary cp dgraph/dgraph ~/go/bin/dgraph # run the tests diff --git a/contrib/Dockerfile b/contrib/Dockerfile index 08dd77f9f17..1d2fcacebfe 100644 --- a/contrib/Dockerfile +++ b/contrib/Dockerfile @@ -14,8 +14,8 @@ RUN rm -rf /var/lib/apt/lists/* # only update, don't run upgrade # use cache busting to avoid old versions -# remove /var/lib/apt/lists/* to reduce image size. -# see: https://docs.docker.com/develop/develop-images/dockerfile_best-practices +# remove /var/lib/apt/lists/* to reduce image size. +# see: https://docs.docker.com/develop/develop-images/dockerfile_best-practices RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ htop \ @@ -33,4 +33,4 @@ RUN mkdir /dgraph WORKDIR /dgraph ENV GODEBUG=madvdontneed=1 -CMD ["dgraph"] # Shows the dgraph version and commands available. +CMD ["dgraph"] diff --git a/dgraphtest/config.go b/dgraphtest/config.go index 93ddb36e033..3005b50cc7e 100644 --- a/dgraphtest/config.go +++ b/dgraphtest/config.go @@ -74,8 +74,8 @@ func AllUpgradeCombos(v20 bool) []UpgradeCombo { // In mainCombos list, we keep latest version to current HEAD as well as // older versions of dgraph to ensure that a change does not cause failures. mainCombos := []UpgradeCombo{ - {"v23.1.0", localVersion, BackupRestore}, - {"v23.1.0", localVersion, InPlace}, + {"v24.0.0", localVersion, BackupRestore}, + {"v24.0.0", localVersion, InPlace}, } if v20 { @@ -90,10 +90,10 @@ func AllUpgradeCombos(v20 bool) []UpgradeCombo { }...) } - if os.Getenv("DGRAPH_UPGRADE_MAIN_ONLY") == "true" { - return mainCombos - } else { + if os.Getenv("DGRAPH_UPGRADE_MAIN_ONLY") == "false" { return fixedVersionCombos + } else { + return mainCombos } } diff --git a/dgraphtest/dgraph.go b/dgraphtest/dgraph.go index 993ee87ca6c..415a8b3bc3f 100644 --- a/dgraphtest/dgraph.go +++ b/dgraphtest/dgraph.go @@ -421,7 +421,7 @@ func mountBinary(c *LocalCluster) (mount.Mount, error) { } // ShouldSkipTest skips a given test if clusterVersion < minVersion -func ShouldSkipTest(t *testing.T, minVersion, clusterVersion string) error { +func ShouldSkipTest(t *testing.T, minVersion, clusterVersion string) { supported, err := IsHigherVersion(clusterVersion, minVersion) if err != nil { t.Fatal(err) @@ -429,5 +429,4 @@ func ShouldSkipTest(t *testing.T, minVersion, clusterVersion string) error { if !supported { t.Skipf("test is valid for commits greater than [%v]", minVersion) } - return nil } diff --git a/dgraphtest/image.go b/dgraphtest/image.go index 1b680dd691d..d658c46b0e9 100644 --- a/dgraphtest/image.go +++ b/dgraphtest/image.go @@ -73,13 +73,6 @@ func ensureDgraphClone() error { } return runGitClone() } - - // we do not return error if git fetch fails because maybe there are no changes - // to pull and it doesn't make sense to fail right now. We can fail later when we - // do not find the reference that we are looking for. - if err := runGitFetch(); err != nil { - log.Printf("[WARNING] error in fetching latest git changes: %v", err) - } return nil } @@ -92,6 +85,7 @@ func runGitClone() error { // a copy of this folder by running git clone using this already cloned dgraph // repo. After the quick clone, we update the original URL to point to the // GitHub dgraph repo and perform a "git fetch". + log.Printf("[INFO] cloning dgraph repo from [%v]", baseRepoDir) cmd := exec.Command("git", "clone", baseRepoDir, repoDir) if out, err := cmd.CombinedOutput(); err != nil { return errors.Wrapf(err, "error cloning dgraph repo\noutput:%v", string(out)) @@ -256,8 +250,8 @@ func IsHigherVersion(higher, lower string) (bool, error) { cmd := exec.Command("git", "merge-base", "--is-ancestor", lower, higher) cmd.Dir = repoDir if out, err := cmd.CombinedOutput(); err != nil { - if exitError, ok := err.(*exec.ExitError); ok { - return exitError.ExitCode() == 0, nil + if exitError, ok := err.(*exec.ExitError); ok && exitError.ExitCode() == 1 { + return false, nil } return false, errors.Wrapf(err, "error checking if [%v] is ancestor of [%v]\noutput:%v", diff --git a/edgraph/server.go b/edgraph/server.go index 2845e086eed..2ef353b6658 100644 --- a/edgraph/server.go +++ b/edgraph/server.go @@ -2020,7 +2020,7 @@ func validateAndConvertFacets(nquads []*api.NQuad) error { // validateForGraphql validate nquads for graphql func validateForGraphql(nq *api.NQuad, isGraphql bool) error { // Check whether the incoming predicate is graphql reserved predicate or not. - if !isGraphql && x.IsGraphqlReservedPredicate(nq.Predicate) { + if !isGraphql && x.IsOtherReservedPredicate(nq.Predicate) { return errors.Errorf("Cannot mutate graphql reserved predicate %s", nq.Predicate) } return nil diff --git a/ee/acl/acl_test.go b/ee/acl/acl_test.go index 25f568d40d7..9e10e72df46 100644 --- a/ee/acl/acl_test.go +++ b/ee/acl/acl_test.go @@ -171,7 +171,7 @@ const ( }` // This is the groot schema after adding @unique directive to the dgraph.xid predicate - newGrootSchema = `{ + uniqueXidGrootSchema = `{ "schema": [ { "predicate": "dgraph.acl.rule", @@ -301,6 +301,169 @@ const ( "name": "dgraph.type.User" } ] + }` + + grootSchemaWithNamespaceSchema = `{ + "schema": [ + { + "predicate": "dgraph.acl.rule", + "type": "uid", + "list": true + }, + { + "predicate":"dgraph.drop.op", + "type":"string" + }, + { + "predicate":"dgraph.graphql.p_query", + "type":"string", + "index":true, + "tokenizer":["sha256"] + }, + { + "predicate": "dgraph.graphql.schema", + "type": "string" + }, + { + "predicate": "dgraph.graphql.xid", + "type": "string", + "index": true, + "tokenizer": [ + "exact" + ], + "upsert": true + }, + { + "predicate": "dgraph.namespace.id", + "type": "int", + "index": true, + "tokenizer": [ + "int" + ], + "upsert": true, + "unique": true + }, + { + "predicate": "dgraph.namespace.name", + "type": "string", + "index": true, + "tokenizer": [ + "exact" + ], + "upsert": true, + "unique": true + }, + { + "predicate": "dgraph.password", + "type": "password" + }, + { + "predicate": "dgraph.rule.permission", + "type": "int" + }, + { + "predicate": "dgraph.rule.predicate", + "type": "string", + "index": true, + "tokenizer": [ + "exact" + ], + "upsert": true + }, + { + "predicate": "dgraph.type", + "type": "string", + "index": true, + "tokenizer": [ + "exact" + ], + "list": true + }, + { + "predicate": "dgraph.user.group", + "type": "uid", + "reverse": true, + "list": true + }, + { + "predicate": "dgraph.xid", + "type": "string", + "index": true, + "tokenizer": [ + "exact" + ], + "upsert": true, + "unique": true + } + ], + "types": [ + { + "fields": [ + { + "name": "dgraph.graphql.schema" + }, + { + "name": "dgraph.graphql.xid" + } + ], + "name": "dgraph.graphql" + }, + { + "fields": [ + { + "name": "dgraph.graphql.p_query" + } + ], + "name": "dgraph.graphql.persisted_query" + }, + { + "fields": [ + { + "name": "dgraph.namespace.name" + }, + { + "name": "dgraph.namespace.id" + } + ], + "name": "dgraph.namespace" + }, + { + "fields": [ + { + "name": "dgraph.xid" + }, + { + "name": "dgraph.acl.rule" + } + ], + "name": "dgraph.type.Group" + }, + { + "fields": [ + { + "name": "dgraph.rule.predicate" + }, + { + "name": "dgraph.rule.permission" + } + ], + "name": "dgraph.type.Rule" + }, + { + "fields": [ + { + "name": "dgraph.xid" + }, + { + "name": "dgraph.password" + }, + { + "name": "dgraph.user.group" + } + ], + "name": "dgraph.type.User" + } + ] }` ) @@ -567,12 +730,12 @@ var ( func alterPreDefinedPredicates(t *testing.T, dg *dgo.Dgraph, clusterVersion string) { ctx := context.Background() - // Commit daa5805739ed258e913a157c6e0f126b2291b1b0 represents the latest update to the main branch. + // Commit 532df27a09ba25f88687bab344e3add2b81b5c23 represents the latest update to the main branch. // In this commit, the @unique directive is not applied to ACL predicates. // Therefore, we are now deciding which schema to test. // 'newGrootSchema' refers to the default schema with the @unique directive defined on ACL predicates. // 'oldGrootSchema' refers to the default schema without the @unique directive on ACL predicates. - supported, err := dgraphtest.IsHigherVersion(clusterVersion, "daa5805739ed258e913a157c6e0f126b2291b1b0") + supported, err := dgraphtest.IsHigherVersion(clusterVersion, "532df27a09ba25f88687bab344e3add2b81b5c23") require.NoError(t, err) if supported { require.NoError(t, dg.Alter(ctx, &api.Operation{ @@ -2087,7 +2250,7 @@ func (asuite *AclTestSuite) TestQueryUserInfo() { func (asuite *AclTestSuite) TestQueriesWithUserAndGroupOfSameName() { t := asuite.T() - dgraphtest.ShouldSkipTest(t, asuite.dc.GetVersion(), "7b1f473ddf01547e24b44f580a68e6b049502d69") + dgraphtest.ShouldSkipTest(t, asuite.dc.GetVersion(), "532df27a09ba25f88687bab344e3add2b81b5c23") ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second) defer cancel() @@ -2225,6 +2388,10 @@ func (asuite *AclTestSuite) TestSchemaQueryWithACL() { "fields":[], "name":"dgraph.graphql.persisted_query" }, + { + "fields": [], + "name": "dgraph.namespace" + }, { "fields": [], "name": "dgraph.type.Group" @@ -2254,10 +2421,14 @@ func (asuite *AclTestSuite) TestSchemaQueryWithACL() { require.NoError(t, gc.DropAll()) resp, err := gc.Query(schemaQuery) require.NoError(t, err) - supported, err := dgraphtest.IsHigherVersion(asuite.dc.GetVersion(), "daa5805739ed258e913a157c6e0f126b2291b1b0") + uniqueSchemaSupported, err := dgraphtest.IsHigherVersion(asuite.dc.GetVersion(), "532df27a09ba25f88687bab344e3add2b81b5c23") require.NoError(t, err) - if supported { - require.JSONEq(t, newGrootSchema, string(resp.GetJson())) + nsSchemaSupported, err := dgraphtest.IsHigherVersion(asuite.dc.GetVersion(), "053a44054dc665f573ee7b92136b551a7b70c37c") + require.NoError(t, err) + if nsSchemaSupported { + require.JSONEq(t, grootSchemaWithNamespaceSchema, string(resp.GetJson())) + } else if uniqueSchemaSupported { + require.JSONEq(t, uniqueXidGrootSchema, string(resp.GetJson())) } else { require.JSONEq(t, oldGrootSchema, string(resp.GetJson())) } diff --git a/ee/acl/upgrade_test.go b/ee/acl/upgrade_test.go index 359923f5676..7a9660a12d2 100644 --- a/ee/acl/upgrade_test.go +++ b/ee/acl/upgrade_test.go @@ -54,7 +54,7 @@ func (asuite *AclTestSuite) Upgrade() { } func TestACLSuite(t *testing.T) { - for _, uc := range dgraphtest.AllUpgradeCombos(true) { + for _, uc := range dgraphtest.AllUpgradeCombos(false) { log.Printf("running upgrade tests for config: %+v", uc) aclSuite := AclTestSuite{uc: uc} suite.Run(t, &aclSuite) diff --git a/graphql/e2e/directives/schema_response.json b/graphql/e2e/directives/schema_response.json index b41cb67668b..5f756d3f407 100644 --- a/graphql/e2e/directives/schema_response.json +++ b/graphql/e2e/directives/schema_response.json @@ -4,16 +4,12 @@ "predicate": "Animal.category", "type": "string", "index": true, - "tokenizer": [ - "hash" - ] + "tokenizer": ["hash"] }, { "index": true, "predicate": "Employer.company", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, @@ -24,10 +20,7 @@ { "index": true, "predicate": "author1.name", - "tokenizer": [ - "hash", - "trigram" - ], + "tokenizer": ["hash", "trigram"], "type": "string", "upsert": true }, @@ -38,18 +31,14 @@ { "index": true, "predicate": "Worker.empId", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, { "index": true, "predicate": "Worker.regNo", - "tokenizer": [ - "int" - ], + "tokenizer": ["int"], "type": "int", "upsert": true }, @@ -57,9 +46,7 @@ "predicate": "Astronaut.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -79,9 +66,7 @@ { "index": true, "predicate": "Team.teamName", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, @@ -97,18 +82,14 @@ { "index": true, "predicate": "Team.teamID", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, { "index": true, "predicate": "Member.name", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, @@ -123,18 +104,14 @@ { "index": true, "predicate": "LibraryManager.name", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, { "index": true, "predicate": "Member.refID", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, @@ -168,9 +145,7 @@ "predicate": "Book.bookId", "type": "int", "index": true, - "tokenizer": [ - "int" - ], + "tokenizer": ["int"], "upsert": true }, { @@ -181,28 +156,21 @@ { "index": true, "predicate": "Employer.name", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, { "index": true, "predicate": "Worker.uniqueId", - "tokenizer": [ - "int" - ], + "tokenizer": ["int"], "type": "int", "upsert": true }, { - "index": true, "index": true, "predicate": "Employer.companyId", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, @@ -215,9 +183,7 @@ "index": true, "lang": true, "predicate": "Person.name", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string" }, { @@ -250,9 +216,7 @@ "predicate": "Chapter.chapterId", "type": "int", "index": true, - "tokenizer": [ - "int" - ], + "tokenizer": ["int"], "upsert": true }, { @@ -267,9 +231,7 @@ "predicate": "Comment1.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -281,27 +243,20 @@ "predicate": "Country.name", "type": "string", "index": true, - "tokenizer": [ - "hash", - "trigram" - ] + "tokenizer": ["hash", "trigram"] }, { "predicate": "Dataset.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { "predicate": "Dataset.name", "type": "string", "index": true, - "tokenizer": [ - "hash" - ] + "tokenizer": ["hash"] }, { "predicate": "Dataset.owner", @@ -315,9 +270,7 @@ "predicate": "District.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -328,9 +281,7 @@ "predicate": "Dog.breed", "type": "string", "index": true, - "tokenizer": [ - "term" - ] + "tokenizer": ["term"] }, { "predicate": "Home.address", @@ -349,33 +300,25 @@ "predicate": "Hotel.area", "type": "geo", "index": true, - "tokenizer": [ - "geo" - ] + "tokenizer": ["geo"] }, { "predicate": "Hotel.branches", "type": "geo", "index": true, - "tokenizer": [ - "geo" - ] + "tokenizer": ["geo"] }, { "predicate": "Hotel.location", "type": "geo", "index": true, - "tokenizer": [ - "geo" - ] + "tokenizer": ["geo"] }, { "predicate": "Hotel.name", "type": "string", "index": true, - "tokenizer": [ - "exact" - ] + "tokenizer": ["exact"] }, { "predicate": "Human.starships", @@ -399,9 +342,7 @@ "predicate": "Mission.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -434,9 +375,7 @@ "predicate": "Owner.username", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -452,9 +391,7 @@ "predicate": "People.xid", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -484,9 +421,7 @@ "predicate": "Post1.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -498,18 +433,14 @@ "predicate": "Project.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { "predicate": "Project.name", "type": "string", "index": true, - "tokenizer": [ - "hash" - ] + "tokenizer": ["hash"] }, { "predicate": "Project.owner", @@ -523,9 +454,7 @@ "predicate": "Region.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -536,9 +465,7 @@ "predicate": "SpaceShip.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -550,9 +477,7 @@ "predicate": "Planet.id", "type": "int", "index": true, - "tokenizer": [ - "int" - ], + "tokenizer": ["int"], "upsert": true }, { @@ -576,10 +501,7 @@ "predicate": "State.xcode", "type": "string", "index": true, - "tokenizer": [ - "hash", - "trigram" - ], + "tokenizer": ["hash", "trigram"], "upsert": true }, { @@ -628,9 +550,7 @@ "predicate": "User.name", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -646,9 +566,7 @@ "predicate": "appears_in", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "list": true }, { @@ -663,9 +581,7 @@ "predicate": "dgraph.graphql.p_query", "type": "string", "index": true, - "tokenizer": [ - "sha256" - ] + "tokenizer": ["sha256"] }, { "predicate": "dgraph.graphql.schema", @@ -675,18 +591,30 @@ "predicate": "dgraph.graphql.xid", "type": "string", "index": true, - "tokenizer": [ - "exact" - ], + "tokenizer": ["exact"], + "upsert": true + }, + { + "index": true, + "predicate": "dgraph.namespace.name", + "tokenizer": ["exact"], + "type": "string", + "unique": true, + "upsert": true + }, + { + "index": true, + "predicate": "dgraph.namespace.id", + "tokenizer": ["int"], + "type": "int", + "unique": true, "upsert": true }, { "predicate": "dgraph.type", "type": "string", "index": true, - "tokenizer": [ - "exact" - ], + "tokenizer": ["exact"], "list": true }, { @@ -708,9 +636,7 @@ "predicate": "is_published", "type": "bool", "index": true, - "tokenizer": [ - "bool" - ] + "tokenizer": ["bool"] }, { "predicate": "myPost.category", @@ -720,52 +646,38 @@ "predicate": "myPost.numLikes", "type": "int", "index": true, - "tokenizer": [ - "int" - ] + "tokenizer": ["int"] }, { "predicate": "myPost.numViews", "type": "int", "index": true, - "tokenizer": [ - "int" - ] + "tokenizer": ["int"] }, { "predicate": "myPost.postType", "type": "string", "index": true, - "tokenizer": [ - "hash", - "trigram" - ] + "tokenizer": ["hash", "trigram"] }, { "predicate": "myPost.tags", "type": "string", "index": true, - "tokenizer": [ - "exact" - ], + "tokenizer": ["exact"], "list": true }, { "predicate": "myPost.title", "type": "string", "index": true, - "tokenizer": [ - "fulltext", - "term" - ] + "tokenizer": ["fulltext", "term"] }, { "predicate": "performance.character.name", "type": "string", "index": true, - "tokenizer": [ - "exact" - ] + "tokenizer": ["exact"] }, { "predicate": "post", @@ -789,18 +701,13 @@ "predicate": "post1.numLikes", "type": "int", "index": true, - "tokenizer": [ - "int" - ] + "tokenizer": ["int"] }, { "predicate": "post1.title", "type": "string", "index": true, - "tokenizer": [ - "hash", - "trigram" - ], + "tokenizer": ["hash", "trigram"], "upsert": true }, { @@ -819,9 +726,7 @@ "predicate": "star.ship.name", "type": "string", "index": true, - "tokenizer": [ - "term" - ] + "tokenizer": ["term"] }, { "predicate": "test.dgraph.author.country", @@ -831,18 +736,13 @@ "predicate": "test.dgraph.author.dob", "type": "datetime", "index": true, - "tokenizer": [ - "year" - ] + "tokenizer": ["year"] }, { "predicate": "test.dgraph.author.name", "type": "string", "index": true, - "tokenizer": [ - "hash", - "trigram" - ] + "tokenizer": ["hash", "trigram"] }, { "predicate": "test.dgraph.author.posts", @@ -853,18 +753,13 @@ "predicate": "test.dgraph.author.qualification", "type": "string", "index": true, - "tokenizer": [ - "hash", - "trigram" - ] + "tokenizer": ["hash", "trigram"] }, { "predicate": "test.dgraph.author.reputation", "type": "float", "index": true, - "tokenizer": [ - "float" - ] + "tokenizer": ["float"] }, { "predicate": "test.dgraph.employee.en.ename", @@ -874,17 +769,13 @@ "predicate": "test.dgraph.topic", "type": "string", "index": true, - "tokenizer": [ - "exact" - ] + "tokenizer": ["exact"] }, { "predicate": "text", "type": "string", "index": true, - "tokenizer": [ - "fulltext" - ] + "tokenizer": ["fulltext"] }, { "predicate": "职业", @@ -1424,6 +1315,17 @@ ], "name": "dgraph.graphql.persisted_query" }, + { + "fields": [ + { + "name": "dgraph.namespace.id" + }, + { + "name": "dgraph.namespace.name" + } + ], + "name": "dgraph.namespace" + }, { "fields": [ { diff --git a/graphql/e2e/normal/schema_response.json b/graphql/e2e/normal/schema_response.json index 310dcbe6279..f4faaaadd18 100644 --- a/graphql/e2e/normal/schema_response.json +++ b/graphql/e2e/normal/schema_response.json @@ -4,16 +4,12 @@ "predicate": "Animal.category", "type": "string", "index": true, - "tokenizer": [ - "hash" - ] + "tokenizer": ["hash"] }, { "index": true, "predicate": "Employer.company", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, @@ -29,9 +25,7 @@ { "index": true, "predicate": "Team.teamName", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, @@ -47,18 +41,14 @@ { "index": true, "predicate": "Team.teamID", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, { "index": true, "predicate": "Member.name", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, @@ -73,18 +63,14 @@ { "index": true, "predicate": "LibraryManager.name", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, { "index": true, "predicate": "Member.refID", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, @@ -108,10 +94,7 @@ { "index": true, "predicate": "author1.name", - "tokenizer": [ - "hash", - "trigram" - ], + "tokenizer": ["hash", "trigram"], "type": "string", "upsert": true }, @@ -124,9 +107,7 @@ "predicate": "Astronaut.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -150,18 +131,13 @@ "predicate": "Author.dob", "type": "datetime", "index": true, - "tokenizer": [ - "year" - ] + "tokenizer": ["year"] }, { "predicate": "Author.name", "type": "string", "index": true, - "tokenizer": [ - "hash", - "trigram" - ] + "tokenizer": ["hash", "trigram"] }, { "predicate": "Author.posts", @@ -172,26 +148,19 @@ "predicate": "Author.qualification", "type": "string", "index": true, - "tokenizer": [ - "hash", - "trigram" - ] + "tokenizer": ["hash", "trigram"] }, { "predicate": "Author.reputation", "type": "float", "index": true, - "tokenizer": [ - "float" - ] + "tokenizer": ["float"] }, { "predicate": "Book.bookId", "type": "int", "index": true, - "tokenizer": [ - "int" - ], + "tokenizer": ["int"], "upsert": true }, { @@ -224,9 +193,7 @@ "predicate": "Chapter.chapterId", "type": "int", "index": true, - "tokenizer": [ - "int" - ], + "tokenizer": ["int"], "upsert": true }, { @@ -237,18 +204,14 @@ "predicate": "Character.appearsIn", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "list": true }, { "predicate": "Character.name", "type": "string", "index": true, - "tokenizer": [ - "exact" - ] + "tokenizer": ["exact"] }, { "predicate": "Cheetah.speed", @@ -258,9 +221,7 @@ "predicate": "Comment1.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -272,10 +233,7 @@ "predicate": "Country.name", "type": "string", "index": true, - "tokenizer": [ - "hash", - "trigram" - ] + "tokenizer": ["hash", "trigram"] }, { "predicate": "Country.states", @@ -286,18 +244,14 @@ "predicate": "Dataset.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { "predicate": "Dataset.name", "type": "string", "index": true, - "tokenizer": [ - "hash" - ] + "tokenizer": ["hash"] }, { "predicate": "Dataset.owner", @@ -311,9 +265,7 @@ "predicate": "District.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -324,9 +276,7 @@ "predicate": "Dog.breed", "type": "string", "index": true, - "tokenizer": [ - "term" - ] + "tokenizer": ["term"] }, { "predicate": "Droid.primaryFunction", @@ -353,33 +303,25 @@ "predicate": "Hotel.area", "type": "geo", "index": true, - "tokenizer": [ - "geo" - ] + "tokenizer": ["geo"] }, { "predicate": "Hotel.branches", "type": "geo", "index": true, - "tokenizer": [ - "geo" - ] + "tokenizer": ["geo"] }, { "predicate": "Hotel.location", "type": "geo", "index": true, - "tokenizer": [ - "geo" - ] + "tokenizer": ["geo"] }, { "predicate": "Hotel.name", "type": "string", "index": true, - "tokenizer": [ - "exact" - ] + "tokenizer": ["exact"] }, { "predicate": "Human.starships", @@ -407,9 +349,7 @@ "predicate": "Mission.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -433,18 +373,14 @@ { "index": true, "predicate": "Worker.empId", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, { "index": true, "predicate": "Worker.regNo", - "tokenizer": [ - "int" - ], + "tokenizer": ["int"], "type": "int", "upsert": true }, @@ -474,9 +410,7 @@ "predicate": "Owner.username", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -492,9 +426,7 @@ "predicate": "People.xid", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -506,9 +438,7 @@ "index": true, "lang": true, "predicate": "Person.name", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string" }, { @@ -541,68 +471,50 @@ "predicate": "Post.isPublished", "type": "bool", "index": true, - "tokenizer": [ - "bool" - ] + "tokenizer": ["bool"] }, { "predicate": "Post.numLikes", "type": "int", "index": true, - "tokenizer": [ - "int" - ] + "tokenizer": ["int"] }, { "predicate": "Post.numViews", "type": "int", "index": true, - "tokenizer": [ - "int" - ] + "tokenizer": ["int"] }, { "predicate": "Post.postType", "type": "string", "index": true, - "tokenizer": [ - "hash", - "trigram" - ] + "tokenizer": ["hash", "trigram"] }, { "predicate": "Post.tags", "type": "string", "index": true, - "tokenizer": [ - "exact" - ], + "tokenizer": ["exact"], "list": true }, { "predicate": "Post.text", "type": "string", "index": true, - "tokenizer": [ - "fulltext" - ] + "tokenizer": ["fulltext"] }, { "predicate": "Post.title", "type": "string", "index": true, - "tokenizer": [ - "fulltext", - "term" - ] + "tokenizer": ["fulltext", "term"] }, { "predicate": "Post.topic", "type": "string", "index": true, - "tokenizer": [ - "exact" - ] + "tokenizer": ["exact"] }, { "predicate": "Post1.comments", @@ -613,9 +525,7 @@ "predicate": "Post1.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -627,18 +537,14 @@ "predicate": "Project.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { "predicate": "Project.name", "type": "string", "index": true, - "tokenizer": [ - "hash" - ] + "tokenizer": ["hash"] }, { "predicate": "Project.owner", @@ -652,9 +558,7 @@ "predicate": "Region.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -665,9 +569,7 @@ "predicate": "SpaceShip.id", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -679,9 +581,7 @@ "predicate": "Planet.id", "type": "int", "index": true, - "tokenizer": [ - "int" - ], + "tokenizer": ["int"], "upsert": true }, { @@ -697,9 +597,7 @@ "predicate": "Starship.name", "type": "string", "index": true, - "tokenizer": [ - "term" - ] + "tokenizer": ["term"] }, { "predicate": "State.capital", @@ -721,10 +619,7 @@ "predicate": "State.xcode", "type": "string", "index": true, - "tokenizer": [ - "hash", - "trigram" - ], + "tokenizer": ["hash", "trigram"], "upsert": true }, { @@ -740,18 +635,14 @@ { "index": true, "predicate": "Employer.name", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, { "index": true, "predicate": "Worker.uniqueId", - "tokenizer": [ - "int" - ], + "tokenizer": ["int"], "type": "int", "upsert": true }, @@ -759,9 +650,7 @@ "index": true, "index": true, "predicate": "Employer.companyId", - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "type": "string", "upsert": true }, @@ -806,9 +695,7 @@ "predicate": "User.name", "type": "string", "index": true, - "tokenizer": [ - "hash" - ], + "tokenizer": ["hash"], "upsert": true }, { @@ -832,9 +719,7 @@ "predicate": "dgraph.graphql.p_query", "type": "string", "index": true, - "tokenizer": [ - "sha256" - ] + "tokenizer": ["sha256"] }, { "predicate": "dgraph.graphql.schema", @@ -844,18 +729,30 @@ "predicate": "dgraph.graphql.xid", "type": "string", "index": true, - "tokenizer": [ - "exact" - ], + "tokenizer": ["exact"], + "upsert": true + }, + { + "index": true, + "predicate": "dgraph.namespace.name", + "tokenizer": ["exact"], + "type": "string", + "unique": true, + "upsert": true + }, + { + "index": true, + "predicate": "dgraph.namespace.id", + "tokenizer": ["int"], + "type": "int", + "unique": true, "upsert": true }, { "predicate": "dgraph.type", "type": "string", "index": true, - "tokenizer": [ - "exact" - ], + "tokenizer": ["exact"], "list": true }, { @@ -872,18 +769,13 @@ "predicate": "post1.numLikes", "type": "int", "index": true, - "tokenizer": [ - "int" - ] + "tokenizer": ["int"] }, { "predicate": "post1.title", "type": "string", "index": true, - "tokenizer": [ - "hash", - "trigram" - ], + "tokenizer": ["hash", "trigram"], "upsert": true } ], @@ -1503,6 +1395,17 @@ ], "name": "dgraph.graphql.persisted_query" }, + { + "fields": [ + { + "name": "dgraph.namespace.id" + }, + { + "name": "dgraph.namespace.name" + } + ], + "name": "dgraph.namespace" + }, { "fields": [ { diff --git a/query/upgrade_test.go b/query/upgrade_test.go index 84177a3cf77..c7e70d89c1d 100644 --- a/query/upgrade_test.go +++ b/query/upgrade_test.go @@ -76,7 +76,7 @@ func TestMain(m *testing.M) { } } - for _, uc := range dgraphtest.AllUpgradeCombos(true) { + for _, uc := range dgraphtest.AllUpgradeCombos(false) { log.Printf("running upgrade tests for confg: %+v", uc) runTest(uc) } diff --git a/schema/schema.go b/schema/schema.go index d3ecd4d3c45..fe56d6ec233 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -673,7 +673,8 @@ func initialTypesInternal(namespace uint64, all bool) []*pb.TypeUpdate { ValueType: pb.Posting_STRING, }, }, - }, &pb.TypeUpdate{ + }, + &pb.TypeUpdate{ TypeName: "dgraph.graphql.persisted_query", Fields: []*pb.SchemaUpdate{ { @@ -683,26 +684,44 @@ func initialTypesInternal(namespace uint64, all bool) []*pb.TypeUpdate { }, }) + if namespace == x.GalaxyNamespace { + initialTypes = append(initialTypes, + &pb.TypeUpdate{ + TypeName: "dgraph.namespace", + Fields: []*pb.SchemaUpdate{ + { + Predicate: "dgraph.namespace.name", + ValueType: pb.Posting_STRING, + }, + { + Predicate: "dgraph.namespace.id", + ValueType: pb.Posting_INT, + }, + }, + }) + } + if all || x.WorkerConfig.AclEnabled { // These type definitions are required for deleteUser and deleteGroup GraphQL API to work // properly. - initialTypes = append(initialTypes, &pb.TypeUpdate{ - TypeName: "dgraph.type.User", - Fields: []*pb.SchemaUpdate{ - { - Predicate: "dgraph.xid", - ValueType: pb.Posting_STRING, - }, - { - Predicate: "dgraph.password", - ValueType: pb.Posting_PASSWORD, - }, - { - Predicate: "dgraph.user.group", - ValueType: pb.Posting_UID, + initialTypes = append(initialTypes, + &pb.TypeUpdate{ + TypeName: "dgraph.type.User", + Fields: []*pb.SchemaUpdate{ + { + Predicate: "dgraph.xid", + ValueType: pb.Posting_STRING, + }, + { + Predicate: "dgraph.password", + ValueType: pb.Posting_PASSWORD, + }, + { + Predicate: "dgraph.user.group", + ValueType: pb.Posting_UID, + }, }, }, - }, &pb.TypeUpdate{ TypeName: "dgraph.type.Group", Fields: []*pb.SchemaUpdate{ @@ -759,31 +778,57 @@ func CompleteInitialSchema(namespace uint64) []*pb.SchemaUpdate { func initialSchemaInternal(namespace uint64, all bool) []*pb.SchemaUpdate { var initialSchema []*pb.SchemaUpdate - initialSchema = append(initialSchema, - &pb.SchemaUpdate{ + initialSchema = append(initialSchema, []*pb.SchemaUpdate{ + { Predicate: "dgraph.type", ValueType: pb.Posting_STRING, Directive: pb.SchemaUpdate_INDEX, Tokenizer: []string{"exact"}, List: true, - }, &pb.SchemaUpdate{ + }, + { Predicate: "dgraph.drop.op", ValueType: pb.Posting_STRING, - }, &pb.SchemaUpdate{ + }, + { Predicate: "dgraph.graphql.schema", ValueType: pb.Posting_STRING, - }, &pb.SchemaUpdate{ + }, + { Predicate: "dgraph.graphql.xid", ValueType: pb.Posting_STRING, Directive: pb.SchemaUpdate_INDEX, Tokenizer: []string{"exact"}, Upsert: true, - }, &pb.SchemaUpdate{ + }, + { Predicate: "dgraph.graphql.p_query", ValueType: pb.Posting_STRING, Directive: pb.SchemaUpdate_INDEX, Tokenizer: []string{"sha256"}, - }) + }, + }...) + + if namespace == x.GalaxyNamespace { + initialSchema = append(initialSchema, []*pb.SchemaUpdate{ + { + Predicate: "dgraph.namespace.name", + ValueType: pb.Posting_STRING, + Directive: pb.SchemaUpdate_INDEX, + Tokenizer: []string{"exact"}, + Unique: true, + Upsert: true, + }, + { + Predicate: "dgraph.namespace.id", + ValueType: pb.Posting_INT, + Directive: pb.SchemaUpdate_INDEX, + Tokenizer: []string{"int"}, + Unique: true, + Upsert: true, + }, + }...) + } if all || x.WorkerConfig.AclEnabled { // propose the schema update for acl predicates diff --git a/systest/backup/filesystem/backup_test.go b/systest/backup/filesystem/backup_test.go index 1c46c4327e9..0ac56801374 100644 --- a/systest/backup/filesystem/backup_test.go +++ b/systest/backup/filesystem/backup_test.go @@ -228,8 +228,8 @@ func TestBackupFilesystem(t *testing.T) { // Check the predicates and types in the schema are as expected. // TODO: refactor tests so that minio and filesystem tests share most of their logic. preds := []string{"dgraph.graphql.schema", "name", "dgraph.graphql.xid", "dgraph.type", - "movie", "dgraph.graphql.p_query", "dgraph.drop.op"} - types := []string{"Node", "dgraph.graphql", "dgraph.graphql.persisted_query"} + "movie", "dgraph.graphql.p_query", "dgraph.drop.op", "dgraph.namespace.name", "dgraph.namespace.id"} + types := []string{"Node", "dgraph.graphql", "dgraph.namespace", "dgraph.graphql.persisted_query"} testutil.CheckSchema(t, preds, types) verifyUids := func(count int) { diff --git a/systest/backup/minio/backup_test.go b/systest/backup/minio/backup_test.go index d834b2438e5..8c4783f9dd6 100644 --- a/systest/backup/minio/backup_test.go +++ b/systest/backup/minio/backup_test.go @@ -128,8 +128,8 @@ func TestBackupMinio(t *testing.T) { // Check the predicates and types in the schema are as expected. // TODO: refactor tests so that minio and filesystem tests share most of their logic. preds := []string{"dgraph.graphql.schema", "dgraph.graphql.xid", "dgraph.type", "movie", - "dgraph.graphql.p_query", "dgraph.drop.op"} - types := []string{"Node", "dgraph.graphql", "dgraph.graphql.persisted_query"} + "dgraph.graphql.p_query", "dgraph.drop.op", "dgraph.namespace.name", "dgraph.namespace.id"} + types := []string{"Node", "dgraph.graphql", "dgraph.namespace", "dgraph.graphql.persisted_query"} testutil.CheckSchema(t, preds, types) checks := []struct { diff --git a/systest/export/export_test.go b/systest/export/export_test.go index 4148b159f0f..19ad7416f9a 100644 --- a/systest/export/export_test.go +++ b/systest/export/export_test.go @@ -83,7 +83,9 @@ var expectedSchema = `[0x0] :string .` + " " + ` [0x0] :[string] @index(exact) .` + " " + ` [0x0] :string .` + " " + ` [0x0] :string @index(exact) @upsert .` + " " + ` +[0x0] :int @index(int) @upsert @unique .` + " " + ` [0x0] :string .` + " " + ` +[0x0] :string @index(exact) @upsert @unique .` + " " + ` [0x0] :string @index(sha256) .` + " " + ` [0x0] type { movie @@ -92,6 +94,10 @@ var expectedSchema = `[0x0] :string .` + " " + ` dgraph.graphql.schema dgraph.graphql.xid } +[0x0] type { + dgraph.namespace.name + dgraph.namespace.id +} [0x0] type { dgraph.graphql.p_query } diff --git a/systest/integration2/acl_test.go b/systest/integration2/acl_test.go index bf7ffa5d3de..4e84ae4e22f 100644 --- a/systest/integration2/acl_test.go +++ b/systest/integration2/acl_test.go @@ -44,7 +44,8 @@ type Received struct { } func testDuplicateUserUpgradeStrat(t *testing.T, strat dgraphtest.UpgradeStrategy) { - conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1).WithReplicas(1).WithACL(time.Hour).WithVersion("v23.0.1") + conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1). + WithReplicas(1).WithACL(time.Hour).WithVersion("v23.0.1") c, err := dgraphtest.NewLocalCluster(conf) require.NoError(t, err) defer func() { c.Cleanup(t.Failed()) }() @@ -94,7 +95,7 @@ func testDuplicateUserUpgradeStrat(t *testing.T, strat dgraphtest.UpgradeStrateg query = `{ q(func: has(name)) { - count(uid) + count(uid) } }` resp, err = gc.Query(query) diff --git a/systest/mutations-and-queries/integration_test.go b/systest/mutations-and-queries/integration_test.go index fc608043a9a..7c19eb0ef58 100644 --- a/systest/mutations-and-queries/integration_test.go +++ b/systest/mutations-and-queries/integration_test.go @@ -35,9 +35,7 @@ type SystestTestSuite struct { func (ssuite *SystestTestSuite) SetupTest() { ssuite.dc = dgraphtest.NewComposeCluster() -} -func (ssuite *SystestTestSuite) SetupSubTest() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -53,6 +51,6 @@ func (ssuite *SystestTestSuite) Upgrade() { // Not implemented for integration tests } -func TestSystestTestSuite(t *testing.T) { +func TestSystestSuite(t *testing.T) { suite.Run(t, new(SystestTestSuite)) } diff --git a/systest/mutations-and-queries/mutations_test.go b/systest/mutations-and-queries/mutations_test.go index 087bd1aa0d7..76005547ff7 100644 --- a/systest/mutations-and-queries/mutations_test.go +++ b/systest/mutations-and-queries/mutations_test.go @@ -41,65 +41,7 @@ import ( "github.com/hypermodeinc/dgraph/v24/testutil" ) -// TestSystem uses the externally run Dgraph cluster for testing. Most other -// tests in this package are using a suite struct system, which runs Dgraph and -// loads data with bulk and live loader. -func (ssuite *SystestTestSuite) TestSystem() { - ssuite.Run("n-quad mutation", ssuite.NQuadMutationTest) - ssuite.Run("list with languages", ssuite.ListWithLanguagesTest) - ssuite.Run("delete all reverse index", ssuite.DeleteAllReverseIndex) - ssuite.Run("normalise edge cases", ssuite.NormalizeEdgeCasesTest) - ssuite.Run("facets with order", ssuite.FacetOrderTest) - ssuite.Run("facets on scalar list", ssuite.FacetsOnScalarList) - ssuite.Run("lang and sort bug", ssuite.LangAndSortBugTest) - ssuite.Run("sort facets return nil", ssuite.SortFacetsReturnNil) - ssuite.Run("check schema after deleting node", ssuite.SchemaAfterDeleteNode) - ssuite.Run("fulltext equal", ssuite.FullTextEqual) - ssuite.Run("json blank node", ssuite.JSONBlankNode) - ssuite.Run("scalar to list", ssuite.ScalarToList) - ssuite.Run("list to scalar", ssuite.ListToScalar) - ssuite.Run("set after delete for list", ssuite.SetAfterDeletionListType) - ssuite.Run("empty strings with exact", ssuite.EmptyNamesWithExact) - ssuite.Run("empty strings with term", ssuite.EmptyRoomsWithTermIndex) - ssuite.Run("delete with expand all", ssuite.DeleteWithExpandAll) - ssuite.Run("facets using nquads", ssuite.FacetsUsingNQuadsError) - ssuite.Run("skip empty pl for has", ssuite.SkipEmptyPLForHas) - ssuite.Run("has with dash", ssuite.HasWithDash) - ssuite.Run("list geo filter", ssuite.ListGeoFilterTest) - ssuite.Run("list regex filter", ssuite.ListRegexFilterTest) - ssuite.Run("regex query with vars with slash", ssuite.RegexQueryWithVarsWithSlash) - ssuite.Run("regex query vars", ssuite.RegexQueryWithVars) - ssuite.Run("graphql var child", ssuite.GraphQLVarChild) - ssuite.Run("math ge", ssuite.MathGe) - ssuite.Run("has should not have deleted edge", ssuite.HasDeletedEdge) - ssuite.Run("has should have reverse edges", ssuite.HasReverseEdge) - ssuite.Run("facet json input supports anyofterms query", ssuite.FacetJsonInputSupportsAnyOfTerms) - ssuite.Run("max predicate size", ssuite.MaxPredicateSize) - ssuite.Run("restore reserved preds", ssuite.RestoreReservedPreds) - ssuite.Run("drop data", ssuite.DropData) - ssuite.Run("drop data and drop all", ssuite.DropDataAndDropAll) - ssuite.Run("drop type", ssuite.DropType) - ssuite.Run("drop type without specified type", ssuite.DropTypeNoValue) - ssuite.Run("reverse count index", ssuite.ReverseCountIndex) - ssuite.Run("type predicate check", ssuite.TypePredicateCheck) - ssuite.Run("internal predicate check", ssuite.InternalPredicateCheck) - ssuite.Run("infer schema as list", ssuite.InferSchemaAsList) - ssuite.Run("infer schema as list JSON", ssuite.InferSchemaAsListJSON) - ssuite.Run("force schema as list JSON", ssuite.ForceSchemaAsListJSON) - ssuite.Run("force schema as single JSON", ssuite.ForceSchemaAsSingleJSON) - ssuite.Run("count index concurrent setdel", ssuite.CountIndexConcurrentSetDelUIDList) - ssuite.Run("count index concurrent setdel scalar predicate", - ssuite.CountIndexConcurrentSetDelScalarPredicate) - ssuite.Run("count index delete on non list predicate", ssuite.CountIndexNonlistPredicateDelete) - ssuite.Run("Reverse count index delete", ssuite.ReverseCountIndexDelete) - ssuite.Run("overwrite uid predicates", ssuite.OverwriteUidPredicates) - ssuite.Run("overwrite uid predicates across txns", ssuite.OverwriteUidPredicatesMultipleTxn) - ssuite.Run("overwrite uid predicates reverse index", ssuite.OverwriteUidPredicatesReverse) - ssuite.Run("delete and query same txn", ssuite.DeleteAndQuerySameTxn) - ssuite.Run("add and query zero datetime value", ssuite.AddAndQueryZeroTimeValue) -} - -func (ssuite *SystestTestSuite) FacetJsonInputSupportsAnyOfTerms() { +func (ssuite *SystestTestSuite) TestFacetJsonInputSupportsAnyOfTerms() { t := ssuite.T() type Node struct { @@ -178,7 +120,7 @@ func (ssuite *SystestTestSuite) FacetJsonInputSupportsAnyOfTerms() { }`, assigned.Uids["a"], assigned.Uids["b"]), string(resp.GetJson())) } -func (ssuite *SystestTestSuite) ListWithLanguagesTest() { +func (ssuite *SystestTestSuite) TestListWithLanguages() { t := ssuite.T() // Upgrade @@ -195,7 +137,7 @@ func (ssuite *SystestTestSuite) ListWithLanguagesTest() { require.Error(t, err) } -func (ssuite *SystestTestSuite) NQuadMutationTest() { +func (ssuite *SystestTestSuite) TestNQuadMutation() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -283,7 +225,7 @@ func (ssuite *SystestTestSuite) NQuadMutationTest() { }]}`, string(resp.Json)) } -func (ssuite *SystestTestSuite) DeleteAllReverseIndex() { +func (ssuite *SystestTestSuite) TestDeleteAllReverseIndex() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -343,7 +285,7 @@ func (ssuite *SystestTestSuite) DeleteAllReverseIndex() { dgraphapi.CompareJSON(fmt.Sprintf(`{"q":[{"~link": [{"uid": "%s"}]}]}`, aId), string(resp.Json)) } -func (ssuite *SystestTestSuite) NormalizeEdgeCasesTest() { +func (ssuite *SystestTestSuite) TestNormalizeEdgeCases() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -431,7 +373,7 @@ func (ssuite *SystestTestSuite) NormalizeEdgeCasesTest() { } } -func (ssuite *SystestTestSuite) FacetOrderTest() { +func (ssuite *SystestTestSuite) TestFacetOrder() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -510,7 +452,7 @@ func (ssuite *SystestTestSuite) FacetOrderTest() { `, string(resp.Json)) } -func (ssuite *SystestTestSuite) FacetsOnScalarList() { +func (ssuite *SystestTestSuite) TestFacetsOnScalarList() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -593,7 +535,7 @@ func (ssuite *SystestTestSuite) FacetsOnScalarList() { } // Shows fix for issue #1918. -func (ssuite *SystestTestSuite) LangAndSortBugTest() { +func (ssuite *SystestTestSuite) TestLangAndSortBug() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -642,7 +584,7 @@ func (ssuite *SystestTestSuite) LangAndSortBugTest() { `, string(resp.Json)) } -func (ssuite *SystestTestSuite) SortFacetsReturnNil() { +func (ssuite *SystestTestSuite) TestSortFacetsReturnNil() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -710,7 +652,7 @@ func (ssuite *SystestTestSuite) SortFacetsReturnNil() { `, string(resp.Json)) } -func (ssuite *SystestTestSuite) SchemaAfterDeleteNode() { +func (ssuite *SystestTestSuite) TestSchemaAfterDeleteNode() { // Upgrade ssuite.Upgrade() @@ -752,7 +694,7 @@ func (ssuite *SystestTestSuite) SchemaAfterDeleteNode() { `{"predicate":"name","type":"default"}`}) } -func (ssuite *SystestTestSuite) FullTextEqual() { +func (ssuite *SystestTestSuite) TestFullTextEqual() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -803,7 +745,7 @@ func (ssuite *SystestTestSuite) FullTextEqual() { } } -func (ssuite *SystestTestSuite) JSONBlankNode() { +func (ssuite *SystestTestSuite) TestJSONBlankNode() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -842,7 +784,7 @@ func (ssuite *SystestTestSuite) JSONBlankNode() { require.JSONEq(t, `{"q":[{"name":"Michael","friend":[{"name":"Alice"}]}]}`, string(resp.Json)) } -func (ssuite *SystestTestSuite) ScalarToList() { +func (ssuite *SystestTestSuite) TestScalarToList() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -942,7 +884,7 @@ func (ssuite *SystestTestSuite) ScalarToList() { require.Equal(t, `{"me":[]}`, string(resp.Json)) } -func (ssuite *SystestTestSuite) ListToScalar() { +func (ssuite *SystestTestSuite) TestListToScalar() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -969,7 +911,7 @@ func (ssuite *SystestTestSuite) ListToScalar() { require.NoError(t, gcli.Alter(ctx, op)) } -func (ssuite *SystestTestSuite) SetAfterDeletionListType() { +func (ssuite *SystestTestSuite) TestSetAfterDeletionListType() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -1030,7 +972,7 @@ func (ssuite *SystestTestSuite) SetAfterDeletionListType() { require.Equal(t, `{"me":[{"property.test":["rewritten value"]}]}`, string(resp.Json)) } -func (ssuite *SystestTestSuite) EmptyNamesWithExact() { +func (ssuite *SystestTestSuite) TestEmptyNamesWithExact() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -1069,7 +1011,7 @@ func (ssuite *SystestTestSuite) EmptyNamesWithExact() { require.Equal(t, `{"names":[{"count":2}]}`, string(resp.Json)) } -func (ssuite *SystestTestSuite) EmptyRoomsWithTermIndex() { +func (ssuite *SystestTestSuite) TestEmptyRoomsWithTermIndex() { op := &api.Operation{} op.Schema = ` room: string @index(term) . @@ -1112,7 +1054,7 @@ func (ssuite *SystestTestSuite) EmptyRoomsWithTermIndex() { require.Equal(t, `{"offices":[{"count(office.room)":1}]}`, string(resp.GetJson())) } -func (ssuite *SystestTestSuite) DeleteWithExpandAll() { +func (ssuite *SystestTestSuite) TestDeleteWithExpandAll() { op := &api.Operation{} op.Schema = ` to: [uid] . @@ -1222,7 +1164,7 @@ func testTimeValue(t *testing.T, c *dgraphapi.GrpcClient, timeBytes []byte) { require.Contains(t, string(resp.Json), "since") } -func (ssuite *SystestTestSuite) FacetsUsingNQuadsError() { +func (ssuite *SystestTestSuite) TestFacetsUsingNQuadsError() { // test time in go binary format t := ssuite.T() timeBinary, err := time.Now().MarshalBinary() @@ -1241,7 +1183,7 @@ func (ssuite *SystestTestSuite) FacetsUsingNQuadsError() { testTimeValue(t, gcli, []byte("2018-01-01")) } -func (ssuite *SystestTestSuite) SkipEmptyPLForHas() { +func (ssuite *SystestTestSuite) TestSkipEmptyPLForHas() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -1288,7 +1230,7 @@ func (ssuite *SystestTestSuite) SkipEmptyPLForHas() { require.JSONEq(t, `{"users": []}`, string(resp.Json)) } -func (ssuite *SystestTestSuite) HasWithDash() { +func (ssuite *SystestTestSuite) TestHasWithDash() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -1335,7 +1277,7 @@ func (ssuite *SystestTestSuite) HasWithDash() { dgraphapi.CompareJSON(`{"q":[{"new-friend":[{"name":"Bob"},{"name":"Charlie"}]}]}`, string(resp.Json)) } -func (ssuite *SystestTestSuite) ListGeoFilterTest() { +func (ssuite *SystestTestSuite) TestListGeoFilter() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -1393,7 +1335,7 @@ func (ssuite *SystestTestSuite) ListGeoFilterTest() { `, string(resp.GetJson())) } -func (ssuite *SystestTestSuite) ListRegexFilterTest() { +func (ssuite *SystestTestSuite) TestListRegexFilter() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -1451,7 +1393,7 @@ func (ssuite *SystestTestSuite) ListRegexFilterTest() { `, string(resp.GetJson())) } -func (ssuite *SystestTestSuite) RegexQueryWithVarsWithSlash() { +func (ssuite *SystestTestSuite) TestRegexQueryWithVarsWithSlash() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -1515,7 +1457,7 @@ func (ssuite *SystestTestSuite) RegexQueryWithVarsWithSlash() { `, string(resp.GetJson())) } -func (ssuite *SystestTestSuite) RegexQueryWithVars() { +func (ssuite *SystestTestSuite) TestRegexQueryWithVars() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -1574,7 +1516,7 @@ func (ssuite *SystestTestSuite) RegexQueryWithVars() { `, string(resp.GetJson())) } -func (ssuite *SystestTestSuite) GraphQLVarChild() { +func (ssuite *SystestTestSuite) TestGraphQLVarChild() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -1685,7 +1627,7 @@ func (ssuite *SystestTestSuite) GraphQLVarChild() { } -func (ssuite *SystestTestSuite) MathGe() { +func (ssuite *SystestTestSuite) TestMathGe() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -1734,7 +1676,7 @@ func (ssuite *SystestTestSuite) MathGe() { `, string(resp.GetJson())) } -func (ssuite *SystestTestSuite) HasDeletedEdge() { +func (ssuite *SystestTestSuite) TestHasDeletedEdge() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -1844,7 +1786,7 @@ func (ssuite *SystestTestSuite) HasDeletedEdge() { } } -func (ssuite *SystestTestSuite) HasReverseEdge() { +func (ssuite *SystestTestSuite) TestHasReverseEdge() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -1903,7 +1845,7 @@ func (ssuite *SystestTestSuite) HasReverseEdge() { require.Equal(t, revs[0].Name, "carol") } -func (ssuite *SystestTestSuite) MaxPredicateSize() { +func (ssuite *SystestTestSuite) TestMaxPredicateSize() { // Create a string that has more than 2^16 chars. var b strings.Builder for i := 0; i < 10000; i++ { @@ -1944,7 +1886,7 @@ func (ssuite *SystestTestSuite) MaxPredicateSize() { require.Contains(t, err.Error(), "Predicate name length cannot be bigger than 2^16") } -func (ssuite *SystestTestSuite) RestoreReservedPreds() { +func (ssuite *SystestTestSuite) TestRestoreReservedPreds() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -1962,7 +1904,7 @@ func (ssuite *SystestTestSuite) RestoreReservedPreds() { dgraphapi.CompareJSON(`{"schema": [{"predicate":"dgraph.type"}]}`, string(resp.Json)) } -func (ssuite *SystestTestSuite) DropData() { +func (ssuite *SystestTestSuite) TestDropData() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2019,7 +1961,7 @@ func (ssuite *SystestTestSuite) DropData() { dgraphapi.CompareJSON(`{"q": []}`, string(resp.GetJson())) } -func (ssuite *SystestTestSuite) DropDataAndDropAll() { +func (ssuite *SystestTestSuite) TestDropDataAndDropAll() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2034,7 +1976,7 @@ func (ssuite *SystestTestSuite) DropDataAndDropAll() { require.Contains(t, err.Error(), "Only one of DropAll and DropData can be true") } -func (ssuite *SystestTestSuite) DropType() { +func (ssuite *SystestTestSuite) TestDropType() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2076,7 +2018,7 @@ func (ssuite *SystestTestSuite) DropType() { dgraphapi.CompareJSON("{}", string(resp.Json)) } -func (ssuite *SystestTestSuite) DropTypeNoValue() { +func (ssuite *SystestTestSuite) TestDropTypeNoValue() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2089,7 +2031,7 @@ func (ssuite *SystestTestSuite) DropTypeNoValue() { require.Contains(t, err.Error(), "DropValue must not be empty") } -func (ssuite *SystestTestSuite) CountIndexConcurrentSetDelUIDList() { +func (ssuite *SystestTestSuite) TestCountIndexConcurrentSetDelUIDList() { t := ssuite.T() dgraphtest.ShouldSkipTest(t, "8631dab37c951b288f839789bbabac5e7088b58f", ssuite.dc.GetVersion()) gcli, cleanup, err := doGrpcLogin(ssuite) @@ -2220,7 +2162,7 @@ func (ssuite *SystestTestSuite) CountIndexConcurrentSetDelUIDList() { dgraphapi.CompareJSON(`{"me":[]}`, string(resp.GetJson())) } -func (ssuite *SystestTestSuite) CountIndexConcurrentSetDelScalarPredicate() { +func (ssuite *SystestTestSuite) TestCountIndexConcurrentSetDelScalarPredicate() { t := ssuite.T() dgraphtest.ShouldSkipTest(t, "8631dab37c951b288f839789bbabac5e7088b58f", ssuite.dc.GetVersion()) gcli, cleanup, err := doGrpcLogin(ssuite) @@ -2305,7 +2247,7 @@ func (ssuite *SystestTestSuite) CountIndexConcurrentSetDelScalarPredicate() { dgraphapi.CompareJSON(`{"q":[]}`, string(resp.GetJson())) } -func (ssuite *SystestTestSuite) CountIndexNonlistPredicateDelete() { +func (ssuite *SystestTestSuite) TestCountIndexNonlistPredicateDelete() { t := ssuite.T() dgraphtest.ShouldSkipTest(t, "8631dab37c951b288f839789bbabac5e7088b58f", ssuite.dc.GetVersion()) gcli, cleanup, err := doGrpcLogin(ssuite) @@ -2357,7 +2299,7 @@ func (ssuite *SystestTestSuite) CountIndexNonlistPredicateDelete() { dgraphapi.CompareJSON(`{"q": [{"uid": "0x1"}]}`, string(resp.GetJson())) } -func (ssuite *SystestTestSuite) ReverseCountIndexDelete() { +func (ssuite *SystestTestSuite) TestReverseCountIndexDelete() { t := ssuite.T() dgraphtest.ShouldSkipTest(t, "8631dab37c951b288f839789bbabac5e7088b58f", ssuite.dc.GetVersion()) gcli, cleanup, err := doGrpcLogin(ssuite) @@ -2407,7 +2349,7 @@ func (ssuite *SystestTestSuite) ReverseCountIndexDelete() { } -func (ssuite *SystestTestSuite) ReverseCountIndex() { +func (ssuite *SystestTestSuite) TestReverseCountIndex() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2473,7 +2415,7 @@ func (ssuite *SystestTestSuite) ReverseCountIndex() { dgraphapi.CompareJSON(`{"me":[{"name":"Alice","count(~friend)":10}]}`, string(resp.GetJson())) } -func (ssuite *SystestTestSuite) TypePredicateCheck() { +func (ssuite *SystestTestSuite) TestTypePredicateCheck() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2526,7 +2468,7 @@ func (ssuite *SystestTestSuite) TypePredicateCheck() { require.NoError(t, gcli.Alter(ctx, op)) } -func (ssuite *SystestTestSuite) InternalPredicateCheck() { +func (ssuite *SystestTestSuite) TestInternalPredicateCheck() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2548,7 +2490,7 @@ func (ssuite *SystestTestSuite) InternalPredicateCheck() { require.Contains(t, err.Error(), "Cannot create user-defined predicate with internal name uid") } -func (ssuite *SystestTestSuite) InferSchemaAsList() { +func (ssuite *SystestTestSuite) TestInferSchemaAsList() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2579,7 +2521,7 @@ func (ssuite *SystestTestSuite) InferSchemaAsList() { {"predicate":"nickname"}]}`, string(resp.Json)) } -func (ssuite *SystestTestSuite) InferSchemaAsListJSON() { +func (ssuite *SystestTestSuite) TestInferSchemaAsListJSON() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2607,7 +2549,7 @@ func (ssuite *SystestTestSuite) InferSchemaAsListJSON() { {"predicate":"nickname"}]}`, string(resp.Json)) } -func (ssuite *SystestTestSuite) ForceSchemaAsListJSON() { +func (ssuite *SystestTestSuite) TestForceSchemaAsListJSON() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2636,7 +2578,7 @@ func (ssuite *SystestTestSuite) ForceSchemaAsListJSON() { {"predicate":"nickname"}]}`, string(resp.Json)) } -func (ssuite *SystestTestSuite) ForceSchemaAsSingleJSON() { +func (ssuite *SystestTestSuite) TestForceSchemaAsSingleJSON() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2665,7 +2607,7 @@ func (ssuite *SystestTestSuite) ForceSchemaAsSingleJSON() { string(resp.Json)) } -func (ssuite *SystestTestSuite) OverwriteUidPredicates() { +func (ssuite *SystestTestSuite) TestOverwriteUidPredicates() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2730,7 +2672,7 @@ func (ssuite *SystestTestSuite) OverwriteUidPredicates() { string(resp.GetJson())) } -func (ssuite *SystestTestSuite) OverwriteUidPredicatesReverse() { +func (ssuite *SystestTestSuite) TestOverwriteUidPredicatesReverse() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2834,7 +2776,7 @@ func (ssuite *SystestTestSuite) OverwriteUidPredicatesReverse() { string(resp.GetJson())) } -func (ssuite *SystestTestSuite) OverwriteUidPredicatesMultipleTxn() { +func (ssuite *SystestTestSuite) TestOverwriteUidPredicatesMultipleTxn() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2896,7 +2838,7 @@ func (ssuite *SystestTestSuite) OverwriteUidPredicatesMultipleTxn() { string(resp.GetJson())) } -func (ssuite *SystestTestSuite) DeleteAndQuerySameTxn() { +func (ssuite *SystestTestSuite) TestDeleteAndQuerySameTxn() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -2959,7 +2901,7 @@ func (ssuite *SystestTestSuite) DeleteAndQuerySameTxn() { string(resp.GetJson())) } -func (ssuite *SystestTestSuite) AddAndQueryZeroTimeValue() { +func (ssuite *SystestTestSuite) TestAddAndQueryZeroTimeValue() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() diff --git a/systest/mutations-and-queries/queries_test.go b/systest/mutations-and-queries/queries_test.go index dcd214bd89e..014e78db5e3 100644 --- a/systest/mutations-and-queries/queries_test.go +++ b/systest/mutations-and-queries/queries_test.go @@ -32,24 +32,7 @@ import ( "github.com/hypermodeinc/dgraph/v24/x" ) -func (ssuite *SystestTestSuite) TestQuery() { - ssuite.Run("schema response", ssuite.SchemaQueryTest) - ssuite.Run("schema response http", ssuite.SchemaQueryTestHTTP) - ssuite.Run("schema predicate names", ssuite.SchemaQueryTestPredicate1) - ssuite.Run("schema specific predicate fields", ssuite.SchemaQueryTestPredicate2) - ssuite.Run("schema specific predicate field", ssuite.SchemaQueryTestPredicate3) - ssuite.Run("multiple block eval", ssuite.MultipleBlockEval) - ssuite.Run("unmatched var assignment eval", ssuite.UnmatchedVarEval) - ssuite.Run("hash index queries", ssuite.QueryHashIndex) - ssuite.Run("fuzzy matching", ssuite.FuzzyMatch) - ssuite.Run("regexp with toggled trigram index", ssuite.RegexpToggleTrigramIndex) - ssuite.Run("eq with altering order of trigram and term index", ssuite.EqWithAlteredIndexOrder) - ssuite.Run("groupby uid that works", ssuite.GroupByUidWorks) - ssuite.Run("parameterized cascade", ssuite.CascadeParams) - ssuite.Run("cleanup", ssuite.SchemaQueryCleanup) -} - -func (ssuite *SystestTestSuite) SchemaQueryCleanup() { +func (ssuite *SystestTestSuite) TestSchemaQueryCleanup() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) defer cleanup() @@ -57,7 +40,7 @@ func (ssuite *SystestTestSuite) SchemaQueryCleanup() { require.NoError(t, gcli.Alter(context.Background(), &api.Operation{DropAll: true})) } -func (ssuite *SystestTestSuite) MultipleBlockEval() { +func (ssuite *SystestTestSuite) TestMultipleBlockEval() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) @@ -230,7 +213,7 @@ func (ssuite *SystestTestSuite) MultipleBlockEval() { } } -func (ssuite *SystestTestSuite) UnmatchedVarEval() { +func (ssuite *SystestTestSuite) TestUnmatchedVarEval() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) @@ -332,7 +315,7 @@ func (ssuite *SystestTestSuite) UnmatchedVarEval() { } } -func (ssuite *SystestTestSuite) SchemaQueryTest() { +func (ssuite *SystestTestSuite) TestSchemaQuery() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) @@ -366,7 +349,7 @@ func (ssuite *SystestTestSuite) SchemaQueryTest() { }`}) } -func (ssuite *SystestTestSuite) SchemaQueryTestPredicate1() { +func (ssuite *SystestTestSuite) TestSchemaQueryPredicate1() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) @@ -456,7 +439,7 @@ func (ssuite *SystestTestSuite) SchemaQueryTestPredicate1() { dgraphapi.CompareJSON(js, string(resp.Json)) } -func (ssuite *SystestTestSuite) SchemaQueryTestPredicate2() { +func (ssuite *SystestTestSuite) TestSchemaQueryPredicate2() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) @@ -499,7 +482,7 @@ func (ssuite *SystestTestSuite) SchemaQueryTestPredicate2() { dgraphapi.CompareJSON(js, string(resp.Json)) } -func (ssuite *SystestTestSuite) SchemaQueryTestPredicate3() { +func (ssuite *SystestTestSuite) TestSchemaQueryPredicate3() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) @@ -551,7 +534,7 @@ func (ssuite *SystestTestSuite) SchemaQueryTestPredicate3() { dgraphapi.CompareJSON(js, string(resp.Json)) } -func (ssuite *SystestTestSuite) SchemaQueryTestHTTP() { +func (ssuite *SystestTestSuite) TestSchemaQueryHTTP() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) @@ -595,7 +578,7 @@ func (ssuite *SystestTestSuite) SchemaQueryTestHTTP() { }`}), string(m["data"])) } -func (ssuite *SystestTestSuite) FuzzyMatch() { +func (ssuite *SystestTestSuite) TestFuzzyMatch() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) @@ -751,7 +734,7 @@ func (ssuite *SystestTestSuite) FuzzyMatch() { } } -func (ssuite *SystestTestSuite) CascadeParams() { +func (ssuite *SystestTestSuite) TestCascadeParams() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) @@ -1222,7 +1205,7 @@ func (ssuite *SystestTestSuite) CascadeParams() { } } -func (ssuite *SystestTestSuite) QueryHashIndex() { +func (ssuite *SystestTestSuite) TestQueryHashIndex() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) @@ -1343,7 +1326,7 @@ func (ssuite *SystestTestSuite) QueryHashIndex() { } } -func (ssuite *SystestTestSuite) RegexpToggleTrigramIndex() { +func (ssuite *SystestTestSuite) TestRegexpToggleTrigramIndex() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) @@ -1421,7 +1404,7 @@ func (ssuite *SystestTestSuite) RegexpToggleTrigramIndex() { require.Contains(t, err.Error(), "Attribute name does not have trigram index for regex matching.") } -func (ssuite *SystestTestSuite) EqWithAlteredIndexOrder() { +func (ssuite *SystestTestSuite) TestEqWithAlteredIndexOrder() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) @@ -1467,7 +1450,7 @@ func (ssuite *SystestTestSuite) EqWithAlteredIndexOrder() { dgraphapi.CompareJSON(expectedResult, string(resp.Json)) } -func (ssuite *SystestTestSuite) GroupByUidWorks() { +func (ssuite *SystestTestSuite) TestGroupByUidWorks() { t := ssuite.T() gcli, cleanup, err := doGrpcLogin(ssuite) diff --git a/systest/mutations-and-queries/upgrade_test.go b/systest/mutations-and-queries/upgrade_test.go index f67668135fb..7cd13369656 100644 --- a/systest/mutations-and-queries/upgrade_test.go +++ b/systest/mutations-and-queries/upgrade_test.go @@ -40,7 +40,7 @@ type SystestTestSuite struct { uc dgraphtest.UpgradeCombo } -func (ssuite *SystestTestSuite) SetupSubTest() { +func (ssuite *SystestTestSuite) SetupTest() { conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1).WithReplicas(1). WithACL(20 * time.Second).WithEncryption().WithVersion(ssuite.uc.Before) c, err := dgraphtest.NewLocalCluster(conf) @@ -54,7 +54,7 @@ func (ssuite *SystestTestSuite) SetupSubTest() { ssuite.lc = c } -func (ssuite *SystestTestSuite) TearDownSubTest() { +func (ssuite *SystestTestSuite) TearDownTest() { ssuite.lc.Cleanup(ssuite.T().Failed()) } @@ -71,14 +71,14 @@ func (ssuite *SystestTestSuite) Upgrade() { require.NoError(ssuite.T(), ssuite.lc.Upgrade(ssuite.uc.After, ssuite.uc.Strategy)) } -func TestSystestTestSuite(t *testing.T) { +func TestSystestSuite(t *testing.T) { for _, uc := range dgraphtest.AllUpgradeCombos(false) { log.Printf("running: backup in [%v], restore in [%v]", uc.Before, uc.After) var ssuite SystestTestSuite ssuite.uc = uc suite.Run(t, &ssuite) if t.Failed() { - x.Panic(errors.New("TestSystestTestSuite tests failed")) + x.Panic(errors.New("TestSystestSuite tests failed")) } } } diff --git a/testutil/schema.go b/testutil/schema.go index fcb6234d26b..113f45d3274 100644 --- a/testutil/schema.go +++ b/testutil/schema.go @@ -44,7 +44,9 @@ const ( {"predicate":"dgraph.drop.op", "type": "string"}, {"predicate":"dgraph.graphql.p_query","type":"string","index":true,"tokenizer":["sha256"]}, {"predicate":"dgraph.graphql.schema", "type": "string"}, -{"predicate":"dgraph.graphql.xid","type":"string","index":true,"tokenizer":["exact"],"upsert":true} +{"predicate":"dgraph.graphql.xid","type":"string","index":true,"tokenizer":["exact"],"upsert":true}, +{"predicate":"dgraph.namespace.name","type":"string","index":true,"tokenizer":["exact"],"unique":true,"upsert":true}, +{"predicate":"dgraph.namespace.id","type":"int","index":true,"tokenizer":["int"],"unique":true,"upsert":true} ` aclTypes = ` { @@ -65,6 +67,9 @@ const ( },{ "fields": [{"name": "dgraph.graphql.p_query"}], "name": "dgraph.graphql.persisted_query" +},{ + "fields": [{"name": "dgraph.namespace.name"}, {"name": "dgraph.namespace.id"}], + "name": "dgraph.namespace" } ` ) diff --git a/worker/groups.go b/worker/groups.go index 7a01a517918..cd44b2cccc7 100644 --- a/worker/groups.go +++ b/worker/groups.go @@ -235,8 +235,7 @@ func (g *groupi) applyInitialSchema() { } else if gid == 0 { // The tablet is not being served currently. apply(s) - } else if curr, _ := schema.State().Get(ctx, s.Predicate); gid == g.groupId() && - !proto.Equal(s, &curr) { + } else if curr, _ := schema.State().Get(ctx, s.Predicate); gid == g.groupId() && !proto.Equal(s, &curr) { // If this tablet is served to the group, do not upsert the schema unless the // stored schema and the proposed one are different. apply(s) diff --git a/worker/online_restore.go b/worker/online_restore.go index 2b891a07e29..28a29796422 100644 --- a/worker/online_restore.go +++ b/worker/online_restore.go @@ -412,6 +412,8 @@ func handleRestoreProposal(ctx context.Context, req *pb.RestoreRequest, pidx uin posting.ResetCache() ResetAclCache() + groups().applyInitialSchema() + groups().applyInitialTypes() // Reset gql schema only when the restore is not partial, so that after this restore // the cluster can be in non-draining mode and hence gqlSchema can be lazy loaded. diff --git a/x/keys.go b/x/keys.go index 4740db3118c..9a26b70f50b 100644 --- a/x/keys.go +++ b/x/keys.go @@ -645,11 +645,13 @@ var aclPredicateMap = map[string]struct{}{ // TODO: rename this map to a better suited name as per its properties. It is not just for GraphQL // predicates, but for all those which are PreDefined and whose value is not allowed to be mutated // by users. When renaming this also rename the IsGraphql context key in edgraph/server.go. -var graphqlReservedPredicate = map[string]struct{}{ +var otherReservedPredicate = map[string]struct{}{ "dgraph.graphql.xid": {}, "dgraph.graphql.schema": {}, "dgraph.drop.op": {}, "dgraph.graphql.p_query": {}, + "dgraph.namespace.id": {}, + "dgraph.namespace.name": {}, } // internalPredicateMap stores a set of Dgraph's internal predicate. An internal @@ -666,13 +668,14 @@ var preDefinedTypeMap = map[string]struct{}{ "dgraph.type.Group": {}, "dgraph.type.Rule": {}, "dgraph.graphql.persisted_query": {}, + "dgraph.namespace": {}, } -// IsGraphqlReservedPredicate returns true if it is the predicate is reserved by graphql. +// IsOtherReservedPredicate returns true if it is the predicate is reserved by graphql. // These are a subset of PreDefined predicates, so follow all their properties. In addition, // the value for these predicates is also not allowed to be mutated directly by the users. -func IsGraphqlReservedPredicate(pred string) bool { - _, ok := graphqlReservedPredicate[pred] +func IsOtherReservedPredicate(pred string) bool { + _, ok := otherReservedPredicate[pred] return ok } @@ -710,7 +713,7 @@ func IsReservedPredicate(pred string) bool { func IsPreDefinedPredicate(pred string) bool { pred = ParseAttr(pred) _, ok := starAllPredicateMap[strings.ToLower(pred)] - return ok || IsAclPredicate(pred) || IsGraphqlReservedPredicate(pred) + return ok || IsAclPredicate(pred) || IsOtherReservedPredicate(pred) } // IsAclPredicate returns true if the predicate is in the list of reserved