Barazo AppView backend barazo.forum
at main 34 lines 1.4 kB view raw
1import { pgTable, pgPolicy, text, timestamp, index, serial, check } from 'drizzle-orm/pg-core' 2import { sql } from 'drizzle-orm' 3import { appRole } from './roles.js' 4 5export const modNotes = pgTable( 6 'mod_notes', 7 { 8 id: serial('id').primaryKey(), 9 communityDid: text('community_did').notNull(), 10 authorDid: text('author_did').notNull(), 11 subjectDid: text('subject_did'), 12 subjectUri: text('subject_uri'), 13 content: text('content').notNull(), 14 noteType: text('note_type', { 15 enum: ['note', 'warning_context'], 16 }).notNull(), 17 createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(), 18 }, 19 (table) => [ 20 check('subject_check', sql`(subject_did IS NOT NULL AND subject_uri IS NULL) OR (subject_did IS NULL AND subject_uri IS NOT NULL)`), 21 index('mod_notes_community_did_idx').on(table.communityDid), 22 index('mod_notes_author_did_idx').on(table.authorDid), 23 index('mod_notes_subject_did_idx').on(table.subjectDid), 24 index('mod_notes_subject_uri_idx').on(table.subjectUri), 25 index('mod_notes_created_at_idx').on(table.createdAt), 26 pgPolicy('tenant_isolation', { 27 as: 'permissive', 28 to: appRole, 29 for: 'all', 30 using: sql`community_did = current_setting('app.current_community_did', true)`, 31 withCheck: sql`community_did = current_setting('app.current_community_did', true)`, 32 }), 33 ] 34).enableRLS()