the-tip-top-backend/scripts/fix-user-id.js
2025-11-17 23:47:54 +01:00

23 lines
682 B
JavaScript

import { pool } from '../db.js';
const fixUserIdConstraint = async () => {
try {
console.log('🔄 Modification de la contrainte user_id...\n');
await pool.query('ALTER TABLE tickets ALTER COLUMN user_id DROP NOT NULL');
console.log('✅ Contrainte NOT NULL supprimée de user_id');
await pool.query('CREATE INDEX IF NOT EXISTS idx_tickets_unused ON tickets(user_id) WHERE user_id IS NULL');
console.log('✅ Index créé pour les tickets non utilisés\n');
await pool.end();
process.exit(0);
} catch (error) {
console.error('❌ Erreur:', error.message);
await pool.end();
process.exit(1);
}
};
fixUserIdConstraint();