diff --git a/crates/db_schema/replaceable_schema/triggers.sql b/crates/db_schema/replaceable_schema/triggers.sql index df86f11e5..77d368287 100644 --- a/crates/db_schema/replaceable_schema/triggers.sql +++ b/crates/db_schema/replaceable_schema/triggers.sql @@ -731,12 +731,12 @@ BEGIN AND p.thing_id = OLD.thing_id; ELSIF (TG_OP = 'INSERT') THEN IF NEW.saved IS NOT NULL THEN - INSERT INTO person_saved_combined (published, person_id, thing_id) + INSERT INTO person_saved_combined (saved, person_id, thing_id) VALUES (NEW.saved, NEW.person_id, NEW.thing_id); END IF; ELSIF (TG_OP = 'UPDATE') THEN IF NEW.saved IS NOT NULL THEN - INSERT INTO person_saved_combined (published, person_id, thing_id) + INSERT INTO person_saved_combined (saved, person_id, thing_id) VALUES (NEW.saved, NEW.person_id, NEW.thing_id); -- If saved gets set as null, delete the row ELSE diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 44f2ab03c..7bdeeb6f2 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -751,7 +751,7 @@ diesel::table! { diesel::table! { person_saved_combined (id) { id -> Int4, - published -> Timestamptz, + saved -> Timestamptz, person_id -> Int4, post_id -> Nullable, comment_id -> Nullable, diff --git a/crates/db_schema/src/source/combined/person_saved.rs b/crates/db_schema/src/source/combined/person_saved.rs index 4b0e80ea9..bee11e8b8 100644 --- a/crates/db_schema/src/source/combined/person_saved.rs +++ b/crates/db_schema/src/source/combined/person_saved.rs @@ -16,7 +16,7 @@ use i_love_jesus::CursorKeysModule; /// A combined person_saved table. pub struct PersonSavedCombined { pub id: PersonSavedCombinedId, - pub published: DateTime, + pub saved: DateTime, pub person_id: PersonId, pub post_id: Option, pub comment_id: Option, diff --git a/crates/db_views/src/person_saved_combined_view.rs b/crates/db_views/src/person_saved_combined_view.rs index 94b93e9d8..cb6eef3e7 100644 --- a/crates/db_views/src/person_saved_combined_view.rs +++ b/crates/db_views/src/person_saved_combined_view.rs @@ -220,9 +220,9 @@ impl PersonSavedCombinedQuery { query = query.after(page_after); } - // Sorting by published + // Sorting by saved desc query = query - .then_desc(key::published) + .then_desc(key::saved) // Tie breaker .then_desc(key::id); 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 973535b89..805d2ca94 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 @@ -31,7 +31,7 @@ FROM -- This one is special, because you use the saved date, not the ordinary published CREATE TABLE person_saved_combined ( id serial PRIMARY KEY, - published timestamptz NOT NULL, + saved timestamptz NOT NULL, person_id int NOT NULL REFERENCES person 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, @@ -39,12 +39,12 @@ CREATE TABLE person_saved_combined ( 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 (saved DESC, id DESC); 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, comment_id) +INSERT INTO person_saved_combined (saved, person_id, post_id, comment_id) SELECT saved, person_id,