@12-apps/prisma 1.2.0 → 1.3.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@12-apps/prisma",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Prisma host: the multi-file schema folder, the plugin migration seam, and the shared PrismaClient singleton with its audit / append-only extensions",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@12-apps/entitlements": "^1.20.1",
|
|
53
|
-
"@12-apps/entity-lifecycle": "^2.
|
|
53
|
+
"@12-apps/entity-lifecycle": "^2.1.0",
|
|
54
54
|
"@12-apps/eslint-config": "^1.20.0",
|
|
55
55
|
"@12-apps/jobs": "^2.0.0",
|
|
56
56
|
"@12-apps/payments-backend": "^2.0.0",
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
-- @12-apps/entity-lifecycle (12-17): the four generic lifecycle tables, owned
|
|
2
|
+
-- by the package and copied into a host's migrations folder by its
|
|
3
|
+
-- plugin-migration sync. Deliberately NO foreign keys into host tables (the
|
|
4
|
+
-- payments-backend doctrine): `client_id`, `entity_id` and the actor ids are
|
|
5
|
+
-- by-value scalars, and the host's own migration may add FK constraints
|
|
6
|
+
-- (recommended: client_id ON DELETE CASCADE). The tree relation INTERNAL to
|
|
7
|
+
-- recycle_bin_entries IS constrained, with a cascade, so a removed root can
|
|
8
|
+
-- never leave orphan children. The CHECK constraints ARE here: kind/status/
|
|
9
|
+
-- action are the library's own closed sets, not host vocabulary.
|
|
10
|
+
--
|
|
11
|
+
-- Runs identically on PostgreSQL + PGlite.
|
|
12
|
+
|
|
13
|
+
-- ---------------------------------------------------------------------------
|
|
14
|
+
-- Version history. v1 (and any retention-compaction base) is a FULL snapshot;
|
|
15
|
+
-- other rows are DELTAS (changed top-level fields + removed field names). The
|
|
16
|
+
-- state at version N is rebuilt by replaying rows 1..N. Append-only.
|
|
17
|
+
-- ---------------------------------------------------------------------------
|
|
18
|
+
CREATE TABLE "entity_versions" (
|
|
19
|
+
"id" TEXT NOT NULL,
|
|
20
|
+
"client_id" TEXT NOT NULL,
|
|
21
|
+
"entity_type" TEXT NOT NULL,
|
|
22
|
+
"entity_id" TEXT NOT NULL,
|
|
23
|
+
"version" INTEGER NOT NULL,
|
|
24
|
+
"kind" TEXT NOT NULL,
|
|
25
|
+
"is_snapshot" BOOLEAN NOT NULL,
|
|
26
|
+
"data" JSONB NOT NULL,
|
|
27
|
+
"removed_fields" JSONB NOT NULL DEFAULT '[]',
|
|
28
|
+
"actor_id" TEXT,
|
|
29
|
+
"restored_from" INTEGER,
|
|
30
|
+
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
31
|
+
|
|
32
|
+
CONSTRAINT "entity_versions_pkey" PRIMARY KEY ("id")
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
CREATE UNIQUE INDEX "entity_versions_client_id_entity_type_entity_id_version_key"
|
|
36
|
+
ON "entity_versions"("client_id", "entity_type", "entity_id", "version");
|
|
37
|
+
CREATE INDEX "entity_versions_client_id_entity_type_entity_id_idx"
|
|
38
|
+
ON "entity_versions"("client_id", "entity_type", "entity_id");
|
|
39
|
+
-- Serves the retention sweep ("versions older than N days").
|
|
40
|
+
CREATE INDEX "entity_versions_created_at_idx" ON "entity_versions"("created_at");
|
|
41
|
+
|
|
42
|
+
ALTER TABLE "entity_versions" ADD CONSTRAINT "entity_versions_kind_check"
|
|
43
|
+
CHECK ("kind" IN ('CREATE', 'UPDATE', 'RESTORE'));
|
|
44
|
+
ALTER TABLE "entity_versions" ADD CONSTRAINT "entity_versions_version_positive"
|
|
45
|
+
CHECK ("version" >= 1);
|
|
46
|
+
|
|
47
|
+
-- ---------------------------------------------------------------------------
|
|
48
|
+
-- Recycle bin. A deletion records a TREE (root + one child per dependent
|
|
49
|
+
-- record, linked via parent_entry_id). Restore/purge keep the row as an audit
|
|
50
|
+
-- trail (status flip, never a delete).
|
|
51
|
+
-- ---------------------------------------------------------------------------
|
|
52
|
+
CREATE TABLE "recycle_bin_entries" (
|
|
53
|
+
"id" TEXT NOT NULL,
|
|
54
|
+
"client_id" TEXT NOT NULL,
|
|
55
|
+
"entity_type" TEXT NOT NULL,
|
|
56
|
+
"entity_id" TEXT NOT NULL,
|
|
57
|
+
"parent_entry_id" TEXT,
|
|
58
|
+
"label" TEXT NOT NULL,
|
|
59
|
+
"snapshot" JSONB NOT NULL,
|
|
60
|
+
"status" TEXT NOT NULL DEFAULT 'DELETED',
|
|
61
|
+
"deleted_by" TEXT,
|
|
62
|
+
"deleted_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
63
|
+
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
64
|
+
|
|
65
|
+
CONSTRAINT "recycle_bin_entries_pkey" PRIMARY KEY ("id")
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
CREATE INDEX "recycle_bin_entries_client_id_status_deleted_at_idx"
|
|
69
|
+
ON "recycle_bin_entries"("client_id", "status", "deleted_at");
|
|
70
|
+
CREATE INDEX "recycle_bin_entries_client_id_entity_type_entity_id_idx"
|
|
71
|
+
ON "recycle_bin_entries"("client_id", "entity_type", "entity_id");
|
|
72
|
+
CREATE INDEX "recycle_bin_entries_parent_entry_id_idx"
|
|
73
|
+
ON "recycle_bin_entries"("parent_entry_id");
|
|
74
|
+
|
|
75
|
+
ALTER TABLE "recycle_bin_entries" ADD CONSTRAINT "recycle_bin_entries_status_check"
|
|
76
|
+
CHECK ("status" IN ('DELETED', 'RESTORED', 'PURGED'));
|
|
77
|
+
ALTER TABLE "recycle_bin_entries" ADD CONSTRAINT "recycle_bin_entries_parent_entry_id_fkey"
|
|
78
|
+
FOREIGN KEY ("parent_entry_id") REFERENCES "recycle_bin_entries"("id")
|
|
79
|
+
ON DELETE CASCADE ON UPDATE CASCADE;
|
|
80
|
+
|
|
81
|
+
-- ---------------------------------------------------------------------------
|
|
82
|
+
-- Drafts. entity_id NULL = draft of a brand-new item. At most one OPEN draft
|
|
83
|
+
-- per (tenant, type, entity) — a partial unique index, which Prisma cannot
|
|
84
|
+
-- express in the schema (hence raw SQL here).
|
|
85
|
+
-- ---------------------------------------------------------------------------
|
|
86
|
+
CREATE TABLE "entity_drafts" (
|
|
87
|
+
"id" TEXT NOT NULL,
|
|
88
|
+
"client_id" TEXT NOT NULL,
|
|
89
|
+
"entity_type" TEXT NOT NULL,
|
|
90
|
+
"entity_id" TEXT,
|
|
91
|
+
"data" JSONB NOT NULL,
|
|
92
|
+
"status" TEXT NOT NULL DEFAULT 'OPEN',
|
|
93
|
+
"created_by" TEXT,
|
|
94
|
+
"updated_by" TEXT,
|
|
95
|
+
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
96
|
+
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
97
|
+
|
|
98
|
+
CONSTRAINT "entity_drafts_pkey" PRIMARY KEY ("id")
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
CREATE INDEX "entity_drafts_client_id_entity_type_status_idx"
|
|
102
|
+
ON "entity_drafts"("client_id", "entity_type", "status");
|
|
103
|
+
CREATE INDEX "entity_drafts_client_id_entity_type_entity_id_idx"
|
|
104
|
+
ON "entity_drafts"("client_id", "entity_type", "entity_id");
|
|
105
|
+
CREATE UNIQUE INDEX "entity_drafts_open_entity_key"
|
|
106
|
+
ON "entity_drafts"("client_id", "entity_type", "entity_id")
|
|
107
|
+
WHERE "status" = 'OPEN' AND "entity_id" IS NOT NULL;
|
|
108
|
+
|
|
109
|
+
ALTER TABLE "entity_drafts" ADD CONSTRAINT "entity_drafts_status_check"
|
|
110
|
+
CHECK ("status" IN ('OPEN', 'PUBLISHED', 'DISCARDED'));
|
|
111
|
+
|
|
112
|
+
-- ---------------------------------------------------------------------------
|
|
113
|
+
-- Change approvals. Writes by non-approvers park here; deciders apply/reject.
|
|
114
|
+
-- Decided rows are kept as an audit trail.
|
|
115
|
+
-- ---------------------------------------------------------------------------
|
|
116
|
+
CREATE TABLE "change_requests" (
|
|
117
|
+
"id" TEXT NOT NULL,
|
|
118
|
+
"client_id" TEXT NOT NULL,
|
|
119
|
+
"entity_type" TEXT NOT NULL,
|
|
120
|
+
"entity_id" TEXT,
|
|
121
|
+
"action" TEXT NOT NULL,
|
|
122
|
+
"payload" JSONB NOT NULL,
|
|
123
|
+
"status" TEXT NOT NULL DEFAULT 'PENDING',
|
|
124
|
+
"requested_by" TEXT,
|
|
125
|
+
"requested_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
126
|
+
"decided_by" TEXT,
|
|
127
|
+
"decided_at" TIMESTAMP(3),
|
|
128
|
+
"decision_note" TEXT,
|
|
129
|
+
|
|
130
|
+
CONSTRAINT "change_requests_pkey" PRIMARY KEY ("id")
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
CREATE INDEX "change_requests_client_id_status_requested_at_idx"
|
|
134
|
+
ON "change_requests"("client_id", "status", "requested_at");
|
|
135
|
+
CREATE INDEX "change_requests_client_id_entity_type_entity_id_idx"
|
|
136
|
+
ON "change_requests"("client_id", "entity_type", "entity_id");
|
|
137
|
+
|
|
138
|
+
ALTER TABLE "change_requests" ADD CONSTRAINT "change_requests_action_check"
|
|
139
|
+
CHECK ("action" IN ('CREATE', 'UPDATE', 'DELETE'));
|
|
140
|
+
ALTER TABLE "change_requests" ADD CONSTRAINT "change_requests_status_check"
|
|
141
|
+
CHECK ("status" IN ('PENDING', 'APPROVED', 'REJECTED'));
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"20260810160000_report_default_range_month",
|
|
26
26
|
"20260810180000_add_report_working_copy",
|
|
27
27
|
"20260812120000_add_rbac_tables",
|
|
28
|
-
"20260812120000_add_retention_watermarks"
|
|
28
|
+
"20260812120000_add_retention_watermarks",
|
|
29
|
+
"20260813120000_add_entity_lifecycle_tables"
|
|
29
30
|
]
|
|
30
31
|
}
|