Skip to content

Commit

Permalink
Adding diesel table aliases, removing sql view hack. Fixes #2101
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines committed Sep 24, 2022
1 parent 8196981 commit 93ddc39
Show file tree
Hide file tree
Showing 25 changed files with 210 additions and 417 deletions.
102 changes: 0 additions & 102 deletions crates/db_schema/src/impls/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,108 +66,6 @@ mod safe_type {
}
}

mod safe_type_alias_1 {
use crate::{schema::person_alias_1::columns::*, source::person::PersonAlias1, traits::ToSafe};

type Columns = (
id,
name,
display_name,
avatar,
banned,
published,
updated,
actor_id,
bio,
local,
banner,
deleted,
inbox_url,
shared_inbox_url,
matrix_user_id,
admin,
bot_account,
ban_expires,
);

impl ToSafe for PersonAlias1 {
type SafeColumns = Columns;
fn safe_columns_tuple() -> Self::SafeColumns {
(
id,
name,
display_name,
avatar,
banned,
published,
updated,
actor_id,
bio,
local,
banner,
deleted,
inbox_url,
shared_inbox_url,
matrix_user_id,
admin,
bot_account,
ban_expires,
)
}
}
}

mod safe_type_alias_2 {
use crate::{schema::person_alias_2::columns::*, source::person::PersonAlias2, traits::ToSafe};

type Columns = (
id,
name,
display_name,
avatar,
banned,
published,
updated,
actor_id,
bio,
local,
banner,
deleted,
inbox_url,
shared_inbox_url,
matrix_user_id,
admin,
bot_account,
ban_expires,
);

impl ToSafe for PersonAlias2 {
type SafeColumns = Columns;
fn safe_columns_tuple() -> Self::SafeColumns {
(
id,
name,
display_name,
avatar,
banned,
published,
updated,
actor_id,
bio,
local,
banner,
deleted,
inbox_url,
shared_inbox_url,
matrix_user_id,
admin,
bot_account,
ban_expires,
)
}
}
}

impl Crud for Person {
type Form = PersonForm;
type IdType = PersonId;
Expand Down
66 changes: 0 additions & 66 deletions crates/db_schema/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,59 +531,6 @@ table! {
}
}

// These are necessary since diesel doesn't have self joins / aliases
table! {
person_alias_1 (id) {
id -> Int4,
name -> Varchar,
display_name -> Nullable<Varchar>,
avatar -> Nullable<Varchar>,
banned -> Bool,
published -> Timestamp,
updated -> Nullable<Timestamp>,
actor_id -> Varchar,
bio -> Nullable<Text>,
local -> Bool,
private_key -> Nullable<Text>,
public_key -> Text,
last_refreshed_at -> Timestamp,
banner -> Nullable<Varchar>,
deleted -> Bool,
inbox_url -> Varchar,
shared_inbox_url -> Nullable<Varchar>,
matrix_user_id -> Nullable<Text>,
admin -> Bool,
bot_account -> Bool,
ban_expires -> Nullable<Timestamp>,
}
}

table! {
person_alias_2 (id) {
id -> Int4,
name -> Varchar,
display_name -> Nullable<Varchar>,
avatar -> Nullable<Varchar>,
banned -> Bool,
published -> Timestamp,
updated -> Nullable<Timestamp>,
actor_id -> Varchar,
bio -> Nullable<Text>,
local -> Bool,
private_key -> Nullable<Text>,
public_key -> Text,
last_refreshed_at -> Timestamp,
banner -> Nullable<Varchar>,
deleted -> Bool,
inbox_url -> Varchar,
shared_inbox_url -> Nullable<Varchar>,
matrix_user_id -> Nullable<Text>,
admin -> Bool,
bot_account -> Bool,
ban_expires -> Nullable<Timestamp>,
}
}

table! {
secret(id) {
id -> Int4,
Expand Down Expand Up @@ -677,18 +624,7 @@ table! {
}
}

joinable!(person_mention -> person_alias_1 (recipient_id));
joinable!(comment_reply -> person_alias_1 (recipient_id));
joinable!(post -> person_alias_1 (creator_id));
joinable!(comment -> person_alias_1 (creator_id));
joinable!(private_message_report -> person_alias_1 (resolver_id));

joinable!(post_report -> person_alias_2 (resolver_id));
joinable!(comment_report -> person_alias_2 (resolver_id));
joinable!(private_message_report -> person_alias_2 (resolver_id));

joinable!(person_block -> person (person_id));
joinable!(person_block -> person_alias_1 (target_id));

joinable!(comment -> person (creator_id));
joinable!(comment -> post (post_id));
Expand Down Expand Up @@ -800,8 +736,6 @@ allow_tables_to_appear_in_same_query!(
private_message_report,
site,
site_aggregates,
person_alias_1,
person_alias_2,
admin_purge_comment,
admin_purge_community,
admin_purge_person,
Expand Down
104 changes: 1 addition & 103 deletions crates/db_schema/src/source/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::newtypes::{DbUrl, PersonId};
use serde::{Deserialize, Serialize};

#[cfg(feature = "full")]
use crate::schema::{person, person_alias_1, person_alias_2};
use crate::schema::person;

#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
Expand Down Expand Up @@ -56,108 +56,6 @@ pub struct PersonSafe {
pub ban_expires: Option<chrono::NaiveDateTime>,
}

#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", diesel(table_name = person_alias_1))]
pub struct PersonAlias1 {
pub id: PersonId,
pub name: String,
pub display_name: Option<String>,
pub avatar: Option<DbUrl>,
pub banned: bool,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub actor_id: DbUrl,
pub bio: Option<String>,
pub local: bool,
pub private_key: Option<String>,
pub public_key: String,
pub last_refreshed_at: chrono::NaiveDateTime,
pub banner: Option<DbUrl>,
pub deleted: bool,
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
pub admin: bool,
pub bot_account: bool,
pub ban_expires: Option<chrono::NaiveDateTime>,
}

#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", diesel(table_name = person_alias_1))]
pub struct PersonSafeAlias1 {
pub id: PersonId,
pub name: String,
pub display_name: Option<String>,
pub avatar: Option<DbUrl>,
pub banned: bool,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub actor_id: DbUrl,
pub bio: Option<String>,
pub local: bool,
pub banner: Option<DbUrl>,
pub deleted: bool,
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
pub admin: bool,
pub bot_account: bool,
pub ban_expires: Option<chrono::NaiveDateTime>,
}

#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", diesel(table_name = person_alias_2))]
pub struct PersonAlias2 {
pub id: PersonId,
pub name: String,
pub display_name: Option<String>,
pub avatar: Option<DbUrl>,
pub banned: bool,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub actor_id: DbUrl,
pub bio: Option<String>,
pub local: bool,
pub private_key: Option<String>,
pub public_key: String,
pub last_refreshed_at: chrono::NaiveDateTime,
pub banner: Option<DbUrl>,
pub deleted: bool,
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
pub admin: bool,
pub bot_account: bool,
pub ban_expires: Option<chrono::NaiveDateTime>,
}

#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", diesel(table_name = person_alias_1))]
pub struct PersonSafeAlias2 {
pub id: PersonId,
pub name: String,
pub display_name: Option<String>,
pub avatar: Option<DbUrl>,
pub banned: bool,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub actor_id: DbUrl,
pub bio: Option<String>,
pub local: bool,
pub banner: Option<DbUrl>,
pub deleted: bool,
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
pub admin: bool,
pub bot_account: bool,
pub ban_expires: Option<chrono::NaiveDateTime>,
}

#[derive(Clone, Default)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", diesel(table_name = person))]
Expand Down
Loading

0 comments on commit 93ddc39

Please sign in to comment.