feat!: add instance internal id on objects table

This commit is contained in:
əlemi 2024-05-29 03:44:20 +02:00
parent 40c80fa181
commit b89bb87c19
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 32 additions and 0 deletions

View file

@ -46,6 +46,7 @@ pub enum Objects {
Table, Table,
Internal, Internal,
Id, Id,
Instance,
ObjectType, ObjectType,
AttributedTo, AttributedTo,
Name, Name,
@ -200,6 +201,14 @@ impl MigrationTrait for Migration {
.auto_increment() .auto_increment()
) )
.col(ColumnDef::new(Objects::Id).string().not_null().unique_key()) .col(ColumnDef::new(Objects::Id).string().not_null().unique_key())
.col(ColumnDef::new(Objects::Instance).big_integer().not_null())
.foreign_key(
ForeignKey::create()
.name("fkey-objects-instances")
.from(Objects::Table, Objects::Instance)
.to(Instances::Table, Instances::Internal)
.on_update(ForeignKeyAction::Cascade)
)
.col(ColumnDef::new(Objects::ObjectType).string().not_null()) .col(ColumnDef::new(Objects::ObjectType).string().not_null())
.col(ColumnDef::new(Objects::AttributedTo).string().null()) .col(ColumnDef::new(Objects::AttributedTo).string().null())
// .foreign_key( // .foreign_key(

View file

@ -27,6 +27,8 @@ pub enum Relation {
Actors, Actors,
#[sea_orm(has_many = "super::addressing::Entity")] #[sea_orm(has_many = "super::addressing::Entity")]
Addressing, Addressing,
#[sea_orm(has_many = "super::object::Entity")]
Objects,
} }
impl Related<super::actor::Entity> for Entity { impl Related<super::actor::Entity> for Entity {
@ -41,6 +43,12 @@ impl Related<super::addressing::Entity> for Entity {
} }
} }
impl Related<super::object::Entity> for Entity {
fn to() -> RelationDef {
Relation::Objects.def()
}
}
impl ActiveModelBehavior for ActiveModel {} impl ActiveModelBehavior for ActiveModel {}
impl Entity { impl Entity {

View file

@ -12,6 +12,7 @@ pub struct Model {
pub internal: i64, pub internal: i64,
#[sea_orm(unique)] #[sea_orm(unique)]
pub id: String, pub id: String,
pub instance: i64,
pub object_type: ObjectType, pub object_type: ObjectType,
pub attributed_to: Option<String>, pub attributed_to: Option<String>,
pub name: Option<String>, pub name: Option<String>,
@ -52,6 +53,14 @@ pub enum Relation {
Attachments, Attachments,
#[sea_orm(has_many = "super::hashtag::Entity")] #[sea_orm(has_many = "super::hashtag::Entity")]
Hashtags, Hashtags,
#[sea_orm(
belongs_to = "super::instance::Entity",
from = "Column::Instance",
to = "super::instance::Column::Internal",
on_update = "Cascade",
on_delete = "NoAction"
)]
Instances,
#[sea_orm(has_many = "super::like::Entity")] #[sea_orm(has_many = "super::like::Entity")]
Likes, Likes,
#[sea_orm(has_many = "super::mention::Entity")] #[sea_orm(has_many = "super::mention::Entity")]
@ -102,6 +111,12 @@ impl Related<super::hashtag::Entity> for Entity {
} }
} }
impl Related<super::instance::Entity> for Entity {
fn to() -> RelationDef {
Relation::Instances.def()
}
}
impl Related<super::like::Entity> for Entity { impl Related<super::like::Entity> for Entity {
fn to() -> RelationDef { fn to() -> RelationDef {
Relation::Likes.def() Relation::Likes.def()