Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new properties to user profiles #51

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dbschema/migrations/00027-m1mim5p.edgeql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE MIGRATION m1mim5pih5xgtor6tm6znfotxp7wlkobamdoy7ih72fnwlrldagcqa
ONTO m1hq7rmg46b7aiblmrpr75s7uo4iob2q254cbv6zgwzzn27b2pxsqq
{
ALTER TYPE user::Profile {
CREATE PROPERTY birthday: std::datetime;
CREATE PROPERTY pronouns: std::str;
};
};
11 changes: 11 additions & 0 deletions dbschema/migrations/00028-m1vnk3u.edgeql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE MIGRATION m1vnk3u6ttr6yrd4dkxficgsidqy5264drzusoppur7gowyhmkzmwa
ONTO m1mim5pih5xgtor6tm6znfotxp7wlkobamdoy7ih72fnwlrldagcqa
{
ALTER TYPE user::Profile {
CREATE PROPERTY n7_major: std::str;
};
ALTER TYPE user::Profile {
CREATE PROPERTY graduation_year: std::str;
DROP PROPERTY promotion;
};
};
9 changes: 9 additions & 0 deletions dbschema/migrations/00029-m1cpmoz.edgeql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE MIGRATION m1cpmoz6ue576uzldgepkp5bolfgg2n7l32dfx4ga5gudxbo7ypxxa
ONTO m1vnk3u6ttr6yrd4dkxficgsidqy5264drzusoppur7gowyhmkzmwa
{
ALTER TYPE user::Profile {
ALTER PROPERTY graduation_year {
SET TYPE std::int16 USING (<std::int16>.graduation_year);
};
};
};
5 changes: 4 additions & 1 deletion dbschema/user.esdl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ module user {
}

type Profile {
property birthday -> datetime;
property full_name -> str;
property graduation_year -> int16;
property photo -> str;
property promotion -> str;
property pronouns -> str;
property n7_major -> str;
property telephone -> str;
required link user -> User {
constraint exclusive;
Expand Down
24 changes: 12 additions & 12 deletions nanapi/database/calendar/guild_event_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,9 @@ class ProjectionStatus(StrEnum):


class GuildEventDeleteResultClient(BaseModel):
id: UUID
password_hash: str
username: str


class GuildEventDeleteResultProjection(BaseModel):
id: UUID
channel_id: int
channel_id_str: str
message_id: int | None
message_id_str: str | None
name: str
status: ProjectionStatus
password_hash: str


class GuildEventDeleteResultParticipants(BaseModel):
Expand All @@ -51,6 +41,16 @@ class GuildEventDeleteResultOrganizer(BaseModel):
discord_username: str


class GuildEventDeleteResultProjection(BaseModel):
id: UUID
channel_id: int
message_id: int | None
name: str
status: ProjectionStatus
channel_id_str: str
message_id_str: str | None


class GuildEventDeleteResult(BaseModel):
url: str | None
start_time: datetime
Expand All @@ -62,9 +62,9 @@ class GuildEventDeleteResult(BaseModel):
description: str | None
discord_id: int
id: UUID
projection: GuildEventDeleteResultProjection | None
organizer: GuildEventDeleteResultOrganizer
participants: list[GuildEventDeleteResultParticipants]
projection: GuildEventDeleteResultProjection | None
client: GuildEventDeleteResultClient


Expand Down
24 changes: 12 additions & 12 deletions nanapi/database/calendar/guild_event_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ class ProjectionStatus(StrEnum):
COMPLETED = 'COMPLETED'


class GuildEventMergeResultProjection(BaseModel):
id: UUID
channel_id: int
message_id: int | None
name: str
status: ProjectionStatus
channel_id_str: str
message_id_str: str | None


class GuildEventMergeResultOrganizer(BaseModel):
id: UUID
discord_id: int
Expand All @@ -79,20 +89,10 @@ class GuildEventMergeResultParticipants(BaseModel):
discord_username: str


class GuildEventMergeResultProjection(BaseModel):
id: UUID
channel_id: int
channel_id_str: str
message_id: int | None
message_id_str: str | None
name: str
status: ProjectionStatus


class GuildEventMergeResultClient(BaseModel):
username: str
id: UUID
password_hash: str
username: str


class GuildEventMergeResult(BaseModel):
Expand All @@ -107,9 +107,9 @@ class GuildEventMergeResult(BaseModel):
start_time: datetime
url: str | None
client: GuildEventMergeResultClient
projection: GuildEventMergeResultProjection | None
participants: list[GuildEventMergeResultParticipants]
organizer: GuildEventMergeResultOrganizer
projection: GuildEventMergeResultProjection | None


adapter = TypeAdapter(GuildEventMergeResult)
Expand Down
24 changes: 12 additions & 12 deletions nanapi/database/calendar/guild_event_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ class ProjectionStatus(StrEnum):
COMPLETED = 'COMPLETED'


class GuildEventSelectResultProjection(BaseModel):
id: UUID
channel_id: int
message_id: int | None
name: str
status: ProjectionStatus
channel_id_str: str
message_id_str: str | None


class GuildEventSelectResultOrganizer(BaseModel):
id: UUID
discord_id: int
Expand All @@ -35,20 +45,10 @@ class GuildEventSelectResultParticipants(BaseModel):
discord_username: str


class GuildEventSelectResultProjection(BaseModel):
id: UUID
channel_id: int
channel_id_str: str
message_id: int | None
message_id_str: str | None
name: str
status: ProjectionStatus


class GuildEventSelectResultClient(BaseModel):
username: str
id: UUID
password_hash: str
username: str


class GuildEventSelectResult(BaseModel):
Expand All @@ -63,9 +63,9 @@ class GuildEventSelectResult(BaseModel):
start_time: datetime
url: str | None
client: GuildEventSelectResultClient
projection: GuildEventSelectResultProjection | None
participants: list[GuildEventSelectResultParticipants]
organizer: GuildEventSelectResultOrganizer
projection: GuildEventSelectResultProjection | None


adapter = TypeAdapter(list[GuildEventSelectResult])
Expand Down
4 changes: 2 additions & 2 deletions nanapi/database/projection/projo_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ class ProjoSelectResult(BaseModel):
external_medias: list[ProjoSelectResultExternalMedias]
participants: list[ProjoSelectResultParticipants]
guild_events: list[ProjoSelectResultGuildEvents]
message_id_str: str | None
channel_id_str: str
status: ProjectionStatus
name: str
message_id_str: str | None
message_id: int | None
channel_id_str: str
channel_id: int
id: UUID

Expand Down
5 changes: 4 additions & 1 deletion nanapi/database/user/profile_get_by_discord_id.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ with
filter .user.discord_id = discord_id
)
select profiles {
birthday,
full_name,
graduation_year,
photo,
promotion,
pronouns,
n7_major,
telephone,
user: {
discord_id,
Expand Down
12 changes: 10 additions & 2 deletions nanapi/database/user/profile_get_by_discord_id.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from edgedb import AsyncIOExecutor
from pydantic import BaseModel, TypeAdapter

Expand All @@ -9,9 +11,12 @@
filter .user.discord_id = discord_id
)
select profiles {
birthday,
full_name,
graduation_year,
photo,
promotion,
pronouns,
n7_major,
telephone,
user: {
discord_id,
Expand All @@ -27,9 +32,12 @@ class ProfileGetByDiscordIdResultUser(BaseModel):


class ProfileGetByDiscordIdResult(BaseModel):
birthday: datetime | None
full_name: str | None
graduation_year: int | None
photo: str | None
promotion: str | None
pronouns: str | None
n7_major: str | None
telephone: str | None
user: ProfileGetByDiscordIdResultUser

Expand Down
20 changes: 16 additions & 4 deletions nanapi/database/user/profile_merge_select.edgeql
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
with
discord_id := <int64>$discord_id,
discord_username := <str>$discord_username,
birthday := <optional datetime>$birthday,
full_name := <optional str>$full_name,
graduation_year := <optional int16>$graduation_year,
photo := <optional str>$photo,
promotion := <optional str>$promotion,
pronouns := <optional str>$pronouns,
n7_major := <optional str>$n7_major,
telephone := <optional str>$telephone,
user := (
insert user::User {
Expand All @@ -19,26 +22,35 @@ with
),
profile := (
insert user::Profile {
birthday := birthday,
full_name := full_name,
graduation_year := graduation_year,
photo := photo,
promotion := promotion,
pronouns := pronouns,
n7_major := n7_major,
telephone := telephone,
user := user,
}
unless conflict on .user
else (
update user::Profile set {
birthday := birthday,
full_name := full_name,
graduation_year := graduation_year,
photo := photo,
promotion := promotion,
pronouns := pronouns,
n7_major := n7_major,
telephone := telephone,
}
)
)
select profile {
birthday,
graduation_year,
full_name,
photo,
promotion,
pronouns,
n7_major,
telephone,
user: {
discord_id,
Expand Down
Loading
Loading