Skip to content

Commit

Permalink
redo the EdgeDB project modules to rely on them rather than migration…
Browse files Browse the repository at this point in the history
…s for version checking (#176)
  • Loading branch information
nsidnev authored Oct 31, 2023
1 parent 10c2054 commit 05427fd
Show file tree
Hide file tree
Showing 28 changed files with 214 additions and 329 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,21 @@ jobs:
with:
submodules: true

- name: Remove migrations for EdgeDB versions greater then current major version (${{ matrix.edgedb-version }})
- name: Remove non ${{ matrix.edgedb-version }} EdgeDB version modules and migrations
env:
EDGEDB_VERSION: ${{ matrix.edgedb-version }}
run: |
EDGEDB_VERSION=${EDGEDB_VERSION%%.*}
for migration_file in `ls priv/edgedb/schema/migrations/`
rm -r "priv/edgedb/schema/migrations/"
for module_file in `ls priv/edgedb/schema/`
do
migration_number=${migration_file%.*}
if test ${migration_number} -gt ${EDGEDB_VERSION}
module_version=${module_file%.esdl}
module_version=${module_version#v}
if test ${module_version} -gt ${EDGEDB_VERSION}
then
rm "priv/edgedb/schema/migrations/${migration_file}"
rm "priv/edgedb/schema/${module_file}"
fi
done
Expand All @@ -76,6 +79,11 @@ jobs:
server-version: ${{ matrix.edgedb-version }}
instance-name: edgedb_elixir

- name: Generate EdgeDB migrations
run: |
edgedb migration create --non-interactive
edgedb migrate
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp-version }}
Expand Down
6 changes: 3 additions & 3 deletions lib/edgedb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule EdgeDB do
```iex
iex(1)> {:ok, client} = EdgeDB.start_link()
iex(2)> EdgeDB.query!(client, "\"\"
...(2)> select Person{
...(2)> select v1::Person{
...(2)> first_name,
...(2)> middle_name,
...(2)> last_name
Expand Down Expand Up @@ -545,8 +545,8 @@ defmodule EdgeDB do
```iex
iex(1)> {:ok, client} = EdgeDB.start_link()
iex(2)> {:ok, tickets} = EdgeDB.transaction(client, fn client ->
...(2)> EdgeDB.query!(client, "insert Ticket{ number := 2}")
...(2)> EdgeDB.query!(client, "select Ticket")
...(2)> EdgeDB.query!(client, "insert v1::Ticket{ number := 2}")
...(2)> EdgeDB.query!(client, "select v1::Ticket")
...(2)> end)
iex(3)> tickets
#EdgeDB.Set<{#EdgeDB.Object<>}>
Expand Down
2 changes: 1 addition & 1 deletion lib/edgedb/types/set.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule EdgeDB.Set do
```iex
iex(1)> {:ok, client} = EdgeDB.start_link()
iex(2)> set = EdgeDB.query!(client, "select Ticket")
iex(2)> set = EdgeDB.query!(client, "select v1::Ticket")
iex(3)> EdgeDB.Set.empty?(set)
true
```
Expand Down
6 changes: 3 additions & 3 deletions pages/rst/api/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A simple example of how to use it:
iex(1)> {:ok, client} = EdgeDB.start_link()
iex(2)> EdgeDB.query!(client, """
...(2)> select Person{
...(2)> select v1::Person{
...(2)> first_name,
...(2)> middle_name,
...(2)> last_name
Expand Down Expand Up @@ -555,8 +555,8 @@ To rollback an open transaction, use ``EdgeDB.rollback/2``.
iex(1)> {:ok, client} = EdgeDB.start_link()
iex(2)> {:ok, tickets} = EdgeDB.transaction(client, fn client ->
...(2)> EdgeDB.query!(client, "insert Ticket{ number := 2}")
...(2)> EdgeDB.query!(client, "select Ticket")
...(2)> EdgeDB.query!(client, "insert v1::Ticket{ number := 2}")
...(2)> EdgeDB.query!(client, "select v1::Ticket")
...(2)> end)
iex(3)> tickets
#EdgeDB.Set<{#EdgeDB.Object<>}>
Expand Down
2 changes: 1 addition & 1 deletion pages/rst/api/edgedb-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Check if set is empty.
.. code:: iex
iex(1)> {:ok, client} = EdgeDB.start_link()
iex(2)> set = EdgeDB.query!(client, "select Ticket")
iex(2)> set = EdgeDB.query!(client, "select v1::Ticket")
iex(3)> EdgeDB.Set.empty?(set)
true
Expand Down
116 changes: 0 additions & 116 deletions priv/edgedb/schema/default.esdl

This file was deleted.

93 changes: 26 additions & 67 deletions priv/edgedb/schema/migrations/00001.edgeql
Original file line number Diff line number Diff line change
@@ -1,78 +1,37 @@
CREATE MIGRATION m1ud5ykhpyzl7tdyqf6w5nezyy75753dwy2kmeznqedph2ddww6cia
CREATE MIGRATION m1c65s2cgnjqbm4zvuyv6saeqpi5c446bceydxxr35zmjbf2ndymsq
ONTO initial
{
CREATE ABSTRACT LINK default::crew {
CREATE PROPERTY list_order -> std::int64;
};
CREATE ABSTRACT TYPE default::HasImage {
CREATE REQUIRED PROPERTY image -> std::str;
CREATE INDEX ON (.image);
};
CREATE TYPE default::Movie EXTENDING default::HasImage {
CREATE PROPERTY description -> std::str;
CREATE REQUIRED PROPERTY title -> std::str;
CREATE REQUIRED PROPERTY year -> std::int64;
CREATE INDEX ON (.year);
CREATE INDEX ON ((.title, .year));
CREATE INDEX ON (.title);
};
CREATE TYPE default::User EXTENDING default::HasImage {
CREATE REQUIRED PROPERTY name -> std::str;
};
CREATE TYPE default::Review {
CREATE REQUIRED LINK movie -> default::Movie;
CREATE REQUIRED PROPERTY rating -> std::int64 {
CREATE CONSTRAINT std::max_value(5);
CREATE CONSTRAINT std::min_value(0);
};
CREATE REQUIRED LINK author -> default::User;
CREATE REQUIRED PROPERTY body -> std::str;
CREATE REQUIRED PROPERTY creation_time -> std::datetime {
SET default := (std::datetime_current());
CREATE MODULE v1 IF NOT EXISTS;
CREATE ABSTRACT LINK v1::crew {
CREATE PROPERTY list_order: std::int64;
};
CREATE TYPE v1::Person {
CREATE REQUIRED PROPERTY first_name: std::str;
CREATE REQUIRED PROPERTY last_name: std::str;
CREATE REQUIRED PROPERTY middle_name: std::str;
};
CREATE TYPE v1::Movie {
CREATE MULTI LINK actors: v1::Person {
EXTENDING v1::crew;
};
CREATE REQUIRED PROPERTY flag -> std::bool {
SET default := false;
CREATE MULTI LINK directors: v1::Person {
EXTENDING v1::crew;
};
CREATE PROPERTY description: std::str;
CREATE REQUIRED PROPERTY title: std::str;
CREATE REQUIRED PROPERTY year: std::int64;
};
ALTER TYPE default::Movie {
CREATE PROPERTY avg_rating := (math::mean(.<movie[IS default::Review].rating));
};
CREATE ALIAS default::MovieAlias := (
default::Movie {
reviews := .<movie[IS default::Review]
}
);
CREATE ALIAS default::ReviewAlias := (
default::Review {
author_name := .author.name,
movie_title := .movie.title
}
);
CREATE ABSTRACT LINK default::actors EXTENDING default::crew;
CREATE TYPE default::Person EXTENDING default::HasImage {
CREATE PROPERTY bio -> std::str;
CREATE REQUIRED PROPERTY first_name -> std::str {
SET default := '';
};
CREATE REQUIRED PROPERTY last_name -> std::str;
CREATE REQUIRED PROPERTY middle_name -> std::str {
SET default := '';
};
CREATE PROPERTY full_name := (((((.first_name ++ ' ') IF (.first_name != '') ELSE '') ++ ((.middle_name ++ ' ') IF (.middle_name != '') ELSE '')) ++ .last_name));
};
ALTER TYPE default::Movie {
CREATE MULTI LINK actors EXTENDING default::crew -> default::Person;
CREATE MULTI LINK directors EXTENDING default::crew -> default::Person;
};
CREATE ABSTRACT LINK default::directors EXTENDING default::crew;
CREATE SCALAR TYPE default::TicketNo EXTENDING std::sequence;
CREATE TYPE default::Ticket {
CREATE PROPERTY number -> default::TicketNo {
CREATE SCALAR TYPE v1::TicketNo EXTENDING std::sequence;
CREATE TYPE v1::Ticket {
CREATE PROPERTY number: v1::TicketNo {
CREATE CONSTRAINT std::exclusive;
};
};
CREATE SCALAR TYPE default::Color EXTENDING enum<Red, Green, Blue>;
CREATE SCALAR TYPE default::short_str EXTENDING std::str {
CREATE TYPE v1::User {
CREATE REQUIRED PROPERTY name: std::str;
};
CREATE SCALAR TYPE v1::Color EXTENDING enum<Red, Green, Blue>;
CREATE SCALAR TYPE v1::short_str EXTENDING std::str {
CREATE CONSTRAINT std::max_len_value(5);
};
};
7 changes: 4 additions & 3 deletions priv/edgedb/schema/migrations/00002.edgeql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE MIGRATION m1ryrngpym75cc5zcmkrfebkg6dcmyflzu7727vnjhmy2zl4q3tjda
ONTO m1ud5ykhpyzl7tdyqf6w5nezyy75753dwy2kmeznqedph2ddww6cia
CREATE MIGRATION m1s4rwuphzakukj3i6wqbwi534ctcmaulpn4a4wfclpejyowtxkloq
ONTO m1c65s2cgnjqbm4zvuyv6saeqpi5c446bceydxxr35zmjbf2ndymsq
{
CREATE GLOBAL default::current_user -> std::str;
CREATE MODULE v2 IF NOT EXISTS;
CREATE GLOBAL v2::current_user -> std::str;
};
7 changes: 4 additions & 3 deletions priv/edgedb/schema/migrations/00003.edgeql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CREATE MIGRATION m16wualxmsuqqryhwrn6kgd6upwxge3cwruitgz63wbe5mynxxieva
ONTO m1ryrngpym75cc5zcmkrfebkg6dcmyflzu7727vnjhmy2zl4q3tjda
CREATE MIGRATION m17xqasqccfam62oqoyltgemn7mrdws33vik4bodj67kcmwfa3mq6q
ONTO m1s4rwuphzakukj3i6wqbwi534ctcmaulpn4a4wfclpejyowtxkloq
{
CREATE EXTENSION pgvector VERSION '0.4';
CREATE SCALAR TYPE default::ExVector EXTENDING ext::pgvector::vector<1602>;
CREATE MODULE v3 IF NOT EXISTS;
CREATE SCALAR TYPE v3::ExVector EXTENDING ext::pgvector::vector<1602>;
};
5 changes: 5 additions & 0 deletions priv/edgedb/schema/migrations/00004.edgeql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE MIGRATION m12bi2uxbraa4docb2s3ajj5eodgcc2gbno6cf2jrwudhz6mhhdvta
ONTO m17xqasqccfam62oqoyltgemn7mrdws33vik4bodj67kcmwfa3mq6q
{
CREATE MODULE v4 IF NOT EXISTS;
};
37 changes: 37 additions & 0 deletions priv/edgedb/schema/v1.esdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module v1 {
scalar type Color extending enum<Red, Green, Blue>;
scalar type TicketNo extending sequence;

scalar type short_str extending str {
constraint max_len_value(5);
};

type User {
required property name -> str;
}

type Person {
required property first_name -> str;
required property middle_name -> str;
required property last_name -> str;
}

abstract link crew {
property list_order -> int64;
}

type Movie {
required property title -> str;
required property year -> int64;
property description -> str;

multi link directors extending crew -> Person;
multi link actors extending crew -> Person;
}

type Ticket {
property number -> TicketNo {
constraint exclusive;
}
}
}
3 changes: 3 additions & 0 deletions priv/edgedb/schema/v2.esdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module v2 {
global current_user -> str;
}
5 changes: 5 additions & 0 deletions priv/edgedb/schema/v3.esdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using extension pgvector;

module v3 {
scalar type ExVector extending ext::pgvector::vector<1602>;
}
1 change: 1 addition & 0 deletions priv/edgedb/schema/v4.esdl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module v4 {}
Loading

0 comments on commit 05427fd

Please sign in to comment.