EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
migrate-platform.js
Go to the documentation of this file.
1/**
2 * @file Database Migration Utility - Add Platform Column to Agents Table
3 * @description
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.
7 *
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.
10 *
11 * Migration actions:
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)
15 *
16 * Platform values:
17 * - **win32**: Windows operating systems
18 * - **linux**: Linux distributions
19 * - **darwin**: macOS/OS X
20 *
21 * Usage workflow:
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
28 * @requires express
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
32 */
33
34const express = require('express');
35const router = express.Router();
36const pool = require('../services/db');
37
38/**
39 * @api {post} /migrate-platform/add-platform-column Add Platform Column Migration
40 * @apiName AddPlatformColumn
41 * @apiGroup Migrations
42 * @apiDescription
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.
45 *
46 * SQL executed:
47 * ```sql
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)';
50 * ```
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:
61 * {
62 * "success": true,
63 * "message": "Platform column added to agents table",
64 * "note": "DELETE routes/migrate-platform.js after running this once"
65 * }
66 */
67
68// One-time migration endpoint to add platform column
69// DELETE THIS FILE AFTER RUNNING
70router.post('/add-platform-column', async (req, res) => {
71 try {
72 console.log('🔄 Applying platform column migration...');
73
74 await pool.query(`
75 ALTER TABLE agents
76 ADD COLUMN IF NOT EXISTS platform VARCHAR(20);
77 `);
78
79 await pool.query(`
80 COMMENT ON COLUMN agents.platform IS 'Operating system platform (win32, linux, darwin)';
81 `);
82
83 console.log('✅ Platform column migration applied successfully!');
84
85 res.json({
86 success: true,
87 message: 'Platform column added to agents table',
88 note: 'DELETE routes/migrate-platform.js after running this once'
89 });
90
91 } catch (err) {
92 console.error('❌ Migration failed:', err.message);
93 res.status(500).json({ error: err.message });
94 }
95});
96
97module.exports = router;