Schema

EdgeDB schemas are declared using SDL (EdgeDB’s Schema Definition Language).

SDL

Your schema is defined inside .esdl files. Its common to define your entire schema in a single file called default.esdl, but you can split it across multiple files if you wish.

By convention, your schema files should live in a directory called dbschema in the root of your project.

  1. # dbschema/default.esdl
  2. type Movie {
  3. required property title -> str;
  4. required link director -> Person;
  5. }
  6. type Person {
  7. required property name -> str;
  8. }

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 over time. Just update the contents of your .esdl file(s) and use the EdgeDB CLI to create and apply migrations.

  1. $
  1. edgedb migration create
  1. Created dbschema/migrations/00001.esdl
  1. $
  1. edgedb migrate
  1. Applied dbschema/migrations/00001.esdl.

For a full guide on migrations, refer to 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 using SDL and the migration system when building applications, however you’re free to use DDL directly if you prefer.

Terminology

Instance

An EdgeDB instance is a collection of databases that store their data in a shared directory, listen for queries on a particular port, and are managed by a running EdgeDB process. Instances can be created, started, stopped, and destroyed locally with the EdgeDB CLI.

Database

Each instance can contain several databases, each with a unique name. At the time of creation, all instances contain a single default database called edgedb. All incoming queries are executed against it unless otherwise specified.

Module

Each database has a schema consisting of several modules, each with a unique name. Modules can be used to organize large schemas into logical units. In practice, though, most users put their entire schema inside a single module called default.

  1. module default {
  2. # declare types here
  3. }

Name resolution

When referencing schema objects from another module, you must use a fully-qualified name in the form module_name::object_name.

The following module names are reserved by EdgeDB and contain pre-defined types, utility functions, and operators.

  • std: standard types, functions, and operators in the standard library

  • math: algebraic and statistical functions

  • cal: local (non-timezone-aware) and relative date/time types and functions

  • schema: types describing the introspection schema

  • sys: system-wide entities, such as user roles and databases

  • cfg: configuration and settings