2 * @file Database Migration Utility - Add Platform Column to Agents Table
4 * **TEMPORARY MIGRATION SCRIPT** - One-time database schema migration endpoint to add
5 * `platform` column to `agents` table. This file stores Operating System platform detection
6 * (win32, linux, darwin) for multi-platform RMM agent support.
8 * ⚠️ **IMPORTANT**: This file should be DELETED after running the migration once in production.
9 * Keeping migration scripts in codebase after execution creates security risks and confusion.
12 * - Adds `platform VARCHAR(20)` column to `agents` table (idempotent with IF NOT EXISTS)
13 * - Sets column comment for documentation
14 * - Safe to run multiple times (IF NOT EXISTS prevents errors)
17 * - **win32**: Windows operating systems
18 * - **linux**: Linux distributions
19 * - **darwin**: macOS/OS X
22 * 1. Deploy code with this migration file
23 * 2. Call POST /migrate-platform/add-platform-column once
24 * 3. Verify migration success in response
25 * 4. Delete routes/migrate-platform.js from codebase
26 * 5. Remove route registration from main app.js
27 * @module routes/migrate-platform
29 * @requires ../services/db - PostgreSQL database pool
30 * @deprecated DELETE THIS FILE AFTER RUNNING MIGRATION
31 * @warning This is a temporary utility - not a permanent API endpoint
34const express = require('express');
35const router = express.Router();
36const pool = require('../services/db');
39 * @api {post} /migrate-platform/add-platform-column Add Platform Column Migration
40 * @apiName AddPlatformColumn
41 * @apiGroup Migrations
43 * **ONE-TIME MIGRATION** - Adds platform column to agents table for OS platform tracking.
44 * Idempotent operation safe to run multiple times. DELETE THIS FILE AFTER RUNNING ONCE.
48 * ALTER TABLE agents ADD COLUMN IF NOT EXISTS platform VARCHAR(20);
49 * COMMENT ON COLUMN agents.platform IS 'Operating system platform (win32, linux, darwin)';
51 * @apiPermission public
52 * @apiNote No authentication for migrations (should be protected in production by firewall/VPN)
53 * @apiWarning DELETE routes/migrate-platform.js after running this migration
54 * @apiSuccess {boolean} success Migration success status (true)
55 * @apiSuccess {string} message Success message
56 * @apiSuccess {string} note Reminder to delete migration file
57 * @apiError (500) {String} error SQL error message if migration fails
58 * @apiExample {curl} Example Request:
59 * curl -X POST https://api.ibghub.com/api/migrate-platform/add-platform-column
60 * @apiExample {json} Example Response:
63 * "message": "Platform column added to agents table",
64 * "note": "DELETE routes/migrate-platform.js after running this once"
68// One-time migration endpoint to add platform column
69// DELETE THIS FILE AFTER RUNNING
70router.post('/add-platform-column', async (req, res) => {
72 console.log('🔄 Applying platform column migration...');
76 ADD COLUMN IF NOT EXISTS platform VARCHAR(20);
80 COMMENT ON COLUMN agents.platform IS 'Operating system platform (win32, linux, darwin)';
83 console.log('✅ Platform column migration applied successfully!');
87 message: 'Platform column added to agents table',
88 note: 'DELETE routes/migrate-platform.js after running this once'
92 console.error('❌ Migration failed:', err.message);
93 res.status(500).json({ error: err.message });
97module.exports = router;