Skip to content

Commit e8be19d

Browse files
bchapuisclaude
andcommitted
Add optional id to Schema so user-defined schemas preserve identity at runtime
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b1c2c58 commit e8be19d

4 files changed

Lines changed: 18 additions & 11 deletions

File tree

apps/api/src/runtime/cloudflare-schema-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class CloudflareSchemaService implements SchemaService {
2121
if (!row) return undefined;
2222

2323
return {
24+
id: schemaId,
2425
name: row.name,
2526
description: row.description,
2627
fields: JSON.parse(row.fields),

apps/app/src/pages/database-explorer-page.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ function SchemaFlowCanvas({ tables }: SchemaFlowCanvasProps) {
142142
// fall back to the primary key column of the referenced table.
143143
let targetCol = fk.referencedColumn;
144144
if (!targetCol) {
145-
const refTable = tables.find(
146-
(t) => t.name === fk.referencedTable
147-
);
145+
const refTable = tables.find((t) => t.name === fk.referencedTable);
148146
const pk = refTable?.columns.find((c) => c.primaryKey);
149147
if (!pk) return null;
150148
targetCol = pk.name;

packages/runtime/src/nodes/database/database-put-row-node.test.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,25 @@ describe("DatabasePutRowNode", () => {
149149
expect(result.error).toContain("Invalid schema");
150150
});
151151

152-
it("should return error for schema without primary key", async () => {
152+
it("should insert row with INSERT INTO for schema without primary key", async () => {
153153
const node = createNode();
154+
const connection = createMockConnection();
154155
const result = await node.execute(
155-
createContext({
156-
database: "db-1",
157-
schema: schemaWithoutPk,
158-
record: { message: "test" },
159-
})
156+
createContext(
157+
{
158+
database: "db-1",
159+
schema: schemaWithoutPk,
160+
record: { message: "hello", level: "info" },
161+
},
162+
connection
163+
)
160164
);
161165

162-
expect(result.status).toBe("error");
163-
expect(result.error).toContain("no primary key defined");
166+
expect(result.status).toBe("completed");
167+
expect(connection.execute).toHaveBeenCalledWith(
168+
"INSERT INTO logs (message, level) VALUES (?, ?)",
169+
["hello", "info"]
170+
);
164171
});
165172

166173
it("should return error for missing record", async () => {

packages/types/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export interface Field {
4545
* Schema definition
4646
*/
4747
export interface Schema {
48+
id?: string;
4849
name: string;
4950
description?: string;
5051
fields: Field[];

0 commit comments

Comments
 (0)