Skip to content

Commit

Permalink
prepare oauth and user
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienPensart committed Nov 5, 2023
1 parent 4bb5f55 commit 345f3d9
Show file tree
Hide file tree
Showing 24 changed files with 469 additions and 475 deletions.
23 changes: 21 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ musicbot database
Commands:
clean (clean-db,erase) Clean all musics in DB
drop Drop entire schema from DB
edgeql (execute,fetch,query) EdgeDB raw query
graphiql Explore with GraphiQL
graphql GraphQL query
Expand All @@ -124,6 +125,21 @@ musicbot database clean
-y, --yes Confirm action
-h, --help Show this message and exit.
musicbot database drop
**********************
.. code-block::
Usage: musicbot database drop [OPTIONS]
Drop entire schema from DB
Options:
MusicDB options:
--dsn TEXT DSN to MusicBot EdgeDB
--graphql TEXT DSN to MusicBot GrapQL
-y, --yes Confirm action
-h, --help Show this message and exit.
musicbot database edgeql
************************
.. code-block::
Expand Down Expand Up @@ -198,12 +214,15 @@ musicbot database ui
********************
.. code-block::
Usage: musicbot database ui [OPTIONS]
Usage: musicbot database ui [OPTIONS] [EDGEDB_ARGS]...
Explore with EdgeDB UI
Options:
-h, --help Show this message and exit.
MusicDB options:
--dsn TEXT DSN to MusicBot EdgeDB
--graphql TEXT DSN to MusicBot GrapQL
-h, --help Show this message and exit.
musicbot folder
***************
Expand Down
47 changes: 32 additions & 15 deletions dbschema/default.esdl
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
module default {
# global current_user := (
# assert_single((
# select User { id, name }
# filter .identity = global ext::auth::ClientTokenIdentity
# ))
# );

# type User {
# required name: str;
# required identity: ext::auth::Identity;
# }

function bytes_to_human(size: int64, k: int64 = 1000, decimals: int64 = 2, units: array<str> = [' B', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB']) -> str {
using (
select '0' ++ units[0] if size = 0
Expand Down Expand Up @@ -29,9 +41,8 @@ module default {
}

type Artist {
required name: str {
constraint exclusive;
}
# required user: User;
required name: str;
required created_at: datetime {
default := std::datetime_current();
readonly := true;
Expand Down Expand Up @@ -60,15 +71,19 @@ module default {
property duration := (select to_duration(seconds := <float64>.length));
property human_duration := (select to_str(.duration, "HH24:MI:SS"));

constraint exclusive on ((.name));

index fts::index on (
fts::with_options(
.name,
language := fts::Language.eng,
)
);

}

type Album {
# required user: User;
required name: str;
required created_at: datetime {
default := std::datetime_current();
Expand Down Expand Up @@ -101,18 +116,19 @@ module default {
property all_genres := (select to_str(array_agg(.musics.genre.name), " "));

constraint exclusive on ((.name, .artist));
index on ((.name, .artist));

index fts::index on (
fts::with_options(
.name,
language := fts::Language.eng,
language := fts::Language.eng
)
);
}

type Folder {
# required user: User;
required name: str;
required username: str;
required created_at: datetime {
default := std::datetime_current();
readonly := true;
Expand All @@ -121,7 +137,6 @@ module default {
rewrite insert, update using (datetime_of_statement())
}

required user: str;
required ipv4: str;

multi link musics := .<folders[is Music];
Expand Down Expand Up @@ -149,8 +164,7 @@ module default {
property n_genres := (select count(.genres));
property all_genres := (select to_str(array_agg(.musics.genre.name), " "));

constraint exclusive on ((.name, .ipv4));
index on ((.name, .ipv4));
constraint exclusive on ((.name, .username, .ipv4));

index fts::index on (
fts::with_options(
Expand All @@ -162,6 +176,7 @@ module default {

# define a local music
type Music {
# required user: User;
required name: str;
required created_at: datetime {
default := std::datetime_current();
Expand Down Expand Up @@ -202,7 +217,6 @@ module default {
property paths := (select .folders@path);

constraint exclusive on ((.name, .album));
index on ((.name, .album));

index fts::index on (
fts::with_options(
Expand All @@ -213,9 +227,8 @@ module default {
}

type Keyword {
required name: str {
constraint exclusive;
}
# required user: User;
required name: str;
required created_at: datetime {
default := std::datetime_current();
readonly := true;
Expand All @@ -242,6 +255,8 @@ module default {
property size := (select sum(.musics.size));
property human_size := (select bytes_to_human(.size));

constraint exclusive on ((.name));

index fts::index on (
fts::with_options(
.name,
Expand All @@ -251,9 +266,8 @@ module default {
}

type Genre {
required name: str {
constraint exclusive;
}
# required user: User;
required name: str;
required created_at: datetime {
default := std::datetime_current();
readonly := true;
Expand Down Expand Up @@ -282,6 +296,8 @@ module default {
property size := (select sum(.musics.size));
property human_size := (select bytes_to_human(.size));

constraint exclusive on ((.name));

index fts::index on (
fts::with_options(
.name,
Expand All @@ -293,3 +309,4 @@ module default {

using extension graphql;
using extension edgeql_http;
# using extension auth;
Loading

0 comments on commit 345f3d9

Please sign in to comment.