CREATE TABLE Crate(crateid INTEGER PRIMARY KEY, name TEXT, area TEXT, rack INT, location TEXT, SN TEXT, Function TEXT, rocid INT, host TEXT, IP TEXT);
CREATE TABLE Module(moduleid INTEGER PRIMARY KEY, crateid INTEGER, slot INT, type TEXT, SN TEXT);
CREATE TABLE Channel(chanid INTEGER PRIMARY KEY, moduleid INTEGER, name TEXT, channel INT, system TEXT, col_name TEXT, enable INTEGER DEFAULT 1);
CREATE TABLE Detector_Hierarchy( id INTEGER PRIMARY KEY, parent_id INTEGER, name TEXT, type TEXT, chanid INTEGER, mtime DATETIME DEFAULT CURRENT_TIMESTAMP);



INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 1, NULL, 'COMCAL', 'Detector', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 2, 1, 'lv', 'Voltage type', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 3, 2, 'pulser', 'LV Channel', 6 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 4, 1, 'bias', 'Voltage type', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 5, 4, 'pulser', 'Bias Channel', 15 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 6, 1, 'hv', 'Voltage type', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 7, 6, 'pulser', 'Component', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 8, 7, '1', 'HV Channel', 39 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 9, 7, '2', 'HV Channel', 40 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 10, NULL, 'DIRC', 'Detector', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 11, 10, 'lv', 'Voltage type', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 12, 11, 'pulser', 'Subsystem', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 13, 12, '5V', 'LV Channel', 5 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 14, 12, '12V', 'LV Channel', 14 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 15, 10, 'bias', 'Voltage type', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 16, 15, 'pulser', 'Bias Channel', 13 );
INSERT INTO Crate ( crateid, name, Function, host, area, rack, location, rocid, SN ) VALUES (1, 'D2-5-MID', 'BIAS/LV', 'd2-5-mid', 'D2', '5', 'MID', '9166', '701');
INSERT INTO Module ( moduleid, crateid, slot, type, SN ) VALUES (1, 1, '0', 'MPV8008L', '612');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name, enable ) VALUES (5, 1, 4, 'lv_chanid', 'DIRC', '4', '1');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name, enable ) VALUES (6, 1, 5, 'lv_chanid', 'COMCAL', '5', '1');
INSERT INTO Module ( moduleid, crateid, slot, type, SN ) VALUES (2, 1, '1', 'MPV8030L', '612');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name, enable ) VALUES (13, 2, 4, 'lv_chanid', 'DIRC', '4', '1');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name, enable ) VALUES (14, 2, 5, 'lv_chanid', 'DIRC', '5', '1');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name, enable ) VALUES (15, 2, 6, 'lv_chanid', 'COMCAL', '6', '1');

INSERT INTO Crate ( crateid, name, Function, host, area, rack, location, rocid, SN ) VALUES (2, 'D2-8-MID', 'HV', 'd2-8-MID', 'D2', '8', 'MID', '9104', '805');
INSERT INTO Module ( moduleid, crateid, slot, type, SN ) VALUES (3, 2, '14', 'A7236SN', '1515');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name, enable ) VALUES (39, 3, 22, 'hv_chanid', 'COMCAL', '22', '1');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name, enable ) VALUES (40, 3, 23, 'hv_chanid', 'COMCAL', '23', '1');

