@mastra/libsql 1.17.0-alpha.3 → 1.17.0-alpha.4
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/CHANGELOG.md +12 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agent-builder-overview.md +2 -0
- package/dist/index.cjs +33 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -1
- package/dist/index.js.map +1 -1
- package/dist/storage/factory-storage.d.ts.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @mastra/libsql
|
|
2
2
|
|
|
3
|
+
## 1.17.0-alpha.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix factory storage error classification and schema drift handling. ([#20002](https://github.com/mastra-ai/mastra/pull/20002))
|
|
8
|
+
|
|
9
|
+
- `isUniqueViolation` in the LibSQL factory storage now only matches real unique-index violations (`SQLITE_CONSTRAINT_UNIQUE` / `SQLITE_CONSTRAINT_PRIMARYKEY`). Previously any `SQLITE_CONSTRAINT` failure — including NOT NULL violations — was reported as a "Unique constraint violation", which masked the real error (seen as `Unique constraint violation on collection 'factory_rule_evaluations'` when polled ingestion inserted nullable columns into a stale table).
|
|
10
|
+
- `ensureCollections` in both the LibSQL and Postgres factory storage adapters now relaxes stale NOT NULL constraints when a column becomes nullable in the schema. Postgres uses `ALTER COLUMN ... DROP NOT NULL`; LibSQL rebuilds the table in place since SQLite cannot drop NOT NULL directly. Existing rows and unique indexes are preserved.
|
|
11
|
+
|
|
12
|
+
- Updated dependencies:
|
|
13
|
+
- @mastra/core@1.52.0-alpha.13
|
|
14
|
+
|
|
3
15
|
## 1.17.0-alpha.3
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -88,6 +88,8 @@ Start Mastra's development server:
|
|
|
88
88
|
npx mastra dev
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
+
For Agent Builder development, you can also use `mastra factory dev`, which uses the same dev runtime and flags as `mastra dev` and writes to the same `.mastra/output` directory. Both commands share a dev lock and can't run simultaneously in the same project. See the [CLI reference](https://mastra.ai/reference/cli/mastra) for details.
|
|
92
|
+
|
|
91
93
|
The Agent Builder is mounted at `http://localhost:4111/agent-builder`.
|
|
92
94
|
|
|
93
95
|
## Disabling the Builder
|
package/dist/index.cjs
CHANGED
|
@@ -13365,8 +13365,10 @@ function assertIdentifier(kind, name) {
|
|
|
13365
13365
|
}
|
|
13366
13366
|
}
|
|
13367
13367
|
function isUniqueViolation(error) {
|
|
13368
|
+
const code = typeof error === "object" && error !== null ? error.code : void 0;
|
|
13369
|
+
if (code === "SQLITE_CONSTRAINT_UNIQUE" || code === "SQLITE_CONSTRAINT_PRIMARYKEY") return true;
|
|
13368
13370
|
const message = error instanceof Error ? error.message : String(error);
|
|
13369
|
-
return message.includes("UNIQUE constraint failed") || message.includes("
|
|
13371
|
+
return message.includes("UNIQUE constraint failed") || message.includes("SQLITE_CONSTRAINT_UNIQUE") || message.includes("SQLITE_CONSTRAINT_PRIMARYKEY");
|
|
13370
13372
|
}
|
|
13371
13373
|
function primaryKeyOf(schema) {
|
|
13372
13374
|
const pks = Object.entries(schema.columns).filter(([, spec]) => spec.type === "uuid-pk" || spec.primaryKey);
|
|
@@ -13710,6 +13712,35 @@ var LibSQLFactoryStorage = class extends storage.FactoryStorage {
|
|
|
13710
13712
|
if (spec.default !== void 0) ddl += ` DEFAULT ${serializeDefault(spec.default)}`;
|
|
13711
13713
|
return ddl;
|
|
13712
13714
|
}
|
|
13715
|
+
/**
|
|
13716
|
+
* A table created by an older schema may still say NOT NULL on a column the
|
|
13717
|
+
* current schema declares nullable — inserts of null then fail on databases
|
|
13718
|
+
* that predate the change. SQLite has no `ALTER COLUMN DROP NOT NULL`, so
|
|
13719
|
+
* relaxation swaps in a table rebuilt from the current schema (create shadow
|
|
13720
|
+
* → copy → drop → rename) atomically.
|
|
13721
|
+
*/
|
|
13722
|
+
async #relaxDriftedNotNulls(schema) {
|
|
13723
|
+
const info = await this.#client.execute(`PRAGMA table_info("${schema.name}")`);
|
|
13724
|
+
const hasDrift = info.rows.some((row) => {
|
|
13725
|
+
const spec = schema.columns[String(row.name)];
|
|
13726
|
+
if (!spec || spec.type === "uuid-pk" || spec.primaryKey) return false;
|
|
13727
|
+
return spec.nullable === true && Number(row.notnull) === 1;
|
|
13728
|
+
});
|
|
13729
|
+
if (!hasDrift) return;
|
|
13730
|
+
const ddl = Object.entries(schema.columns).map(([name, spec]) => this.#columnDdl(name, spec));
|
|
13731
|
+
const shadow = `${schema.name}__nullable_rebuild`;
|
|
13732
|
+
const cols = Object.keys(schema.columns).map((name) => `"${name}"`).join(", ");
|
|
13733
|
+
await this.#client.batch(
|
|
13734
|
+
[
|
|
13735
|
+
`DROP TABLE IF EXISTS "${shadow}"`,
|
|
13736
|
+
`CREATE TABLE "${shadow}" (${ddl.join(", ")})`,
|
|
13737
|
+
`INSERT INTO "${shadow}" (${cols}) SELECT ${cols} FROM "${schema.name}"`,
|
|
13738
|
+
`DROP TABLE "${schema.name}"`,
|
|
13739
|
+
`ALTER TABLE "${shadow}" RENAME TO "${schema.name}"`
|
|
13740
|
+
],
|
|
13741
|
+
"write"
|
|
13742
|
+
);
|
|
13743
|
+
}
|
|
13713
13744
|
async #ensureCollection(schema) {
|
|
13714
13745
|
assertIdentifier("collection", schema.name);
|
|
13715
13746
|
primaryKeyOf(schema);
|
|
@@ -13721,6 +13752,7 @@ var LibSQLFactoryStorage = class extends storage.FactoryStorage {
|
|
|
13721
13752
|
if (existing.has(name)) continue;
|
|
13722
13753
|
await this.#client.execute(`ALTER TABLE "${schema.name}" ADD COLUMN ${this.#columnDdl(name, spec)}`);
|
|
13723
13754
|
}
|
|
13755
|
+
await this.#relaxDriftedNotNulls(schema);
|
|
13724
13756
|
for (const index of schema.uniqueIndexes ?? []) {
|
|
13725
13757
|
assertIdentifier("index", index.name);
|
|
13726
13758
|
index.columns.forEach((column) => assertIdentifier("column", column));
|