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, 'BEAM', 'Detector', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 2, 1, 'TAC', 'SubDetector', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 3, 2, 'hv', 'Voltage type', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 4, 3, '0', 'HV Channel', 21 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 5, 1, 'LUMI', 'SubDetector', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 6, 5, 'hv', 'Voltage type', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 7, 6, '0', 'HV Channel', 22 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 8, 1, 'HALO', 'SubDetector', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 9, 8, 'hv', 'Voltage type', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 10, 9, 'e:tag', 'PMT Assembly', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 11, 10, 'b', 'HV Channel', 71 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 12, 10, 't', 'HV Channel', 70 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 13, 10, 'l', 'HV Channel', 72 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 14, 9, 'g:tag', 'PMT Assembly', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 15, 14, 'r', 'HV Channel', 68 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 16, 14, 'b', 'HV Channel', 69 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 17, 14, 'l', 'HV Channel', 66 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 18, 14, 't', 'HV Channel', 67 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 19, 9, 'g:tgt', 'PMT Assembly', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 20, 19, 'r', 'HV Channel', 27 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 21, 19, 'b', 'HV Channel', 28 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 22, 19, 'l', 'HV Channel', 25 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 23, 19, 't', 'HV Channel', 26 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 24, 9, 'g:col', 'PMT Assembly', NULL );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 25, 24, 'r', 'HV Channel', 31 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 26, 24, 'b', 'HV Channel', 32 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 27, 24, 'l', 'HV Channel', 29 );
INSERT INTO Detector_Hierarchy ( id, parent_id, name, type, chanid ) VALUES ( 28, 24, 't', 'HV Channel', 30 );
INSERT INTO Crate ( crateid, name, Function, host, area, rack, location, rocid, SN ) VALUES (3, 'T1-8-BOT', 'HV', 't1-8-bot', 'T2', '8', 'BOT', '912', '503');
INSERT INTO Module ( moduleid, crateid, slot, type, SN ) VALUES (3, 3, '8', 'A1535SN', '1515');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (66, 3, 17, 'hv_chanid', 'BEAM', 'l');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (67, 3, 18, 'hv_chanid', 'BEAM', 't');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (68, 3, 19, 'hv_chanid', 'BEAM', 'r');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (69, 3, 20, 'hv_chanid', 'BEAM', 'b');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (70, 3, 21, 'hv_chanid', 'BEAM', 't');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (71, 3, 22, 'hv_chanid', 'BEAM', 'b');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (72, 3, 23, 'hv_chanid', 'BEAM', 'l');

INSERT INTO Crate ( crateid, name, Function, host, area, rack, location, rocid, SN ) VALUES (1, 'D2-8-TOP', 'HV', 'd2-8-top', 'D2', '8', 'TOP', '910', '500');
INSERT INTO Module ( moduleid, crateid, slot, type, SN ) VALUES (1, 1, '14', 'A1535SN', '1515');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (21, 1, 20, 'hv_chanid', 'BEAM', '0');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (22, 1, 21, 'hv_chanid', 'BEAM', '0');

INSERT INTO Crate ( crateid, name, Function, host, area, rack, location, rocid, SN ) VALUES (2, 'U1-9-TOP', 'HV', 'u1-9-top', 'U1', '9', 'TOP', '911', '501');
INSERT INTO Module ( moduleid, crateid, slot, type, SN ) VALUES (2, 2, '15', 'A1535SN', '1515');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (25, 2, 0, 'hv_chanid', 'BEAM', 'l');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (26, 2, 1, 'hv_chanid', 'BEAM', 't');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (27, 2, 2, 'hv_chanid', 'BEAM', 'r');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (28, 2, 3, 'hv_chanid', 'BEAM', 'b');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (29, 2, 4, 'hv_chanid', 'BEAM', 'l');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (30, 2, 5, 'hv_chanid', 'BEAM', 't');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (31, 2, 6, 'hv_chanid', 'BEAM', 'r');
INSERT INTO Channel ( chanid, moduleid, channel, col_name, system, name ) VALUES (32, 2, 7, 'hv_chanid', 'BEAM', 'b');

