Barazo AppView backend
barazo.forum
1import { pgTable, pgPolicy, text, timestamp, index, serial, integer } from 'drizzle-orm/pg-core'
2import { sql } from 'drizzle-orm'
3import { appRole } from './roles.js'
4
5export const communityRules = pgTable(
6 'community_rules',
7 {
8 id: serial('id').primaryKey(),
9 communityDid: text('community_did').notNull(),
10 title: text('title').notNull(),
11 description: text('description').notNull(),
12 displayOrder: integer('display_order').notNull(),
13 createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
14 updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
15 archivedAt: timestamp('archived_at', { withTimezone: true }),
16 },
17 (table) => [
18 index('community_rules_community_did_idx').on(table.communityDid),
19 index('community_rules_display_order_idx').on(table.displayOrder),
20 pgPolicy('tenant_isolation', {
21 as: 'permissive',
22 to: appRole,
23 for: 'all',
24 using: sql`community_did = current_setting('app.current_community_did', true)`,
25 withCheck: sql`community_did = current_setting('app.current_community_did', true)`,
26 }),
27 ]
28).enableRLS()