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: keep feedback when deleting user
Brad Barbinc9876488a75d
diff --git a/.github/workflows/remove-preview.yml b/.github/workflows/remove-preview.ymldeleted file mode 100644index 864fd93396..0000000000--- a/.github/workflows/remove-preview.yml+++ /dev/null@@ -1,38 +0,0 @@-name: Remove Supabase Preview Branch--on:- pull_request:- types: [closed]- paths: ["packages/database/supabase/**"]- workflow_dispatch:--jobs:- remove-preview:- name: Remove Supabase Preview Branch- runs-on: ubuntu-latest- if: github.event.pull_request.merged == true-- env:- SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}-- steps:- - uses: actions/checkout@v4-- - uses: actions/setup-node@v3- with:- node-version: "20"-- - uses: supabase/setup-cli@v1- with:- version: latest-- - name: Install dependencies- run: |- npm install- npm install --prefix ci-- - name: Remove preview branch- run: |- BRANCH_NAME="${{ github.event.pull_request.head.ref }}"- SANITIZED_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9]/-/g')- supabase db branch delete "$SANITIZED_BRANCH_NAME" --project-ref ${{ secrets.SUPABASE_PROJECT_REF }} --db-url ${{ secrets.SUPABASE_DB_URL }}diff --git a/packages/database/supabase/migrations/20250430134846_delete-users.sql b/packages/database/supabase/migrations/20250430134846_delete-users.sqlnew file mode 100644index 0000000000..2698307478--- /dev/null+++ b/packages/database/supabase/migrations/20250430134846_delete-users.sql@@ -0,0 +1,9 @@+-- Modify the feedback table to allow userId to be null+ALTER TABLE "feedback" ALTER COLUMN "userId" DROP NOT NULL;++-- Drop the existing foreign key constraint+ALTER TABLE "feedback" DROP CONSTRAINT "feedback_userId_fkey";++-- Add a new foreign key constraint with ON DELETE SET NULL+ALTER TABLE "feedback" ADD CONSTRAINT "feedback_userId_fkey"+ FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE SET NULL;diff --git a/scripts/delete-company-files.ts b/scripts/delete-company-files.tsnew file mode 100644index 0000000000..92b0749c58--- /dev/null+++ b/scripts/delete-company-files.ts@@ -0,0 +1,74 @@+// import type { User } from "@supabase/supabase-js";+import { createClient } from "@supabase/supabase-js";+import * as dotenv from "dotenv";++dotenv.config();++// The way I was doing this was doing a SELECT name FROM storage.objects WHERE name LIKE '<companyId>%' and then exporting as JSON, and copying the results here:+// It is necessary to do one run for the public bucket and one for the private bucket. Starting with the private bucket is recommended.++const files = [+ {+ name: "crul4qo4gfk5a5f8u160/logo-dark-icon.png",+ },+ {+ name: "crul4qo4gfk5a5f8u160/logo-dark.png",+ },+ {+ name: "crul4qo4gfk5a5f8u160/logo-light-icon.png",+ },+ {+ name: "crul4qo4gfk5a5f8u160/logo-light.png",+ },+ {+ name: "crul4qo4gfk5a5f8u160/logo.png",+ },+];++console.log(process.env.SUPABASE_URL);++const supabaseAdmin = createClient(+ process.env.SUPABASE_URL!,+ process.env.SUPABASE_SERVICE_ROLE_KEY!,+ {+ auth: {+ autoRefreshToken: false,+ persistSession: false,+ },+ }+);++(async () => {+ // Batch files into groups of 50+ const batchSize = 50;+ const fileNames = files.map((file) => file.name);+ const batches: string[][] = [];++ for (let i = 0; i < fileNames.length; i += batchSize) {+ batches.push(fileNames.slice(i, i + batchSize));+ }++ console.log(+ `Processing ${batches.length} batches of up to ${batchSize} files each`+ );++ for (let i = 0; i < batches.length; i++) {+ const batch = batches[i];+ console.log(+ `Processing batch ${i + 1}/${batches.length} (${batch.length} files)`+ );++ const { data, error } = await supabaseAdmin.storage+ .from("public")+ .remove(batch);++ if (error) {+ console.error(`Error in batch ${i + 1}:`, error);+ throw error;+ }++ console.log(`Successfully processed batch ${i + 1}:`, data);+ }++ console.log("All files processed successfully");+})();