Repository navigation
Closed
Labels
Description
Problem
Schema operations in HttpAdapter still use old REST endpoints instead of SurrealQL queries:
addSchemaField()removeSchemaField()updateSchemaField()deleteSchema()
These operations call ${this.baseUrl}/api/schemas/... endpoints that depend on the custom HTTP dev-server which was removed in PR #497.
Impact
- Blocks full removal of custom dev-server code
- Schema modifications won't work in browser dev mode after migration
- Inconsistent with the SurrealQL migration approach used for CRUD/query/mention operations
Proposed Solution
Migrate schema operations to SurrealQL queries (similar to how getSchema() was migrated). Schema nodes are stored as regular nodes with node_type = "schema", so modifications can be done via UPDATE queries on the properties field.
Example Implementation
async addSchemaField(schemaId: string, config: AddFieldConfig): Promise<AddFieldResult> {
try {
// Fetch current schema
const schema = await this.getSchema(schemaId);
// Add new field to schema definition
const updatedFields = [...schema.fields, {
name: config.fieldName,
field_type: config.fieldType,
protection: config.protection || 'user',
// ... other field properties
}];
// Update schema node via SurrealQL
const sql = \`
UPDATE nodes:\\\`${schemaId}\\\`
SET properties.fields = ${this.toSurrealValue(updatedFields)},
properties.version = properties.version + 1,
modified_at = time::now()
WHERE node_type = "schema";
\`;
await this.surrealQuery(sql);
return {
schemaId,
newVersion: schema.version + 1,
success: true
};
} catch (error) {
throw new Error(\`Failed to add schema field: ${error}\`);
}
}Acceptance Criteria
-
addSchemaField()migrated to SurrealQL UPDATE query -
removeSchemaField()migrated to SurrealQL UPDATE query -
updateSchemaField()migrated to SurrealQL UPDATE query -
deleteSchema()migrated to SurrealQL DELETE query - All schema operations tested with integration tests
- Old REST endpoint calls removed from HttpAdapter
- Schema operations work in browser dev mode
Related
- PR Simplify Browser Dev Mode: Use SurrealDB HTTP Server Instead of Custom REST Layer #497: SurrealDB dev server migration (CRUD/query/mention operations)
- Issue Simplify Browser Dev Mode: Use SurrealDB HTTP Server Instead of Custom REST Layer #490: Simplify browser dev mode with SurrealDB
Priority
Medium - Blocks full cleanup of custom dev-server code, but schema operations are less frequently used than CRUD operations.
Activity
Address code review: Add mentions table, fix docs, document test cons…
Address code review: Add mentions table, fix docs, document test cons…
Address code review: Add mentions table, fix docs, document test cons…
Address code review: Add mentions table, fix docs, document test cons…