import Surreal from 'surrealdb'; /** * Migration: Add is_public field to node table * * This script adds the is_public field to all existing nodes, * defaulting them to public (true) to align with the public-by-default * philosophy of ATproto. */ async function migrate() { const db = new Surreal(); try { await db.connect('ws://localhost:8000/rpc'); await db.signin({ username: 'root', password: 'root' }); await db.use({ namespace: 'ponderants', database: 'main' }); console.log('Adding is_public field definition to node table...'); // Define the field (should already be in schema.surql, but ensuring it's applied) await db.query(` DEFINE FIELD is_public ON TABLE node TYPE bool DEFAULT true; `); console.log('✓ Field definition added'); console.log('Setting existing nodes to public...'); // Set all existing nodes where is_public is NONE to true (public by default) const result = await db.query(` UPDATE node SET is_public = true WHERE is_public = NONE; `); console.log('Result:', result); console.log('✓ Migration complete: All existing nodes are now public by default'); } catch (error) { console.error('Migration failed:', error); process.exit(1); } finally { await db.close(); } } migrate();