diff --git a/README.md b/README.md index 1068b6f..62d39ef 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/migrations/V0018__relationship__add_id.sql b/migrations/V0018__relationship__add_id.sql new file mode 100644 index 0000000..f5c427a --- /dev/null +++ b/migrations/V0018__relationship__add_id.sql @@ -0,0 +1 @@ +ALTER TABLE relationship ADD COLUMN id INTEGER GENERATED BY DEFAULT AS IDENTITY; diff --git a/migrations/schema.sql b/migrations/schema.sql index 7c6947e..03a2a96 100644 --- a/migrations/schema.sql +++ b/migrations/schema.sql @@ -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) diff --git a/src/models/relationships/queries.rs b/src/models/relationships/queries.rs index eb5bd64..9e965c2 100644 --- a/src/models/relationships/queries.rs +++ b/src/models/relationships/queries.rs @@ -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?; diff --git a/src/models/relationships/types.rs b/src/models/relationships/types.rs index 64dbfba..cf2d8d7 100644 --- a/src/models/relationships/types.rs +++ b/src/models/relationships/types.rs @@ -22,7 +22,7 @@ impl TryFrom<&Row> for Relationship { fn try_from(row: &Row) -> Result { 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")?,