Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: add database tables for integrations

Brad Barbincf4dcd9879b6
diff --git a/apps/carbon/app/styles/background.css b/apps/carbon/app/styles/background.css
index c73eec8210..d20e255a63 100644
--- a/apps/carbon/app/styles/background.css
+++ b/apps/carbon/app/styles/background.css
@@ -32,7 +32,7 @@
.background:after {
content: "";
- background-image: url("/static/grid.svg");
+ background-image: url("/grid.svg");
z-index: 1;
position: absolute;
width: 100%;
diff --git a/apps/carbon/public/static/grid.svg b/apps/carbon/public/grid.svg
similarity index 100%
rename from apps/carbon/public/static/grid.svg
rename to apps/carbon/public/grid.svg
diff --git a/packages/database/SCHEMA.md b/packages/database/SCHEMA.md
index b340fd0134..ada67328b8 100644
--- a/packages/database/SCHEMA.md
+++ b/packages/database/SCHEMA.md
@@ -1623,7 +1623,7 @@ CREATE POLICY "Customers with sales_view can view contacts from their organizati
)
);
-CREATE POLICY "Many employees can create contact" ON "contact"
+CREATE POLICY "Many employees can create contacts" ON "contact"
FOR INSERT
WITH CHECK (
(
@@ -7415,3 +7415,59 @@ CREATE POLICY "Authenticated users can read currencyExchangeRate" ON "currencyEx
FOR SELECT USING (auth.role() = 'authenticated');
```
+
+
+## `integrations`
+
+```sql
+-- Enable the "pg_jsonschema" extension
+CREATE EXTENSION pg_jsonschema WITH SCHEMA extensions;
+
+CREATE TABLE integration (
+ "name" TEXT NOT NULL,
+ "active" BOOLEAN NOT NULL DEFAULT FALSE,
+ "visible" BOOLEAN NOT NULL DEFAULT TRUE,
+ "jsonschema" JSON NOT NULL,
+ "metadata" JSON NOT NULL DEFAULT '{}',
+ "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
+ "updatedBy" TEXT,
+
+ CONSTRAINT integration_pkey PRIMARY KEY ("name"),
+ CHECK (
+ active = false OR
+ json_matches_schema(jsonschema, metadata)
+ ),
+ CONSTRAINT "integration_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id") ON UPDATE CASCADE
+);
+
+CREATE POLICY "Employees with settings_view can view integrations." ON "integration"
+ FOR SELECT USING (
+ coalesce(get_my_claim('settings_view')::boolean,false) AND
+ (get_my_claim('role'::text)) = '"employee"'::jsonb
+ );
+
+CREATE POLICY "Employees with settings_update can update integrations." ON "integration"
+ FOR UPDATE
+ USING (
+ coalesce(get_my_claim('settings_update')::boolean,false) AND
+ (get_my_claim('role'::text)) = '"employee"'::jsonb
+ );
+
+INSERT INTO "integration" ("name", "jsonschema")
+VALUES (
+ 'exchangeRatesV1',
+ '{
+ "type": "object",
+ "properties": {
+ "apiKey": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "apiKey"
+ ]
+ }'::json);
+
+
+```
+
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 9e1dd60ef4..8186d793d7 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -3189,6 +3189,55 @@ export interface Database {
}
];
};
+ integration: {
+ Row: {
+ active: boolean;
+ jsonschema: Json;
+ metadata: Json;
+ name: string;
+ updatedAt: string;
+ updatedBy: string | null;
+ visible: boolean;
+ };
+ Insert: {
+ active?: boolean;
+ jsonschema: Json;
+ metadata?: Json;
+ name: string;
+ updatedAt?: string;
+ updatedBy?: string | null;
+ visible?: boolean;
+ };
+ Update: {
+ active?: boolean;
+ jsonschema?: Json;
+ metadata?: Json;
+ name?: string;
+ updatedAt?: string;
+ updatedBy?: string | null;
+ visible?: boolean;
+ };
+ Relationships: [
+ {
+ foreignKeyName: "integration_updatedBy_fkey";
+ columns: ["updatedBy"];
+ referencedRelation: "user";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "integration_updatedBy_fkey";
+ columns: ["updatedBy"];
+ referencedRelation: "employeeSummary";
+ referencedColumns: ["id"];
+ },
+ {
+ foreignKeyName: "integration_updatedBy_fkey";
+ columns: ["updatedBy"];
+ referencedRelation: "userDefaults";
+ referencedColumns: ["userId"];
+ }
+ ];
+ };
journal: {
Row: {
accountingPeriodId: string | null;
diff --git a/packages/database/supabase/migrations/20240119095150_integrations.sql b/packages/database/supabase/migrations/20240119095150_integrations.sql
new file mode 100644
index 0000000000..0fa3937130
--- /dev/null
+++ b/packages/database/supabase/migrations/20240119095150_integrations.sql
@@ -0,0 +1,48 @@
+-- Enable the "pg_jsonschema" extension
+CREATE EXTENSION pg_jsonschema WITH SCHEMA extensions;
+
+CREATE TABLE integration (
+ "name" TEXT NOT NULL,
+ "active" BOOLEAN NOT NULL DEFAULT FALSE,
+ "visible" BOOLEAN NOT NULL DEFAULT TRUE,
+ "jsonschema" JSON NOT NULL,
+ "metadata" JSON NOT NULL DEFAULT '{}',
+ "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
+ "updatedBy" TEXT,
+
+ CONSTRAINT integration_pkey PRIMARY KEY ("name"),
+ CONSTRAINT integration_metadata CHECK (
+ active = false OR
+ json_matches_schema(jsonschema, metadata)
+ ),
+ CONSTRAINT "integration_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id") ON UPDATE CASCADE
+);
+
+CREATE POLICY "Employees with settings_view can view integrations." ON "integration"
+ FOR SELECT USING (
+ coalesce(get_my_claim('settings_view')::boolean,false) AND
+ (get_my_claim('role'::text)) = '"employee"'::jsonb
+ );
+
+CREATE POLICY "Employees with settings_update can update integrations." ON "integration"
+ FOR UPDATE
+ USING (
+ coalesce(get_my_claim('settings_update')::boolean,false) AND
+ (get_my_claim('role'::text)) = '"employee"'::jsonb
+ );
+
+INSERT INTO "integration" ("name", "jsonschema")
+VALUES (
+ 'exchangeRatesV1',
+ '{
+ "type": "object",
+ "properties": {
+ "apiKey": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "apiKey"
+ ]
+ }'::json);
+