From 260781c6687a70653ae71d14208d0bb10adf27fb Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Tue, 18 Nov 2025 13:57:49 -0500 Subject: [PATCH] create leaflet_to_documents table --- drizzle/relations.ts | 24 ++++--- drizzle/schema.ts | 12 +++- supabase/database.types.ts | 39 ++++++++++++ ...251118185507_add_leaflets_to_documents.sql | 63 +++++++++++++++++++ 4 files changed, 128 insertions(+), 10 deletions(-) create mode 100644 supabase/migrations/20251118185507_add_leaflets_to_documents.sql diff --git a/drizzle/relations.ts b/drizzle/relations.ts index ee948385..1e08d4fe 100644 --- a/drizzle/relations.ts +++ b/drizzle/relations.ts @@ -1,19 +1,15 @@ import { relations } from "drizzle-orm/relations"; -import { identities, publications, documents, comments_on_documents, bsky_profiles, entity_sets, entities, facts, email_auth_tokens, poll_votes_on_entity, permission_tokens, phone_rsvps_to_entity, custom_domains, custom_domain_routes, email_subscriptions_to_entity, atp_poll_records, atp_poll_votes, bsky_follows, subscribers_to_publications, permission_token_on_homepage, documents_in_publications, document_mentions_in_bsky, bsky_posts, publication_domains, leaflets_in_publications, publication_subscriptions, permission_token_rights } from "./schema"; +import { identities, notifications, publications, documents, comments_on_documents, bsky_profiles, entity_sets, entities, facts, email_auth_tokens, poll_votes_on_entity, permission_tokens, phone_rsvps_to_entity, custom_domains, custom_domain_routes, email_subscriptions_to_entity, atp_poll_records, atp_poll_votes, bsky_follows, subscribers_to_publications, permission_token_on_homepage, documents_in_publications, document_mentions_in_bsky, bsky_posts, publication_domains, leaflets_in_publications, publication_subscriptions, permission_token_rights } from "./schema"; -export const publicationsRelations = relations(publications, ({one, many}) => ({ +export const notificationsRelations = relations(notifications, ({one}) => ({ identity: one(identities, { - fields: [publications.identity_did], + fields: [notifications.recipient], references: [identities.atp_did] }), - subscribers_to_publications: many(subscribers_to_publications), - documents_in_publications: many(documents_in_publications), - publication_domains: many(publication_domains), - leaflets_in_publications: many(leaflets_in_publications), - publication_subscriptions: many(publication_subscriptions), })); export const identitiesRelations = relations(identities, ({one, many}) => ({ + notifications: many(notifications), publications: many(publications), email_auth_tokens: many(email_auth_tokens), bsky_profiles: many(bsky_profiles), @@ -39,6 +35,18 @@ export const identitiesRelations = relations(identities, ({one, many}) => ({ publication_subscriptions: many(publication_subscriptions), })); +export const publicationsRelations = relations(publications, ({one, many}) => ({ + identity: one(identities, { + fields: [publications.identity_did], + references: [identities.atp_did] + }), + subscribers_to_publications: many(subscribers_to_publications), + documents_in_publications: many(documents_in_publications), + publication_domains: many(publication_domains), + leaflets_in_publications: many(leaflets_in_publications), + publication_subscriptions: many(publication_subscriptions), +})); + export const comments_on_documentsRelations = relations(comments_on_documents, ({one}) => ({ document: one(documents, { fields: [comments_on_documents.document], diff --git a/drizzle/schema.ts b/drizzle/schema.ts index 4745bf86..153b82e6 100644 --- a/drizzle/schema.ts +++ b/drizzle/schema.ts @@ -1,4 +1,4 @@ -import { pgTable, pgEnum, text, jsonb, index, foreignKey, timestamp, uuid, bigint, boolean, unique, uniqueIndex, smallint, primaryKey } from "drizzle-orm/pg-core" +import { pgTable, pgEnum, text, jsonb, foreignKey, timestamp, boolean, uuid, index, bigint, unique, uniqueIndex, smallint, primaryKey } from "drizzle-orm/pg-core" import { sql } from "drizzle-orm" export const aal_level = pgEnum("aal_level", ['aal1', 'aal2', 'aal3']) @@ -15,7 +15,7 @@ export const key_type = pgEnum("key_type", ['aead-ietf', 'aead-det', 'hmacsha512 export const rsvp_status = pgEnum("rsvp_status", ['GOING', 'NOT_GOING', 'MAYBE']) export const action = pgEnum("action", ['INSERT', 'UPDATE', 'DELETE', 'TRUNCATE', 'ERROR']) export const equality_op = pgEnum("equality_op", ['eq', 'neq', 'lt', 'lte', 'gt', 'gte', 'in']) -export const buckettype = pgEnum("buckettype", ['STANDARD', 'ANALYTICS']) +export const buckettype = pgEnum("buckettype", ['STANDARD', 'ANALYTICS', 'VECTOR']) export const oauth_state_store = pgTable("oauth_state_store", { @@ -23,6 +23,14 @@ export const oauth_state_store = pgTable("oauth_state_store", { state: jsonb("state").notNull(), }); +export const notifications = pgTable("notifications", { + recipient: text("recipient").notNull().references(() => identities.atp_did, { onDelete: "cascade", onUpdate: "cascade" } ), + created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), + read: boolean("read").default(false).notNull(), + data: jsonb("data").notNull(), + id: uuid("id").primaryKey().notNull(), +}); + export const publications = pgTable("publications", { uri: text("uri").primaryKey().notNull(), indexed_at: timestamp("indexed_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), diff --git a/supabase/database.types.ts b/supabase/database.types.ts index ae0c93b0..93efcbe3 100644 --- a/supabase/database.types.ts +++ b/supabase/database.types.ts @@ -624,6 +624,45 @@ export type Database = { }, ] } + leaflets_to_documents: { + Row: { + created_at: string + description: string + document: string + leaflet: string + title: string + } + Insert: { + created_at?: string + description?: string + document: string + leaflet: string + title?: string + } + Update: { + created_at?: string + description?: string + document?: string + leaflet?: string + title?: string + } + Relationships: [ + { + foreignKeyName: "leaflets_to_documents_document_fkey" + columns: ["document"] + isOneToOne: false + referencedRelation: "documents" + referencedColumns: ["uri"] + }, + { + foreignKeyName: "leaflets_to_documents_leaflet_fkey" + columns: ["leaflet"] + isOneToOne: false + referencedRelation: "permission_tokens" + referencedColumns: ["id"] + }, + ] + } notifications: { Row: { created_at: string diff --git a/supabase/migrations/20251118185507_add_leaflets_to_documents.sql b/supabase/migrations/20251118185507_add_leaflets_to_documents.sql new file mode 100644 index 00000000..f79aa7cd --- /dev/null +++ b/supabase/migrations/20251118185507_add_leaflets_to_documents.sql @@ -0,0 +1,63 @@ +create table "public"."leaflets_to_documents" ( + "leaflet" uuid not null, + "document" text not null, + "created_at" timestamp with time zone not null default now(), + "title" text not null default ''::text, + "description" text not null default ''::text +); + +alter table "public"."leaflets_to_documents" enable row level security; + +CREATE UNIQUE INDEX leaflets_to_documents_pkey ON public.leaflets_to_documents USING btree (leaflet, document); + +alter table "public"."leaflets_to_documents" add constraint "leaflets_to_documents_pkey" PRIMARY KEY using index "leaflets_to_documents_pkey"; + +alter table "public"."leaflets_to_documents" add constraint "leaflets_to_documents_document_fkey" FOREIGN KEY (document) REFERENCES documents(uri) ON UPDATE CASCADE ON DELETE CASCADE not valid; + +alter table "public"."leaflets_to_documents" validate constraint "leaflets_to_documents_document_fkey"; + +alter table "public"."leaflets_to_documents" add constraint "leaflets_to_documents_leaflet_fkey" FOREIGN KEY (leaflet) REFERENCES permission_tokens(id) ON UPDATE CASCADE ON DELETE CASCADE not valid; + +alter table "public"."leaflets_to_documents" validate constraint "leaflets_to_documents_leaflet_fkey"; + +grant delete on table "public"."leaflets_to_documents" to "anon"; + +grant insert on table "public"."leaflets_to_documents" to "anon"; + +grant references on table "public"."leaflets_to_documents" to "anon"; + +grant select on table "public"."leaflets_to_documents" to "anon"; + +grant trigger on table "public"."leaflets_to_documents" to "anon"; + +grant truncate on table "public"."leaflets_to_documents" to "anon"; + +grant update on table "public"."leaflets_to_documents" to "anon"; + +grant delete on table "public"."leaflets_to_documents" to "authenticated"; + +grant insert on table "public"."leaflets_to_documents" to "authenticated"; + +grant references on table "public"."leaflets_to_documents" to "authenticated"; + +grant select on table "public"."leaflets_to_documents" to "authenticated"; + +grant trigger on table "public"."leaflets_to_documents" to "authenticated"; + +grant truncate on table "public"."leaflets_to_documents" to "authenticated"; + +grant update on table "public"."leaflets_to_documents" to "authenticated"; + +grant delete on table "public"."leaflets_to_documents" to "service_role"; + +grant insert on table "public"."leaflets_to_documents" to "service_role"; + +grant references on table "public"."leaflets_to_documents" to "service_role"; + +grant select on table "public"."leaflets_to_documents" to "service_role"; + +grant trigger on table "public"."leaflets_to_documents" to "service_role"; + +grant truncate on table "public"."leaflets_to_documents" to "service_role"; + +grant update on table "public"."leaflets_to_documents" to "service_role"; -- 2.51.2