Barazo AppView backend
barazo.forum
1import { pgTable, pgPolicy, text, timestamp, index, serial, integer, uniqueIndex } from 'drizzle-orm/pg-core'
2import { sql } from 'drizzle-orm'
3import { appRole } from './roles.js'
4
5export const accountFilters = pgTable(
6 'account_filters',
7 {
8 id: serial('id').primaryKey(),
9 did: text('did').notNull(),
10 communityDid: text('community_did').notNull(),
11 status: text('status', {
12 enum: ['active', 'warned', 'filtered'],
13 })
14 .notNull()
15 .default('active'),
16 reason: text('reason'),
17 reportCount: integer('report_count').notNull().default(0),
18 banCount: integer('ban_count').notNull().default(0),
19 lastReviewedAt: timestamp('last_reviewed_at', { withTimezone: true }),
20 filteredBy: text('filtered_by'),
21 createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
22 updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
23 },
24 (table) => [
25 uniqueIndex('account_filters_did_community_idx').on(table.did, table.communityDid),
26 index('account_filters_did_idx').on(table.did),
27 index('account_filters_community_did_idx').on(table.communityDid),
28 index('account_filters_status_idx').on(table.status),
29 index('account_filters_updated_at_idx').on(table.updatedAt),
30 pgPolicy('tenant_isolation', {
31 as: 'permissive',
32 to: appRole,
33 for: 'all',
34 using: sql`community_did = current_setting('app.current_community_did', true)`,
35 withCheck: sql`community_did = current_setting('app.current_community_did', true)`,
36 }),
37 ]
38).enableRLS()