api/internal/migrations/001_create_browser_sessions.sql (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
CREATE TABLE browser_sessions ( id UUID PRIMARY KEY, display_number INTEGER NOT NULL, vnc_port INTEGER NOT NULL, debug_port INTEGER NOT NULL, status VARCHAR(20) NOT NULL, -- 'starting', 'running', 'stopped', 'failed' created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, error_message TEXT, xvfb_pid INTEGER, chrome_pid INTEGER, vnc_pid INTEGER ); -- Index for finding available display numbers CREATE INDEX idx_browser_sessions_display_number ON browser_sessions(display_number); -- Index for status queries CREATE INDEX idx_browser_sessions_status ON browser_sessions(status); -- Function to update updated_at timestamp CREATE OR REPLACE FUNCTION update_updated_at_column() RETURNS TRIGGER AS $$ BEGIN NEW.updated_at = CURRENT_TIMESTAMP; RETURN NEW; END; $$ language 'plpgsql'; -- Trigger to automatically update updated_at CREATE TRIGGER update_browser_sessions_updated_at BEFORE UPDATE ON browser_sessions FOR EACH ROW EXECUTE FUNCTION update_updated_at_column(); |