Barazo AppView backend
barazo.forum
1import { pgTable, pgPolicy, text, boolean, timestamp, index, serial } from 'drizzle-orm/pg-core'
2import { sql } from 'drizzle-orm'
3import { appRole } from './roles.js'
4
5export const notifications = pgTable(
6 'notifications',
7 {
8 id: serial('id').primaryKey(),
9 recipientDid: text('recipient_did').notNull(),
10 type: text('type', {
11 enum: [
12 'reply',
13 'reaction',
14 'mention',
15 'mod_action',
16 'global_report',
17 'cross_post_failed',
18 'cross_post_revoked',
19 ],
20 }).notNull(),
21 subjectUri: text('subject_uri').notNull(),
22 actorDid: text('actor_did').notNull(),
23 communityDid: text('community_did').notNull(),
24 read: boolean('read').notNull().default(false),
25 createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
26 },
27 (table) => [
28 index('notifications_recipient_did_idx').on(table.recipientDid),
29 index('notifications_recipient_read_idx').on(table.recipientDid, table.read),
30 index('notifications_created_at_idx').on(table.createdAt),
31 pgPolicy('tenant_isolation', {
32 as: 'permissive',
33 to: appRole,
34 for: 'all',
35 using: sql`community_did = current_setting('app.current_community_did', true)`,
36 withCheck: sql`community_did = current_setting('app.current_community_did', true)`,
37 }),
38 ]
39).enableRLS()