@paperclipai/db 2026.1007.0-canary.7 → 2026.1007.0-canary.8

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.
@@ -0,0 +1,28 @@
1
+ -- Runs through the Paperclip migration executor outside a file-wide transaction.
2
+ -- Each idempotent keyset batch commits before advancing; history is recorded last.
3
+ -- Bind historical inline draft images to their first owned task. Unbound drafts
4
+ -- remain uploader-only. Attachment deletion never makes the draft company-open.
5
+ DO $$
6
+ DECLARE cursor_id uuid := '00000000-0000-0000-0000-000000000000'; next_id uuid;
7
+ BEGIN
8
+ LOOP
9
+ SELECT max(id::text)::uuid INTO next_id FROM (
10
+ SELECT id FROM assets WHERE id > cursor_id AND object_key LIKE company_id::text || '/assets/issues/drafts/%'
11
+ ORDER BY id LIMIT 1000
12
+ ) batch;
13
+ EXIT WHEN next_id IS NULL;
14
+ INSERT INTO issue_attachments (company_id, issue_id, asset_id)
15
+ SELECT a.company_id, first_issue.id, a.id FROM assets a
16
+ CROSS JOIN LATERAL (
17
+ SELECT i.id FROM issues i WHERE i.company_id = a.company_id
18
+ AND (i.created_by_user_id = a.created_by_user_id OR i.responsible_user_id = a.created_by_user_id
19
+ OR i.created_by_agent_id = a.created_by_agent_id)
20
+ AND strpos(coalesce(i.description, ''), '/api/assets/' || a.id::text || '/content') > 0
21
+ ORDER BY i.created_at, i.id LIMIT 1
22
+ ) first_issue
23
+ WHERE a.id > cursor_id AND a.id <= next_id AND a.object_key LIKE a.company_id::text || '/assets/issues/drafts/%'
24
+ ON CONFLICT DO NOTHING;
25
+ cursor_id := next_id;
26
+ COMMIT;
27
+ END LOOP;
28
+ END $$;
@@ -2185,6 +2185,13 @@
2185
2185
  "when": 1791371746435,
2186
2186
  "tag": "0313_private_task_access",
2187
2187
  "breakpoints": true
2188
+ },
2189
+ {
2190
+ "idx": 314,
2191
+ "version": "7",
2192
+ "when": 1791371819805,
2193
+ "tag": "0314_private_task_draft_assets",
2194
+ "breakpoints": true
2188
2195
  }
2189
2196
  ]
2190
- }
2197
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=private-task-draft-assets-migration.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private-task-draft-assets-migration.test.d.ts","sourceRoot":"","sources":["../src/private-task-draft-assets-migration.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import fs from "node:fs/promises";
3
+ import postgres from "postgres";
4
+ import { expect, it } from "vitest";
5
+ import { applyPendingMigrations } from "./client.js";
6
+ import { getEmbeddedPostgresTestSupport, startEmbeddedPostgresTestDatabase } from "./test-embedded-postgres.js";
7
+ const embeddedPostgresSupport = await getEmbeddedPostgresTestSupport();
8
+ const itEmbeddedPostgres = embeddedPostgresSupport.supported ? it : it.skip;
9
+ itEmbeddedPostgres("backfills owned draft images without attaching another uploader's images", async () => {
10
+ const database = await startEmbeddedPostgresTestDatabase("paperclip-draft-privacy-");
11
+ const sql = postgres(database.connectionString, { max: 1, onnotice: () => { } });
12
+ try {
13
+ const migration = await fs.readFile(new URL("./migrations/0314_private_task_draft_assets.sql", import.meta.url), "utf8");
14
+ const hash = createHash("sha256").update(migration).digest("hex");
15
+ const company = randomUUID(), task = randomUUID(), owned = randomUUID(), foreign = randomUUID();
16
+ await sql `INSERT INTO companies (id, name, issue_prefix) VALUES (${company}, 'Draft privacy', 'DRAFT')`;
17
+ for (const [id, owner] of [[owned, 'owner'], [foreign, 'someone-else']]) {
18
+ await sql `INSERT INTO assets (id, company_id, provider, object_key, content_type, byte_size, sha256, created_by_user_id)
19
+ VALUES (${id}, ${company}, 'local_disk', ${`${company}/assets/issues/drafts/${id}`}, 'image/png', 1, 'test', ${owner})`;
20
+ }
21
+ await sql `INSERT INTO issues (id, company_id, title, description, visibility, created_by_user_id)
22
+ VALUES (${task}, ${company}, 'Private task', ${`![owned](/api/assets/${owned}/content) ![foreign](/api/assets/${foreign}/content)`}, 'private', 'owner')`;
23
+ for (let run = 0; run < 2; run += 1) {
24
+ await sql `DELETE FROM drizzle.__drizzle_migrations WHERE hash = ${hash}`;
25
+ await applyPendingMigrations(database.connectionString);
26
+ expect(await sql `SELECT issue_id, asset_id FROM issue_attachments WHERE company_id = ${company}`)
27
+ .toEqual([{ issue_id: task, asset_id: owned }]);
28
+ }
29
+ }
30
+ finally {
31
+ await sql.end();
32
+ await database.cleanup();
33
+ }
34
+ }, 60_000);
35
+ //# sourceMappingURL=private-task-draft-assets-migration.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private-task-draft-assets-migration.test.js","sourceRoot":"","sources":["../src/private-task-draft-assets-migration.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,8BAA8B,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAC;AAEhH,MAAM,uBAAuB,GAAG,MAAM,8BAA8B,EAAE,CAAC;AACvE,MAAM,kBAAkB,GAAG,uBAAuB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC;AAE5E,kBAAkB,CAAC,0EAA0E,EAAE,KAAK,IAAI,EAAE;IACxG,MAAM,QAAQ,GAAG,MAAM,iCAAiC,CAAC,0BAA0B,CAAC,CAAC;IACrF,MAAM,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC,CAAC;IAChF,IAAI,CAAC;QACH,MAAM,S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AAC,GAAG,EAAE,CAAC;QAChB,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;AACH,CAAC,EAAE,MAAM,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paperclipai/db",
3
- "version": "2026.1007.0-canary.7",
3
+ "version": "2026.1007.0-canary.8",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/paperclipai/paperclip",
6
6
  "bugs": {
@@ -39,7 +39,7 @@
39
39
  "seed": "tsx src/seed.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@paperclipai/shared": "2026.1007.0-canary.7",
42
+ "@paperclipai/shared": "2026.1007.0-canary.8",
43
43
  "drizzle-orm": "^0.45.2",
44
44
  "embedded-postgres": "^18.1.0-beta.16",
45
45
  "postgres": "^3.4.9"