1// Migration to add time tracking and notes tables
2const pool = require('../../backend/services/db');
6 console.log('Running migration: adding time tracking and notes tables');
8 // Create time entries table
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,
16 duration_minutes INTEGER,
18 billable BOOLEAN DEFAULT true,
19 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
23 // Create notes table supporting both public and private notes
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
36 // Add indices for performance
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);
43 console.log('Migration completed successfully');
45 console.error('Migration failed:', err);