@aria-framework/db-worker 0.20.2 → 0.20.3
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 +1 -1
- package/tenancyMigration.js +22 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aria-framework/db-worker",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.3",
|
|
4
4
|
"description": "Aria App Framework \u2014 db-worker module. Async RPC bridge over synchronous better-sqlite3: a worker-thread dispatcher (runWorker), a main-thread client with per-call timeouts and crash handling (DbClient), and a SQLite layer with WAL pragmas + a numbered-migration runner (database).",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
package/tenancyMigration.js
CHANGED
|
@@ -197,7 +197,28 @@ function generateTenancyMigration(opts = {}) {
|
|
|
197
197
|
let n = 0;
|
|
198
198
|
for (const { table } of ordered) {
|
|
199
199
|
for (const fk of tenantFks(table)) {
|
|
200
|
-
|
|
200
|
+
// ── SET NULL ON A COMPOSITE KEY NULLS *BOTH* COLUMNS ──────────────────────────────
|
|
201
|
+
//
|
|
202
|
+
// The single-column FK this is derived from says ON DELETE SET NULL, and on
|
|
203
|
+
// (author_id) alone that is right: author_id is nullable, so deleting a user leaves
|
|
204
|
+
// their note attributed to nobody. Copied verbatim onto (author_id, partner_id) it also
|
|
205
|
+
// nulls the TENANT column — which is NOT NULL — so the delete fails outright:
|
|
206
|
+
//
|
|
207
|
+
// null value in column "partner_id" of relation "record_notes"
|
|
208
|
+
// violates not-null constraint
|
|
209
|
+
//
|
|
210
|
+
// MEASURED: deleting a user who had authored one note. The app could not remove a user
|
|
211
|
+
// who had ever done anything, on Postgres only, with an error naming a column nobody
|
|
212
|
+
// had touched. Postgres 15+ takes a column list on SET NULL, which nulls exactly the
|
|
213
|
+
// child column and leaves the tenant intact — the behaviour the original FK described.
|
|
214
|
+
//
|
|
215
|
+
// Only SET NULL needs this. CASCADE deletes the whole row (partner_id goes with it),
|
|
216
|
+
// and RESTRICT/NO ACTION write nothing.
|
|
217
|
+
const del = !fk.onDelete || fk.onDelete === 'NO ACTION'
|
|
218
|
+
? ''
|
|
219
|
+
: (fk.onDelete === 'SET NULL'
|
|
220
|
+
? ` ON DELETE SET NULL (${fk.from})`
|
|
221
|
+
: ` ON DELETE ${fk.onDelete}`);
|
|
201
222
|
out.push(
|
|
202
223
|
`ALTER TABLE ${table} ADD CONSTRAINT fk_${table}_${fk.from}_partner`
|
|
203
224
|
+ ` FOREIGN KEY (${fk.from}, partner_id)`
|