EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
add_ticket_features.js
Go to the documentation of this file.
1// Migration to add time tracking and notes tables
2const pool = require('../../backend/services/db');
3
4(async function run() {
5 try {
6 console.log('Running migration: adding time tracking and notes tables');
7
8 // Create time entries table
9 await pool.query(`
10 CREATE TABLE IF NOT EXISTS ticket_time_entries (
11 entry_id SERIAL PRIMARY KEY,
12 ticket_id INTEGER REFERENCES tickets(ticket_id) ON DELETE CASCADE,
13 user_id INTEGER REFERENCES users(user_id),
14 start_time TIMESTAMP NOT NULL,
15 end_time TIMESTAMP,
16 duration_minutes INTEGER,
17 description TEXT,
18 billable BOOLEAN DEFAULT true,
19 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
20 );
21 `);
22
23 // Create notes table supporting both public and private notes
24 await pool.query(`
25 CREATE TABLE IF NOT EXISTS ticket_notes (
26 note_id SERIAL PRIMARY KEY,
27 ticket_id INTEGER REFERENCES tickets(ticket_id) ON DELETE CASCADE,
28 user_id INTEGER REFERENCES users(user_id),
29 content TEXT NOT NULL,
30 is_private BOOLEAN DEFAULT false,
31 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
32 updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
33 );
34 `);
35
36 // Add indices for performance
37 await pool.query(`
38 CREATE INDEX IF NOT EXISTS idx_time_entries_ticket ON ticket_time_entries(ticket_id);
39 CREATE INDEX IF NOT EXISTS idx_notes_ticket ON ticket_notes(ticket_id);
40 CREATE INDEX IF NOT EXISTS idx_notes_private ON ticket_notes(is_private);
41 `);
42
43 console.log('Migration completed successfully');
44 } catch (err) {
45 console.error('Migration failed:', err);
46 process.exitCode = 1;
47 } finally {
48 await pool.end();
49 }
50})();