deepspace 0.3.3 → 0.3.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/dist/worker.d.ts +8 -0
- package/dist/worker.js +13 -11
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
package/dist/worker.d.ts
CHANGED
|
@@ -2845,6 +2845,14 @@ declare const COST_RATES: {
|
|
|
2845
2845
|
* ])
|
|
2846
2846
|
* ```
|
|
2847
2847
|
*
|
|
2848
|
+
* **SQL formatting:** statements may span multiple lines freely. The runner
|
|
2849
|
+
* splits each migration string on `;` and runs each fragment via
|
|
2850
|
+
* `prepare().run()`. That sidesteps `db.exec()`'s newline-or-semicolon quirks
|
|
2851
|
+
* (it's optimized for migration files, not inline strings) and gets you
|
|
2852
|
+
* predictable single-statement semantics. Trailing `;` after the last
|
|
2853
|
+
* statement is fine; semicolons inside string literals are not (we use a
|
|
2854
|
+
* naive split, since DDL almost never has them).
|
|
2855
|
+
*
|
|
2848
2856
|
* Each entry in the array is one migration. The runner records the index of
|
|
2849
2857
|
* each successfully-applied migration in `_dpc_migrations`; subsequent calls
|
|
2850
2858
|
* skip rows already recorded. Adding a new migration means appending to the
|
package/dist/worker.js
CHANGED
|
@@ -6118,12 +6118,9 @@ var COST_RATES = {
|
|
|
6118
6118
|
|
|
6119
6119
|
// src/server/utils/d1-migrations.ts
|
|
6120
6120
|
var META_TABLE = "_dpc_migrations";
|
|
6121
|
-
var META_BOOTSTRAP_SQL = `CREATE TABLE IF NOT EXISTS ${META_TABLE} (
|
|
6122
|
-
idx INTEGER PRIMARY KEY,
|
|
6123
|
-
applied_at TEXT NOT NULL
|
|
6124
|
-
);`;
|
|
6121
|
+
var META_BOOTSTRAP_SQL = `CREATE TABLE IF NOT EXISTS ${META_TABLE} (idx INTEGER PRIMARY KEY, applied_at TEXT NOT NULL)`;
|
|
6125
6122
|
async function runMigrations(db, migrations) {
|
|
6126
|
-
await db.
|
|
6123
|
+
await db.prepare(META_BOOTSTRAP_SQL).run();
|
|
6127
6124
|
const row = await db.prepare(`SELECT COUNT(*) AS n FROM ${META_TABLE}`).first();
|
|
6128
6125
|
const fromVersion = row?.n ?? 0;
|
|
6129
6126
|
if (fromVersion >= migrations.length) {
|
|
@@ -6131,18 +6128,23 @@ async function runMigrations(db, migrations) {
|
|
|
6131
6128
|
}
|
|
6132
6129
|
let current = fromVersion;
|
|
6133
6130
|
for (let i = fromVersion; i < migrations.length; i++) {
|
|
6134
|
-
const
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6131
|
+
const statements = splitStatements(migrations[i]);
|
|
6132
|
+
for (const stmt of statements) {
|
|
6133
|
+
try {
|
|
6134
|
+
await db.prepare(stmt).run();
|
|
6135
|
+
} catch (err) {
|
|
6136
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
6137
|
+
throw new Error(`Migration ${i} failed (db at version=${current}): ${msg}`);
|
|
6138
|
+
}
|
|
6140
6139
|
}
|
|
6141
6140
|
await db.prepare(`INSERT INTO ${META_TABLE} (idx, applied_at) VALUES (?, ?)`).bind(i, (/* @__PURE__ */ new Date()).toISOString()).run();
|
|
6142
6141
|
current = i + 1;
|
|
6143
6142
|
}
|
|
6144
6143
|
return { fromVersion, toVersion: current, applied: current - fromVersion };
|
|
6145
6144
|
}
|
|
6145
|
+
function splitStatements(sql) {
|
|
6146
|
+
return sql.split(";").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
6147
|
+
}
|
|
6146
6148
|
export {
|
|
6147
6149
|
AI_CHATS_SCHEMA,
|
|
6148
6150
|
AI_MESSAGES_SCHEMA,
|