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 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<Utc>,
#[cfg_attr(feature = "full", ts(optional))]
pub post_id: Option<PostId>,
#[cfg_attr(feature = "full", ts(optional))]
pub comment_id: Option<CommentId>,
}

View file

@ -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<Utc>,
pub person_id: PersonId,
#[cfg_attr(feature = "full", ts(optional))]
pub post_id: Option<PostId>,
#[cfg_attr(feature = "full", ts(optional))]
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,
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