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.

fix: race condition in crbn up

Sidwebworksd141880f103b
diff --git a/packages/dev/src/commands/up.ts b/packages/dev/src/commands/up.ts
index 578d02dbf9..70899ef2a0 100644
--- a/packages/dev/src/commands/up.ts
+++ b/packages/dev/src/commands/up.ts
@@ -22,7 +22,12 @@ import {
spawnStripeListener,
syncEnvSymlinks
} from "../services/apps.js";
-import { bootSharedRedis, bootStack } from "../services/compose.js";
+import {
+ bootSharedRedis,
+ bootStack,
+ listContainers,
+ tailServiceLogs
+} from "../services/compose.js";
import {
applyMigrations,
waitForStorageTables,
@@ -150,7 +155,26 @@ export async function up(
`tcp:${ports.PORT_INNGEST}`
]);
msg("storage tables");
- await waitForStorageTables(ports.PORT_DB);
+ await waitForStorageTables(ports.PORT_DB, {
+ onTimeout: async () => {
+ const containers = await listContainers(root, slug);
+ const out: string[] = ["", "--- container state ---"];
+ for (const name of ["postgres", "storage"]) {
+ const c = containers.find((x) => x.Service === name);
+ out.push(
+ c
+ ? `${name.padEnd(10)} state=${c.State} health=${c.Health ?? "n/a"} ${c.Status}`
+ : `${name.padEnd(10)} (not found)`
+ );
+ }
+ out.push("", "--- storage logs (last 50) ---");
+ out.push(await tailServiceLogs(root, slug, "storage", 50));
+ out.push("", "--- postgres logs (last 20) ---");
+ out.push(await tailServiceLogs(root, slug, "postgres", 20));
+ out.push("");
+ process.stderr.write(out.join("\n") + "\n");
+ }
+ });
return "all services responding";
}
},
diff --git a/packages/dev/src/services/compose.ts b/packages/dev/src/services/compose.ts
index 8dbd4ff501..96ad97ea94 100644
--- a/packages/dev/src/services/compose.ts
+++ b/packages/dev/src/services/compose.ts
@@ -90,6 +90,34 @@ export async function listContainers(
.map((l) => JSON.parse(l) as Container);
}
+// Tail logs for a single compose service. Returns merged stdout/stderr —
+// docker compose writes log content to stderr on some versions. Empty string
+// if the call fails; callers use this for best-effort diagnostics.
+export async function tailServiceLogs(
+ root: string,
+ slug: string,
+ service: string,
+ lines: number
+): Promise<string> {
+ const r = await execa(
+ "docker",
+ [
+ "compose",
+ "-f",
+ COMPOSE_DEV_FILE,
+ "-p",
+ projectName(slug),
+ "logs",
+ "--tail",
+ String(lines),
+ "--no-color",
+ service
+ ],
+ { cwd: root, reject: false }
+ );
+ return ((r.stdout ?? "") + (r.stderr ?? "")).trim();
+}
+
export async function dockerProjectStates(): Promise<Map<string, string>> {
const out = new Map<string, string>();
const r = await execa(
diff --git a/packages/dev/src/services/migrations.ts b/packages/dev/src/services/migrations.ts
index cfbaf28379..6c7e2506d2 100644
--- a/packages/dev/src/services/migrations.ts
+++ b/packages/dev/src/services/migrations.ts
@@ -42,20 +42,47 @@ function tryConnect(host: string, port: number): Promise<boolean> {
});
}
-// Block until supabase storage-api bootstraps `storage.buckets`.
-export async function waitForStorageTables(port: number) {
+// Block until postgres accepts queries, then until supabase storage-api
+// bootstraps `storage.buckets`. Postgres opens its TCP port well before init
+// scripts finish — querying `SELECT 1` is the real readiness signal. Storage
+// only starts its bootstrap once postgres is healthy, so both gates share one
+// budget. `onTimeout` runs before the throw so callers can surface container
+// state / logs without leaking compose-project knowledge into this module.
+export async function waitForStorageTables(
+ port: number,
+ opts: { onTimeout?: () => Promise<void> } = {}
+) {
const url = `postgresql://postgres:postgres@localhost:${port}/postgres`;
- const deadline = Date.now() + 60_000;
+ const env = { ...process.env, PGSSLMODE: "disable" };
+ const deadline = Date.now() + 180_000;
+
+ while (Date.now() < deadline) {
+ const r = await execa("psql", [url, "-tAc", "SELECT 1"], {
+ env,
+ reject: false
+ });
+ if (r.exitCode === 0 && r.stdout?.trim() === "1") break;
+ await sleep(1000);
+ }
+
while (Date.now() < deadline) {
const r = await execa(
"psql",
[url, "-tAc", "SELECT to_regclass('storage.buckets')"],
- { env: { ...process.env, PGSSLMODE: "disable" }, reject: false }
+ { env, reject: false }
);
if (r.exitCode === 0 && r.stdout?.trim() === "storage.buckets") return;
await sleep(1000);
}
- throw new Error("storage.buckets did not appear within 60s");
+
+ if (opts.onTimeout) {
+ try {
+ await opts.onTimeout();
+ } catch {
+ // diagnostics are best-effort; original error below is what matters
+ }
+ }
+ throw new Error("storage.buckets did not appear within 180s");
}
// --include-all: supabase bootstrap inserts a sentinel into schema_migrations
diff --git a/packages/locale/locales/de/erp.po b/packages/locale/locales/de/erp.po
index 2fa11b3f8e..85101581de 100644
--- a/packages/locale/locales/de/erp.po
+++ b/packages/locale/locales/de/erp.po
@@ -4607,7 +4607,7 @@ msgstr "Mitarbeitertyp bearbeiten"
msgid "Edit expiration date"
msgstr "Ablaufdatum bearbeiten"
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:245
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:242
msgid "Edit Expiry"
msgstr "Ablaufdatum bearbeiten"
@@ -13859,7 +13859,7 @@ msgstr "Verfolgen Sie jede Änderung an Ihren Bestellungen, Rechnungen, Kunden,
msgid "Track when batches or serials of this item expire."
msgstr "Verfolgen Sie, wann Chargen oder Seriennummern dieses Artikels ablaufen."
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:260
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:257
#: apps/erp/app/modules/inventory/ui/useInventorySubmodules.tsx:71
#: apps/erp/app/routes/x+/inventory+/tracked-entities.tsx:16
#: apps/erp/app/routes/x+/issue+/$id.tsx:147
diff --git a/packages/locale/locales/en/erp.po b/packages/locale/locales/en/erp.po
index c51c0ceed1..141af554c4 100644
--- a/packages/locale/locales/en/erp.po
+++ b/packages/locale/locales/en/erp.po
@@ -4607,7 +4607,7 @@ msgstr "Edit Employee Type"
msgid "Edit expiration date"
msgstr "Edit expiration date"
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:245
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:242
msgid "Edit Expiry"
msgstr "Edit Expiry"
@@ -13859,7 +13859,7 @@ msgstr "Track every change to your orders, invoices, customers, suppliers, and m
msgid "Track when batches or serials of this item expire."
msgstr "Track when batches or serials of this item expire."
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:260
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:257
#: apps/erp/app/modules/inventory/ui/useInventorySubmodules.tsx:71
#: apps/erp/app/routes/x+/inventory+/tracked-entities.tsx:16
#: apps/erp/app/routes/x+/issue+/$id.tsx:147
diff --git a/packages/locale/locales/es/erp.po b/packages/locale/locales/es/erp.po
index e1096f011b..09c5cf5cda 100644
--- a/packages/locale/locales/es/erp.po
+++ b/packages/locale/locales/es/erp.po
@@ -4607,7 +4607,7 @@ msgstr "Editar Tipo de Empleado"
msgid "Edit expiration date"
msgstr "Editar fecha de vencimiento"
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:245
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:242
msgid "Edit Expiry"
msgstr "Editar Vencimiento"
@@ -13859,7 +13859,7 @@ msgstr "Realiza un seguimiento de cada cambio en tus pedidos, facturas, clientes
msgid "Track when batches or serials of this item expire."
msgstr "Realiza un seguimiento de cuándo vencen los lotes o números de serie de este artículo."
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:260
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:257
#: apps/erp/app/modules/inventory/ui/useInventorySubmodules.tsx:71
#: apps/erp/app/routes/x+/inventory+/tracked-entities.tsx:16
#: apps/erp/app/routes/x+/issue+/$id.tsx:147
diff --git a/packages/locale/locales/fr/erp.po b/packages/locale/locales/fr/erp.po
index 887447b38b..72c67e07c5 100644
--- a/packages/locale/locales/fr/erp.po
+++ b/packages/locale/locales/fr/erp.po
@@ -4607,7 +4607,7 @@ msgstr "Modifier le type d'employé"
msgid "Edit expiration date"
msgstr "Modifier la date d'expiration"
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:245
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:242
msgid "Edit Expiry"
msgstr "Modifier l'expiration"
@@ -13859,7 +13859,7 @@ msgstr "Suivez chaque modification apportée à vos commandes, factures, clients
msgid "Track when batches or serials of this item expire."
msgstr "Suivez l'expiration des lots ou numéros de série de cet article."
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:260
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:257
#: apps/erp/app/modules/inventory/ui/useInventorySubmodules.tsx:71
#: apps/erp/app/routes/x+/inventory+/tracked-entities.tsx:16
#: apps/erp/app/routes/x+/issue+/$id.tsx:147
diff --git a/packages/locale/locales/hi/erp.po b/packages/locale/locales/hi/erp.po
index 26f832065b..312c93cf7f 100644
--- a/packages/locale/locales/hi/erp.po
+++ b/packages/locale/locales/hi/erp.po
@@ -4607,7 +4607,7 @@ msgstr "कर्मचारी प्रकार संपादित कर
msgid "Edit expiration date"
msgstr "समाप्ति तारीख संपादित करें"
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:245
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:242
msgid "Edit Expiry"
msgstr "समाप्ति तिथि संपादित करें"
@@ -13859,7 +13859,7 @@ msgstr "अपने ऑर्डर, इनवॉइस, ग्राहको
msgid "Track when batches or serials of this item expire."
msgstr "इस आइटम के बैच या सीरीज़ कब समाप्त होते हैं, इसे ट्रैक करें।"
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:260
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:257
#: apps/erp/app/modules/inventory/ui/useInventorySubmodules.tsx:71
#: apps/erp/app/routes/x+/inventory+/tracked-entities.tsx:16
#: apps/erp/app/routes/x+/issue+/$id.tsx:147
diff --git a/packages/locale/locales/it/erp.po b/packages/locale/locales/it/erp.po
index 64a3e226c1..b745406fba 100644
--- a/packages/locale/locales/it/erp.po
+++ b/packages/locale/locales/it/erp.po
@@ -4607,7 +4607,7 @@ msgstr "Modifica Tipo di Dipendente"
msgid "Edit expiration date"
msgstr "Modifica data di scadenza"
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:245
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:242
msgid "Edit Expiry"
msgstr "Modifica Scadenza"
@@ -13859,7 +13859,7 @@ msgstr "Traccia ogni modifica ai tuoi ordini, fatture, clienti, fornitori e altr
msgid "Track when batches or serials of this item expire."
msgstr "Traccia quando i lotti o i numeri seriali di questo articolo scadono."
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:260
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:257
#: apps/erp/app/modules/inventory/ui/useInventorySubmodules.tsx:71
#: apps/erp/app/routes/x+/inventory+/tracked-entities.tsx:16
#: apps/erp/app/routes/x+/issue+/$id.tsx:147
diff --git a/packages/locale/locales/ja/erp.po b/packages/locale/locales/ja/erp.po
index f3ca9de270..8a6d6c38fb 100644
--- a/packages/locale/locales/ja/erp.po
+++ b/packages/locale/locales/ja/erp.po
@@ -4607,7 +4607,7 @@ msgstr "従業員タイプを編集"
msgid "Edit expiration date"
msgstr "有効期限を編集"
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:245
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:242
msgid "Edit Expiry"
msgstr "有効期限を編集"
@@ -13859,7 +13859,7 @@ msgstr "ご注文、請求書、顧客、仕入先など、すべての変更を
msgid "Track when batches or serials of this item expire."
msgstr "このアイテムのバッチまたはシリアルの有効期限を追跡します。"
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:260
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:257
#: apps/erp/app/modules/inventory/ui/useInventorySubmodules.tsx:71
#: apps/erp/app/routes/x+/inventory+/tracked-entities.tsx:16
#: apps/erp/app/routes/x+/issue+/$id.tsx:147
diff --git a/packages/locale/locales/pl/erp.po b/packages/locale/locales/pl/erp.po
index 674dabfcf4..97fdd57326 100644
--- a/packages/locale/locales/pl/erp.po
+++ b/packages/locale/locales/pl/erp.po
@@ -4607,7 +4607,7 @@ msgstr "Edytuj typ pracownika"
msgid "Edit expiration date"
msgstr "Edytuj datę wygaśnięcia"
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:245
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:242
msgid "Edit Expiry"
msgstr "Edytuj datę ważności"
@@ -13859,7 +13859,7 @@ msgstr "Śledź każdą zmianę w swoich zamówieniach, fakturach, klientach, do
msgid "Track when batches or serials of this item expire."
msgstr "Śledź, kiedy partie lub numery seryjne tego artykułu wygasają."
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:260
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:257
#: apps/erp/app/modules/inventory/ui/useInventorySubmodules.tsx:71
#: apps/erp/app/routes/x+/inventory+/tracked-entities.tsx:16
#: apps/erp/app/routes/x+/issue+/$id.tsx:147
diff --git a/packages/locale/locales/pt/erp.po b/packages/locale/locales/pt/erp.po
index d4159df069..c11ae09698 100644
--- a/packages/locale/locales/pt/erp.po
+++ b/packages/locale/locales/pt/erp.po
@@ -4607,7 +4607,7 @@ msgstr "Editar Tipo de Funcionário"
msgid "Edit expiration date"
msgstr "Editar data de expiração"
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:245
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:242
msgid "Edit Expiry"
msgstr "Editar Validade"
@@ -13859,7 +13859,7 @@ msgstr "Rastreie todas as alterações em seus pedidos, faturas, clientes, forne
msgid "Track when batches or serials of this item expire."
msgstr "Rastreie quando os lotes ou números de série deste item expiram."
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:260
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:257
#: apps/erp/app/modules/inventory/ui/useInventorySubmodules.tsx:71
#: apps/erp/app/routes/x+/inventory+/tracked-entities.tsx:16
#: apps/erp/app/routes/x+/issue+/$id.tsx:147
diff --git a/packages/locale/locales/ru/erp.po b/packages/locale/locales/ru/erp.po
index 272d649584..ee6d4efd10 100644
--- a/packages/locale/locales/ru/erp.po
+++ b/packages/locale/locales/ru/erp.po
@@ -4607,7 +4607,7 @@ msgstr "Редактировать тип сотрудника"
msgid "Edit expiration date"
msgstr "Изменить дату истечения"
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:245
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:242
msgid "Edit Expiry"
msgstr "Редактировать срок годности"
@@ -13859,7 +13859,7 @@ msgstr "Отслеживайте каждое изменение ваших за
msgid "Track when batches or serials of this item expire."
msgstr "Отслеживайте, когда партии или серийные номера этого товара истекают."
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:260
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:257
#: apps/erp/app/modules/inventory/ui/useInventorySubmodules.tsx:71
#: apps/erp/app/routes/x+/inventory+/tracked-entities.tsx:16
#: apps/erp/app/routes/x+/issue+/$id.tsx:147
diff --git a/packages/locale/locales/zh/erp.po b/packages/locale/locales/zh/erp.po
index 5840c89a48..aed918cdea 100644
--- a/packages/locale/locales/zh/erp.po
+++ b/packages/locale/locales/zh/erp.po
@@ -4607,7 +4607,7 @@ msgstr "编辑员工类型"
msgid "Edit expiration date"
msgstr "编辑过期日期"
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:245
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:242
msgid "Edit Expiry"
msgstr "编辑过期日期"
@@ -13859,7 +13859,7 @@ msgstr "跟踪对您的订单、发票、客户、供应商等的每项更改。
msgid "Track when batches or serials of this item expire."
msgstr "跟踪此项目的批次或序列号何时过期。"
-#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:260
+#: apps/erp/app/modules/inventory/ui/Traceability/TrackedEntitiesTable.tsx:257
#: apps/erp/app/modules/inventory/ui/useInventorySubmodules.tsx:71
#: apps/erp/app/routes/x+/inventory+/tracked-entities.tsx:16
#: apps/erp/app/routes/x+/issue+/$id.tsx:147