import { db, schema } from '../src/lib/db';
import { sql } from 'drizzle-orm';

async function updateSessions() {
  try {
    console.log('Updating existing sessions...');
    
    // First get existing sessions
    const existingSessions = await db.select().from(schema.sessions);
    
    // Update each session individually
    for (const session of existingSessions) {
      await db
        .update(schema.sessions)
        .set({
          refreshTokenHash: `legacy_session_${session.id}`,
          tokenFamily: `legacy_family_${session.id}`,
          revokedAt: new Date(),
        })
        .where(sql`id = ${session.id}`);
    }
    
    console.log(`Updated ${existingSessions.length} sessions successfully`);
    process.exit(0);
  } catch (error) {
    console.error('Error updating sessions:', error);
    process.exit(1);
  }
}

updateSessions();
