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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat: add deployment
Brad Barbin38d08a1449fa
diff --git a/ci/package.json b/ci/package.jsonnew file mode 100644index 0000000000..2286f44f0c--- /dev/null+++ b/ci/package.json@@ -0,0 +1,14 @@+{+ "private": true,+ "name": "ci",+ "version": "0.0.1",+ "description": "Deployment scripts for supabase ",+ "dependencies": {+ "@supabase/supabase-js": "2.39.8",+ "execa": "8.0.1"+ },+ "scripts": {+ "ci:migrations": "tsx src/migrations.ts",+ "test": "tsx src/test.ts"+ }+}diff --git a/ci/src/client.ts b/ci/src/client.tsnew file mode 100644index 0000000000..cc0a7d07e7--- /dev/null+++ b/ci/src/client.ts@@ -0,0 +1,20 @@+import { createClient } from "@supabase/supabase-js";+import { SUPABASE_SERVICE_ROLE, SUPABASE_URL } from "./env";++export const client = createClient(SUPABASE_URL, SUPABASE_SERVICE_ROLE);++export type Customer = {+ id: number;+ name: string;+ slug: string;+ active: boolean;+ seeded: boolean;+ database_url: string | null;+ project_id: string | null;+ decrypted_access_token: string | null;+ decrypted_anon_key: string | null;+ decrypted_database_password: string | null;+ decrypted_jwt_key: string | null;+ decrypted_service_role_key: string | null;+ latest_migration: string | null;+};diff --git a/ci/src/env.ts b/ci/src/env.tsnew file mode 100644index 0000000000..d52dcb6554--- /dev/null+++ b/ci/src/env.ts@@ -0,0 +1,12 @@+import * as dotenv from "dotenv";+dotenv.config();++const SUPABASE_URL = process.env.SUPABASE_URL as string;+const SUPABASE_SERVICE_ROLE = process.env.SUPABASE_SERVICE_ROLE as string;+const SUPABASE_ACCESS_TOKEN = process.env.SUPABASE_ACCESS_TOKEN as string;++if (!SUPABASE_ACCESS_TOKEN) throw new Error("Missing SUPABASE_ACCESS_TOKEN");+if (!SUPABASE_URL) throw new Error("Missing SUPABSE_URL");+if (!SUPABASE_SERVICE_ROLE) throw new Error("Missing SUPABASE_SERVICE_ROLE");++export { SUPABASE_ACCESS_TOKEN, SUPABASE_SERVICE_ROLE, SUPABASE_URL };diff --git a/ci/src/migrations.ts b/ci/src/migrations.tsnew file mode 100644index 0000000000..ad9991bf0d--- /dev/null+++ b/ci/src/migrations.ts@@ -0,0 +1,92 @@+import { $ } from "execa";+import type { Customer } from "./client";+import { client } from "./client";+import { SUPABASE_ACCESS_TOKEN } from "./env";++async function migrate(): Promise<void> {+ console.log("✅ 🌱 Starting migrations");++ const { data: customers, error } = await client+ .from("decrypted_customer")+ .select("*");++ if (error) {+ console.error("🔴 🍳 Failed to fetch customers", error);+ return;+ }++ console.log("✅ 🛩️ Successfully retreived customers");++ console.log("👯♀️ Copying supabase folder");+ await $`cd ../packages/database/supabase`;++ for await (const customer of customers as Customer[]) {+ try {+ console.log(`✅ 🥚 Migrating ${customer.name}`);+ const {+ database_url,+ decrypted_database_password,+ decrypted_service_role_key,+ project_id,+ } = customer;+ if (+ !database_url ||+ !project_id ||+ !decrypted_database_password ||+ !decrypted_service_role_key+ ) {+ console.log(`🔴🍳 Missing keys for ${customer.name}`);+ continue;+ }++ console.log(`✅ 🔑 Setting up environment for ${customer.name}`);++ let $$ = $({+ env: {+ SUPABASE_ACCESS_TOKEN:+ customer.decrypted_access_token === null+ ? SUPABASE_ACCESS_TOKEN+ : customer.decrypted_access_token,+ SUPABASE_API_URL: database_url,+ SUPABASE_DB_PASSWORD: decrypted_database_password,+ SUPABASE_PROJECT_ID: project_id,+ SUPABASE_SERVICE_ROLE: decrypted_service_role_key,+ },+ cwd: "supabase",+ });++ await $$`supabase link`;+ console.log(`✅ 🐣 Starting migrations for ${customer.name}`);+ await $$`supabase db push`;+ console.log(`✅ 🐣 Starting deployments for ${customer.name}`);+ await $$`supabase functions deploy`;++ if (!customer.seeded) {+ try {+ console.log(`✅ 🌱 Seeding ${customer.name}`);+ await $$`tsx ../../carbon/packages/database/src/seed.ts`;+ const { error } = await client+ .from("customer")+ .update({ seeded: true })+ .eq("id", customer.id);++ if (error) {+ throw new Error(+ `🔴 🍳 Failed to mark ${customer.name} as seeded: ${error.message}`+ );+ }++ // TODO: run the seed.sql file+ } catch (e) {+ console.error(`🔴 🍳 Failed to seed ${customer.name}`, e);+ }+ }++ console.log(`✅ 🐓 Successfully migrated ${customer.name}`);+ } catch (error) {+ console.error(`🔴 🍳 Failed to migrate ${customer.name}`, error);+ }+ }+}++migrate();diff --git a/package-lock.json b/package-lock.jsonindex 4167a9f4e9..a95efcb7a6 100644--- a/package-lock.json+++ b/package-lock.json@@ -6,6 +6,7 @@"": {"workspaces": ["apps/*",+ "ci","packages/*"],"devDependencies": {@@ -237,6 +238,197 @@"eslint-config-next": "14.2.3"}},+ "ci": {+ "version": "0.0.1",+ "dependencies": {+ "@supabase/supabase-js": "2.39.8",+ "execa": "8.0.1"+ }+ },+ "ci/node_modules/@supabase/functions-js": {+ "version": "2.1.5",+ "resolved": "https://registry.npmjs.org/@supabase/functions-js/-/functions-js-2.1.5.tgz",+ "integrity": "sha512-BNzC5XhCzzCaggJ8s53DP+WeHHGT/NfTsx2wUSSGKR2/ikLFQTBCDzMvGz/PxYMqRko/LwncQtKXGOYp1PkPaw==",+ "dependencies": {+ "@supabase/node-fetch": "^2.6.14"+ }+ },+ "ci/node_modules/@supabase/postgrest-js": {+ "version": "1.9.2",+ "resolved": "https://registry.npmjs.org/@supabase/postgrest-js/-/postgrest-js-1.9.2.tgz",+ "integrity": "sha512-I6yHo8CC9cxhOo6DouDMy9uOfW7hjdsnCxZiaJuIVZm1dBGTFiQPgfMa9zXCamEWzNyWRjZvupAUuX+tqcl5Sw==",+ "dependencies": {+ "@supabase/node-fetch": "^2.6.14"+ }+ },+ "ci/node_modules/@supabase/realtime-js": {+ "version": "2.9.3",+ "resolved": "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.9.3.tgz",+ "integrity": "sha512-lAp50s2n3FhGJFq+wTSXLNIDPw5Y0Wxrgt44eM5nLSA3jZNUUP3Oq2Ccd1CbZdVntPCWLZvJaU//pAd2NE+QnQ==",+ "dependencies": {+ "@supabase/node-fetch": "^2.6.14",+ "@types/phoenix": "^1.5.4",+ "@types/ws": "^8.5.10",+ "ws": "^8.14.2"+ }+ },+ "ci/node_modules/@supabase/supabase-js": {+ "version": "2.39.8",+ "resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.39.8.tgz",+ "integrity": "sha512-WpiawHjseIRcCQTZbMJtHUSOepz5+M9qE1jP9BDmg8X7ehALFwgEkiKyHAu59qm/pKP2ryyQXLtu2XZNRbUarw==",+ "dependencies": {+ "@supabase/functions-js": "2.1.5",+ "@supabase/gotrue-js": "2.62.2",+ "@supabase/node-fetch": "2.6.15",+ "@supabase/postgrest-js": "1.9.2",+ "@supabase/realtime-js": "2.9.3",+ "@supabase/storage-js": "2.5.5"+ }+ },+ "ci/node_modules/execa": {+ "version": "8.0.1",+ "resolved": "https://registry.npmjs.org/execa/-/execa-8.0.1.tgz",+ "integrity": "sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==",+ "dependencies": {+ "cross-spawn": "^7.0.3",+ "get-stream": "^8.0.1",+ "human-signals": "^5.0.0",+ "is-stream": "^3.0.0",+ "merge-stream": "^2.0.0",+ "npm-run-path": "^5.1.0",+ "onetime": "^6.0.0",+ "signal-exit": "^4.1.0",+ "strip-final-newline": "^3.0.0"+ },+ "engines": {+ "node": ">=16.17"+ },+ "funding": {+ "url": "https://github.com/sindresorhus/execa?sponsor=1"+ }+ },+ "ci/node_modules/get-stream": {+ "version": "8.0.1",+ "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-8.0.1.tgz",+ "integrity": "sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==",+ "engines": {+ "node": ">=16"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "ci/node_modules/human-signals": {+ "version": "5.0.0",+ "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-5.0.0.tgz",+ "integrity": "sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==",+ "engines": {+ "node": ">=16.17.0"+ }+ },+ "ci/node_modules/is-stream": {+ "version": "3.0.0",+ "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz",+ "integrity": "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==",+ "engines": {+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "ci/node_modules/mimic-fn": {+ "version": "4.0.0",+ "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz",+ "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==",+ "engines": {+ "node": ">=12"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "ci/node_modules/npm-run-path": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.3.0.tgz",+ "integrity": "sha512-ppwTtiJZq0O/ai0z7yfudtBpWIoxM8yE6nHi1X47eFR2EWORqfbu6CnPlNsjeN683eT0qG6H/Pyf9fCcvjnnnQ==",+ "dependencies": {+ "path-key": "^4.0.0"+ },+ "engines": {+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "ci/node_modules/onetime": {+ "version": "6.0.0",+ "resolved": "https://registry.npmjs.org/onetime/-/onetime-6.0.0.tgz",+ "integrity": "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==",+ "dependencies": {+ "mimic-fn": "^4.0.0"+ },+ "engines": {+ "node": ">=12"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "ci/node_modules/path-key": {+ "version": "4.0.0",+ "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz",+ "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==",+ "engines": {+ "node": ">=12"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "ci/node_modules/signal-exit": {+ "version": "4.1.0",+ "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",+ "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==",+ "engines": {+ "node": ">=14"+ },+ "funding": {+ "url": "https://github.com/sponsors/isaacs"+ }+ },+ "ci/node_modules/strip-final-newline": {+ "version": "3.0.0",+ "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-3.0.0.tgz",+ "integrity": "sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==",+ "engines": {+ "node": ">=12"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "ci/node_modules/ws": {+ "version": "8.17.0",+ "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.0.tgz",+ "integrity": "sha512-uJq6108EgZMAl20KagGkzCKfMEjxmKvZHG7Tlq0Z6nOky7YF7aq4mOx6xK8TJ/i1LeK4Qus7INktacctDgY8Ow==",+ "engines": {+ "node": ">=10.0.0"+ },+ "peerDependencies": {+ "bufferutil": "^4.0.1",+ "utf-8-validate": ">=5.0.2"+ },+ "peerDependenciesMeta": {+ "bufferutil": {+ "optional": true+ },+ "utf-8-validate": {+ "optional": true+ }+ }+ },"node_modules/@alloc/quick-lru": {"version": "5.2.0","resolved": "https://registry.npmjs.org/@alloc/quick-lru/-/quick-lru-5.2.0.tgz",@@ -8400,6 +8592,14 @@"@supabase/node-fetch": "^2.6.14"}},+ "node_modules/@supabase/gotrue-js": {+ "version": "2.62.2",+ "resolved": "https://registry.npmjs.org/@supabase/gotrue-js/-/gotrue-js-2.62.2.tgz",+ "integrity": "sha512-AP6e6W9rQXFTEJ7sTTNYQrNf0LCcnt1hUW+RIgUK+Uh3jbWvcIST7wAlYyNZiMlS9+PYyymWQ+Ykz/rOYSO0+A==",+ "dependencies": {+ "@supabase/node-fetch": "^2.6.14"+ }+ },"node_modules/@supabase/node-fetch": {"version": "2.6.15","resolved": "https://registry.npmjs.org/@supabase/node-fetch/-/node-fetch-2.6.15.tgz",@@ -12370,6 +12570,10 @@"node": ">=10"}},+ "node_modules/ci": {+ "resolved": "ci",+ "link": true+ },"node_modules/ci-info": {"version": "3.9.0","resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz",diff --git a/package.json b/package.jsonindex 789b61e744..d810da6716 100755--- a/package.json+++ b/package.json@@ -29,6 +29,7 @@"build": "turbo run build","build:packages": "turbo run build --filter=./packages/*","build:app": "turbo run build --filter=!www",+ "ci:migrations": "npm run -w ci ci:migrations","clean": "turbo run clean && rimraf ./node_modules && rimraf ./package-lock.json","db:build": "run-s db:kill db:start setup","db:function:new": "npm run db:function:new -w @carbon/database",@@ -60,6 +61,7 @@},"workspaces": ["apps/*",+ "ci","packages/*"]}