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
- Rust 1.51+
- Postgresql
- PostgreSQL 10.2+
- IPFS 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 (
id INTEGER GENERATED BY DEFAULT AS IDENTITY,
source_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)

View file

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

View file

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