EdgeDB v2 (Sagittarius)

v2.0 - 图1

EdgeDB 2.0 was released on July 28th, 2022. Read the announcement blog post here.

We would like to thank our community for reporting issues and contributing fixes. You are awesome! ❤️

To play with the new features, install the CLI and initialize a new project. For an interesting schema with test data, check out the MCU Sandbox repo.

  1. $
  1. edgedb project init

Upgrading

Local instances

To upgrade a local project, run the following command inside the project directory.

  1. $
  1. edgedb project upgrade --to-latest

Alternatively, specify an instance name if you aren’t using a project.

  1. $
  1. edgedb project upgrade --to-latest -I my_instance

Hosted instances

To upgrade a remote (hosted) instance, we recommend the following dump-and-restore process.

1. Spin up an empty 2.0 instance by following one of our deployment guides. These guides have been updated to 2.0. Keep the DSN of the newly created instance handy.

  1. Take your application offline, then dump your v1.x database with the CLI
  1. ```
  2. $
  3. ```
  4. ```
  5. edgedb dump --dsn <old dsn> --all my_database.dump/
  6. ```
  7. This will dump the schema and contents of your current database to a file on your local disk called `my_database.dump`. The file name isnt important.
  1. Restore the empty v2.x instance from the dump
  1. ```
  2. $
  3. ```
  4. ```
  5. edgedb restore --all my_database.dump/ --dsn <new dsn>
  6. ```
  7. Once the restore is complete, update your application to connect to the new instance.

This process will involve some downtime, specifically during steps 2 and 3. We are working on an in-place upgrade workflow that will reduce the amount of downtime involved and avoid the need to spin up a new instance. We’ll publish that soon; join the Discord for updates. Though for most applications the dump-and-restore workflow will be simpler and less error-prone.

Client libraries

We’ve released new versions of our JavaScript and Python client libraries that support all 2.0 features and implement the updated protocol. These versions are backwards compatible with v1.x instances, so we encourage all users to upgrade.

TypeScript/JS

edgedb@0.21.0

Python

edgedb@0.24.0

Golang

edgedb@0.12.0

Rust

edgedb-tokio@0.3.0

.NET (community-maintained)

EdgeDB.Net.Driver@0.3.0

Elixir (community-maintained)

edgedb@0.4.0

New features

Integrated admin UI

All v2 instances ship with a built-in rich admin GUI. Access it by running edgedb ui inside any EdgeDB project, or specify a local instance name with edgedb ui -I my_inst. The command opens the instance’s admin UI using the default system browser.

The current iteration of the GUI has

  • a data browser and editor

  • a REPL for writing and executing EdgeQL queries

  • a schema introspection tool with text-based and graphical visualizations of the instance’s current schema

v2.0 - 图2

The new GROUP expression can be used to partition and aggregate data. The output of GROUP are free objects representing each group, including the grouping, the grouping key, and the set of elements.

  1. db>
  1. group Movie { title } by .release_year;
  1. {
  2. {
  3. key: {release_year: 2017},
  4. grouping: {'release_year'},
  5. elements: {
  6. default::Movie {title: 'Guardians of the Galaxy Vol. 2'},
  7. default::Movie {title: 'Spider-Man: Homecoming'},
  8. default::Movie {title: 'Thor: Ragnarok'},
  9. },
  10. },
  11. {
  12. key: {release_year: 2013},
  13. grouping: {'release_year'},
  14. elements: {
  15. default::Movie {title: 'Iron Man 3'},
  16. default::Movie {title: 'Thor: The Dark World'},
  17. },
  18. },
  19. ...
  20. }

Browse the docs for more details and examples, or refer to the original RFC 1009.

Global variables

Your schema can now contain global variables. These are contextual variables that are provided by the client and can be referenced in your queries and schema.

  1. global current_user -> uuid;
  1. select User filter .id = global current_user;

Client libraries have been updated to provide method for attaching global variables to a Client instance; these values are sent along with all queries originating from that Client.

TypeScript

Python

Go

  1. import {createClient} from 'edgedb';
  2. const client = createClient().withGlobals({
  3. current_user: '2141a5b4-5634-4ccc-b835-437863534c51',
  4. });
  5. await client.query(`select global current_user;`);
  1. from edgedb import create_client
  2. client = create_client().with_globals({
  3. 'current_user': '580cc652-8ab8-4a20-8db9-4c79a4b1fd81'
  4. })
  5. result = client.query("""
  6. select global current_user;
  7. """)
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "log"
  6. "github.com/edgedb/edgedb-go"
  7. )
  8. func main() {
  9. ctx := context.Background()
  10. client, err := edgedb.CreateClient(ctx, edgedb.Options{})
  11. if err != nil {
  12. log.Fatal(err)
  13. }
  14. defer client.Close()
  15. id, err := edgedb.ParseUUID("2141a5b4-5634-4ccc-b835-437863534c51")
  16. if err != nil {
  17. log.Fatal(err)
  18. }
  19. var result edgedb.UUID
  20. err = client.
  21. WithGlobals(map[string]interface{}{"current_user": id}).
  22. QuerySingle(ctx, "SELECT global current_user;", &result)
  23. if err != nil {
  24. log.Fatal(err)
  25. }
  26. fmt.Println(result)
  27. }

Globals are primarily intended as an enabling mechanism for object-level security.

Object-level security

Object types can now be augmented with object-level access policies. When combined with global variables, access policies can be used to push authorization logic into the database.

  1. global current_user -> uuid;
  2. type User {
  3. required property email -> str { constraint exclusive; };
  4. }
  5. type BlogPost {
  6. required property title -> str;
  7. link author -> User;
  8. access policy own_posts allow all using (
  9. .author.id ?= global current_user
  10. )
  11. }

Refer to the docs or RFC 1011 for full details.

Range types

EdgeDB now supports range types representing intervals of values.

  1. db>
  1. select range(1, 10);
  1. {range(1, 10, inc_lower := true, inc_upper := false)}
  1. db>
  1. select range_unpack(range(1, 10))
  1. {1, 2, 3, 4, 5, 6, 7, 8, 9}

This release also introduces a new datatype cal::date_duration to represent a span of months/days. It is nearly equivalent to the existing cal::relative_duration but cannot represent sub-day durations.

This type is primarily intended to simplify cal::local_date logic.

  1. db> select <cal::local_date>'2022-06-25' +
  2. ... <cal::date_duration>'5 days';
  3. {<cal::local_date>'2022-06-30'}
  4. db> select <cal::local_date>'2022-06-30' -
  5. ... <cal::local_date>'2022-06-25';
  6. {<cal::date_duration>'P5D'}

Source deletion policies

Add deletion cascade functionality with on source delete.

  1. type BlogPost {
  2. property title -> str;
  3. }
  4. type Person {
  5. multi link posts -> BlogPost {
  6. on source delete delete target;
  7. }
  8. }

Under this policy, deleting a User will unconditionally delete its posts as well.

To avoid deleting a Post that is linked to by other schema entities, append if orphan.

  1. type Person {
  2. multi link posts -> BlogPost {
  3. on source delete delete target;
  4. on source delete delete target if orphan;
  5. }
  6. }

Additional changes

EdgeQL

Server

  • Support socket activation to reduce memory footprint on developer machines (#3899).

  • Introduce edgedb+http, a which tunnels the binary protocol over HTTP using JWT for authentication (#3979).

  • Support using JWT to authenticate to local instances (#3991).

Bug fixes

  • Generate unique id fields for each free shape object, and don’t use an actual in-database object to represent it, and make multiplicity inference understand free shapes better (#3631, #3633, #3634).

  • Fail if local Postgres cluster fails to start.

  • Add cfg::memory to base types descriptor IDs table (#3882).

  • Fix a cross-type exclusive constraint bug that could allow exclusive constraints to be violated in some complex type hierarchies (#3887).

  • Fix issue where server might attempt to acquire one more connection than it is configured to permit (#3901).

  • Fix use of assert_exists on properties that are being directly output (#3911).

  • Fix a scope leakage that could cause a link referenced inside a computable to improperly correlate with something outside the computable (#3912).

  • Fix a number of issues with the floordiv (//) and modulus (%) operators where we could return incorrect values or produce spurious errors, especially on very large values (#3909).

  • Allow adding annotations to abstract annotation definitions (#3929).

  • Expose body and language fields on schema::Function (#3944).

  • Make indexes extend from schema::InheritingObject (#3942).

  • Fix some mis-compilations of nested shapes inside calls to functions like assert_single (#3927).

  • Fix SET TYPE on properties with default values (#3954).

  • Fix describe/populate/describe sequence (#3959).

  • Upgrade many casts and functions from “Stable” to “Immutable” (#3975).

  • Fix link properties in type filtered shape links (#3987).

  • Allow DML statements in free shapes (#4002).

  • Allow customizing assertion messages in assert_exists and friends (#4019).

Protocol overhaul

  • A new version of the protocol—version 1.0—has been introduced. It eliminates all server state associated with connections that do not use transactions.

  • Support passing parameters to and returning values from multi-statement scripts.

2.1

  • Fix global defaults with nontrivial computation (#4182)

  • Fix migration that removes policy using clause (#4183)

  • Support ELSE-less UNLESS CONFLICT on explicit id INSERT (#4185)

  • Don’t create constraints on derived views when adding a pointer to a type (#4187)

  • Fix a bunch of missing source contexts in declarative (#4188)

  • Fix an ISE when a computed link is directly a property reference (#4193)

  • Fix an ISE when using an empty shape in some contexts (#4194)

  • Fix a number of error messages involving collection types in schemas (#4195)

  • Avoid doing semi-joins after a sequence of single links (#4196)

  • Make range() properly strict in its non-optional arguments (#4207)

  • Allow multiple FDs per socket in activation (#4189)

  • Add SCRAM authentication over HTTP (#4197)

  • Always arm auto-shutdown timer when it’s greater than zero (#4214)

  • Fix json -> array<json> cast of ‘[]’ (#4217)