mirror of
https://github.com/versia-pub/activitypub.git
synced 2025-12-06 14:48:19 +01:00
Add user follow relation
This commit is contained in:
parent
9acf6578bf
commit
468371d43d
|
|
@ -3,6 +3,7 @@ pub use sea_orm_migration::prelude::*;
|
||||||
mod m20220101_000001_post_table;
|
mod m20220101_000001_post_table;
|
||||||
mod m20240417_230111_user_table;
|
mod m20240417_230111_user_table;
|
||||||
mod m20240417_233430_post_user_keys;
|
mod m20240417_233430_post_user_keys;
|
||||||
|
mod m20240505_002524_user_follow_relation;
|
||||||
|
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
|
|
@ -13,6 +14,7 @@ impl MigratorTrait for Migrator {
|
||||||
Box::new(m20220101_000001_post_table::Migration),
|
Box::new(m20220101_000001_post_table::Migration),
|
||||||
Box::new(m20240417_230111_user_table::Migration),
|
Box::new(m20240417_230111_user_table::Migration),
|
||||||
Box::new(m20240417_233430_post_user_keys::Migration),
|
Box::new(m20240417_233430_post_user_keys::Migration),
|
||||||
|
Box::new(m20240505_002524_user_follow_relation::Migration),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
66
migration/src/m20240505_002524_user_follow_relation.rs
Normal file
66
migration/src/m20240505_002524_user_follow_relation.rs
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
|
use crate::m20240417_230111_user_table::User;
|
||||||
|
|
||||||
|
#[derive(DeriveMigrationName)]
|
||||||
|
pub struct Migration;
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl MigrationTrait for Migration {
|
||||||
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
|
||||||
|
manager
|
||||||
|
.create_table(
|
||||||
|
Table::create()
|
||||||
|
.table(FollowRelation::Table)
|
||||||
|
.if_not_exists()
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(FollowRelation::Id)
|
||||||
|
.integer()
|
||||||
|
.not_null()
|
||||||
|
.auto_increment()
|
||||||
|
.primary_key(),
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(FollowRelation::FolloweeId).string().not_null())
|
||||||
|
.col(ColumnDef::new(FollowRelation::FollowerId).string().not_null())
|
||||||
|
.col(ColumnDef::new(FollowRelation::FolloweeHost).string())
|
||||||
|
.col(ColumnDef::new(FollowRelation::FollowerHost).string())
|
||||||
|
.col(ColumnDef::new(FollowRelation::FolloweeInbox).string())
|
||||||
|
.col(ColumnDef::new(FollowRelation::FollowerInbox).string())
|
||||||
|
.foreign_key(
|
||||||
|
ForeignKey::create()
|
||||||
|
.name("fk_follow_relation_followee_id")
|
||||||
|
.from(FollowRelation::Table, FollowRelation::FolloweeId)
|
||||||
|
.to(User::Table, User::Id)
|
||||||
|
.on_delete(ForeignKeyAction::Cascade),
|
||||||
|
)
|
||||||
|
.foreign_key(
|
||||||
|
ForeignKey::create()
|
||||||
|
.name("fk_follow_relation_follower_id")
|
||||||
|
.from(FollowRelation::Table, FollowRelation::FollowerId)
|
||||||
|
.to(User::Table, User::Id)
|
||||||
|
.on_delete(ForeignKeyAction::Cascade),
|
||||||
|
)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.drop_table(Table::drop().table(FollowRelation::Table).to_owned())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(DeriveIden)]
|
||||||
|
enum FollowRelation {
|
||||||
|
Table,
|
||||||
|
Id,
|
||||||
|
FolloweeId,
|
||||||
|
FollowerId,
|
||||||
|
FolloweeHost,
|
||||||
|
FollowerHost,
|
||||||
|
FolloweeInbox,
|
||||||
|
FollowerInbox
|
||||||
|
}
|
||||||
38
src/entities/follow_relation.rs
Normal file
38
src/entities/follow_relation.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.10
|
||||||
|
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||||
|
#[sea_orm(table_name = "follow_relation")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key)]
|
||||||
|
pub id: i32,
|
||||||
|
pub followee_id: String,
|
||||||
|
pub follower_id: String,
|
||||||
|
pub followee_host: Option<String>,
|
||||||
|
pub follower_host: Option<String>,
|
||||||
|
pub followee_inbox: Option<String>,
|
||||||
|
pub follower_inbox: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "super::user::Entity",
|
||||||
|
from = "Column::FollowerId",
|
||||||
|
to = "super::user::Column::Id",
|
||||||
|
on_update = "NoAction",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
User2,
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "super::user::Entity",
|
||||||
|
from = "Column::FolloweeId",
|
||||||
|
to = "super::user::Column::Id",
|
||||||
|
on_update = "NoAction",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
User1,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
|
@ -4,3 +4,4 @@ pub mod prelude;
|
||||||
|
|
||||||
pub mod post;
|
pub mod post;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
pub mod follow_relation;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.10
|
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.10
|
||||||
|
|
||||||
|
pub use super::follow_relation::Entity as FollowRelation;
|
||||||
pub use super::post::Entity as Post;
|
pub use super::post::Entity as Post;
|
||||||
pub use super::user::Entity as User;
|
pub use super::user::Entity as User;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue