Add ID column to relationship table

This commit is contained in:
silverpill 2022-01-02 13:38:40 +00:00
parent c11cd26961
commit 40958500c1
5 changed files with 7 additions and 4 deletions

View file

@ -20,7 +20,7 @@ Demo instance: https://mitra.social/ (invite-only)
## Requirements ## Requirements
- Rust 1.51+ - Rust 1.51+
- Postgresql - PostgreSQL 10.2+
- IPFS node (optional) - IPFS node (optional)
- Ethereum node (optional) - Ethereum node (optional)

View file

@ -0,0 +1 @@
ALTER TABLE relationship ADD COLUMN id INTEGER GENERATED BY DEFAULT AS IDENTITY;

View file

@ -57,6 +57,7 @@ CREATE TABLE post_reaction (
); );
CREATE TABLE relationship ( CREATE TABLE relationship (
id INTEGER GENERATED BY DEFAULT AS IDENTITY,
source_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE, source_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
target_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE, target_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
PRIMARY KEY (source_id, target_id) PRIMARY KEY (source_id, target_id)

View file

@ -26,7 +26,7 @@ pub async fn get_relationships(
let rows = db_client.query( let rows = db_client.query(
" "
SELECT SELECT
actor_profile.id, actor_profile.id AS profile_id,
EXISTS ( EXISTS (
SELECT 1 FROM relationship SELECT 1 FROM relationship
WHERE source_id = $1 AND target_id = actor_profile.id WHERE source_id = $1 AND target_id = actor_profile.id
@ -59,7 +59,7 @@ pub async fn get_relationship(
let maybe_row = db_client.query_opt( let maybe_row = db_client.query_opt(
" "
SELECT SELECT
actor_profile.id, actor_profile.id AS profile_id,
EXISTS ( EXISTS (
SELECT 1 FROM relationship SELECT 1 FROM relationship
WHERE source_id = $1 AND target_id = actor_profile.id WHERE source_id = $1 AND target_id = actor_profile.id
@ -250,6 +250,7 @@ pub async fn get_followers(
JOIN relationship JOIN relationship
ON (actor_profile.id = relationship.source_id) ON (actor_profile.id = relationship.source_id)
WHERE relationship.target_id = $1 WHERE relationship.target_id = $1
ORDER BY relationship.id DESC
", ",
&[&profile_id], &[&profile_id],
).await?; ).await?;

View file

@ -22,7 +22,7 @@ impl TryFrom<&Row> for Relationship {
fn try_from(row: &Row) -> Result<Self, Self::Error> { fn try_from(row: &Row) -> Result<Self, Self::Error> {
let relationship = Relationship { let relationship = Relationship {
id: row.try_get("id")?, id: row.try_get("profile_id")?,
following: row.try_get("following")?, following: row.try_get("following")?,
followed_by: row.try_get("followed_by")?, followed_by: row.try_get("followed_by")?,
requested: row.try_get("requested")?, requested: row.try_get("requested")?,