+16
-8
drizzle/relations.ts
+16
-8
drizzle/relations.ts
···
1
1
import { relations } from "drizzle-orm/relations";
2
-
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";
2
+
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";
3
3
4
-
export const publicationsRelations = relations(publications, ({one, many}) => ({
4
+
export const notificationsRelations = relations(notifications, ({one}) => ({
5
5
identity: one(identities, {
6
-
fields: [publications.identity_did],
6
+
fields: [notifications.recipient],
7
7
references: [identities.atp_did]
8
8
}),
9
-
subscribers_to_publications: many(subscribers_to_publications),
10
-
documents_in_publications: many(documents_in_publications),
11
-
publication_domains: many(publication_domains),
12
-
leaflets_in_publications: many(leaflets_in_publications),
13
-
publication_subscriptions: many(publication_subscriptions),
14
9
}));
15
10
16
11
export const identitiesRelations = relations(identities, ({one, many}) => ({
12
+
notifications: many(notifications),
17
13
publications: many(publications),
18
14
email_auth_tokens: many(email_auth_tokens),
19
15
bsky_profiles: many(bsky_profiles),
···
36
32
subscribers_to_publications: many(subscribers_to_publications),
37
33
permission_token_on_homepages: many(permission_token_on_homepage),
38
34
publication_domains: many(publication_domains),
35
+
publication_subscriptions: many(publication_subscriptions),
36
+
}));
37
+
38
+
export const publicationsRelations = relations(publications, ({one, many}) => ({
39
+
identity: one(identities, {
40
+
fields: [publications.identity_did],
41
+
references: [identities.atp_did]
42
+
}),
43
+
subscribers_to_publications: many(subscribers_to_publications),
44
+
documents_in_publications: many(documents_in_publications),
45
+
publication_domains: many(publication_domains),
46
+
leaflets_in_publications: many(leaflets_in_publications),
39
47
publication_subscriptions: many(publication_subscriptions),
40
48
}));
41
49
+10
-2
drizzle/schema.ts
+10
-2
drizzle/schema.ts
···
1
-
import { pgTable, pgEnum, text, jsonb, index, foreignKey, timestamp, uuid, bigint, boolean, unique, uniqueIndex, smallint, primaryKey } from "drizzle-orm/pg-core"
1
+
import { pgTable, pgEnum, text, jsonb, foreignKey, timestamp, boolean, uuid, index, bigint, unique, uniqueIndex, smallint, primaryKey } from "drizzle-orm/pg-core"
2
2
import { sql } from "drizzle-orm"
3
3
4
4
export const aal_level = pgEnum("aal_level", ['aal1', 'aal2', 'aal3'])
···
15
15
export const rsvp_status = pgEnum("rsvp_status", ['GOING', 'NOT_GOING', 'MAYBE'])
16
16
export const action = pgEnum("action", ['INSERT', 'UPDATE', 'DELETE', 'TRUNCATE', 'ERROR'])
17
17
export const equality_op = pgEnum("equality_op", ['eq', 'neq', 'lt', 'lte', 'gt', 'gte', 'in'])
18
-
export const buckettype = pgEnum("buckettype", ['STANDARD', 'ANALYTICS'])
18
+
export const buckettype = pgEnum("buckettype", ['STANDARD', 'ANALYTICS', 'VECTOR'])
19
19
20
20
21
21
export const oauth_state_store = pgTable("oauth_state_store", {
22
22
key: text("key").primaryKey().notNull(),
23
23
state: jsonb("state").notNull(),
24
+
});
25
+
26
+
export const notifications = pgTable("notifications", {
27
+
recipient: text("recipient").notNull().references(() => identities.atp_did, { onDelete: "cascade", onUpdate: "cascade" } ),
28
+
created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(),
29
+
read: boolean("read").default(false).notNull(),
30
+
data: jsonb("data").notNull(),
31
+
id: uuid("id").primaryKey().notNull(),
24
32
});
25
33
26
34
export const publications = pgTable("publications", {
+39
supabase/database.types.ts
+39
supabase/database.types.ts
···
624
624
},
625
625
]
626
626
}
627
+
leaflets_to_documents: {
628
+
Row: {
629
+
created_at: string
630
+
description: string
631
+
document: string
632
+
leaflet: string
633
+
title: string
634
+
}
635
+
Insert: {
636
+
created_at?: string
637
+
description?: string
638
+
document: string
639
+
leaflet: string
640
+
title?: string
641
+
}
642
+
Update: {
643
+
created_at?: string
644
+
description?: string
645
+
document?: string
646
+
leaflet?: string
647
+
title?: string
648
+
}
649
+
Relationships: [
650
+
{
651
+
foreignKeyName: "leaflets_to_documents_document_fkey"
652
+
columns: ["document"]
653
+
isOneToOne: false
654
+
referencedRelation: "documents"
655
+
referencedColumns: ["uri"]
656
+
},
657
+
{
658
+
foreignKeyName: "leaflets_to_documents_leaflet_fkey"
659
+
columns: ["leaflet"]
660
+
isOneToOne: false
661
+
referencedRelation: "permission_tokens"
662
+
referencedColumns: ["id"]
663
+
},
664
+
]
665
+
}
627
666
notifications: {
628
667
Row: {
629
668
created_at: string
+63
supabase/migrations/20251118185507_add_leaflets_to_documents.sql
+63
supabase/migrations/20251118185507_add_leaflets_to_documents.sql
···
1
+
create table "public"."leaflets_to_documents" (
2
+
"leaflet" uuid not null,
3
+
"document" text not null,
4
+
"created_at" timestamp with time zone not null default now(),
5
+
"title" text not null default ''::text,
6
+
"description" text not null default ''::text
7
+
);
8
+
9
+
alter table "public"."leaflets_to_documents" enable row level security;
10
+
11
+
CREATE UNIQUE INDEX leaflets_to_documents_pkey ON public.leaflets_to_documents USING btree (leaflet, document);
12
+
13
+
alter table "public"."leaflets_to_documents" add constraint "leaflets_to_documents_pkey" PRIMARY KEY using index "leaflets_to_documents_pkey";
14
+
15
+
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;
16
+
17
+
alter table "public"."leaflets_to_documents" validate constraint "leaflets_to_documents_document_fkey";
18
+
19
+
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;
20
+
21
+
alter table "public"."leaflets_to_documents" validate constraint "leaflets_to_documents_leaflet_fkey";
22
+
23
+
grant delete on table "public"."leaflets_to_documents" to "anon";
24
+
25
+
grant insert on table "public"."leaflets_to_documents" to "anon";
26
+
27
+
grant references on table "public"."leaflets_to_documents" to "anon";
28
+
29
+
grant select on table "public"."leaflets_to_documents" to "anon";
30
+
31
+
grant trigger on table "public"."leaflets_to_documents" to "anon";
32
+
33
+
grant truncate on table "public"."leaflets_to_documents" to "anon";
34
+
35
+
grant update on table "public"."leaflets_to_documents" to "anon";
36
+
37
+
grant delete on table "public"."leaflets_to_documents" to "authenticated";
38
+
39
+
grant insert on table "public"."leaflets_to_documents" to "authenticated";
40
+
41
+
grant references on table "public"."leaflets_to_documents" to "authenticated";
42
+
43
+
grant select on table "public"."leaflets_to_documents" to "authenticated";
44
+
45
+
grant trigger on table "public"."leaflets_to_documents" to "authenticated";
46
+
47
+
grant truncate on table "public"."leaflets_to_documents" to "authenticated";
48
+
49
+
grant update on table "public"."leaflets_to_documents" to "authenticated";
50
+
51
+
grant delete on table "public"."leaflets_to_documents" to "service_role";
52
+
53
+
grant insert on table "public"."leaflets_to_documents" to "service_role";
54
+
55
+
grant references on table "public"."leaflets_to_documents" to "service_role";
56
+
57
+
grant select on table "public"."leaflets_to_documents" to "service_role";
58
+
59
+
grant trigger on table "public"."leaflets_to_documents" to "service_role";
60
+
61
+
grant truncate on table "public"."leaflets_to_documents" to "service_role";
62
+
63
+
grant update on table "public"."leaflets_to_documents" to "service_role";