@marinoscar/platform-db 0.1.0-next.3 → 0.1.0-next.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +109 -0
- package/README.md +158 -13
- package/dist/baseline/deps.d.ts.map +1 -1
- package/dist/baseline/deps.js +2 -0
- package/dist/baseline/deps.js.map +1 -1
- package/dist/baseline/errors.d.ts +3 -1
- package/dist/baseline/errors.d.ts.map +1 -1
- package/dist/baseline/errors.js.map +1 -1
- package/dist/baseline/report.d.ts +3 -1
- package/dist/baseline/report.d.ts.map +1 -1
- package/dist/baseline/report.js +4 -0
- package/dist/baseline/report.js.map +1 -1
- package/dist/baseline/run.d.ts +12 -1
- package/dist/baseline/run.d.ts.map +1 -1
- package/dist/baseline/run.js +19 -0
- package/dist/baseline/run.js.map +1 -1
- package/dist/bin/db-commands.d.ts +1 -1
- package/dist/bin/db-commands.d.ts.map +1 -1
- package/dist/bin/db-commands.js +40 -5
- package/dist/bin/db-commands.js.map +1 -1
- package/dist/drift/app-objects.d.ts +107 -0
- package/dist/drift/app-objects.d.ts.map +1 -0
- package/dist/drift/app-objects.js +193 -0
- package/dist/drift/app-objects.js.map +1 -0
- package/dist/drift/db-conformance.d.ts +3 -0
- package/dist/drift/db-conformance.d.ts.map +1 -1
- package/dist/drift/db-conformance.js +24 -0
- package/dist/drift/db-conformance.js.map +1 -1
- package/dist/drift/index.d.ts +5 -2
- package/dist/drift/index.d.ts.map +1 -1
- package/dist/drift/index.js +18 -1
- package/dist/drift/index.js.map +1 -1
- package/dist/drift/raw-sql-tripwire.d.ts +44 -3
- package/dist/drift/raw-sql-tripwire.d.ts.map +1 -1
- package/dist/drift/raw-sql-tripwire.js +39 -11
- package/dist/drift/raw-sql-tripwire.js.map +1 -1
- package/dist/drift/rls-policies.d.ts +226 -0
- package/dist/drift/rls-policies.d.ts.map +1 -0
- package/dist/drift/rls-policies.js +317 -0
- package/dist/drift/rls-policies.js.map +1 -0
- package/dist/drift/run.d.ts +24 -0
- package/dist/drift/run.d.ts.map +1 -1
- package/dist/drift/run.js +52 -1
- package/dist/drift/run.js.map +1 -1
- package/dist/drift/sql-expression.d.ts +27 -0
- package/dist/drift/sql-expression.d.ts.map +1 -0
- package/dist/drift/sql-expression.js +64 -0
- package/dist/drift/sql-expression.js.map +1 -0
- package/dist/lock/index.d.ts +1 -1
- package/dist/lock/index.d.ts.map +1 -1
- package/dist/lock/index.js.map +1 -1
- package/dist/lock/lock.d.ts +37 -0
- package/dist/lock/lock.d.ts.map +1 -1
- package/dist/lock/lock.js +11 -0
- package/dist/lock/lock.js.map +1 -1
- package/dist/lock/manifest.d.ts +8 -0
- package/dist/lock/manifest.d.ts.map +1 -1
- package/dist/lock/manifest.js +1 -0
- package/dist/lock/manifest.js.map +1 -1
- package/dist/seed/index.d.ts +1 -0
- package/dist/seed/index.d.ts.map +1 -1
- package/dist/seed/index.js +7 -1
- package/dist/seed/index.js.map +1 -1
- package/dist/seed/seed-platform.d.ts +16 -3
- package/dist/seed/seed-platform.d.ts.map +1 -1
- package/dist/seed/seed-platform.js +37 -5
- package/dist/seed/seed-platform.js.map +1 -1
- package/dist/seed/steps.d.ts +172 -0
- package/dist/seed/steps.d.ts.map +1 -0
- package/dist/seed/steps.js +136 -0
- package/dist/seed/steps.js.map +1 -0
- package/dist/seed/types.d.ts +12 -2
- package/dist/seed/types.d.ts.map +1 -1
- package/dist/sync/app-migrations.d.ts +52 -0
- package/dist/sync/app-migrations.d.ts.map +1 -0
- package/dist/sync/app-migrations.js +62 -0
- package/dist/sync/app-migrations.js.map +1 -0
- package/dist/sync/apply.d.ts.map +1 -1
- package/dist/sync/apply.js +1 -0
- package/dist/sync/apply.js.map +1 -1
- package/dist/sync/check.d.ts +5 -2
- package/dist/sync/check.d.ts.map +1 -1
- package/dist/sync/check.js +8 -1
- package/dist/sync/check.js.map +1 -1
- package/dist/sync/errors.d.ts +2 -1
- package/dist/sync/errors.d.ts.map +1 -1
- package/dist/sync/errors.js.map +1 -1
- package/dist/sync/index.d.ts +1 -0
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +3 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/plan.d.ts +3 -1
- package/dist/sync/plan.d.ts.map +1 -1
- package/dist/sync/plan.js +9 -2
- package/dist/sync/plan.js.map +1 -1
- package/dist/sync/promote.d.ts +4 -0
- package/dist/sync/promote.d.ts.map +1 -1
- package/dist/sync/promote.js +2 -0
- package/dist/sync/promote.js.map +1 -1
- package/migrations/0025_org_scoped_rls/migration.sql +215 -0
- package/migrations/0026_add_groups/migration.sql +165 -0
- package/migrations/0027_add_grants/migration.sql +117 -0
- package/migrations/0028_add_org_settings/migration.sql +49 -0
- package/migrations/0029_add_org_credentials/migration.sql +54 -0
- package/migrations/0030_add_jobs_org_id/migration.sql +18 -0
- package/migrations/0031_add_jobs_org_id_status_index/migration.sql +6 -0
- package/migrations/0032_add_broadcast_target_org/migration.sql +21 -0
- package/migrations/0033_add_android_app/migration.sql +60 -0
- package/migrations/0034_open_job_reason/migration.sql +16 -0
- package/migrations/0035_ai_usage_feature/migration.sql +37 -0
- package/migrations/0036_add_app_metadata/migration.sql +49 -0
- package/migrations/0037_open_sharing_vocabularies/migration.sql +97 -0
- package/migrations/0038_add_worker_node_events/migration.sql +21 -0
- package/migrations/0039_add_webhooks/migration.sql +125 -0
- package/migrations/0040_add_alerts/migration.sql +66 -0
- package/migrations/0041_notifications_state_counted/migration.sql +19 -0
- package/migrations/0042_add_storage_migrations/migration.sql +130 -0
- package/migrations/manifest.json +185 -0
- package/package.json +5 -2
- package/raw-sql-indexes.json +72 -0
- package/rls-policies.json +102 -0
- package/schema/ai.prisma +59 -2
- package/schema/alerts.prisma +75 -0
- package/schema/android-app.prisma +47 -0
- package/schema/credentials.prisma +62 -0
- package/schema/identity.prisma +34 -1
- package/schema/jobs.prisma +69 -7
- package/schema/notifications.prisma +84 -5
- package/schema/settings.prisma +25 -0
- package/schema/sharing.prisma +223 -0
- package/schema/storage.prisma +143 -4
- package/schema/webhooks.prisma +108 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
-- =============================================================================
|
|
2
|
+
-- Outbound webhooks: webhook_endpoints and webhook_deliveries (#1046)
|
|
3
|
+
-- =============================================================================
|
|
4
|
+
--
|
|
5
|
+
-- Two new org-owned tables. org_id is NULLABLE on both: NULL only for a
|
|
6
|
+
-- system-scope endpoint and its deliveries, visible to the bypass (system)
|
|
7
|
+
-- client only, as for ai_usage_events in 0025_org_scoped_rls. A delivery carries
|
|
8
|
+
-- its endpoint's org_id because a policy cannot join through its parent; the
|
|
9
|
+
-- endpoint link is a simple FK (a composite FK on a nullable org_id is not
|
|
10
|
+
-- enforced by MATCH SIMPLE and would add no isolation). The signing secret is
|
|
11
|
+
-- never a column: it lives in the encrypted credentials store.
|
|
12
|
+
--
|
|
13
|
+
-- No raw-SQL partial index: the (endpoint_id, event_id) uniqueness is a plain
|
|
14
|
+
-- composite UNIQUE. No backfill: the tables are new, so RLS is enabled at once.
|
|
15
|
+
-- =============================================================================
|
|
16
|
+
|
|
17
|
+
BEGIN;
|
|
18
|
+
SELECT set_config('app.rls_bypass', 'on', true);
|
|
19
|
+
|
|
20
|
+
-- CreateEnum
|
|
21
|
+
CREATE TYPE "WebhookScope" AS ENUM ('user', 'org', 'system');
|
|
22
|
+
|
|
23
|
+
-- CreateEnum
|
|
24
|
+
CREATE TYPE "WebhookDeliveryStatus" AS ENUM ('pending', 'delivering', 'succeeded', 'failed', 'dead');
|
|
25
|
+
|
|
26
|
+
-- CreateTable
|
|
27
|
+
CREATE TABLE "webhook_endpoints" (
|
|
28
|
+
"id" UUID NOT NULL,
|
|
29
|
+
"org_id" UUID,
|
|
30
|
+
"scope" "WebhookScope" NOT NULL,
|
|
31
|
+
"owner_user_id" UUID,
|
|
32
|
+
"created_by_id" UUID,
|
|
33
|
+
"name" VARCHAR(120) NOT NULL,
|
|
34
|
+
"description" VARCHAR(500),
|
|
35
|
+
"url" VARCHAR(2048) NOT NULL,
|
|
36
|
+
"event_keys" TEXT[],
|
|
37
|
+
"enabled" BOOLEAN NOT NULL DEFAULT true,
|
|
38
|
+
"secret_version" INTEGER NOT NULL DEFAULT 1,
|
|
39
|
+
"previous_secret_until" TIMESTAMPTZ,
|
|
40
|
+
"consecutive_failures" INTEGER NOT NULL DEFAULT 0,
|
|
41
|
+
"disabled_reason" VARCHAR(64),
|
|
42
|
+
"last_delivery_at" TIMESTAMPTZ,
|
|
43
|
+
"last_success_at" TIMESTAMPTZ,
|
|
44
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
45
|
+
"updated_at" TIMESTAMPTZ NOT NULL,
|
|
46
|
+
|
|
47
|
+
CONSTRAINT "webhook_endpoints_pkey" PRIMARY KEY ("id")
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
-- CreateTable
|
|
51
|
+
CREATE TABLE "webhook_deliveries" (
|
|
52
|
+
"id" UUID NOT NULL,
|
|
53
|
+
"org_id" UUID,
|
|
54
|
+
"endpoint_id" UUID NOT NULL,
|
|
55
|
+
"event_key" VARCHAR(128) NOT NULL,
|
|
56
|
+
"event_id" UUID NOT NULL,
|
|
57
|
+
"payload" JSONB NOT NULL,
|
|
58
|
+
"status" "WebhookDeliveryStatus" NOT NULL DEFAULT 'pending',
|
|
59
|
+
"attempt" INTEGER NOT NULL DEFAULT 0,
|
|
60
|
+
"response_status" INTEGER,
|
|
61
|
+
"response_snippet" VARCHAR(1024),
|
|
62
|
+
"error_code" VARCHAR(64),
|
|
63
|
+
"duration_ms" INTEGER,
|
|
64
|
+
"next_attempt_at" TIMESTAMPTZ,
|
|
65
|
+
"delivered_at" TIMESTAMPTZ,
|
|
66
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
67
|
+
|
|
68
|
+
CONSTRAINT "webhook_deliveries_pkey" PRIMARY KEY ("id")
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
-- CreateIndex
|
|
72
|
+
CREATE INDEX "webhook_endpoints_org_id_scope_enabled_idx" ON "webhook_endpoints"("org_id", "scope", "enabled");
|
|
73
|
+
|
|
74
|
+
-- CreateIndex
|
|
75
|
+
CREATE INDEX "webhook_endpoints_owner_user_id_idx" ON "webhook_endpoints"("owner_user_id");
|
|
76
|
+
|
|
77
|
+
-- CreateIndex
|
|
78
|
+
CREATE INDEX "webhook_deliveries_endpoint_id_created_at_idx" ON "webhook_deliveries"("endpoint_id", "created_at" DESC);
|
|
79
|
+
|
|
80
|
+
-- CreateIndex
|
|
81
|
+
CREATE INDEX "webhook_deliveries_org_id_created_at_idx" ON "webhook_deliveries"("org_id", "created_at");
|
|
82
|
+
|
|
83
|
+
-- CreateIndex
|
|
84
|
+
CREATE INDEX "webhook_deliveries_event_id_idx" ON "webhook_deliveries"("event_id");
|
|
85
|
+
|
|
86
|
+
-- CreateIndex
|
|
87
|
+
CREATE INDEX "webhook_deliveries_created_at_idx" ON "webhook_deliveries"("created_at");
|
|
88
|
+
|
|
89
|
+
-- CreateIndex
|
|
90
|
+
CREATE UNIQUE INDEX "webhook_deliveries_endpoint_id_event_id_key" ON "webhook_deliveries"("endpoint_id", "event_id");
|
|
91
|
+
|
|
92
|
+
-- AddForeignKey
|
|
93
|
+
ALTER TABLE "webhook_endpoints" ADD CONSTRAINT "webhook_endpoints_owner_user_id_fkey" FOREIGN KEY ("owner_user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
94
|
+
|
|
95
|
+
-- AddForeignKey
|
|
96
|
+
ALTER TABLE "webhook_endpoints" ADD CONSTRAINT "webhook_endpoints_org_id_fkey" FOREIGN KEY ("org_id") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
97
|
+
|
|
98
|
+
-- AddForeignKey
|
|
99
|
+
ALTER TABLE "webhook_deliveries" ADD CONSTRAINT "webhook_deliveries_endpoint_id_fkey" FOREIGN KEY ("endpoint_id") REFERENCES "webhook_endpoints"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
100
|
+
|
|
101
|
+
-- =============================================================================
|
|
102
|
+
-- Row-level security, as in 0025_org_scoped_rls (ai_usage_events). The policy
|
|
103
|
+
-- names are listed in RLS_POLICIES (rls-policies.json) and asserted against
|
|
104
|
+
-- pg_policies by the drift test. NULLIF(..., '') because current_setting(name,
|
|
105
|
+
-- true) is the empty string on a connection that ever held a transaction-local
|
|
106
|
+
-- value. A NULL org_id never equals app.org_id, so those rows need the bypass.
|
|
107
|
+
-- =============================================================================
|
|
108
|
+
|
|
109
|
+
ALTER TABLE "webhook_endpoints" ENABLE ROW LEVEL SECURITY;
|
|
110
|
+
ALTER TABLE "webhook_endpoints" FORCE ROW LEVEL SECURITY;
|
|
111
|
+
CREATE POLICY "webhook_endpoints_org_isolation" ON "webhook_endpoints"
|
|
112
|
+
USING ("org_id" = NULLIF(current_setting('app.org_id', true), '')::uuid
|
|
113
|
+
OR current_setting('app.rls_bypass', true) = 'on')
|
|
114
|
+
WITH CHECK ("org_id" = NULLIF(current_setting('app.org_id', true), '')::uuid
|
|
115
|
+
OR current_setting('app.rls_bypass', true) = 'on');
|
|
116
|
+
|
|
117
|
+
ALTER TABLE "webhook_deliveries" ENABLE ROW LEVEL SECURITY;
|
|
118
|
+
ALTER TABLE "webhook_deliveries" FORCE ROW LEVEL SECURITY;
|
|
119
|
+
CREATE POLICY "webhook_deliveries_org_isolation" ON "webhook_deliveries"
|
|
120
|
+
USING ("org_id" = NULLIF(current_setting('app.org_id', true), '')::uuid
|
|
121
|
+
OR current_setting('app.rls_bypass', true) = 'on')
|
|
122
|
+
WITH CHECK ("org_id" = NULLIF(current_setting('app.org_id', true), '')::uuid
|
|
123
|
+
OR current_setting('app.rls_bypass', true) = 'on');
|
|
124
|
+
|
|
125
|
+
COMMIT;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE "alert_rules" (
|
|
3
|
+
"id" UUID NOT NULL,
|
|
4
|
+
"org_id" UUID,
|
|
5
|
+
"key" VARCHAR(64),
|
|
6
|
+
"name" VARCHAR(120) NOT NULL,
|
|
7
|
+
"description" VARCHAR(500),
|
|
8
|
+
"enabled" BOOLEAN NOT NULL DEFAULT false,
|
|
9
|
+
"kind" VARCHAR(32) NOT NULL,
|
|
10
|
+
"severity" VARCHAR(16) NOT NULL,
|
|
11
|
+
"config" JSONB NOT NULL,
|
|
12
|
+
"for_seconds" INTEGER NOT NULL DEFAULT 0,
|
|
13
|
+
"cooldown_seconds" INTEGER NOT NULL DEFAULT 900,
|
|
14
|
+
"notify_channels" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
15
|
+
"webhook" BOOLEAN NOT NULL DEFAULT true,
|
|
16
|
+
"created_by_id" UUID,
|
|
17
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
18
|
+
"updated_at" TIMESTAMPTZ NOT NULL,
|
|
19
|
+
"last_evaluated_at" TIMESTAMPTZ,
|
|
20
|
+
"last_error" VARCHAR(500),
|
|
21
|
+
|
|
22
|
+
CONSTRAINT "alert_rules_pkey" PRIMARY KEY ("id")
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
-- CreateTable
|
|
26
|
+
CREATE TABLE "alert_incidents" (
|
|
27
|
+
"id" UUID NOT NULL,
|
|
28
|
+
"rule_id" UUID NOT NULL,
|
|
29
|
+
"labels_key" VARCHAR(512) NOT NULL,
|
|
30
|
+
"labels" JSONB NOT NULL,
|
|
31
|
+
"state" VARCHAR(16) NOT NULL,
|
|
32
|
+
"severity" VARCHAR(16) NOT NULL,
|
|
33
|
+
"pending_since" TIMESTAMPTZ,
|
|
34
|
+
"fired_at" TIMESTAMPTZ,
|
|
35
|
+
"resolved_at" TIMESTAMPTZ,
|
|
36
|
+
"last_value" DOUBLE PRECISION,
|
|
37
|
+
"last_seen_at" TIMESTAMPTZ NOT NULL,
|
|
38
|
+
"summary" VARCHAR(500) NOT NULL,
|
|
39
|
+
"acknowledged_at" TIMESTAMPTZ,
|
|
40
|
+
"acknowledged_by_id" UUID,
|
|
41
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
42
|
+
|
|
43
|
+
CONSTRAINT "alert_incidents_pkey" PRIMARY KEY ("id")
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
-- CreateIndex
|
|
47
|
+
CREATE UNIQUE INDEX "alert_rules_key_key" ON "alert_rules"("key");
|
|
48
|
+
|
|
49
|
+
-- CreateIndex
|
|
50
|
+
CREATE INDEX "alert_rules_enabled_kind_idx" ON "alert_rules"("enabled", "kind");
|
|
51
|
+
|
|
52
|
+
-- CreateIndex
|
|
53
|
+
CREATE INDEX "alert_incidents_rule_id_state_idx" ON "alert_incidents"("rule_id", "state");
|
|
54
|
+
|
|
55
|
+
-- CreateIndex
|
|
56
|
+
CREATE INDEX "alert_incidents_state_fired_at_idx" ON "alert_incidents"("state", "fired_at");
|
|
57
|
+
|
|
58
|
+
-- CreateIndex
|
|
59
|
+
CREATE INDEX "alert_incidents_resolved_at_idx" ON "alert_incidents"("resolved_at");
|
|
60
|
+
|
|
61
|
+
-- AddForeignKey
|
|
62
|
+
ALTER TABLE "alert_incidents" ADD CONSTRAINT "alert_incidents_rule_id_fkey" FOREIGN KEY ("rule_id") REFERENCES "alert_rules"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
63
|
+
|
|
64
|
+
-- CreateIndex (raw SQL, intentional schema drift: Prisma cannot express a partial unique index)
|
|
65
|
+
-- One OPEN incident per rule and label set. The evaluator relies on it to stay idempotent.
|
|
66
|
+
CREATE UNIQUE INDEX "alert_incidents_open_uniq_idx" ON "alert_incidents"("rule_id", "labels_key") WHERE "state" IN ('pending', 'firing');
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
-- AlterTable
|
|
2
|
+
ALTER TABLE "notifications" ADD COLUMN "data" JSONB,
|
|
3
|
+
ADD COLUMN "dedup_key" TEXT,
|
|
4
|
+
ADD COLUMN "dismissed_at" TIMESTAMPTZ,
|
|
5
|
+
ADD COLUMN "scope_id" UUID,
|
|
6
|
+
ADD COLUMN "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
|
7
|
+
|
|
8
|
+
-- CreateIndex
|
|
9
|
+
CREATE INDEX "notifications_dismissed_at_idx" ON "notifications"("dismissed_at");
|
|
10
|
+
|
|
11
|
+
-- Existing rows were last changed when they were created (or read); the new
|
|
12
|
+
-- column's default would otherwise stamp them all with the migration time.
|
|
13
|
+
UPDATE "notifications" SET "updated_at" = COALESCE("read_at", "created_at");
|
|
14
|
+
|
|
15
|
+
-- At most one LIVE foldable (STATE or COUNTED) row per (user, dedup key).
|
|
16
|
+
-- Raw SQL: Prisma cannot express a partial unique index. Listed in
|
|
17
|
+
-- packages/platform-db/raw-sql-indexes.json; never replace it with @@unique or
|
|
18
|
+
-- a find-then-insert.
|
|
19
|
+
CREATE UNIQUE INDEX "notifications_live_dedup_uniq_idx" ON "notifications"("user_id", "dedup_key") WHERE "dismissed_at" IS NULL AND "dedup_key" IS NOT NULL;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
-- =============================================================================
|
|
2
|
+
-- Copy-only storage provider migration: storage_migration_runs and
|
|
3
|
+
-- storage_migration_items (#1093)
|
|
4
|
+
-- =============================================================================
|
|
5
|
+
--
|
|
6
|
+
-- Two new org-owned tables. A run is deployment-wide today, so its org_id is
|
|
7
|
+
-- NULLABLE (NULL: visible to the bypass client only, as for a system-scope
|
|
8
|
+
-- webhook_endpoints row in 0039_add_webhooks). An item carries its object's
|
|
9
|
+
-- org_id (NOT NULL) because a policy cannot join through the parent, and links
|
|
10
|
+
-- to the object by the composite (object_id, org_id) foreign key (ADR 0002 D5).
|
|
11
|
+
--
|
|
12
|
+
-- storage_migration_runs_active_uniq_idx is a raw-SQL partial unique index
|
|
13
|
+
-- (listed in raw-sql-indexes.json): at most one pending or running run. No
|
|
14
|
+
-- backfill: the tables are new, so RLS is enabled at once.
|
|
15
|
+
-- =============================================================================
|
|
16
|
+
|
|
17
|
+
BEGIN;
|
|
18
|
+
SELECT set_config('app.rls_bypass', 'on', true);
|
|
19
|
+
|
|
20
|
+
-- CreateEnum
|
|
21
|
+
CREATE TYPE "StorageMigrationRunStatus" AS ENUM ('pending', 'running', 'completed', 'failed', 'cancelled');
|
|
22
|
+
|
|
23
|
+
-- CreateEnum
|
|
24
|
+
CREATE TYPE "StorageMigrationItemStatus" AS ENUM ('pending', 'copying', 'migrated', 'failed', 'skipped');
|
|
25
|
+
|
|
26
|
+
-- CreateTable
|
|
27
|
+
CREATE TABLE "storage_migration_runs" (
|
|
28
|
+
"id" UUID NOT NULL,
|
|
29
|
+
"org_id" UUID,
|
|
30
|
+
"source_provider" VARCHAR(48) NOT NULL,
|
|
31
|
+
"target_provider" VARCHAR(48) NOT NULL,
|
|
32
|
+
"status" "StorageMigrationRunStatus" NOT NULL DEFAULT 'pending',
|
|
33
|
+
"total_count" INTEGER NOT NULL DEFAULT 0,
|
|
34
|
+
"migrated_count" INTEGER NOT NULL DEFAULT 0,
|
|
35
|
+
"failed_count" INTEGER NOT NULL DEFAULT 0,
|
|
36
|
+
"skipped_count" INTEGER NOT NULL DEFAULT 0,
|
|
37
|
+
"planned_at" TIMESTAMPTZ,
|
|
38
|
+
"started_by_id" UUID,
|
|
39
|
+
"cancelled_by_id" UUID,
|
|
40
|
+
"started_at" TIMESTAMPTZ,
|
|
41
|
+
"finished_at" TIMESTAMPTZ,
|
|
42
|
+
"cancelled_at" TIMESTAMPTZ,
|
|
43
|
+
"last_error" VARCHAR(1000),
|
|
44
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
45
|
+
"updated_at" TIMESTAMPTZ NOT NULL,
|
|
46
|
+
|
|
47
|
+
CONSTRAINT "storage_migration_runs_pkey" PRIMARY KEY ("id")
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
-- CreateTable
|
|
51
|
+
CREATE TABLE "storage_migration_items" (
|
|
52
|
+
"id" UUID NOT NULL,
|
|
53
|
+
"run_id" UUID NOT NULL,
|
|
54
|
+
"object_id" UUID NOT NULL,
|
|
55
|
+
"org_id" UUID NOT NULL,
|
|
56
|
+
"status" "StorageMigrationItemStatus" NOT NULL DEFAULT 'pending',
|
|
57
|
+
"job_id" UUID,
|
|
58
|
+
"size_bytes" BIGINT,
|
|
59
|
+
"checksum_sha256" CHAR(64),
|
|
60
|
+
"last_error" VARCHAR(1000),
|
|
61
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
62
|
+
"updated_at" TIMESTAMPTZ NOT NULL,
|
|
63
|
+
|
|
64
|
+
CONSTRAINT "storage_migration_items_pkey" PRIMARY KEY ("id")
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
-- CreateIndex
|
|
68
|
+
CREATE INDEX "storage_migration_runs_created_at_idx" ON "storage_migration_runs"("created_at" DESC);
|
|
69
|
+
|
|
70
|
+
-- CreateIndex
|
|
71
|
+
CREATE INDEX "storage_migration_runs_status_idx" ON "storage_migration_runs"("status");
|
|
72
|
+
|
|
73
|
+
-- CreateIndex
|
|
74
|
+
CREATE INDEX "storage_migration_runs_org_id_idx" ON "storage_migration_runs"("org_id");
|
|
75
|
+
|
|
76
|
+
-- CreateIndex
|
|
77
|
+
CREATE INDEX "storage_migration_items_run_id_status_idx" ON "storage_migration_items"("run_id", "status");
|
|
78
|
+
|
|
79
|
+
-- CreateIndex
|
|
80
|
+
CREATE INDEX "storage_migration_items_org_id_object_id_idx" ON "storage_migration_items"("org_id", "object_id");
|
|
81
|
+
|
|
82
|
+
-- CreateIndex
|
|
83
|
+
CREATE UNIQUE INDEX "storage_migration_items_run_id_object_id_key" ON "storage_migration_items"("run_id", "object_id");
|
|
84
|
+
|
|
85
|
+
-- AddForeignKey
|
|
86
|
+
ALTER TABLE "storage_migration_runs" ADD CONSTRAINT "storage_migration_runs_org_id_fkey" FOREIGN KEY ("org_id") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
87
|
+
|
|
88
|
+
-- AddForeignKey
|
|
89
|
+
ALTER TABLE "storage_migration_runs" ADD CONSTRAINT "storage_migration_runs_started_by_id_fkey" FOREIGN KEY ("started_by_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
90
|
+
|
|
91
|
+
-- AddForeignKey
|
|
92
|
+
ALTER TABLE "storage_migration_runs" ADD CONSTRAINT "storage_migration_runs_cancelled_by_id_fkey" FOREIGN KEY ("cancelled_by_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
93
|
+
|
|
94
|
+
-- AddForeignKey
|
|
95
|
+
ALTER TABLE "storage_migration_items" ADD CONSTRAINT "storage_migration_items_run_id_fkey" FOREIGN KEY ("run_id") REFERENCES "storage_migration_runs"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
96
|
+
|
|
97
|
+
-- AddForeignKey
|
|
98
|
+
ALTER TABLE "storage_migration_items" ADD CONSTRAINT "storage_migration_items_object_id_org_id_fkey" FOREIGN KEY ("object_id", "org_id") REFERENCES "storage_objects"("id", "org_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
99
|
+
|
|
100
|
+
-- AddForeignKey
|
|
101
|
+
ALTER TABLE "storage_migration_items" ADD CONSTRAINT "storage_migration_items_org_id_fkey" FOREIGN KEY ("org_id") REFERENCES "organizations"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
102
|
+
|
|
103
|
+
-- At most one pending or running migration run, deployment-wide: a
|
|
104
|
+
-- constant-expression partial unique index Prisma cannot express. A concurrent
|
|
105
|
+
-- second start loses on this index (P2002 -> 409), never a findFirst pre-check.
|
|
106
|
+
CREATE UNIQUE INDEX "storage_migration_runs_active_uniq_idx" ON "storage_migration_runs" ((true)) WHERE "status" IN ('pending', 'running');
|
|
107
|
+
|
|
108
|
+
-- =============================================================================
|
|
109
|
+
-- Row-level security, as in 0039_add_webhooks. The policy names are listed in
|
|
110
|
+
-- RLS_POLICIES (rls-policies.json). A NULL org_id never equals app.org_id, so a
|
|
111
|
+
-- deployment-wide run needs the bypass.
|
|
112
|
+
-- =============================================================================
|
|
113
|
+
|
|
114
|
+
ALTER TABLE "storage_migration_runs" ENABLE ROW LEVEL SECURITY;
|
|
115
|
+
ALTER TABLE "storage_migration_runs" FORCE ROW LEVEL SECURITY;
|
|
116
|
+
CREATE POLICY "storage_migration_runs_org_isolation" ON "storage_migration_runs"
|
|
117
|
+
USING ("org_id" = NULLIF(current_setting('app.org_id', true), '')::uuid
|
|
118
|
+
OR current_setting('app.rls_bypass', true) = 'on')
|
|
119
|
+
WITH CHECK ("org_id" = NULLIF(current_setting('app.org_id', true), '')::uuid
|
|
120
|
+
OR current_setting('app.rls_bypass', true) = 'on');
|
|
121
|
+
|
|
122
|
+
ALTER TABLE "storage_migration_items" ENABLE ROW LEVEL SECURITY;
|
|
123
|
+
ALTER TABLE "storage_migration_items" FORCE ROW LEVEL SECURITY;
|
|
124
|
+
CREATE POLICY "storage_migration_items_org_isolation" ON "storage_migration_items"
|
|
125
|
+
USING ("org_id" = NULLIF(current_setting('app.org_id', true), '')::uuid
|
|
126
|
+
OR current_setting('app.rls_bypass', true) = 'on')
|
|
127
|
+
WITH CHECK ("org_id" = NULLIF(current_setting('app.org_id', true), '')::uuid
|
|
128
|
+
OR current_setting('app.rls_bypass', true) = 'on');
|
|
129
|
+
|
|
130
|
+
COMMIT;
|
package/migrations/manifest.json
CHANGED
|
@@ -236,5 +236,190 @@
|
|
|
236
236
|
"sha256": "11484b30fdabf64abb14ec99e4d218c1897f5692130bd5a04720d08b905e1332",
|
|
237
237
|
"since": "1.0.0",
|
|
238
238
|
"slice": "identity"
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
"dir": "0025_org_scoped_rls",
|
|
242
|
+
"id": "0025_org_scoped_rls",
|
|
243
|
+
"requires": [
|
|
244
|
+
"identity",
|
|
245
|
+
"ai"
|
|
246
|
+
],
|
|
247
|
+
"rls": true,
|
|
248
|
+
"sha256": "f6a0a61d07e5b91767b9bf18824ae1872e236f566877282c4cb2332f024dd636",
|
|
249
|
+
"since": "1.0.0",
|
|
250
|
+
"slice": "storage",
|
|
251
|
+
"touches": [
|
|
252
|
+
"ai",
|
|
253
|
+
"identity"
|
|
254
|
+
]
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
"dir": "0026_add_groups",
|
|
258
|
+
"id": "0026_add_groups",
|
|
259
|
+
"requires": [
|
|
260
|
+
"identity"
|
|
261
|
+
],
|
|
262
|
+
"rls": true,
|
|
263
|
+
"sha256": "93e97e6b72578a89bf5232a036ecfe6a067c883c7f3c9f091bfdc00475c6e714",
|
|
264
|
+
"since": "1.0.0",
|
|
265
|
+
"slice": "sharing"
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
"dir": "0027_add_grants",
|
|
269
|
+
"id": "0027_add_grants",
|
|
270
|
+
"requires": [
|
|
271
|
+
"identity",
|
|
272
|
+
"sharing"
|
|
273
|
+
],
|
|
274
|
+
"rls": true,
|
|
275
|
+
"sha256": "2e2d5515f131c104ee7f4e5b2ee4d76fbf5409e500da0b412edd4bad0b71c6da",
|
|
276
|
+
"since": "1.0.0",
|
|
277
|
+
"slice": "sharing"
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
"dir": "0028_add_org_settings",
|
|
281
|
+
"id": "0028_add_org_settings",
|
|
282
|
+
"requires": [
|
|
283
|
+
"identity"
|
|
284
|
+
],
|
|
285
|
+
"rls": true,
|
|
286
|
+
"sha256": "e4d811ab7c5446d905e5e4fbb3ce2b94e06d82488f916352a2a413cdc55f94a4",
|
|
287
|
+
"since": "1.0.0",
|
|
288
|
+
"slice": "settings"
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
"dir": "0029_add_org_credentials",
|
|
292
|
+
"id": "0029_add_org_credentials",
|
|
293
|
+
"requires": [
|
|
294
|
+
"identity"
|
|
295
|
+
],
|
|
296
|
+
"rls": true,
|
|
297
|
+
"sha256": "fa5db76f0081149b5716f763166d2099b134857f27f15f36f9a4ea33e1a0806e",
|
|
298
|
+
"since": "1.0.0",
|
|
299
|
+
"slice": "credentials"
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
"dir": "0030_add_jobs_org_id",
|
|
303
|
+
"id": "0030_add_jobs_org_id",
|
|
304
|
+
"requires": [
|
|
305
|
+
"identity"
|
|
306
|
+
],
|
|
307
|
+
"sha256": "26556306864283a8feb2233692d5fcb66b9f38d2671cfeb66e2e094d4c8f84bb",
|
|
308
|
+
"since": "1.0.0",
|
|
309
|
+
"slice": "jobs"
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
"dir": "0031_add_jobs_org_id_status_index",
|
|
313
|
+
"id": "0031_add_jobs_org_id_status_index",
|
|
314
|
+
"requires": [
|
|
315
|
+
"identity"
|
|
316
|
+
],
|
|
317
|
+
"sha256": "434d69d4112bcb429de609942a851e08c49793212a538adcc5a2481d1f8b0bb0",
|
|
318
|
+
"since": "1.0.0",
|
|
319
|
+
"slice": "jobs"
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
"dir": "0032_add_broadcast_target_org",
|
|
323
|
+
"id": "0032_add_broadcast_target_org",
|
|
324
|
+
"requires": [],
|
|
325
|
+
"sha256": "9f266799b1e3769233ea72873ce55394340da9f8ef1312a7e0b7b2ae410152e2",
|
|
326
|
+
"since": "1.0.0",
|
|
327
|
+
"slice": "notifications"
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
"dir": "0033_add_android_app",
|
|
331
|
+
"id": "0033_add_android_app",
|
|
332
|
+
"requires": [
|
|
333
|
+
"identity",
|
|
334
|
+
"notifications"
|
|
335
|
+
],
|
|
336
|
+
"sha256": "7f343a96417825c1372388c199ad2dbecfcf8632a4ebc5080afb29c82109b719",
|
|
337
|
+
"since": "1.0.0",
|
|
338
|
+
"slice": "android-app"
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
"dir": "0034_open_job_reason",
|
|
342
|
+
"id": "0034_open_job_reason",
|
|
343
|
+
"requires": [],
|
|
344
|
+
"sha256": "31b16d3aeddb81840ad34ec2df29aeaf065b1f5082c839bbc31c94c90a205d77",
|
|
345
|
+
"since": "1.0.0",
|
|
346
|
+
"slice": "jobs"
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
"dir": "0035_ai_usage_feature",
|
|
350
|
+
"id": "0035_ai_usage_feature",
|
|
351
|
+
"requires": [],
|
|
352
|
+
"sha256": "ad7322539e971a2248cc2f73a12e188453a3312cc1a04d168bc4e7ddd68e5752",
|
|
353
|
+
"since": "1.0.0",
|
|
354
|
+
"slice": "ai"
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
"dir": "0036_add_app_metadata",
|
|
358
|
+
"id": "0036_add_app_metadata",
|
|
359
|
+
"requires": [
|
|
360
|
+
"ai",
|
|
361
|
+
"sharing"
|
|
362
|
+
],
|
|
363
|
+
"sha256": "17e727075b3d02d129f60cdebf156b9736113e3b689ff35513c474c520185f75",
|
|
364
|
+
"since": "1.0.0",
|
|
365
|
+
"slice": "identity",
|
|
366
|
+
"touches": [
|
|
367
|
+
"ai",
|
|
368
|
+
"sharing"
|
|
369
|
+
]
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
"dir": "0037_open_sharing_vocabularies",
|
|
373
|
+
"id": "0037_open_sharing_vocabularies",
|
|
374
|
+
"requires": [],
|
|
375
|
+
"sha256": "4b7047703bacab08af629004ff569e250869355acd03795f17d1b1e5b277c5e6",
|
|
376
|
+
"since": "1.0.0",
|
|
377
|
+
"slice": "sharing"
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
"dir": "0038_add_worker_node_events",
|
|
381
|
+
"id": "0038_add_worker_node_events",
|
|
382
|
+
"requires": [],
|
|
383
|
+
"sha256": "5775b304027a1cb77b30707093fd6be26290fd49df695f4d850e149fe265b196",
|
|
384
|
+
"since": "1.0.0",
|
|
385
|
+
"slice": "jobs"
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
"dir": "0039_add_webhooks",
|
|
389
|
+
"id": "0039_add_webhooks",
|
|
390
|
+
"requires": [
|
|
391
|
+
"identity"
|
|
392
|
+
],
|
|
393
|
+
"rls": true,
|
|
394
|
+
"sha256": "8f719dc380610f61133612a52921fa6d89ee21957635372c2bc4bdc69d4c0a92",
|
|
395
|
+
"since": "1.0.0",
|
|
396
|
+
"slice": "webhooks"
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
"dir": "0040_add_alerts",
|
|
400
|
+
"id": "0040_add_alerts",
|
|
401
|
+
"requires": [],
|
|
402
|
+
"sha256": "ec4af7e5123ecd8bb6faf3505893cb2efab4d793dae84a98d8b7f26f2dff3776",
|
|
403
|
+
"since": "1.0.0",
|
|
404
|
+
"slice": "alerts"
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
"dir": "0041_notifications_state_counted",
|
|
408
|
+
"id": "0041_notifications_state_counted",
|
|
409
|
+
"requires": [],
|
|
410
|
+
"sha256": "c9285347971920da5310a279351d8de8acac3bba4b281e227cb025745dafc73c",
|
|
411
|
+
"since": "1.0.0",
|
|
412
|
+
"slice": "notifications"
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
"dir": "0042_add_storage_migrations",
|
|
416
|
+
"id": "0042_add_storage_migrations",
|
|
417
|
+
"requires": [
|
|
418
|
+
"identity"
|
|
419
|
+
],
|
|
420
|
+
"rls": true,
|
|
421
|
+
"sha256": "8d37841523a5b4737379df567d5ad3feb37abb0f29dcef416cd34f20167ba181",
|
|
422
|
+
"since": "1.0.0",
|
|
423
|
+
"slice": "storage"
|
|
239
424
|
}
|
|
240
425
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marinoscar/platform-db",
|
|
3
|
-
"version": "0.1.0-next.
|
|
3
|
+
"version": "0.1.0-next.31",
|
|
4
4
|
"description": "Prisma schema fragments, SQL migrations and seed functions of the platform (CommonJS).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"schema",
|
|
38
38
|
"migrations",
|
|
39
39
|
"raw-sql-indexes.json",
|
|
40
|
+
"rls-policies.json",
|
|
40
41
|
"README.md",
|
|
41
42
|
"CHANGELOG.md",
|
|
42
43
|
"LICENSE"
|
|
@@ -55,7 +56,6 @@
|
|
|
55
56
|
"commander": "^14.0.2"
|
|
56
57
|
},
|
|
57
58
|
"peerDependencies": {
|
|
58
|
-
"@prisma/client": "^7.8.0",
|
|
59
59
|
"prisma": "^7.8.0",
|
|
60
60
|
"zod": "^4.4.3",
|
|
61
61
|
"pg": "^8.23.0"
|
|
@@ -63,6 +63,9 @@
|
|
|
63
63
|
"peerDependenciesMeta": {
|
|
64
64
|
"pg": {
|
|
65
65
|
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"prisma": {
|
|
68
|
+
"optional": true
|
|
66
69
|
}
|
|
67
70
|
},
|
|
68
71
|
"devDependencies": {
|
package/raw-sql-indexes.json
CHANGED
|
@@ -44,6 +44,78 @@
|
|
|
44
44
|
"reason": "Exactly one default organization: a constant-expression partial unique index Prisma cannot express (the default org is a database fact, not a findFirst check).",
|
|
45
45
|
"doc": "docs/specs/platform-packages.md",
|
|
46
46
|
"createdIn": "0023_add_organizations"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"name": "group_invites_pending_uniq_idx",
|
|
50
|
+
"table": "group_invites",
|
|
51
|
+
"unique": true,
|
|
52
|
+
"definition": "CREATE UNIQUE INDEX group_invites_pending_uniq_idx ON public.group_invites USING btree (group_id, email) WHERE ((accepted_at IS NULL) AND (declined_at IS NULL) AND (revoked_at IS NULL))",
|
|
53
|
+
"reason": "At most one PENDING invite per group and address; a declined, revoked or accepted invite does not block re-inviting the address, which a plain @@unique([groupId, email]) would. Prisma cannot express a partial unique index.",
|
|
54
|
+
"doc": "docs/specs/platform-packages.md",
|
|
55
|
+
"createdIn": "0026_add_groups"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "grants_active_user_uniq_idx",
|
|
59
|
+
"table": "grants",
|
|
60
|
+
"unique": true,
|
|
61
|
+
"definition": "CREATE UNIQUE INDEX grants_active_user_uniq_idx ON public.grants USING btree (resource_type, resource_id, grantee_user_id) WHERE ((grantee_kind = 'user'::text) AND (revoked_at IS NULL))",
|
|
62
|
+
"reason": "At most one ACTIVE grant per resource and user (one role per grantee, kvox's rule); a revoked grant does not block a new one. The grants API upserts on it. Prisma cannot express a partial unique index.",
|
|
63
|
+
"doc": "docs/specs/platform-packages.md",
|
|
64
|
+
"createdIn": "0027_add_grants"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "grants_active_group_uniq_idx",
|
|
68
|
+
"table": "grants",
|
|
69
|
+
"unique": true,
|
|
70
|
+
"definition": "CREATE UNIQUE INDEX grants_active_group_uniq_idx ON public.grants USING btree (resource_type, resource_id, grantee_group_id) WHERE ((grantee_kind = 'group'::text) AND (revoked_at IS NULL))",
|
|
71
|
+
"reason": "At most one ACTIVE grant per resource and group; a revoked grant does not block a new one. The grants API upserts on it. Prisma cannot express a partial unique index.",
|
|
72
|
+
"doc": "docs/specs/platform-packages.md",
|
|
73
|
+
"createdIn": "0027_add_grants"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"name": "grants_active_ref_uniq_idx",
|
|
77
|
+
"table": "grants",
|
|
78
|
+
"unique": true,
|
|
79
|
+
"definition": "CREATE UNIQUE INDEX grants_active_ref_uniq_idx ON public.grants USING btree (resource_type, resource_id, grantee_kind, grantee_ref) WHERE ((grantee_kind <> ALL (ARRAY['user'::text, 'group'::text, 'link'::text])) AND (revoked_at IS NULL))",
|
|
80
|
+
"reason": "At most one ACTIVE grant per resource, app-registered grantee kind and reference (one role per grantee, as for users and groups); a revoked grant does not block a new one. The grants API upserts on it. Prisma cannot express a partial unique index.",
|
|
81
|
+
"doc": "docs/specs/platform-packages.md",
|
|
82
|
+
"createdIn": "0037_open_sharing_vocabularies"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"name": "android_app_releases_one_current_uniq_idx",
|
|
86
|
+
"table": "android_app_releases",
|
|
87
|
+
"unique": true,
|
|
88
|
+
"definition": "CREATE UNIQUE INDEX android_app_releases_one_current_uniq_idx ON public.android_app_releases USING btree ((true)) WHERE is_current",
|
|
89
|
+
"reason": "At most one current Android APK release deployment-wide: a constant-expression partial unique index Prisma cannot express. Make-current clears the old flag and sets the new one in one transaction; the index arbitrates concurrent calls (the loser gets 409), never a findFirst pre-check.",
|
|
90
|
+
"doc": "docs/specs/native-companion-architecture.md",
|
|
91
|
+
"createdIn": "0033_add_android_app"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"name": "alert_incidents_open_uniq_idx",
|
|
95
|
+
"table": "alert_incidents",
|
|
96
|
+
"unique": true,
|
|
97
|
+
"definition": "CREATE UNIQUE INDEX alert_incidents_open_uniq_idx ON public.alert_incidents USING btree (rule_id, labels_key) WHERE ((state)::text = ANY ((ARRAY['pending'::character varying, 'firing'::character varying])::text[]))",
|
|
98
|
+
"reason": "At most one OPEN (pending or firing) incident per alert rule and label set; a partial unique index Prisma cannot express. The evaluator creates incidents and treats the unique violation as 'already open', so two overlapping evaluations leave one incident.",
|
|
99
|
+
"doc": "docs/specs/platform-packages.md",
|
|
100
|
+
"createdIn": "0040_add_alerts"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"name": "notifications_live_dedup_uniq_idx",
|
|
104
|
+
"table": "notifications",
|
|
105
|
+
"unique": true,
|
|
106
|
+
"definition": "CREATE UNIQUE INDEX notifications_live_dedup_uniq_idx ON public.notifications USING btree (user_id, dedup_key) WHERE ((dismissed_at IS NULL) AND (dedup_key IS NOT NULL))",
|
|
107
|
+
"reason": "At most one LIVE foldable (STATE or COUNTED) notification per user and dedup key; a partial unique index Prisma cannot express. The writer serializes on an advisory lock and treats a unique violation as 'already live', so concurrent producers leave one row.",
|
|
108
|
+
"doc": "docs/specs/platform-packages.md",
|
|
109
|
+
"createdIn": "0041_notifications_state_counted"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"name": "storage_migration_runs_active_uniq_idx",
|
|
113
|
+
"table": "storage_migration_runs",
|
|
114
|
+
"unique": true,
|
|
115
|
+
"definition": "CREATE UNIQUE INDEX storage_migration_runs_active_uniq_idx ON public.storage_migration_runs USING btree ((true)) WHERE (status = ANY (ARRAY['pending'::\"StorageMigrationRunStatus\", 'running'::\"StorageMigrationRunStatus\"]))",
|
|
116
|
+
"reason": "At most one pending or running storage provider migration run deployment-wide: a constant-expression partial unique index Prisma cannot express. A concurrent second start loses on the index (409 with details.activeRunId), never a findFirst pre-check.",
|
|
117
|
+
"doc": "docs/specs/storage-providers.md",
|
|
118
|
+
"createdIn": "0042_add_storage_migrations"
|
|
47
119
|
}
|
|
48
120
|
]
|
|
49
121
|
}
|