mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-23 23:28:17 +02:00
Merge pull request #120 from R0m1k3/antigravity
feat: add admin service for user management and migration, and routes…
This commit is contained in:
3 files changed
+89
No files matched your search
@@ -362,4 +362,45 @@ router.get('/stats', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/admin/migrate/in-progress
|
||||||
|
* Exécuter la migration pour ajouter la colonne in_progress
|
||||||
|
*/
|
||||||
|
router.post('/migrate/in-progress', async (req, res) => {
|
||||||
|
const pool = new Pool({ connectionString: DATABASE_URL });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const client = await pool.connect();
|
||||||
|
try {
|
||||||
|
logger.info('Lancement manuel de la migration in_progress par admin');
|
||||||
|
|
||||||
|
// Check if column exists
|
||||||
|
const checkRes = await client.query(`
|
||||||
|
SELECT column_name
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_name='global_todos' AND column_name='in_progress'
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (checkRes.rows.length === 0) {
|
||||||
|
await client.query('ALTER TABLE global_todos ADD COLUMN in_progress INTEGER DEFAULT 0');
|
||||||
|
logger.info('✓ Colonne in_progress ajoutée avec succès');
|
||||||
|
res.json({ success: true, message: 'Migration réussie : colonne ajoutée' });
|
||||||
|
} else {
|
||||||
|
logger.info('⚠ Colonne in_progress existe déjà');
|
||||||
|
res.json({ success: true, message: 'Migration non nécessaire : la colonne existe déjà' });
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
client.release();
|
||||||
|
}
|
||||||
|
await pool.end();
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Erreur lors de la migration manuelle:', error);
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
error: 'Erreur lors de la migration',
|
||||||
|
message: error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
@@ -2115,6 +2115,32 @@ const Index = () => {
|
|||||||
<Button onClick={handleSaveSettings}>
|
<Button onClick={handleSaveSettings}>
|
||||||
Enregistrer
|
Enregistrer
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
<div className="border-t pt-4 mt-4">
|
||||||
|
<h3 className="font-semibold mb-2 text-red-600">Zone de danger / Maintenance</h3>
|
||||||
|
<p className="text-sm text-muted-foreground mb-3">
|
||||||
|
Utilisez ces options uniquement si vous rencontrez des problèmes spécifiques.
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="border-red-200 hover:bg-red-50 text-red-700"
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
const result = await AdminService.runInProgressMigration();
|
||||||
|
if (result.success) {
|
||||||
|
showSuccess(result.message);
|
||||||
|
} else {
|
||||||
|
showError(result.message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
showError("Erreur lors de la migration");
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<RefreshCw className="h-4 w-4 mr-2" />
|
||||||
|
Réparer la base de données (Migration)
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
|||||||
@@ -112,6 +112,28 @@ class AdminService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async runInProgressMigration(): Promise<{ success: boolean; message: string }> {
|
||||||
|
try {
|
||||||
|
const response = await fetch("/api/admin/migrate/in-progress", {
|
||||||
|
method: "POST",
|
||||||
|
headers: AuthService.getHeaders()
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(data.message || "Erreur lors de la migration");
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: error instanceof Error ? error.message : "Erreur serveur"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Créer une instance unique
|
// Créer une instance unique
|
||||||
|
|||||||
Reference in new issue
Block a user