fixing duplicate migration

This commit is contained in:
orangecoding
2026-03-17 11:26:23 +01:00
parent c40d275e52
commit 556c0aff35
3 changed files with 19 additions and 16 deletions

View File

@@ -13,7 +13,10 @@ import crypto from 'crypto';
// Each user gets a permanent, non-expiring secret token used for MCP API authentication.
// Tokens are auto-generated for all existing users during this migration.
export function up(db) {
db.exec(`ALTER TABLE users ADD COLUMN mcp_token TEXT`);
const columns = db.prepare(`PRAGMA table_info(users)`).all();
if (!columns.some((col) => col.name === 'mcp_token')) {
db.exec(`ALTER TABLE users ADD COLUMN mcp_token TEXT`);
}
// Backfill all existing users that don't have a token yet
const users = db.prepare(`SELECT id FROM users WHERE mcp_token IS NULL`).all();