Switch DB layer to Diesel from SeaORM and Fjall #2
10 changed files with 11 additions and 42 deletions
|
@ -3,7 +3,5 @@ CREATE TABLE IF NOT EXISTS users (
|
||||||
username TEXT NOT NULL UNIQUE CHECK (LENGTH(username) <= 32),
|
username TEXT NOT NULL UNIQUE CHECK (LENGTH(username) <= 32),
|
||||||
password_hash TEXT NOT NULL,
|
password_hash TEXT NOT NULL,
|
||||||
email TEXT NOT NULL UNIQUE CHECK (LENGTH(email) <= 100),
|
email TEXT NOT NULL UNIQUE CHECK (LENGTH(email) <= 100),
|
||||||
name TEXT NOT NULL CHECK (LENGTH(name) <= 100),
|
name TEXT NOT NULL CHECK (LENGTH(name) <= 100)
|
||||||
created TIMESTAMP NOT NULL,
|
|
||||||
updated TIMESTAMP NOT NULL
|
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
|
|
||||||
DROP TABLE IF EXISTS projects;
|
DROP TABLE IF EXISTS projects;
|
||||||
DROP TABLE IF EXISTS documents;
|
DROP TABLE IF EXISTS documents;
|
||||||
|
|
|
@ -5,10 +5,7 @@ CREATE TABLE IF NOT EXISTS projects (
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
description TEXT NOT NULL,
|
description TEXT NOT NULL,
|
||||||
|
|
||||||
key TEXT NOT NULL,
|
key TEXT NOT NULL
|
||||||
|
|
||||||
created TIMESTAMP NOT NULL,
|
|
||||||
updated TIMESTAMP NOT NULL
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS documents (
|
CREATE TABLE IF NOT EXISTS documents (
|
||||||
|
@ -17,8 +14,5 @@ CREATE TABLE IF NOT EXISTS documents (
|
||||||
project_id UUID_TEXT NOT NULL,
|
project_id UUID_TEXT NOT NULL,
|
||||||
|
|
||||||
title TEXT NOT NULL,
|
title TEXT NOT NULL,
|
||||||
content TEXT NOT NULL,
|
content TEXT NOT NULL
|
||||||
|
|
||||||
created TIMESTAMP NOT NULL,
|
|
||||||
updated TIMESTAMP NOT NULL
|
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,8 +4,5 @@ CREATE TABLE IF NOT EXISTS project_memberships(
|
||||||
|
|
||||||
user_id UUID_TEXT NOT NULL,
|
user_id UUID_TEXT NOT NULL,
|
||||||
project_id UUID_TEXT NOT NULL,
|
project_id UUID_TEXT NOT NULL,
|
||||||
role TEXT NOT NULL,
|
role TEXT NOT NULL
|
||||||
|
|
||||||
created TIMESTAMP NOT NULL,
|
|
||||||
updated TIMESTAMP NOT NULL
|
|
||||||
);
|
);
|
||||||
|
|
|
@ -26,10 +26,12 @@ async fn render_documents_page(ctx: Context, user: User) -> Result<Response, (St
|
||||||
let mut db = ctx.db_pool.get().map_err(internal_error)?;
|
let mut db = ctx.db_pool.get().map_err(internal_error)?;
|
||||||
let documents =
|
let documents =
|
||||||
permissions::query::accessible_documents(&mut db, &user.id).map_err(internal_error)?;
|
permissions::query::accessible_documents(&mut db, &user.id).map_err(internal_error)?;
|
||||||
|
let projects = permissions::query::accessible_projects(&mut db, &user.id).map_err(internal_error)?;
|
||||||
|
|
||||||
let values = context! {
|
let values = context! {
|
||||||
user => user,
|
user => user,
|
||||||
documents => documents,
|
documents => documents,
|
||||||
|
projects => projects,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(ctx.render_resp("documents/list_documents.html", values))
|
Ok(ctx.render_resp("documents/list_documents.html", values))
|
||||||
|
@ -122,10 +124,12 @@ pub async fn edit_document_page(
|
||||||
}
|
}
|
||||||
|
|
||||||
let document = documents::query::by_id(&mut db, &id.to_string()).map_err(internal_error)?;
|
let document = documents::query::by_id(&mut db, &id.to_string()).map_err(internal_error)?;
|
||||||
|
let projects = permissions::query::accessible_projects(&mut db, &user.id).map_err(internal_error)?;
|
||||||
|
|
||||||
let values = context! {
|
let values = context! {
|
||||||
user => user,
|
user => user,
|
||||||
document => document,
|
document => document,
|
||||||
|
projects => projects,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(ctx.render_resp("documents/edit_document.html", values))
|
Ok(ctx.render_resp("documents/edit_document.html", values))
|
||||||
|
|
|
@ -15,10 +15,6 @@ pub struct Document {
|
||||||
pub project_id: String,
|
pub project_id: String,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
#[serde(skip)]
|
|
||||||
pub created: chrono::NaiveDateTime,
|
|
||||||
#[serde(skip)]
|
|
||||||
pub updated: chrono::NaiveDateTime,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable)]
|
#[derive(Insertable)]
|
||||||
|
@ -34,7 +30,7 @@ pub struct NewDocument {
|
||||||
impl NewDocument {
|
impl NewDocument {
|
||||||
pub fn new(creator_id: &str, project_id: &str, title: String, content: String) -> Self {
|
pub fn new(creator_id: &str, project_id: &str, title: String, content: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: Uuid::new_v4().to_string(),
|
id: Uuid::now_v7().to_string(),
|
||||||
creator_id: creator_id.to_string(),
|
creator_id: creator_id.to_string(),
|
||||||
project_id: project_id.to_string(),
|
project_id: project_id.to_string(),
|
||||||
title,
|
title,
|
||||||
|
|
|
@ -50,9 +50,6 @@ pub struct ProjectMembership {
|
||||||
|
|
||||||
#[diesel(serialize_as = String, deserialize_as = String)]
|
#[diesel(serialize_as = String, deserialize_as = String)]
|
||||||
pub role: ProjectRole,
|
pub role: ProjectRole,
|
||||||
|
|
||||||
pub created: chrono::NaiveDateTime,
|
|
||||||
pub updated: chrono::NaiveDateTime,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable)]
|
#[derive(Insertable)]
|
||||||
|
|
|
@ -15,10 +15,6 @@ pub struct Project {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub key: String,
|
pub key: String,
|
||||||
#[serde(skip)]
|
|
||||||
pub created: chrono::NaiveDateTime,
|
|
||||||
#[serde(skip)]
|
|
||||||
pub updated: chrono::NaiveDateTime,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable)]
|
#[derive(Insertable)]
|
||||||
|
@ -34,7 +30,7 @@ pub struct NewProject {
|
||||||
impl NewProject {
|
impl NewProject {
|
||||||
pub fn new(creator_id: String, name: String, description: String, key: String) -> Self {
|
pub fn new(creator_id: String, name: String, description: String, key: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: Uuid::new_v4().to_string(),
|
id: Uuid::now_v7().to_string(),
|
||||||
creator_id,
|
creator_id,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
|
|
|
@ -17,10 +17,6 @@ pub struct User {
|
||||||
pub password_hash: String,
|
pub password_hash: String,
|
||||||
pub email: String,
|
pub email: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
#[serde(skip)]
|
|
||||||
pub created: chrono::NaiveDateTime,
|
|
||||||
#[serde(skip)]
|
|
||||||
pub updated: chrono::NaiveDateTime,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable)]
|
#[derive(Insertable)]
|
||||||
|
@ -37,7 +33,7 @@ impl NewUser {
|
||||||
pub fn new(name: String, username: String, email: String, password: String) -> Self {
|
pub fn new(name: String, username: String, email: String, password: String) -> Self {
|
||||||
let password_hash = password::hash(&password);
|
let password_hash = password::hash(&password);
|
||||||
Self {
|
Self {
|
||||||
id: Uuid::new_v4().to_string(),
|
id: Uuid::now_v7().to_string(),
|
||||||
name,
|
name,
|
||||||
username,
|
username,
|
||||||
email,
|
email,
|
||||||
|
|
|
@ -7,8 +7,6 @@ diesel::table! {
|
||||||
project_id -> Text,
|
project_id -> Text,
|
||||||
title -> Text,
|
title -> Text,
|
||||||
content -> Text,
|
content -> Text,
|
||||||
created -> Timestamp,
|
|
||||||
updated -> Timestamp,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +16,6 @@ diesel::table! {
|
||||||
user_id -> Text,
|
user_id -> Text,
|
||||||
project_id -> Text,
|
project_id -> Text,
|
||||||
role -> Text,
|
role -> Text,
|
||||||
created -> Timestamp,
|
|
||||||
updated -> Timestamp,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,8 +26,6 @@ diesel::table! {
|
||||||
name -> Text,
|
name -> Text,
|
||||||
description -> Text,
|
description -> Text,
|
||||||
key -> Text,
|
key -> Text,
|
||||||
created -> Timestamp,
|
|
||||||
updated -> Timestamp,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,8 +36,6 @@ diesel::table! {
|
||||||
password_hash -> Text,
|
password_hash -> Text,
|
||||||
email -> Text,
|
email -> Text,
|
||||||
name -> Text,
|
name -> Text,
|
||||||
created -> Timestamp,
|
|
||||||
updated -> Timestamp,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue