mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
feat(db): expose channel community lookup
Co-authored-by: npub1jh9wn95s0472h86ahapupaf7m6kx4v9sx2n0atj2hltcfer8k06s5n3pyf <95cae996907d7cab9f5dbf43c0f53edeac6ab0b032a6feae4abfd784e467b3f5@sprout-oss.stage.blox.sqprod.co> Signed-off-by: npub1jh9wn95s0472h86ahapupaf7m6kx4v9sx2n0atj2hltcfer8k06s5n3pyf <95cae996907d7cab9f5dbf43c0f53edeac6ab0b032a6feae4abfd784e467b3f5@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
parent
1adbfbe210
commit
48bc606abf
@@ -286,6 +286,30 @@ impl Db {
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the community that owns a channel, if the channel exists.
|
||||
///
|
||||
/// Internal relay producers use this to derive tenant context from the row
|
||||
/// they are acting on, rather than falling back to an implicit default.
|
||||
pub async fn community_of_channel(&self, channel_id: Uuid) -> Result<Option<CommunityId>> {
|
||||
let row = sqlx::query(
|
||||
r#"
|
||||
SELECT community_id
|
||||
FROM channels
|
||||
WHERE id = $1
|
||||
AND deleted_at IS NULL
|
||||
"#,
|
||||
)
|
||||
.bind(channel_id)
|
||||
.fetch_optional(&self.pool)
|
||||
.await?;
|
||||
|
||||
row.map(|row| {
|
||||
let id: Uuid = row.try_get("community_id")?;
|
||||
Ok(CommunityId::from_uuid(id))
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
|
||||
/// Inserts an event. Returns `(StoredEvent, was_inserted)` — `false` on duplicate.
|
||||
pub async fn insert_event(
|
||||
&self,
|
||||
|
||||
@@ -32,6 +32,7 @@ CREATE TABLE communities (
|
||||
|
||||
CREATE TABLE channels (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
community_id UUID NOT NULL REFERENCES communities(id),
|
||||
name VARCHAR(255) NOT NULL,
|
||||
channel_type channel_type NOT NULL DEFAULT 'stream',
|
||||
visibility channel_visibility NOT NULL DEFAULT 'open',
|
||||
|
||||
@@ -33,6 +33,7 @@ CREATE TABLE communities (
|
||||
|
||||
CREATE TABLE channels (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
community_id UUID NOT NULL REFERENCES communities(id),
|
||||
name VARCHAR(255) NOT NULL,
|
||||
channel_type channel_type NOT NULL DEFAULT 'stream',
|
||||
visibility channel_visibility NOT NULL DEFAULT 'open',
|
||||
|
||||
Reference in New Issue
Block a user