forked from paperclipai/paperclip
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin_company_settings.ts
More file actions
45 lines (44 loc) · 1.92 KB
/
Copy pathplugin_company_settings.ts
File metadata and controls
45 lines (44 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { pgTable, uuid, text, timestamp, jsonb, index, uniqueIndex, boolean } from "drizzle-orm/pg-core";
import { companies } from "./companies.js";
import { plugins } from "./plugins.js";
/**
* `plugin_company_settings` table — stores operator-managed plugin settings
* scoped to a specific company.
*
* This is distinct from `plugin_config`, which stores the plugin's declared
* operator configuration. Each company can have at most one settings row per
* plugin.
*
* Rows represent explicit overrides from the default company behavior:
* - no row => the plugin manifest's `companyEnablement.default` applies
* ("on" when the manifest omits it, i.e. enabled by default)
* - row with `enabled = false` => plugin is disabled for that company
* - row with `enabled = true` => plugin is enabled and stores company settings
*
* See server/src/services/plugin-company-enablement.ts for the evaluation.
*/
export const pluginCompanySettings = pgTable(
"plugin_company_settings",
{
id: uuid("id").primaryKey().defaultRandom(),
companyId: uuid("company_id")
.notNull()
.references(() => companies.id, { onDelete: "cascade" }),
pluginId: uuid("plugin_id")
.notNull()
.references(() => plugins.id, { onDelete: "cascade" }),
enabled: boolean("enabled").notNull().default(true),
settingsJson: jsonb("settings_json").$type<Record<string, unknown>>().notNull().default({}),
lastError: text("last_error"),
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
},
(table) => ({
companyIdx: index("plugin_company_settings_company_idx").on(table.companyId),
pluginIdx: index("plugin_company_settings_plugin_idx").on(table.pluginId),
companyPluginUq: uniqueIndex("plugin_company_settings_company_plugin_uq").on(
table.companyId,
table.pluginId,
),
}),
);