Skip to content

feat: AlterSchema, dropPredicate, and embedded DropAttr#24

Open
mlwelles wants to merge 2 commits into
matthewmcneely:mainfrom
mlwelles:feature/schema-ddl
Open

feat: AlterSchema, dropPredicate, and embedded DropAttr#24
mlwelles wants to merge 2 commits into
matthewmcneely:mainfrom
mlwelles:feature/schema-ddl

Conversation

@mlwelles

@mlwelles mlwelles commented Jun 4, 2026

Copy link
Copy Markdown

What this adds

Raw schema-DDL primitives that complement UpdateSchema's struct-tag inference,
plus matching DropAttr support for the embedded engine.

  • Client.AlterSchema(ctx, schema string) — applies a raw DQL schema string
    directly, giving full control over predicate types, indexes, and directives.
  • Engine.dropPredicate — deletes a single predicate (and its data) from
    the embedded engine via posting.DeletePredicate.
  • embedded routing — an Alter carrying DropAttr routes to
    dropPredicate, so the embedded (file://) path matches a remote cluster's
    DropAttr semantics.

The problem it solves

UpdateSchema infers the schema from Go struct tags, which is convenient but
cannot express predicates no Go type models yet — the common case during a
migration that adds or reshapes predicates ahead of the code. AlterSchema is
the escape hatch: hand Dgraph the exact DDL.

err := client.AlterSchema(ctx, `
    name:  string @index(exact) .
    email: string @index(hash) @upsert .
`)

Dropping a predicate had a second gap: a remote cluster honors an Alter with
DropAttr (delete one predicate and its data), but the embedded engine ignored
it. This wires the embedded path to posting.DeletePredicate, so a single-
predicate drop behaves the same in file:// and dgraph:// modes.

Tests

TestDropPredicateEmbedded runs the full lifecycle — declare → insert →
confirm present → DropAttr → confirm gone — against the embedded engine (and
against a live cluster when MODUSGRAPH_TEST_ADDR is set).

The automated review (cubic) found no issues.

Documentation

A runnable ExampleClient_alterSchema showing predicate types, indexes, and
directives applied directly.

Adds raw schema-DDL primitives that complement UpdateSchema's
object-template inference:

- Client.AlterSchema(ctx, schema) applies a raw DQL schema string directly,
  giving full control over predicate types, indexes, and directives — useful
  for migrations that declare predicates no Go type models yet.
- Engine.dropPredicate deletes a single predicate (and its data) from the
  embedded engine via posting.DeletePredicate.
- embedded_client.go routes an Alter carrying DropAttr to dropPredicate, so
  the embedded path matches a remote Dgraph cluster's DropAttr behavior.

TestDropPredicateEmbedded exercises the full declare/insert/drop cycle
against the embedded engine.
@mlwelles mlwelles requested a review from matthewmcneely as a code owner June 4, 2026 20:11

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Re-trigger cubic

Document the raw schema-DDL path with a runnable example showing predicate
types, indexes, and directives applied directly via AlterSchema.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant