Barazo AppView backend barazo.forum
at main 56 lines 2.1 kB view raw
1import { pgTable, pgPolicy, text, timestamp, index, serial, uniqueIndex } from 'drizzle-orm/pg-core' 2import { sql } from 'drizzle-orm' 3import { appRole } from './roles.js' 4 5export const reports = pgTable( 6 'reports', 7 { 8 id: serial('id').primaryKey(), 9 reporterDid: text('reporter_did').notNull(), 10 targetUri: text('target_uri').notNull(), 11 targetDid: text('target_did').notNull(), 12 reasonType: text('reason_type', { 13 enum: ['spam', 'sexual', 'harassment', 'violation', 'misleading', 'other'], 14 }).notNull(), 15 description: text('description'), 16 communityDid: text('community_did').notNull(), 17 status: text('status', { 18 enum: ['pending', 'resolved'], 19 }) 20 .notNull() 21 .default('pending'), 22 resolutionType: text('resolution_type', { 23 enum: ['dismissed', 'warned', 'labeled', 'removed', 'banned'], 24 }), 25 resolvedBy: text('resolved_by'), 26 resolvedAt: timestamp('resolved_at', { withTimezone: true }), 27 appealReason: text('appeal_reason'), 28 appealedAt: timestamp('appealed_at', { withTimezone: true }), 29 appealStatus: text('appeal_status', { 30 enum: ['none', 'pending', 'rejected'], 31 }) 32 .notNull() 33 .default('none'), 34 createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(), 35 }, 36 (table) => [ 37 index('reports_reporter_did_idx').on(table.reporterDid), 38 index('reports_target_uri_idx').on(table.targetUri), 39 index('reports_target_did_idx').on(table.targetDid), 40 index('reports_community_did_idx').on(table.communityDid), 41 index('reports_status_idx').on(table.status), 42 index('reports_created_at_idx').on(table.createdAt), 43 uniqueIndex('reports_unique_reporter_target_idx').on( 44 table.reporterDid, 45 table.targetUri, 46 table.communityDid 47 ), 48 pgPolicy('tenant_isolation', { 49 as: 'permissive', 50 to: appRole, 51 for: 'all', 52 using: sql`community_did = current_setting('app.current_community_did', true)`, 53 withCheck: sql`community_did = current_setting('app.current_community_did', true)`, 54 }), 55 ] 56).enableRLS()