fix: Add migration script to fix coords_3d field in production
Created a migration script that removes and redefines the coords_3d field to make it optional (TYPE option<array<number>>) 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 <noreply@anthropic.com>
This commit is contained in:
64
scripts/fix-coords-3d-field.js
Normal file
64
scripts/fix-coords-3d-field.js
Normal file
@@ -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<array<number>>
|
||||
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();
|
||||
Reference in New Issue
Block a user