@marinoscar/platform-db 0.1.0-next.3 → 0.1.0-next.30
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 +107 -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,108 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// Outbound webhooks (issue #1046)
|
|
3
|
+
// =============================================================================
|
|
4
|
+
//
|
|
5
|
+
// Two org-owned tables under row-level security (policy `<table>_org_isolation`,
|
|
6
|
+
// raw SQL in the migration, listed in rls-policies.json).
|
|
7
|
+
//
|
|
8
|
+
// `org_id` is NULLABLE on both: NULL only for a `system`-scope endpoint (and the
|
|
9
|
+
// deliveries it produces), which is visible to the bypass (system) client only,
|
|
10
|
+
// exactly like `ai_usage_events`. An org row's `org_id` is never NULL.
|
|
11
|
+
//
|
|
12
|
+
// A delivery carries its endpoint's `org_id` (copied at fan-out) because a
|
|
13
|
+
// policy cannot join through its parent. The endpoint link is a simple FK on
|
|
14
|
+
// `endpoint_id` (ON DELETE CASCADE), not a composite `(endpoint_id, org_id)`:
|
|
15
|
+
// `org_id` is nullable here, and a composite foreign key with a NULL column is
|
|
16
|
+
// not enforced (MATCH SIMPLE), so it would add no isolation. The fan-out code
|
|
17
|
+
// is the only writer and copies `org_id` from the endpoint row it just read.
|
|
18
|
+
//
|
|
19
|
+
// The signing secret is never a column: it lives in the encrypted credentials
|
|
20
|
+
// store, versioned by `secretVersion`. These rows hold no secret material.
|
|
21
|
+
|
|
22
|
+
enum WebhookScope {
|
|
23
|
+
user
|
|
24
|
+
org
|
|
25
|
+
system
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
enum WebhookDeliveryStatus {
|
|
29
|
+
pending
|
|
30
|
+
delivering
|
|
31
|
+
succeeded
|
|
32
|
+
failed
|
|
33
|
+
dead
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/// A destination URL subscribed to platform events. `scope` = user: owned by
|
|
37
|
+
/// `ownerUserId` (receives only events that user may see); org: an
|
|
38
|
+
/// organization's endpoint; system: a deployment-wide endpoint (`orgId` NULL).
|
|
39
|
+
/// `eventKeys` holds exact keys, a trailing wildcard (`nodes.*`) or `*`.
|
|
40
|
+
model WebhookEndpoint {
|
|
41
|
+
id String @id @default(uuid()) @db.Uuid
|
|
42
|
+
orgId String? @map("org_id") @db.Uuid
|
|
43
|
+
scope WebhookScope
|
|
44
|
+
ownerUserId String? @map("owner_user_id") @db.Uuid
|
|
45
|
+
createdById String? @map("created_by_id") @db.Uuid
|
|
46
|
+
name String @db.VarChar(120)
|
|
47
|
+
description String? @db.VarChar(500)
|
|
48
|
+
url String @db.VarChar(2048)
|
|
49
|
+
eventKeys String[] @map("event_keys")
|
|
50
|
+
enabled Boolean @default(true)
|
|
51
|
+
secretVersion Int @default(1) @map("secret_version")
|
|
52
|
+
previousSecretUntil DateTime? @map("previous_secret_until") @db.Timestamptz
|
|
53
|
+
consecutiveFailures Int @default(0) @map("consecutive_failures")
|
|
54
|
+
disabledReason String? @map("disabled_reason") @db.VarChar(64)
|
|
55
|
+
lastDeliveryAt DateTime? @map("last_delivery_at") @db.Timestamptz
|
|
56
|
+
lastSuccessAt DateTime? @map("last_success_at") @db.Timestamptz
|
|
57
|
+
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
|
|
58
|
+
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz
|
|
59
|
+
|
|
60
|
+
// Deleting the owning user (or the organization) deletes the endpoint and,
|
|
61
|
+
// through it, its deliveries.
|
|
62
|
+
owner User? @relation("WebhookEndpointOwner", fields: [ownerUserId], references: [id], onDelete: Cascade)
|
|
63
|
+
organization Organization? @relation(fields: [orgId], references: [id], onDelete: Cascade)
|
|
64
|
+
deliveries WebhookDelivery[]
|
|
65
|
+
|
|
66
|
+
@@index([orgId, scope, enabled])
|
|
67
|
+
@@index([ownerUserId])
|
|
68
|
+
@@map("webhook_endpoints")
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/// One attempt chain of one event to one endpoint. `id` is also the
|
|
72
|
+
/// `webhook-id` header, stable across retries. `payload` is the exact JSON body
|
|
73
|
+
/// sent (already redacted). `@@unique([endpointId, eventId])` makes fan-out
|
|
74
|
+
/// idempotent per endpoint and event.
|
|
75
|
+
model WebhookDelivery {
|
|
76
|
+
id String @id @default(uuid()) @db.Uuid
|
|
77
|
+
orgId String? @map("org_id") @db.Uuid
|
|
78
|
+
endpointId String @map("endpoint_id") @db.Uuid
|
|
79
|
+
eventKey String @map("event_key") @db.VarChar(128)
|
|
80
|
+
eventId String @map("event_id") @db.Uuid
|
|
81
|
+
payload Json
|
|
82
|
+
status WebhookDeliveryStatus @default(pending)
|
|
83
|
+
attempt Int @default(0)
|
|
84
|
+
responseStatus Int? @map("response_status")
|
|
85
|
+
responseSnippet String? @map("response_snippet") @db.VarChar(1024)
|
|
86
|
+
errorCode String? @map("error_code") @db.VarChar(64)
|
|
87
|
+
durationMs Int? @map("duration_ms")
|
|
88
|
+
nextAttemptAt DateTime? @map("next_attempt_at") @db.Timestamptz
|
|
89
|
+
deliveredAt DateTime? @map("delivered_at") @db.Timestamptz
|
|
90
|
+
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
|
|
91
|
+
|
|
92
|
+
endpoint WebhookEndpoint @relation(fields: [endpointId], references: [id], onDelete: Cascade)
|
|
93
|
+
|
|
94
|
+
@@unique([endpointId, eventId])
|
|
95
|
+
@@index([endpointId, createdAt(sort: Desc)])
|
|
96
|
+
@@index([orgId, createdAt])
|
|
97
|
+
@@index([eventId])
|
|
98
|
+
@@index([createdAt])
|
|
99
|
+
@@map("webhook_deliveries")
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
extend model User {
|
|
103
|
+
webhookEndpoints WebhookEndpoint[] @relation("WebhookEndpointOwner")
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
extend model Organization {
|
|
107
|
+
webhookEndpoints WebhookEndpoint[]
|
|
108
|
+
}
|