Barazo AppView backend
barazo.forum
1import { pgTable, pgPolicy, text, timestamp, index, serial } from 'drizzle-orm/pg-core'
2import { sql } from 'drizzle-orm'
3import { appRole } from './roles.js'
4
5export const modWarnings = pgTable(
6 'mod_warnings',
7 {
8 id: serial('id').primaryKey(),
9 communityDid: text('community_did').notNull(),
10 targetDid: text('target_did').notNull(),
11 moderatorDid: text('moderator_did').notNull(),
12 warningType: text('warning_type', {
13 enum: ['off_topic', 'harassment', 'rule_violation', 'other', 'custom'],
14 }).notNull(),
15 message: text('message').notNull(),
16 modComment: text('mod_comment'),
17 internalNote: text('internal_note'),
18 acknowledgedAt: timestamp('acknowledged_at', { withTimezone: true }),
19 createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
20 },
21 (table) => [
22 index('mod_warnings_community_did_idx').on(table.communityDid),
23 index('mod_warnings_target_did_idx').on(table.targetDid),
24 index('mod_warnings_moderator_did_idx').on(table.moderatorDid),
25 index('mod_warnings_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()