From 346326e31fd5ca481e6afe68ae3d04b0bd0a6bd6 Mon Sep 17 00:00:00 2001 From: Albert Date: Sun, 9 Nov 2025 20:42:15 +0000 Subject: [PATCH] fix: Add migration script to fix coords_3d field in production MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created a migration script that removes and redefines the coords_3d field to make it optional (TYPE option>) in production database. This fixes the issue where coords_3d was required but should be NONE until UMAP coordinates are calculated. Migration successfully executed on production database. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- scripts/fix-coords-3d-field.js | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 scripts/fix-coords-3d-field.js diff --git a/scripts/fix-coords-3d-field.js b/scripts/fix-coords-3d-field.js new file mode 100644 index 0000000..e304042 --- /dev/null +++ b/scripts/fix-coords-3d-field.js @@ -0,0 +1,64 @@ +#!/usr/bin/env node + +/** + * Migration script to fix coords_3d field to be optional + */ + +const Surreal = require('surrealdb').default; + +async function fixCoordsField() { + const config = { + url: process.env.SURREALDB_URL, + username: process.env.SURREALDB_USER, + password: process.env.SURREALDB_PASS, + namespace: process.env.SURREALDB_NS, + database: process.env.SURREALDB_DB, + }; + + // Validate required config + const missing = Object.entries(config) + .filter(([_, value]) => !value) + .map(([key]) => key); + + if (missing.length > 0) { + console.error('[Fix coords_3d] Missing required environment variables:', missing.join(', ')); + process.exit(1); + } + + const db = new Surreal(); + + try { + console.log('[Fix coords_3d] Connecting to SurrealDB...'); + await db.connect(config.url); + + console.log('[Fix coords_3d] Signing in...'); + await db.signin({ + username: config.username, + password: config.password, + }); + + console.log('[Fix coords_3d] Using namespace and database...'); + await db.use({ + namespace: config.namespace, + database: config.database, + }); + + console.log('[Fix coords_3d] Removing old coords_3d field definition...'); + await db.query('REMOVE FIELD coords_3d ON TABLE node;'); + + console.log('[Fix coords_3d] Defining new coords_3d field as optional...'); + await db.query(` + DEFINE FIELD coords_3d ON TABLE node TYPE option> + ASSERT $value = NONE OR array::len($value) = 3; + `); + + console.log('[Fix coords_3d] ✓ Field updated successfully!'); + } catch (error) { + console.error('[Fix coords_3d] ✗ Failed:', error); + process.exit(1); + } finally { + await db.close(); + } +} + +fixCoordsField();