fix!: eh make it a string

it breaks object.ap() which is used a lot deep, i dont want to have to
deal with that now tbh
This commit is contained in:
əlemi 2024-05-29 04:33:19 +02:00
parent b89bb87c19
commit 2ca4bfedc4
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 11 additions and 8 deletions

View file

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

View file

@ -12,7 +12,7 @@ pub struct Model {
pub internal: i64,
#[sea_orm(unique)]
pub id: String,
pub instance: i64,
pub domain: String,
pub object_type: ObjectType,
pub attributed_to: Option<String>,
pub name: Option<String>,
@ -55,8 +55,8 @@ pub enum Relation {
Hashtags,
#[sea_orm(
belongs_to = "super::instance::Entity",
from = "Column::Instance",
to = "super::instance::Column::Internal",
from = "Column::Domain",
to = "super::instance::Column::Domain",
on_update = "Cascade",
on_delete = "NoAction"
)]
@ -160,9 +160,12 @@ impl Entity {
impl ActiveModel {
pub fn new(object: &impl apb::Object) -> Result<Self, super::FieldError> {
let ap_id = object.id().ok_or(super::FieldError("id"))?.to_string();
let domain = crate::server::Context::server(&ap_id);
Ok(ActiveModel {
internal: sea_orm::ActiveValue::NotSet,
id: sea_orm::ActiveValue::Set(object.id().ok_or(super::FieldError("id"))?.to_string()),
domain: sea_orm::ActiveValue::Set(domain),
id: sea_orm::ActiveValue::Set(ap_id),
object_type: sea_orm::ActiveValue::Set(object.object_type().ok_or(super::FieldError("type"))?),
attributed_to: sea_orm::ActiveValue::Set(object.attributed_to().id()),
name: sea_orm::ActiveValue::Set(object.name().map(|x| x.to_string())),