cursedbelt-server 4.47.0 → 4.47.1

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.
@@ -340,7 +340,7 @@ export async function pullD1ToSqlite(options) {
340
340
  const dumps = tables.map((table, i) => {
341
341
  const cols = (columnSets[i] ?? []);
342
342
  const plan = tablePlan(table, rows.find((r) => r.name === table)?.sql ?? null, cols);
343
- return { table, ...dumpTable(caller, database, plan) };
343
+ return { table, columns: plan.columns, ...dumpTable(caller, database, plan) };
344
344
  });
345
345
  if (dumps.every((d) => d.rows === 0)) {
346
346
  throw new Error('the D1 pull contains no rows — refusing to snapshot an empty database as if it were the library');
@@ -369,6 +369,19 @@ export async function pullD1ToSqlite(options) {
369
369
  continue;
370
370
  db.exec(row.sql.replace(/^\s*CREATE\s+TABLE\s+(?!IF\s+NOT\s+EXISTS)/i, 'CREATE TABLE IF NOT EXISTS '));
371
371
  }
372
+ // 🔴 Likewise a COLUMN D1 holds that the schema does not declare is added, untyped, so its
373
+ // values land exactly as D1 quoted them: measured on music (2026-10-20), the schema dropped
374
+ // `tracks.rating` before production D1 did, and every night between the two refused with
375
+ // `table tracks has no column named rating`. A backup keeps what the live rows hold.
376
+ for (const { table, columns } of dumps) {
377
+ const local = new Set(db.query(`SELECT name FROM pragma_table_info(${sqlText(table)})`).all().map((c) => c.name.toLowerCase()));
378
+ if (local.size === 0)
379
+ continue;
380
+ for (const column of columns) {
381
+ if (!local.has(column.toLowerCase()))
382
+ db.exec(`ALTER TABLE ${sqlIdent(table)} ADD COLUMN ${sqlIdent(column)}`);
383
+ }
384
+ }
372
385
  // One table at a time, so a fault is located rather than smeared over the whole load.
373
386
  for (const { text } of dumps)
374
387
  if (text)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursedbelt-server",
3
- "version": "4.47.0",
3
+ "version": "4.47.1",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "description": "The app-facing Bun/Hono server tier of the cursedbelt split — storage, sharing, activity, guard, sync. React-free; cursedbelt-core below it.",
@@ -364,6 +364,18 @@ describe('pulling D1 down — paged SELECTs, table by table, never an export', (
364
364
  expect(row?.art_key).toBe('art/1');
365
365
  });
366
366
 
367
+ test('🔴 a column D1 holds that the schema has dropped is added to the snapshot, never refused (music, 2026-10-20)', async () => {
368
+ const dir = scratch();
369
+ // The schema stopped declaring `tracks.rating` before production D1 dropped it: every night
370
+ // between those two refused with `table tracks has no column named rating`.
371
+ const source = live("ALTER TABLE items ADD COLUMN rating INTEGER; INSERT INTO items VALUES ('i1', 'x', 4);");
372
+ await pull(dir, d1(source).run);
373
+ const db = opened(dir);
374
+ const row = db.query('select name, rating from items').get() as { name: string; rating: number } | null;
375
+ db.close();
376
+ expect(row).toEqual({ name: 'x', rating: 4 });
377
+ });
378
+
367
379
  test('🔴 a schema TRIGGER does not fire on the restored rows, and is in the snapshot after (collections, 2026-09-29)', async () => {
368
380
  const dir = scratch();
369
381
  const schema = `${SCHEMA}
@@ -408,7 +408,7 @@ export async function pullD1ToSqlite(options: PullD1Options): Promise<void> {
408
408
  const dumps = tables.map((table, i) => {
409
409
  const cols = (columnSets[i] ?? []) as Array<{ name: string; pk: number }>;
410
410
  const plan = tablePlan(table, rows.find((r) => r.name === table)?.sql ?? null, cols);
411
- return { table, ...dumpTable(caller, database, plan) };
411
+ return { table, columns: plan.columns, ...dumpTable(caller, database, plan) };
412
412
  });
413
413
  if (dumps.every((d) => d.rows === 0)) {
414
414
  throw new Error('the D1 pull contains no rows — refusing to snapshot an empty database as if it were the library');
@@ -441,6 +441,21 @@ export async function pullD1ToSqlite(options: PullD1Options): Promise<void> {
441
441
  if (!tables.includes(row.name) || have.has(row.name) || !row.sql) continue;
442
442
  db.exec(row.sql.replace(/^\s*CREATE\s+TABLE\s+(?!IF\s+NOT\s+EXISTS)/i, 'CREATE TABLE IF NOT EXISTS '));
443
443
  }
444
+ // 🔴 Likewise a COLUMN D1 holds that the schema does not declare is added, untyped, so its
445
+ // values land exactly as D1 quoted them: measured on music (2026-10-20), the schema dropped
446
+ // `tracks.rating` before production D1 did, and every night between the two refused with
447
+ // `table tracks has no column named rating`. A backup keeps what the live rows hold.
448
+ for (const { table, columns } of dumps) {
449
+ const local = new Set(
450
+ (db.query(`SELECT name FROM pragma_table_info(${sqlText(table)})`).all() as { name: string }[]).map((c) =>
451
+ c.name.toLowerCase(),
452
+ ),
453
+ );
454
+ if (local.size === 0) continue;
455
+ for (const column of columns) {
456
+ if (!local.has(column.toLowerCase())) db.exec(`ALTER TABLE ${sqlIdent(table)} ADD COLUMN ${sqlIdent(column)}`);
457
+ }
458
+ }
444
459
  // One table at a time, so a fault is located rather than smeared over the whole load.
445
460
  for (const { text } of dumps) if (text) db.exec(text);
446
461
  for (const t of triggers) db.exec(t.sql);