@aria-framework/db-worker 0.20.4 → 0.20.5
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 +21 -3
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.5",
|
|
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
|
@@ -350,12 +350,30 @@ function generateTenancyMigration(opts = {}) {
|
|
|
350
350
|
|
|
351
351
|
const expr = String(manifest.POLICY_EXPRESSION || '').trim();
|
|
352
352
|
const body = [];
|
|
353
|
-
for (const { table } of ordered) {
|
|
353
|
+
for (const { table, nullable } of ordered) {
|
|
354
354
|
body.push(`ALTER TABLE ${table} ENABLE ROW LEVEL SECURITY;`);
|
|
355
355
|
body.push(`ALTER TABLE ${table} FORCE ROW LEVEL SECURITY;`);
|
|
356
356
|
body.push(`CREATE POLICY tenant_isolation ON ${table} FOR ALL`);
|
|
357
|
-
|
|
358
|
-
|
|
357
|
+
if (nullable) {
|
|
358
|
+
// ── A NULLABLE partner_id MEANS "INSTALLATION-WIDE DEFAULT", AND THE TWO HALVES DIFFER ──
|
|
359
|
+
//
|
|
360
|
+
// The manifest classifies a table nullable precisely so a row with NO partner can act as
|
|
361
|
+
// the default for every tenant. The policy used the same expression for both halves, and
|
|
362
|
+
// `partner_id = current_setting(...)` is NULL for such a row — not true — so the default
|
|
363
|
+
// was INVISIBLE to every partner-scoped read and unwritable by any of them. The whole
|
|
364
|
+
// point of the classification was inoperative on Postgres, and worked on SQLite, where
|
|
365
|
+
// there is no policy to get wrong. Measured: a partner-scoped session saw 0 of 1 such rows
|
|
366
|
+
// and its insert was refused by the policy.
|
|
367
|
+
//
|
|
368
|
+
// READING a default is every tenant's business; CREATING one is not. So USING admits the
|
|
369
|
+
// NULL row and WITH CHECK does not — and platform scope still writes them, because the
|
|
370
|
+
// expression's platform arm is `true` and covers the NULL case on its own.
|
|
371
|
+
body.push(` USING (partner_id IS NULL OR (${expr}))`);
|
|
372
|
+
body.push(` WITH CHECK (${expr});`);
|
|
373
|
+
} else {
|
|
374
|
+
body.push(` USING (${expr})`);
|
|
375
|
+
body.push(` WITH CHECK (${expr});`);
|
|
376
|
+
}
|
|
359
377
|
body.push('');
|
|
360
378
|
}
|
|
361
379
|
const rlsFile = [
|