feat: Refactor user and thought models to use UUIDs instead of integers
- Updated user and thought models to utilize UUIDs for primary keys. - Modified persistence functions to accommodate UUIDs for user and thought IDs. - Implemented tag functionality with new Tag and ThoughtTag models. - Added migration scripts to create new tables for tags and thought-tag relationships. - Enhanced thought creation to parse hashtags and link them to thoughts. - Updated tests to reflect changes in user and thought ID types.
This commit is contained in:
@@ -3,9 +3,9 @@ use sea_orm::entity::prelude::*;
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "thought")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub author_id: i32,
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub author_id: Uuid,
|
||||
pub content: String,
|
||||
pub created_at: DateTimeWithTimeZone,
|
||||
}
|
||||
@@ -20,6 +20,9 @@ pub enum Relation {
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
User,
|
||||
|
||||
#[sea_orm(has_many = "super::thought_tag::Entity")]
|
||||
ThoughtTag,
|
||||
}
|
||||
|
||||
impl Related<super::user::Entity> for Entity {
|
||||
@@ -28,4 +31,13 @@ impl Related<super::user::Entity> for Entity {
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::tag::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
super::thought_tag::Relation::Tag.def()
|
||||
}
|
||||
fn via() -> Option<RelationDef> {
|
||||
Some(super::thought_tag::Relation::Thought.def().rev())
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
Reference in New Issue
Block a user