]> Untitled Git - lemmy.git/commitdiff
Removing community name unique constraint. Removing useless fedi_name column from...
authorDessalines <tyhou13@gmx.com>
Tue, 7 Apr 2020 14:54:15 +0000 (10:54 -0400)
committerDessalines <tyhou13@gmx.com>
Tue, 7 Apr 2020 14:54:15 +0000 (10:54 -0400)
18 files changed:
server/migrations/2020-04-07-135912_add_user_community_apub_constraints/down.sql [new file with mode: 0644]
server/migrations/2020-04-07-135912_add_user_community_apub_constraints/up.sql [new file with mode: 0644]
server/src/api/user.rs
server/src/apub/mod.rs
server/src/db/code_migrations.rs
server/src/db/comment.rs
server/src/db/comment_view.rs
server/src/db/community.rs
server/src/db/moderator.rs
server/src/db/password_reset_request.rs
server/src/db/post.rs
server/src/db/post_view.rs
server/src/db/private_message.rs
server/src/db/user.rs
server/src/db/user_mention.rs
server/src/db/user_view.rs
server/src/schema.rs
ui/src/interfaces.ts

diff --git a/server/migrations/2020-04-07-135912_add_user_community_apub_constraints/down.sql b/server/migrations/2020-04-07-135912_add_user_community_apub_constraints/down.sql
new file mode 100644 (file)
index 0000000..faf24fd
--- /dev/null
@@ -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);
diff --git a/server/migrations/2020-04-07-135912_add_user_community_apub_constraints/up.sql b/server/migrations/2020-04-07-135912_add_user_community_apub_constraints/up.sql
new file mode 100644 (file)
index 0000000..de65191
--- /dev/null
@@ -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);
+
index 629ce8e5a44fffb57e64f6f92e3453bcbb6bd2f6..dda1d9adeb33305d2d637a9786ac1be13d7d2284 100644 (file)
@@ -256,7 +256,6 @@ impl Perform<LoginResponse> for Oper<Register> {
     // 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,
@@ -404,7 +403,6 @@ impl Perform<LoginResponse> for Oper<SaveUserSettings> {
 
     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(),
index f2e5a56f3fe720808b7ee87f4f735c068493754f..fd5cd4c78ddf0675e38661279802c9dafda914e0 100644 (file)
@@ -34,10 +34,10 @@ pub enum EndpointType {
 //       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!(
index 2fdf03d5141fd12693b1ace3fdbe381f87338061..3575462efe7d7bd97077cd88a13b5a3a65b6939b 100644 (file)
@@ -33,7 +33,6 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), Error> {
 
     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(),
index 7550f072e30991fd6b7d9d6e572f4ab144c7c2da..4925aabcd0d46f66003cb399dc5e3c4dd31246b0 100644 (file)
@@ -207,7 +207,6 @@ mod tests {
 
     let new_user = UserForm {
       name: "terry".into(),
-      fedi_name: "rrf".into(),
       preferred_username: None,
       password_encrypted: "nope".into(),
       email: None,
index f0ca723180dd491bea34b971200950aefe0fc033..bbeeecdec16e8e0b66dfabe8a3c510b8b1cea4fd 100644 (file)
@@ -434,7 +434,6 @@ mod tests {
 
     let new_user = UserForm {
       name: "timmy".into(),
-      fedi_name: "rrf".into(),
       preferred_username: None,
       password_encrypted: "nope".into(),
       email: None,
index 08354d420a88b12c782c9ee98ddd2365767db7b4..15915715900be49b4de5cdff0a481744601131ec 100644 (file)
@@ -231,7 +231,6 @@ mod tests {
 
     let new_user = UserForm {
       name: "bobbee".into(),
-      fedi_name: "rrf".into(),
       preferred_username: None,
       password_encrypted: "nope".into(),
       email: None,
index 01acc25e5cf91c11954cea936e52bd5c2e856709..882621120a8ba88e912aecd1823e3d13329d369d 100644 (file)
@@ -438,7 +438,6 @@ mod tests {
 
     let new_mod = UserForm {
       name: "the mod".into(),
-      fedi_name: "rrf".into(),
       preferred_username: None,
       password_encrypted: "nope".into(),
       email: None,
@@ -466,7 +465,6 @@ mod tests {
 
     let new_user = UserForm {
       name: "jim2".into(),
-      fedi_name: "rrf".into(),
       preferred_username: None,
       password_encrypted: "nope".into(),
       email: None,
index c9d18e1cff8049767364655a4fdd94c0a542c4f7..ea8b2964a3bd2ce23c30c88445ebdd4fbabc9c07 100644 (file)
@@ -88,7 +88,6 @@ mod tests {
 
     let new_user = UserForm {
       name: "thommy prw".into(),
-      fedi_name: "rrf".into(),
       preferred_username: None,
       password_encrypted: "nope".into(),
       email: None,
index b0b9bddc06fd1b77535d3f2f7c584f7e45bd1d39..469fa81963935b26b2ea53238e869185b5065cc8 100644 (file)
@@ -240,7 +240,6 @@ mod tests {
 
     let new_user = UserForm {
       name: "jim".into(),
-      fedi_name: "rrf".into(),
       preferred_username: None,
       password_encrypted: "nope".into(),
       email: None,
index 29ff2f1bd2d8bed68ea9d9363acbf953739636ae..420e46df1a8e299efa15186ed334fe8ae19577b3 100644 (file)
@@ -359,7 +359,6 @@ mod tests {
 
     let new_user = UserForm {
       name: user_name.to_owned(),
-      fedi_name: "rrf".into(),
       preferred_username: None,
       password_encrypted: "nope".into(),
       email: None,
index 18ec4963b1fba778d348625175570130e062817e..63607547f72b720911aec5c98b05962da85f543d 100644 (file)
@@ -65,7 +65,6 @@ mod tests {
 
     let creator_form = UserForm {
       name: "creator_pm".into(),
-      fedi_name: "rrf".into(),
       preferred_username: None,
       password_encrypted: "nope".into(),
       email: None,
@@ -93,7 +92,6 @@ mod tests {
 
     let recipient_form = UserForm {
       name: "recipient_pm".into(),
-      fedi_name: "rrf".into(),
       preferred_username: None,
       password_encrypted: "nope".into(),
       email: None,
index 1669d722c63760e2b63f04bb4ee70d31ce270d88..7b10d874ab956c0661deb0b9d63f399f9e6c854a 100644 (file)
@@ -10,7 +10,6 @@ use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData,
 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>,
@@ -39,7 +38,6 @@ pub struct User_ {
 #[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,
@@ -157,7 +155,7 @@ impl User_ {
     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,
@@ -214,7 +212,6 @@ mod tests {
 
     let new_user = UserForm {
       name: "thommy".into(),
-      fedi_name: "rrf".into(),
       preferred_username: None,
       password_encrypted: "nope".into(),
       email: None,
@@ -243,7 +240,6 @@ mod tests {
     let expected_user = User_ {
       id: inserted_user.id,
       name: "thommy".into(),
-      fedi_name: "rrf".into(),
       preferred_username: None,
       password_encrypted: "nope".into(),
       email: None,
index 801df6fe322ef4a63c72fe885979836735401f6a..20eed23e4d875c03d2a484b4106e3746710b5958 100644 (file)
@@ -64,7 +64,6 @@ mod tests {
 
     let new_user = UserForm {
       name: "terrylake".into(),
-      fedi_name: "rrf".into(),
       preferred_username: None,
       password_encrypted: "nope".into(),
       email: None,
@@ -92,7 +91,6 @@ mod tests {
 
     let recipient_form = UserForm {
       name: "terrylakes recipient".into(),
-      fedi_name: "rrf".into(),
       preferred_username: None,
       password_encrypted: "nope".into(),
       email: None,
index 2274ecbdffd2950dbdb78486c7d030811ec932b5..efd84468577e166f844d850bb19c3eb41d8834b5 100644 (file)
@@ -9,7 +9,6 @@ table! {
     avatar -> Nullable<Text>,
     email -> Nullable<Text>,
     matrix_user_id -> Nullable<Text>,
-    fedi_name -> Varchar,
     admin -> Bool,
     banned -> Bool,
     show_avatars -> Bool,
@@ -29,7 +28,6 @@ table! {
     avatar -> Nullable<Text>,
     email -> Nullable<Text>,
     matrix_user_id -> Nullable<Text>,
-    fedi_name -> Varchar,
     admin -> Bool,
     banned -> Bool,
     show_avatars -> Bool,
@@ -52,7 +50,6 @@ pub struct UserView {
   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,
index 819fcd1c5ea15bbdfec83e0725508cae16d2e1a0..01c526c655463e96e4ceecafb3be950efeb97aa6 100644 (file)
@@ -293,7 +293,6 @@ table! {
   user_ (id) {
     id -> Int4,
     name -> Varchar,
-    fedi_name -> Varchar,
     preferred_username -> Nullable<Varchar>,
     password_encrypted -> Text,
     email -> Nullable<Text>,
index 0eeeac06d888f89f58fbf6a5c45f4d3dfdfa5618..283e1944f3a7a93ef4078382f9e11108252a7416 100644 (file)
@@ -102,7 +102,6 @@ export interface UserView {
   avatar?: string;
   email?: string;
   matrix_user_id?: string;
-  fedi_name: string;
   published: string;
   number_of_posts: number;
   post_score: number;