diff --git a/crates/db_schema/src/source/combined/person_content.rs b/crates/db_schema/src/source/combined/person_content.rs index c85b8f3b3..ed83401c0 100644 --- a/crates/db_schema/src/source/combined/person_content.rs +++ b/crates/db_schema/src/source/combined/person_content.rs @@ -6,25 +6,20 @@ use chrono::{DateTime, Utc}; use i_love_jesus::CursorKeysModule; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; -#[cfg(feature = "full")] -use ts_rs::TS; #[skip_serializing_none] #[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)] #[cfg_attr( feature = "full", - derive(Identifiable, Queryable, Selectable, TS, CursorKeysModule) + derive(Identifiable, Queryable, Selectable, CursorKeysModule) )] #[cfg_attr(feature = "full", diesel(table_name = person_content_combined))] #[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] -#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", cursor_keys_module(name = person_content_combined_keys))] /// A combined table for a persons contents (posts and comments) pub struct PersonContentCombined { pub id: PersonContentCombinedId, pub published: DateTime, - #[cfg_attr(feature = "full", ts(optional))] pub post_id: Option, - #[cfg_attr(feature = "full", ts(optional))] pub comment_id: Option, } diff --git a/crates/db_schema/src/source/combined/person_saved.rs b/crates/db_schema/src/source/combined/person_saved.rs index 298360a6d..afd91594d 100644 --- a/crates/db_schema/src/source/combined/person_saved.rs +++ b/crates/db_schema/src/source/combined/person_saved.rs @@ -6,26 +6,21 @@ use chrono::{DateTime, Utc}; use i_love_jesus::CursorKeysModule; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; -#[cfg(feature = "full")] -use ts_rs::TS; #[skip_serializing_none] #[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)] #[cfg_attr( feature = "full", - derive(Identifiable, Queryable, Selectable, TS, CursorKeysModule) + derive(Identifiable, Queryable, Selectable, CursorKeysModule) )] #[cfg_attr(feature = "full", diesel(table_name = person_saved_combined))] #[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] -#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", cursor_keys_module(name = person_saved_combined_keys))] /// A combined person_saved table. pub struct PersonSavedCombined { pub id: PersonSavedCombinedId, pub published: DateTime, pub person_id: PersonId, - #[cfg_attr(feature = "full", ts(optional))] pub post_id: Option, - #[cfg_attr(feature = "full", ts(optional))] pub comment_id: Option, } diff --git a/migrations/2024-12-05-233704_add_person_content_combined_table/up.sql b/migrations/2024-12-05-233704_add_person_content_combined_table/up.sql index a53f52925..cbef85ecc 100644 --- a/migrations/2024-12-05-233704_add_person_content_combined_table/up.sql +++ b/migrations/2024-12-05-233704_add_person_content_combined_table/up.sql @@ -7,7 +7,7 @@ CREATE TABLE person_content_combined ( post_id int UNIQUE REFERENCES post ON UPDATE CASCADE ON DELETE CASCADE, comment_id int UNIQUE REFERENCES COMMENT ON UPDATE CASCADE ON DELETE CASCADE, -- Make sure only one of the columns is not null - CHECK ((post_id IS NOT NULL)::integer + (comment_id IS NOT NULL)::integer = 1) + CHECK (num_nonnulls (post_id, comment_id) = 1) ); CREATE INDEX idx_person_content_combined_published ON person_content_combined (published DESC, id DESC); @@ -15,16 +15,17 @@ CREATE INDEX idx_person_content_combined_published ON person_content_combined (p CREATE INDEX idx_person_content_combined_published_asc ON person_content_combined (reverse_timestamp_sort (published) DESC, id DESC); -- Updating the history -INSERT INTO person_content_combined (published, post_id) +INSERT INTO person_content_combined (published, post_id, comment_id) SELECT published, - id + id, + NULL::int FROM - post; - -INSERT INTO person_content_combined (published, comment_id) + post +UNION ALL SELECT published, + NULL::int, id FROM comment; @@ -37,7 +38,7 @@ CREATE TABLE person_saved_combined ( post_id int UNIQUE REFERENCES post ON UPDATE CASCADE ON DELETE CASCADE, comment_id int UNIQUE REFERENCES COMMENT ON UPDATE CASCADE ON DELETE CASCADE, -- Make sure only one of the columns is not null - CHECK ((post_id IS NOT NULL)::integer + (comment_id IS NOT NULL)::integer = 1) + CHECK (num_nonnulls (post_id, comment_id) = 1) ); CREATE INDEX idx_person_saved_combined_published ON person_saved_combined (published DESC, id DESC); @@ -47,20 +48,21 @@ CREATE INDEX idx_person_saved_combined_published_asc ON person_saved_combined (r CREATE INDEX idx_person_saved_combined ON person_saved_combined (person_id); -- Updating the history -INSERT INTO person_saved_combined (published, person_id, post_id) +INSERT INTO person_saved_combined (published, person_id, post_id, comment_id) SELECT saved, person_id, - post_id + post_id, + NULL::int FROM post_actions WHERE - saved IS NOT NULL; - -INSERT INTO person_saved_combined (published, person_id, comment_id) + saved IS NOT NULL +UNION ALL SELECT saved, person_id, + NULL::int, comment_id FROM comment_actions