schema: make user fields non-nullable
They can always be empty. This simplifies mutation, since graphql_client doesn't have an easy way to conditionally leave out fields (we could do that with `@include`, but that's one bool per field in addition to the field, a bit ugly).
This commit is contained in:
committed by
nitnelave
parent
564c09d6ab
commit
0ac9e134de
@@ -8,9 +8,9 @@ use std::collections::HashSet;
|
||||
pub struct User {
|
||||
pub user_id: String,
|
||||
pub email: String,
|
||||
pub display_name: Option<String>,
|
||||
pub first_name: Option<String>,
|
||||
pub last_name: Option<String>,
|
||||
pub display_name: String,
|
||||
pub first_name: String,
|
||||
pub last_name: String,
|
||||
// pub avatar: ?,
|
||||
pub creation_date: chrono::DateTime<chrono::Utc>,
|
||||
}
|
||||
@@ -21,9 +21,9 @@ impl Default for User {
|
||||
User {
|
||||
user_id: String::new(),
|
||||
email: String::new(),
|
||||
display_name: None,
|
||||
first_name: None,
|
||||
last_name: None,
|
||||
display_name: String::new(),
|
||||
first_name: String::new(),
|
||||
last_name: String::new(),
|
||||
creation_date: chrono::Utc.timestamp(0, 0),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::infra::configuration::Configuration;
|
||||
use async_trait::async_trait;
|
||||
use futures_util::StreamExt;
|
||||
use futures_util::TryStreamExt;
|
||||
use sea_query::{Expr, Iden, Order, Query, SimpleExpr, Value};
|
||||
use sea_query::{Expr, Iden, Order, Query, SimpleExpr};
|
||||
use sqlx::Row;
|
||||
use std::collections::HashSet;
|
||||
|
||||
@@ -179,9 +179,9 @@ impl BackendHandler for SqlBackendHandler {
|
||||
let values = vec![
|
||||
request.user_id.clone().into(),
|
||||
request.email.into(),
|
||||
request.display_name.map(Into::into).unwrap_or(Value::Null),
|
||||
request.first_name.map(Into::into).unwrap_or(Value::Null),
|
||||
request.last_name.map(Into::into).unwrap_or(Value::Null),
|
||||
request.display_name.unwrap_or_default().into(),
|
||||
request.first_name.unwrap_or_default().into(),
|
||||
request.last_name.unwrap_or_default().into(),
|
||||
chrono::Utc::now().naive_utc().into(),
|
||||
];
|
||||
let query = Query::insert()
|
||||
|
||||
@@ -49,9 +49,13 @@ pub async fn init_table(pool: &Pool) -> sqlx::Result<()> {
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Users::Email).string_len(255).not_null())
|
||||
.col(ColumnDef::new(Users::DisplayName).string_len(255))
|
||||
.col(ColumnDef::new(Users::FirstName).string_len(255))
|
||||
.col(ColumnDef::new(Users::LastName).string_len(255))
|
||||
.col(
|
||||
ColumnDef::new(Users::DisplayName)
|
||||
.string_len(255)
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(Users::FirstName).string_len(255).not_null())
|
||||
.col(ColumnDef::new(Users::LastName).string_len(255).not_null())
|
||||
.col(ColumnDef::new(Users::Avatar).binary())
|
||||
.col(ColumnDef::new(Users::CreationDate).date_time().not_null())
|
||||
.col(ColumnDef::new(Users::PasswordHash).binary())
|
||||
|
||||
Reference in New Issue
Block a user