multi tenancy part 1

This commit is contained in:
2025-10-22 22:52:59 +02:00
parent 8e3f09774a
commit e175d28c2c
35 changed files with 1288 additions and 314 deletions
+60 -2
View File
@@ -4,15 +4,51 @@ use uuid::Uuid;
use crate::schema::*;
#[derive(Debug, Clone, Queryable, Identifiable, Associations)]
#[diesel(table_name = user_memberships)]
#[diesel(belongs_to(User, foreign_key = user_id))]
#[diesel(belongs_to(Tenant, foreign_key = tenant_id))]
pub struct UserMembership {
pub id: Uuid,
pub user_id: Uuid,
pub tenant_id: Uuid,
pub role: String,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
}
#[derive(Debug, Insertable)]
#[diesel(table_name = user_memberships)]
pub struct NewUserMembership {
pub id: Uuid,
pub user_id: Uuid,
pub tenant_id: Uuid,
pub role: String,
}
#[derive(Debug, Clone, Queryable, Identifiable)]
#[diesel(table_name = tenants)]
#[diesel(primary_key(tenant_id))]
pub struct Tenant {
pub tenant_id: Uuid,
pub slug: String,
pub storage_root: Option<String>,
pub quickwit_index: Option<String>,
pub status: String,
pub config: serde_json::Value,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
}
#[derive(Debug, Clone, Queryable, Identifiable)]
#[diesel(table_name = users)]
pub struct User {
pub id: Uuid,
pub username: String,
pub password_hash: String,
pub role: String,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
pub tenant_id: Uuid,
}
#[derive(Debug, Insertable)]
@@ -21,7 +57,7 @@ pub struct NewUser {
pub id: Uuid,
pub username: String,
pub password_hash: String,
pub role: String,
pub tenant_id: Uuid,
}
#[derive(Debug, Clone, Queryable, Identifiable)]
@@ -32,6 +68,7 @@ pub struct Folder {
pub parent_id: Option<Uuid>,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
pub tenant_id: Uuid,
}
#[derive(Debug, Insertable)]
@@ -40,6 +77,7 @@ pub struct NewFolder {
pub id: Uuid,
pub name: String,
pub parent_id: Option<Uuid>,
pub tenant_id: Uuid,
}
#[derive(Debug, Clone, Queryable, Identifiable, Associations)]
@@ -58,6 +96,7 @@ pub struct Document {
pub issued_at: Option<NaiveDateTime>,
pub title: String,
pub current_version_id: Uuid,
pub tenant_id: Uuid,
}
#[derive(Debug, Insertable)]
@@ -72,6 +111,7 @@ pub struct NewDocument {
pub metadata: serde_json::Value,
pub issued_at: Option<NaiveDateTime>,
pub title: String,
pub tenant_id: Uuid,
}
#[derive(Debug, Clone, Queryable, Identifiable, Associations)]
@@ -87,6 +127,7 @@ pub struct DocumentVersion {
pub created_at: NaiveDateTime,
pub operations_summary: serde_json::Value,
pub metadata: serde_json::Value,
pub tenant_id: Uuid,
}
#[derive(Debug, Insertable)]
@@ -100,6 +141,7 @@ pub struct NewDocumentVersion {
pub checksum: String,
pub operations_summary: serde_json::Value,
pub metadata: serde_json::Value,
pub tenant_id: Uuid,
}
#[derive(Debug, Clone, Queryable, Identifiable, Associations)]
@@ -113,6 +155,7 @@ pub struct DocumentAsset {
pub metadata: serde_json::Value,
pub created_at: NaiveDateTime,
pub cardinality: Option<i32>,
pub tenant_id: Uuid,
}
#[derive(Debug, Insertable)]
@@ -124,6 +167,7 @@ pub struct NewDocumentAsset {
pub mime_type: String,
pub metadata: serde_json::Value,
pub cardinality: Option<i32>,
pub tenant_id: Uuid,
}
#[derive(Debug, Clone, Queryable, Identifiable, Associations)]
@@ -135,6 +179,7 @@ pub struct DocumentAssetObject {
pub ordinal: i32,
pub s3_key: String,
pub metadata: serde_json::Value,
pub tenant_id: Uuid,
}
#[derive(Debug, Insertable)]
@@ -145,6 +190,7 @@ pub struct NewDocumentAssetObject {
pub ordinal: i32,
pub s3_key: String,
pub metadata: serde_json::Value,
pub tenant_id: Uuid,
}
#[derive(Debug, Clone, Queryable, Identifiable)]
@@ -159,6 +205,7 @@ pub struct Job {
pub last_error: Option<String>,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
pub tenant_id: Uuid,
}
#[derive(Debug, Insertable)]
@@ -169,6 +216,7 @@ pub struct NewJob {
pub payload: serde_json::Value,
pub status: String,
pub run_after: NaiveDateTime,
pub tenant_id: Uuid,
}
#[derive(Debug, Clone, Queryable, Identifiable)]
@@ -178,6 +226,7 @@ pub struct Tag {
pub label: String,
pub color: Option<String>,
pub created_at: NaiveDateTime,
pub tenant_id: Uuid,
}
#[derive(Debug, Insertable)]
@@ -186,6 +235,7 @@ pub struct NewTag {
pub id: Uuid,
pub label: String,
pub color: Option<String>,
pub tenant_id: Uuid,
}
#[allow(dead_code)]
@@ -199,6 +249,7 @@ pub struct DocumentTag {
pub tag_id: Uuid,
pub assigned_at: NaiveDateTime,
pub assigned_by: Option<Uuid>,
pub tenant_id: Uuid,
}
#[derive(Debug, Insertable)]
@@ -207,6 +258,7 @@ pub struct NewDocumentTag {
pub document_id: Uuid,
pub tag_id: Uuid,
pub assigned_by: Option<Uuid>,
pub tenant_id: Uuid,
}
#[derive(Debug, Clone, Queryable, Identifiable)]
@@ -217,6 +269,7 @@ pub struct Correspondent {
pub metadata: serde_json::Value,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
pub tenant_id: Uuid,
}
#[derive(Debug, Insertable)]
@@ -225,6 +278,7 @@ pub struct NewCorrespondent {
pub id: Uuid,
pub name: String,
pub metadata: serde_json::Value,
pub tenant_id: Uuid,
}
#[derive(Debug, Clone, Queryable, Associations)]
@@ -238,6 +292,7 @@ pub struct DocumentCorrespondent {
pub role: String,
pub assigned_at: NaiveDateTime,
pub assigned_by: Option<Uuid>,
pub tenant_id: Uuid,
}
#[derive(Debug, Insertable)]
@@ -247,6 +302,7 @@ pub struct NewDocumentCorrespondent {
pub correspondent_id: Uuid,
pub role: String,
pub assigned_by: Option<Uuid>,
pub tenant_id: Uuid,
}
#[derive(Debug, Clone, Queryable, Identifiable, Associations)]
@@ -261,6 +317,7 @@ pub struct RefreshToken {
pub revoked_at: Option<NaiveDateTime>,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
pub tenant_id: Uuid,
}
#[derive(Debug, Insertable)]
@@ -271,4 +328,5 @@ pub struct NewRefreshToken {
pub token_hash: String,
pub issued_at: NaiveDateTime,
pub expires_at: NaiveDateTime,
pub tenant_id: Uuid,
}