Removing community name unique constraint. Removing useless fedi_name column from user_table.

This commit is contained in:
Dessalines 2020-04-07 10:54:15 -04:00
parent 4fadc4d072
commit 56947e7710
18 changed files with 79 additions and 29 deletions

View file

@ -0,0 +1,36 @@
-- 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);

View file

@ -0,0 +1,38 @@
-- 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);

View file

@ -256,7 +256,6 @@ impl Perform<LoginResponse> for Oper<Register> {
// Register the new user // Register the new user
let user_form = UserForm { let user_form = UserForm {
name: data.username.to_owned(), name: data.username.to_owned(),
fedi_name: Settings::get().hostname.to_owned(),
email: data.email.to_owned(), email: data.email.to_owned(),
matrix_user_id: None, matrix_user_id: None,
avatar: None, avatar: None,
@ -404,7 +403,6 @@ impl Perform<LoginResponse> for Oper<SaveUserSettings> {
let user_form = UserForm { let user_form = UserForm {
name: read_user.name, name: read_user.name,
fedi_name: read_user.fedi_name,
email, email,
matrix_user_id: data.matrix_user_id.to_owned(), matrix_user_id: data.matrix_user_id.to_owned(),
avatar: data.avatar.to_owned(), avatar: data.avatar.to_owned(),

View file

@ -34,10 +34,10 @@ pub enum EndpointType {
// and have it fetch the object. // and have it fetch the object.
pub fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url { pub fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url {
let point = match endpoint_type { let point = match endpoint_type {
EndpointType::Community => "c", EndpointType::Community => "community",
EndpointType::User => "u", EndpointType::User => "user",
EndpointType::Post => "p", EndpointType::Post => "post",
EndpointType::Comment => todo!(), EndpointType::Comment => "comment",
}; };
Url::parse(&format!( Url::parse(&format!(

View file

@ -33,7 +33,6 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), Error> {
let form = UserForm { let form = UserForm {
name: cuser.name.to_owned(), name: cuser.name.to_owned(),
fedi_name: cuser.fedi_name.to_owned(),
email: cuser.email.to_owned(), email: cuser.email.to_owned(),
matrix_user_id: cuser.matrix_user_id.to_owned(), matrix_user_id: cuser.matrix_user_id.to_owned(),
avatar: cuser.avatar.to_owned(), avatar: cuser.avatar.to_owned(),

View file

@ -207,7 +207,6 @@ mod tests {
let new_user = UserForm { let new_user = UserForm {
name: "terry".into(), name: "terry".into(),
fedi_name: "rrf".into(),
preferred_username: None, preferred_username: None,
password_encrypted: "nope".into(), password_encrypted: "nope".into(),
email: None, email: None,

View file

@ -434,7 +434,6 @@ mod tests {
let new_user = UserForm { let new_user = UserForm {
name: "timmy".into(), name: "timmy".into(),
fedi_name: "rrf".into(),
preferred_username: None, preferred_username: None,
password_encrypted: "nope".into(), password_encrypted: "nope".into(),
email: None, email: None,

View file

@ -231,7 +231,6 @@ mod tests {
let new_user = UserForm { let new_user = UserForm {
name: "bobbee".into(), name: "bobbee".into(),
fedi_name: "rrf".into(),
preferred_username: None, preferred_username: None,
password_encrypted: "nope".into(), password_encrypted: "nope".into(),
email: None, email: None,

View file

@ -438,7 +438,6 @@ mod tests {
let new_mod = UserForm { let new_mod = UserForm {
name: "the mod".into(), name: "the mod".into(),
fedi_name: "rrf".into(),
preferred_username: None, preferred_username: None,
password_encrypted: "nope".into(), password_encrypted: "nope".into(),
email: None, email: None,
@ -466,7 +465,6 @@ mod tests {
let new_user = UserForm { let new_user = UserForm {
name: "jim2".into(), name: "jim2".into(),
fedi_name: "rrf".into(),
preferred_username: None, preferred_username: None,
password_encrypted: "nope".into(), password_encrypted: "nope".into(),
email: None, email: None,

View file

@ -88,7 +88,6 @@ mod tests {
let new_user = UserForm { let new_user = UserForm {
name: "thommy prw".into(), name: "thommy prw".into(),
fedi_name: "rrf".into(),
preferred_username: None, preferred_username: None,
password_encrypted: "nope".into(), password_encrypted: "nope".into(),
email: None, email: None,

View file

@ -240,7 +240,6 @@ mod tests {
let new_user = UserForm { let new_user = UserForm {
name: "jim".into(), name: "jim".into(),
fedi_name: "rrf".into(),
preferred_username: None, preferred_username: None,
password_encrypted: "nope".into(), password_encrypted: "nope".into(),
email: None, email: None,

View file

@ -359,7 +359,6 @@ mod tests {
let new_user = UserForm { let new_user = UserForm {
name: user_name.to_owned(), name: user_name.to_owned(),
fedi_name: "rrf".into(),
preferred_username: None, preferred_username: None,
password_encrypted: "nope".into(), password_encrypted: "nope".into(),
email: None, email: None,

View file

@ -65,7 +65,6 @@ mod tests {
let creator_form = UserForm { let creator_form = UserForm {
name: "creator_pm".into(), name: "creator_pm".into(),
fedi_name: "rrf".into(),
preferred_username: None, preferred_username: None,
password_encrypted: "nope".into(), password_encrypted: "nope".into(),
email: None, email: None,
@ -93,7 +92,6 @@ mod tests {
let recipient_form = UserForm { let recipient_form = UserForm {
name: "recipient_pm".into(), name: "recipient_pm".into(),
fedi_name: "rrf".into(),
preferred_username: None, preferred_username: None,
password_encrypted: "nope".into(), password_encrypted: "nope".into(),
email: None, email: None,

View file

@ -10,7 +10,6 @@ use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData,
pub struct User_ { pub struct User_ {
pub id: i32, pub id: i32,
pub name: String, pub name: String,
pub fedi_name: String,
pub preferred_username: Option<String>, pub preferred_username: Option<String>,
pub password_encrypted: String, pub password_encrypted: String,
pub email: Option<String>, pub email: Option<String>,
@ -39,7 +38,6 @@ pub struct User_ {
#[table_name = "user_"] #[table_name = "user_"]
pub struct UserForm { pub struct UserForm {
pub name: String, pub name: String,
pub fedi_name: String,
pub preferred_username: Option<String>, pub preferred_username: Option<String>,
pub password_encrypted: String, pub password_encrypted: String,
pub admin: bool, pub admin: bool,
@ -157,7 +155,7 @@ impl User_ {
let my_claims = Claims { let my_claims = Claims {
id: self.id, id: self.id,
username: self.name.to_owned(), username: self.name.to_owned(),
iss: self.fedi_name.to_owned(), iss: Settings::get().hostname.to_owned(),
show_nsfw: self.show_nsfw, show_nsfw: self.show_nsfw,
theme: self.theme.to_owned(), theme: self.theme.to_owned(),
default_sort_type: self.default_sort_type, default_sort_type: self.default_sort_type,
@ -214,7 +212,6 @@ mod tests {
let new_user = UserForm { let new_user = UserForm {
name: "thommy".into(), name: "thommy".into(),
fedi_name: "rrf".into(),
preferred_username: None, preferred_username: None,
password_encrypted: "nope".into(), password_encrypted: "nope".into(),
email: None, email: None,
@ -243,7 +240,6 @@ mod tests {
let expected_user = User_ { let expected_user = User_ {
id: inserted_user.id, id: inserted_user.id,
name: "thommy".into(), name: "thommy".into(),
fedi_name: "rrf".into(),
preferred_username: None, preferred_username: None,
password_encrypted: "nope".into(), password_encrypted: "nope".into(),
email: None, email: None,

View file

@ -64,7 +64,6 @@ mod tests {
let new_user = UserForm { let new_user = UserForm {
name: "terrylake".into(), name: "terrylake".into(),
fedi_name: "rrf".into(),
preferred_username: None, preferred_username: None,
password_encrypted: "nope".into(), password_encrypted: "nope".into(),
email: None, email: None,
@ -92,7 +91,6 @@ mod tests {
let recipient_form = UserForm { let recipient_form = UserForm {
name: "terrylakes recipient".into(), name: "terrylakes recipient".into(),
fedi_name: "rrf".into(),
preferred_username: None, preferred_username: None,
password_encrypted: "nope".into(), password_encrypted: "nope".into(),
email: None, email: None,

View file

@ -9,7 +9,6 @@ table! {
avatar -> Nullable<Text>, avatar -> Nullable<Text>,
email -> Nullable<Text>, email -> Nullable<Text>,
matrix_user_id -> Nullable<Text>, matrix_user_id -> Nullable<Text>,
fedi_name -> Varchar,
admin -> Bool, admin -> Bool,
banned -> Bool, banned -> Bool,
show_avatars -> Bool, show_avatars -> Bool,
@ -29,7 +28,6 @@ table! {
avatar -> Nullable<Text>, avatar -> Nullable<Text>,
email -> Nullable<Text>, email -> Nullable<Text>,
matrix_user_id -> Nullable<Text>, matrix_user_id -> Nullable<Text>,
fedi_name -> Varchar,
admin -> Bool, admin -> Bool,
banned -> Bool, banned -> Bool,
show_avatars -> Bool, show_avatars -> Bool,
@ -52,7 +50,6 @@ pub struct UserView {
pub avatar: Option<String>, pub avatar: Option<String>,
pub email: Option<String>, pub email: Option<String>,
pub matrix_user_id: Option<String>, pub matrix_user_id: Option<String>,
pub fedi_name: String,
pub admin: bool, pub admin: bool,
pub banned: bool, pub banned: bool,
pub show_avatars: bool, pub show_avatars: bool,

View file

@ -293,7 +293,6 @@ table! {
user_ (id) { user_ (id) {
id -> Int4, id -> Int4,
name -> Varchar, name -> Varchar,
fedi_name -> Varchar,
preferred_username -> Nullable<Varchar>, preferred_username -> Nullable<Varchar>,
password_encrypted -> Text, password_encrypted -> Text,
email -> Nullable<Text>, email -> Nullable<Text>,

View file

@ -102,7 +102,6 @@ export interface UserView {
avatar?: string; avatar?: string;
email?: string; email?: string;
matrix_user_id?: string; matrix_user_id?: string;
fedi_name: string;
published: string; published: string;
number_of_posts: number; number_of_posts: number;
post_score: number; post_score: number;