Barazo AppView backend barazo.forum
at main 81 lines 2.3 kB view raw
1import { 2 pgTable, 3 pgPolicy, 4 text, 5 boolean, 6 timestamp, 7 jsonb, 8 uuid, 9 unique, 10} from 'drizzle-orm/pg-core' 11import { sql } from 'drizzle-orm' 12import { appRole } from './roles.js' 13 14export const plugins = pgTable( 15 'plugins', 16 { 17 id: uuid('id').primaryKey().defaultRandom(), 18 name: text('name').unique().notNull(), 19 displayName: text('display_name').notNull(), 20 version: text('version').notNull(), 21 description: text('description').notNull(), 22 source: text('source', { 23 enum: ['core', 'official', 'community', 'experimental'], 24 }).notNull(), 25 category: text('category').notNull(), 26 enabled: boolean('enabled').notNull().default(false), 27 manifestJson: jsonb('manifest_json').notNull(), 28 installedAt: timestamp('installed_at', { withTimezone: true }).notNull().defaultNow(), 29 updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(), 30 }, 31 () => [ 32 pgPolicy('plugins_instance_wide', { 33 as: 'permissive', 34 to: appRole, 35 for: 'all', 36 using: sql`true`, 37 }), 38 ] 39).enableRLS() 40 41export const pluginSettings = pgTable( 42 'plugin_settings', 43 { 44 id: uuid('id').primaryKey().defaultRandom(), 45 pluginId: uuid('plugin_id') 46 .references(() => plugins.id, { onDelete: 'cascade' }) 47 .notNull(), 48 key: text('key').notNull(), 49 value: jsonb('value').notNull(), 50 }, 51 (table) => [ 52 unique('plugin_settings_plugin_id_key_unique').on(table.pluginId, table.key), 53 pgPolicy('plugin_settings_instance_wide', { 54 as: 'permissive', 55 to: appRole, 56 for: 'all', 57 using: sql`true`, 58 }), 59 ] 60).enableRLS() 61 62export const pluginPermissions = pgTable( 63 'plugin_permissions', 64 { 65 id: uuid('id').primaryKey().defaultRandom(), 66 pluginId: uuid('plugin_id') 67 .references(() => plugins.id, { onDelete: 'cascade' }) 68 .notNull(), 69 permission: text('permission').notNull(), 70 grantedAt: timestamp('granted_at', { withTimezone: true }).notNull().defaultNow(), 71 }, 72 (table) => [ 73 unique('plugin_permissions_plugin_id_permission_unique').on(table.pluginId, table.permission), 74 pgPolicy('plugin_permissions_instance_wide', { 75 as: 'permissive', 76 to: appRole, 77 for: 'all', 78 using: sql`true`, 79 }), 80 ] 81).enableRLS()