Fixing TS issues.

This commit is contained in:
Dessalines 2024-12-08 09:27:29 -05:00
parent cf2b00e0ba
commit 58e62d55d9
3 changed files with 16 additions and 24 deletions

View file

@ -6,25 +6,20 @@ use chrono::{DateTime, Utc};
use i_love_jesus::CursorKeysModule; use i_love_jesus::CursorKeysModule;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")]
use ts_rs::TS;
#[skip_serializing_none] #[skip_serializing_none]
#[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)] #[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)]
#[cfg_attr( #[cfg_attr(
feature = "full", 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(table_name = person_content_combined))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] #[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))] #[cfg_attr(feature = "full", cursor_keys_module(name = person_content_combined_keys))]
/// A combined table for a persons contents (posts and comments) /// A combined table for a persons contents (posts and comments)
pub struct PersonContentCombined { pub struct PersonContentCombined {
pub id: PersonContentCombinedId, pub id: PersonContentCombinedId,
pub published: DateTime<Utc>, pub published: DateTime<Utc>,
#[cfg_attr(feature = "full", ts(optional))]
pub post_id: Option<PostId>, pub post_id: Option<PostId>,
#[cfg_attr(feature = "full", ts(optional))]
pub comment_id: Option<CommentId>, pub comment_id: Option<CommentId>,
} }

View file

@ -6,26 +6,21 @@ use chrono::{DateTime, Utc};
use i_love_jesus::CursorKeysModule; use i_love_jesus::CursorKeysModule;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")]
use ts_rs::TS;
#[skip_serializing_none] #[skip_serializing_none]
#[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)] #[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)]
#[cfg_attr( #[cfg_attr(
feature = "full", 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(table_name = person_saved_combined))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] #[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))] #[cfg_attr(feature = "full", cursor_keys_module(name = person_saved_combined_keys))]
/// A combined person_saved table. /// A combined person_saved table.
pub struct PersonSavedCombined { pub struct PersonSavedCombined {
pub id: PersonSavedCombinedId, pub id: PersonSavedCombinedId,
pub published: DateTime<Utc>, pub published: DateTime<Utc>,
pub person_id: PersonId, pub person_id: PersonId,
#[cfg_attr(feature = "full", ts(optional))]
pub post_id: Option<PostId>, pub post_id: Option<PostId>,
#[cfg_attr(feature = "full", ts(optional))]
pub comment_id: Option<CommentId>, pub comment_id: Option<CommentId>,
} }

View file

@ -7,7 +7,7 @@ CREATE TABLE person_content_combined (
post_id int UNIQUE REFERENCES post ON UPDATE CASCADE ON DELETE CASCADE, post_id int UNIQUE REFERENCES post ON UPDATE CASCADE ON DELETE CASCADE,
comment_id int UNIQUE REFERENCES COMMENT 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 -- 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); 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); CREATE INDEX idx_person_content_combined_published_asc ON person_content_combined (reverse_timestamp_sort (published) DESC, id DESC);
-- Updating the history -- Updating the history
INSERT INTO person_content_combined (published, post_id) INSERT INTO person_content_combined (published, post_id, comment_id)
SELECT SELECT
published, published,
id id,
NULL::int
FROM FROM
post; post
UNION ALL
INSERT INTO person_content_combined (published, comment_id)
SELECT SELECT
published, published,
NULL::int,
id id
FROM FROM
comment; comment;
@ -37,7 +38,7 @@ CREATE TABLE person_saved_combined (
post_id int UNIQUE REFERENCES post ON UPDATE CASCADE ON DELETE CASCADE, post_id int UNIQUE REFERENCES post ON UPDATE CASCADE ON DELETE CASCADE,
comment_id int UNIQUE REFERENCES COMMENT 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 -- 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); 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); CREATE INDEX idx_person_saved_combined ON person_saved_combined (person_id);
-- Updating the history -- 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 SELECT
saved, saved,
person_id, person_id,
post_id post_id,
NULL::int
FROM FROM
post_actions post_actions
WHERE WHERE
saved IS NOT NULL; saved IS NOT NULL
UNION ALL
INSERT INTO person_saved_combined (published, person_id, comment_id)
SELECT SELECT
saved, saved,
person_id, person_id,
NULL::int,
comment_id comment_id
FROM FROM
comment_actions comment_actions