Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+109
@@ -0,0 +1,109 @@
|
||||
-- VR-P32c: typed read-only KWP material positions plus exact tenant boundary.
|
||||
-- Forward-only migration. The inverse SQL at the end is review guidance for a
|
||||
-- coordinated rollback and is never executed automatically.
|
||||
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE "KwpMaterialPosition" (
|
||||
"id" TEXT NOT NULL,
|
||||
"tenantId" TEXT NOT NULL,
|
||||
"dataConnectionId" TEXT NOT NULL,
|
||||
"projektId" TEXT NOT NULL,
|
||||
"externalId" TEXT NOT NULL,
|
||||
"positionNumber" TEXT,
|
||||
"text" TEXT NOT NULL,
|
||||
"longText" TEXT,
|
||||
"quantity" DECIMAL(18,4),
|
||||
"unit" TEXT,
|
||||
"unitPrice" DECIMAL(18,2),
|
||||
"totalPrice" DECIMAL(18,2),
|
||||
"positionMarker" INTEGER NOT NULL,
|
||||
"normalizedFingerprint" TEXT NOT NULL,
|
||||
"lastSeenAt" TIMESTAMP(3) NOT NULL,
|
||||
"lastSyncedAt" TIMESTAMP(3) NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
"archivedAt" TIMESTAMP(3),
|
||||
CONSTRAINT "KwpMaterialPosition_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX "KwpMaterialPosition_tenantId_dataConnectionId_projektId_ext_key"
|
||||
ON "KwpMaterialPosition"("tenantId", "dataConnectionId", "projektId", "externalId");
|
||||
CREATE INDEX "KwpMaterialPosition_tenantId_projektId_archivedAt_positionN_idx"
|
||||
ON "KwpMaterialPosition"("tenantId", "projektId", "archivedAt", "positionNumber");
|
||||
CREATE INDEX "KwpMaterialPosition_tenantId_dataConnectionId_lastSyncedAt_idx"
|
||||
ON "KwpMaterialPosition"("tenantId", "dataConnectionId", "lastSyncedAt");
|
||||
|
||||
ALTER TABLE "KwpMaterialPosition" ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE "KwpMaterialPosition" FORCE ROW LEVEL SECURITY;
|
||||
|
||||
CREATE POLICY "hg_KwpMaterialPosition_select" ON "KwpMaterialPosition"
|
||||
FOR SELECT TO hivegrid_app, hivegrid_worker
|
||||
USING ("tenantId" = NULLIF(current_setting('app.tenant_id', true), ''));
|
||||
|
||||
CREATE POLICY "hg_KwpMaterialPosition_insert" ON "KwpMaterialPosition"
|
||||
FOR INSERT TO hivegrid_app, hivegrid_worker
|
||||
WITH CHECK (
|
||||
"tenantId" = NULLIF(current_setting('app.tenant_id', true), '')
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "DataConnection" AS connection_owner
|
||||
WHERE connection_owner."id" = "KwpMaterialPosition"."dataConnectionId"
|
||||
AND connection_owner."tenantId" = NULLIF(current_setting('app.tenant_id', true), '')
|
||||
AND connection_owner."appId" = 'kwp'
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "Projekt" AS project_owner
|
||||
WHERE project_owner."id" = "KwpMaterialPosition"."projektId"
|
||||
AND project_owner."tenantId" = NULLIF(current_setting('app.tenant_id', true), '')
|
||||
)
|
||||
);
|
||||
|
||||
CREATE POLICY "hg_KwpMaterialPosition_update" ON "KwpMaterialPosition"
|
||||
FOR UPDATE TO hivegrid_app, hivegrid_worker
|
||||
USING (
|
||||
"tenantId" = NULLIF(current_setting('app.tenant_id', true), '')
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "DataConnection" AS connection_owner
|
||||
WHERE connection_owner."id" = "KwpMaterialPosition"."dataConnectionId"
|
||||
AND connection_owner."tenantId" = NULLIF(current_setting('app.tenant_id', true), '')
|
||||
AND connection_owner."appId" = 'kwp'
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "Projekt" AS project_owner
|
||||
WHERE project_owner."id" = "KwpMaterialPosition"."projektId"
|
||||
AND project_owner."tenantId" = NULLIF(current_setting('app.tenant_id', true), '')
|
||||
)
|
||||
)
|
||||
WITH CHECK (
|
||||
"tenantId" = NULLIF(current_setting('app.tenant_id', true), '')
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "DataConnection" AS connection_owner
|
||||
WHERE connection_owner."id" = "KwpMaterialPosition"."dataConnectionId"
|
||||
AND connection_owner."tenantId" = NULLIF(current_setting('app.tenant_id', true), '')
|
||||
AND connection_owner."appId" = 'kwp'
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "Projekt" AS project_owner
|
||||
WHERE project_owner."id" = "KwpMaterialPosition"."projektId"
|
||||
AND project_owner."tenantId" = NULLIF(current_setting('app.tenant_id', true), '')
|
||||
)
|
||||
);
|
||||
|
||||
CREATE POLICY "hg_KwpMaterialPosition_delete" ON "KwpMaterialPosition"
|
||||
FOR DELETE TO hivegrid_app, hivegrid_worker
|
||||
USING ("tenantId" = NULLIF(current_setting('app.tenant_id', true), ''));
|
||||
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "KwpMaterialPosition" TO hivegrid_app;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON "KwpMaterialPosition" TO hivegrid_worker;
|
||||
|
||||
COMMIT;
|
||||
|
||||
-- Inverse SQL (manual, destructive, coordinated rollback only):
|
||||
-- REVOKE SELECT, INSERT, UPDATE, DELETE ON "KwpMaterialPosition" FROM hivegrid_app, hivegrid_worker;
|
||||
-- DROP POLICY IF EXISTS "hg_KwpMaterialPosition_delete" ON "KwpMaterialPosition";
|
||||
-- DROP POLICY IF EXISTS "hg_KwpMaterialPosition_update" ON "KwpMaterialPosition";
|
||||
-- DROP POLICY IF EXISTS "hg_KwpMaterialPosition_insert" ON "KwpMaterialPosition";
|
||||
-- DROP POLICY IF EXISTS "hg_KwpMaterialPosition_select" ON "KwpMaterialPosition";
|
||||
-- ALTER TABLE "KwpMaterialPosition" NO FORCE ROW LEVEL SECURITY;
|
||||
-- ALTER TABLE "KwpMaterialPosition" DISABLE ROW LEVEL SECURITY;
|
||||
-- DROP TABLE "KwpMaterialPosition";
|
||||
Reference in new issue
Block a user