--- /dev/null
+-- User table
+drop view user_view cascade;
+
+alter table user_
+add column fedi_name varchar(40) not null default 'changeme';
+
+alter table user_
+add constraint user__name_fedi_name_key unique (name, fedi_name);
+
+-- Community
+alter table community
+add constraint community_name_key unique (name);
+
+
+create view user_view as
+select
+u.id,
+u.name,
+u.avatar,
+u.email,
+u.matrix_user_id,
+u.fedi_name,
+u.admin,
+u.banned,
+u.show_avatars,
+u.send_notifications_to_email,
+u.published,
+(select count(*) from post p where p.creator_id = u.id) as number_of_posts,
+(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
+(select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
+(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
+from user_ u;
+
+create materialized view user_mview as select * from user_view;
+
+create unique index idx_user_mview_id on user_mview (id);
--- /dev/null
+-- User table
+
+-- Need to regenerate user_view, user_mview
+drop view user_view cascade;
+
+-- Remove the fedi_name constraint, drop that useless column
+alter table user_
+drop constraint user__name_fedi_name_key;
+
+alter table user_
+drop column fedi_name;
+
+-- Community
+alter table community
+drop constraint community_name_key;
+
+create view user_view as
+select
+u.id,
+u.name,
+u.avatar,
+u.email,
+u.matrix_user_id,
+u.admin,
+u.banned,
+u.show_avatars,
+u.send_notifications_to_email,
+u.published,
+(select count(*) from post p where p.creator_id = u.id) as number_of_posts,
+(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
+(select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
+(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
+from user_ u;
+
+create materialized view user_mview as select * from user_view;
+
+create unique index idx_user_mview_id on user_mview (id);
+
// Register the new user
let user_form = UserForm {
name: data.username.to_owned(),
- fedi_name: Settings::get().hostname.to_owned(),
email: data.email.to_owned(),
matrix_user_id: None,
avatar: None,
let user_form = UserForm {
name: read_user.name,
- fedi_name: read_user.fedi_name,
email,
matrix_user_id: data.matrix_user_id.to_owned(),
avatar: data.avatar.to_owned(),
// and have it fetch the object.
pub fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url {
let point = match endpoint_type {
- EndpointType::Community => "c",
- EndpointType::User => "u",
- EndpointType::Post => "p",
- EndpointType::Comment => todo!(),
+ EndpointType::Community => "community",
+ EndpointType::User => "user",
+ EndpointType::Post => "post",
+ EndpointType::Comment => "comment",
};
Url::parse(&format!(
let form = UserForm {
name: cuser.name.to_owned(),
- fedi_name: cuser.fedi_name.to_owned(),
email: cuser.email.to_owned(),
matrix_user_id: cuser.matrix_user_id.to_owned(),
avatar: cuser.avatar.to_owned(),
let new_user = UserForm {
name: "terry".into(),
- fedi_name: "rrf".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
let new_user = UserForm {
name: "timmy".into(),
- fedi_name: "rrf".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
let new_user = UserForm {
name: "bobbee".into(),
- fedi_name: "rrf".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
let new_mod = UserForm {
name: "the mod".into(),
- fedi_name: "rrf".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
let new_user = UserForm {
name: "jim2".into(),
- fedi_name: "rrf".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
let new_user = UserForm {
name: "thommy prw".into(),
- fedi_name: "rrf".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
let new_user = UserForm {
name: "jim".into(),
- fedi_name: "rrf".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
let new_user = UserForm {
name: user_name.to_owned(),
- fedi_name: "rrf".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
let creator_form = UserForm {
name: "creator_pm".into(),
- fedi_name: "rrf".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
let recipient_form = UserForm {
name: "recipient_pm".into(),
- fedi_name: "rrf".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
pub struct User_ {
pub id: i32,
pub name: String,
- pub fedi_name: String,
pub preferred_username: Option<String>,
pub password_encrypted: String,
pub email: Option<String>,
#[table_name = "user_"]
pub struct UserForm {
pub name: String,
- pub fedi_name: String,
pub preferred_username: Option<String>,
pub password_encrypted: String,
pub admin: bool,
let my_claims = Claims {
id: self.id,
username: self.name.to_owned(),
- iss: self.fedi_name.to_owned(),
+ iss: Settings::get().hostname.to_owned(),
show_nsfw: self.show_nsfw,
theme: self.theme.to_owned(),
default_sort_type: self.default_sort_type,
let new_user = UserForm {
name: "thommy".into(),
- fedi_name: "rrf".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
let expected_user = User_ {
id: inserted_user.id,
name: "thommy".into(),
- fedi_name: "rrf".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
let new_user = UserForm {
name: "terrylake".into(),
- fedi_name: "rrf".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
let recipient_form = UserForm {
name: "terrylakes recipient".into(),
- fedi_name: "rrf".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
avatar -> Nullable<Text>,
email -> Nullable<Text>,
matrix_user_id -> Nullable<Text>,
- fedi_name -> Varchar,
admin -> Bool,
banned -> Bool,
show_avatars -> Bool,
avatar -> Nullable<Text>,
email -> Nullable<Text>,
matrix_user_id -> Nullable<Text>,
- fedi_name -> Varchar,
admin -> Bool,
banned -> Bool,
show_avatars -> Bool,
pub avatar: Option<String>,
pub email: Option<String>,
pub matrix_user_id: Option<String>,
- pub fedi_name: String,
pub admin: bool,
pub banned: bool,
pub show_avatars: bool,
user_ (id) {
id -> Int4,
name -> Varchar,
- fedi_name -> Varchar,
preferred_username -> Nullable<Varchar>,
password_encrypted -> Text,
email -> Nullable<Text>,
avatar?: string;
email?: string;
matrix_user_id?: string;
- fedi_name: string;
published: string;
number_of_posts: number;
post_score: number;