fix(company-profile): Projekt-aware Persistenz — Daten werden jetzt pro Projekt gespeichert
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Failing after 36s
CI / test-python-backend-compliance (push) Successful in 35s
CI / test-python-document-crawler (push) Successful in 27s
CI / test-python-dsms-gateway (push) Successful in 21s
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Failing after 36s
CI / test-python-backend-compliance (push) Successful in 35s
CI / test-python-document-crawler (push) Successful in 27s
CI / test-python-dsms-gateway (push) Successful in 21s
Problem: Company Profile nutzte hartcodiertes tenant_id=default ohne project_id. Beim Wechsel zwischen Projekten wurden immer die gleichen (oder keine) Daten geladen. Aenderungen: - Migration 042: project_id Spalte + UNIQUE(tenant_id, project_id) Constraint, fehlende Spalten (offering_urls, Adressfelder) nachgetragen - Backend: Alle Queries nutzen WHERE tenant_id + project_id IS NOT DISTINCT FROM - Proxy: project_id Query-Parameter wird durchgereicht - Frontend: projectId aus SDK-Context, profileApiUrl() Helper fuer alle API-Aufrufe - "Weiter" speichert jetzt immer den Draft (war schon so, ging aber ins Leere) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
-- Migration 042: Add project_id to compliance_company_profiles
|
||||
-- Enables multi-project company profiles (one profile per tenant+project)
|
||||
--
|
||||
-- Previously: UNIQUE(tenant_id) — only one profile per tenant
|
||||
-- Now: UNIQUE(tenant_id, project_id) — one profile per tenant+project
|
||||
|
||||
BEGIN;
|
||||
|
||||
-- 1. Add project_id column (nullable for backwards compat with existing rows)
|
||||
ALTER TABLE compliance_company_profiles
|
||||
ADD COLUMN IF NOT EXISTS project_id UUID;
|
||||
|
||||
-- 2. Add offering_urls column (was in frontend but missing in DB)
|
||||
ALTER TABLE compliance_company_profiles
|
||||
ADD COLUMN IF NOT EXISTS offering_urls JSONB DEFAULT '{}'::jsonb;
|
||||
|
||||
-- 3. Add address columns (were in frontend but missing in DB)
|
||||
ALTER TABLE compliance_company_profiles
|
||||
ADD COLUMN IF NOT EXISTS headquarters_country_other VARCHAR(255) DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS headquarters_street VARCHAR(500) DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS headquarters_zip VARCHAR(20) DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS headquarters_state VARCHAR(255) DEFAULT '';
|
||||
|
||||
-- 4. Drop old UNIQUE constraint on tenant_id alone
|
||||
DO $$
|
||||
BEGIN
|
||||
-- The constraint might be named differently depending on how it was created
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM pg_constraint
|
||||
WHERE conname = 'compliance_company_profiles_tenant_id_key'
|
||||
) THEN
|
||||
ALTER TABLE compliance_company_profiles
|
||||
DROP CONSTRAINT compliance_company_profiles_tenant_id_key;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- 5. Create new UNIQUE constraint on (tenant_id, project_id)
|
||||
-- Using COALESCE to handle NULL project_id (legacy rows)
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_company_profiles_tenant_project
|
||||
ON compliance_company_profiles (tenant_id, COALESCE(project_id, '00000000-0000-0000-0000-000000000000'::uuid));
|
||||
|
||||
-- 6. Add FK to compliance_projects (if the referenced table exists)
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM information_schema.tables
|
||||
WHERE table_name = 'compliance_projects'
|
||||
) THEN
|
||||
-- Only add FK if not already present
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint
|
||||
WHERE conname = 'fk_company_profiles_project'
|
||||
) THEN
|
||||
ALTER TABLE compliance_company_profiles
|
||||
ADD CONSTRAINT fk_company_profiles_project
|
||||
FOREIGN KEY (project_id) REFERENCES compliance_projects(id)
|
||||
ON DELETE CASCADE;
|
||||
END IF;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- 7. Add audit log project_id column too
|
||||
ALTER TABLE compliance_company_profile_audit
|
||||
ADD COLUMN IF NOT EXISTS project_id UUID;
|
||||
|
||||
COMMIT;
|
||||
Reference in New Issue
Block a user