diff --git a/drizzle/relations.ts b/drizzle/relations.ts index 273721d8..d0cd1c6c 100644 --- a/drizzle/relations.ts +++ b/drizzle/relations.ts @@ -1,5 +1,5 @@ import { relations } from "drizzle-orm/relations"; -import { identities, bsky_profiles, publications, documents, comments_on_documents, entities, facts, entity_sets, permission_tokens, email_subscriptions_to_entity, email_auth_tokens, custom_domains, phone_rsvps_to_entity, custom_domain_routes, poll_votes_on_entity, subscribers_to_publications, document_mentions_in_bsky, bsky_posts, permission_token_on_homepage, documents_in_publications, publication_domains, publication_subscriptions, leaflets_in_publications, permission_token_rights } from "./schema"; +import { identities, bsky_profiles, publications, documents, comments_on_documents, entities, facts, entity_sets, permission_tokens, email_subscriptions_to_entity, email_auth_tokens, custom_domains, phone_rsvps_to_entity, custom_domain_routes, poll_votes_on_entity, bsky_follows, subscribers_to_publications, document_mentions_in_bsky, bsky_posts, permission_token_on_homepage, documents_in_publications, publication_domains, publication_subscriptions, leaflets_in_publications, permission_token_rights } from "./schema"; export const bsky_profilesRelations = relations(bsky_profiles, ({one, many}) => ({ identity: one(identities, { @@ -23,6 +23,12 @@ export const identitiesRelations = relations(identities, ({one, many}) => ({ custom_domains_identity_id: many(custom_domains, { relationName: "custom_domains_identity_id_identities_id" }), + bsky_follows_follows: many(bsky_follows, { + relationName: "bsky_follows_follows_identities_atp_did" + }), + bsky_follows_identity: many(bsky_follows, { + relationName: "bsky_follows_identity_identities_atp_did" + }), subscribers_to_publications: many(subscribers_to_publications), permission_token_on_homepages: many(permission_token_on_homepage), publication_domains: many(publication_domains), @@ -176,6 +182,19 @@ export const poll_votes_on_entityRelations = relations(poll_votes_on_entity, ({o }), })); +export const bsky_followsRelations = relations(bsky_follows, ({one}) => ({ + identity_follows: one(identities, { + fields: [bsky_follows.follows], + references: [identities.atp_did], + relationName: "bsky_follows_follows_identities_atp_did" + }), + identity_identity: one(identities, { + fields: [bsky_follows.identity], + references: [identities.atp_did], + relationName: "bsky_follows_identity_identities_atp_did" + }), +})); + export const subscribers_to_publicationsRelations = relations(subscribers_to_publications, ({one}) => ({ identity: one(identities, { fields: [subscribers_to_publications.identity], diff --git a/drizzle/schema.ts b/drizzle/schema.ts index d4db5d5f..7bb2bd1f 100644 --- a/drizzle/schema.ts +++ b/drizzle/schema.ts @@ -184,6 +184,16 @@ export const poll_votes_on_entity = pgTable("poll_votes_on_entity", { voter_token: uuid("voter_token").notNull(), }); +export const bsky_follows = pgTable("bsky_follows", { + identity: text("identity").default('').notNull().references(() => identities.atp_did, { onDelete: "cascade" } ), + follows: text("follows").notNull().references(() => identities.atp_did, { onDelete: "cascade" } ), +}, +(table) => { + return { + bsky_follows_pkey: primaryKey({ columns: [table.identity, table.follows], name: "bsky_follows_pkey"}), + } +}); + export const subscribers_to_publications = pgTable("subscribers_to_publications", { identity: text("identity").notNull().references(() => identities.email, { onUpdate: "cascade" } ), publication: text("publication").notNull().references(() => publications.uri), diff --git a/supabase/database.types.ts b/supabase/database.types.ts index ebe24090..5847d1fe 100644 --- a/supabase/database.types.ts +++ b/supabase/database.types.ts @@ -34,6 +34,36 @@ export type Database = { } public: { Tables: { + bsky_follows: { + Row: { + follows: string + identity: string + } + Insert: { + follows: string + identity?: string + } + Update: { + follows?: string + identity?: string + } + Relationships: [ + { + foreignKeyName: "bsky_follows_follows_fkey" + columns: ["follows"] + isOneToOne: false + referencedRelation: "identities" + referencedColumns: ["atp_did"] + }, + { + foreignKeyName: "bsky_follows_identity_fkey" + columns: ["identity"] + isOneToOne: false + referencedRelation: "identities" + referencedColumns: ["atp_did"] + }, + ] + } bsky_posts: { Row: { cid: string diff --git a/supabase/migrations/20251014215602_add_bsky_follows_table.sql b/supabase/migrations/20251014215602_add_bsky_follows_table.sql new file mode 100644 index 00000000..ac54973c --- /dev/null +++ b/supabase/migrations/20251014215602_add_bsky_follows_table.sql @@ -0,0 +1,62 @@ +create table "public"."bsky_follows" ( + "identity" text not null, + "follows" text not null +); + +alter table "public"."bsky_follows" enable row level security; + +CREATE UNIQUE INDEX bsky_follows_pkey ON public.bsky_follows USING btree (identity, follows); + +CREATE INDEX facts_reference_idx ON public.facts USING btree (((data ->> 'value'::text))) WHERE (((data ->> 'type'::text) = 'reference'::text) OR ((data ->> 'type'::text) = 'ordered-reference'::text)); + +alter table "public"."bsky_follows" add constraint "bsky_follows_pkey" PRIMARY KEY using index "bsky_follows_pkey"; + +alter table "public"."bsky_follows" add constraint "bsky_follows_follows_fkey" FOREIGN KEY (follows) REFERENCES identities(atp_did) ON DELETE CASCADE not valid; + +alter table "public"."bsky_follows" validate constraint "bsky_follows_follows_fkey"; + +alter table "public"."bsky_follows" add constraint "bsky_follows_identity_fkey" FOREIGN KEY (identity) REFERENCES identities(atp_did) ON DELETE CASCADE not valid; + +alter table "public"."bsky_follows" validate constraint "bsky_follows_identity_fkey"; + +grant delete on table "public"."bsky_follows" to "anon"; + +grant insert on table "public"."bsky_follows" to "anon"; + +grant references on table "public"."bsky_follows" to "anon"; + +grant select on table "public"."bsky_follows" to "anon"; + +grant trigger on table "public"."bsky_follows" to "anon"; + +grant truncate on table "public"."bsky_follows" to "anon"; + +grant update on table "public"."bsky_follows" to "anon"; + +grant delete on table "public"."bsky_follows" to "authenticated"; + +grant insert on table "public"."bsky_follows" to "authenticated"; + +grant references on table "public"."bsky_follows" to "authenticated"; + +grant select on table "public"."bsky_follows" to "authenticated"; + +grant trigger on table "public"."bsky_follows" to "authenticated"; + +grant truncate on table "public"."bsky_follows" to "authenticated"; + +grant update on table "public"."bsky_follows" to "authenticated"; + +grant delete on table "public"."bsky_follows" to "service_role"; + +grant insert on table "public"."bsky_follows" to "service_role"; + +grant references on table "public"."bsky_follows" to "service_role"; + +grant select on table "public"."bsky_follows" to "service_role"; + +grant trigger on table "public"."bsky_follows" to "service_role"; + +grant truncate on table "public"."bsky_follows" to "service_role"; + +grant update on table "public"."bsky_follows" to "service_role";