Schema​

One of EdgeDB’s foundational features is declarative schema modeling.

EdgeDB schemas are declared using SDL (EdgeDB Schema Definition Language). SDL’s declarative, object-oriented syntax will look familiar to users of ORM libraries.

  1. type Movie {
  2. required property title -> str;
  3. required link director -> Person;
  4. }
  5. type Person {
  6. required property name -> str;
  7. }

SDL​

SDL has two important properties. First, it’s declarative; you can just write your schema down exactly as you want it to be. It’s easy to see the entire state of your schema at a glance.

Secondly, it’s object-oriented. There are no foreign keys; instead, relationships between types are directly represented with Links; this is part of what makes deep EdgeQL queries so concise. For example:

  1. select Movie {
  2. title,
  3. director: {
  4. name
  5. }
  6. }

.esdl files​

Your schema should be defined in one or more .esdl files. These files should be placed in a directory called dbschema in the root of your project.

Syntax highlighter packages/extensions for .esdl files are available for Visual Studio Code, Sublime Text, Atom, and Vim.

Migrations​

EdgeDB’s baked-in migration system lets you painlessly evolve your schema throughout the development process. After modifying your .esdl files, you can create and apply a migration with the EdgeDB command-line tool. For a full guide on how migrations work, reference the Creating and applying migrations guide.

A migration consists of a sequence of imperative schema-modifying commands like create type, alter property, etc. Collectively these commands are known as DDL (data definition language). We recommend that most users use SDL and migrations when building applications. However, if you prefer SQL-style imperative schema modeling, you are free to use DDL directly; go to Reference > DDL to learn more.