Skip to content

Commit f5a98e8

Browse files
committed
added table schema to installation route.
1 parent 7415c54 commit f5a98e8

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

server.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,28 @@ app.delete('/flush-storage',function(req,res){
3535

3636
})
3737

38-
app.get('/install',()=>{
39-
/**
40-
* Install the trace table in the target database. Example query:
41-
*
42-
CREATE TABLE `trace` (
43-
`trace_id` int(11) NOT NULL AUTO_INCREMENT,
44-
`trace` longtext NOT NULL,
45-
`query` text NOT NULL,
46-
`query_time` float NOT NULL,
47-
`request` varchar(1000) NOT NULL,
48-
UNIQUE KEY `trace_id` (`trace_id`) USING BTREE,
49-
KEY `request` (`request`)
50-
) ENGINE=InnoDB AUTO_INCREMENT=983 DEFAULT CHARSET=utf8
51-
*/
38+
app.get('/install',(req,res)=>{
5239

40+
const installSql = `
41+
CREATE TABLE \`trace\` (
42+
\`trace_id\` int(11) NOT NULL AUTO_INCREMENT,
43+
\`trace\` longtext NOT NULL,
44+
\`query\` longtext NOT NULL,
45+
\`query_time\` float NOT NULL,
46+
\`request\` varchar(1000) NOT NULL,
47+
UNIQUE KEY \`trace_id\` (\`trace_id\`) USING BTREE,
48+
KEY \`request\` (\`request\`)
49+
) ENGINE=InnoDB DEFAULT CHARSET=utf8
50+
`;
51+
52+
53+
storage.createSchema(installSql, function (error, results, fields) {
54+
if (error){
55+
res.json({'ERROR':'E_INSTALLATION_ERROR:'+error.message});
56+
return;
57+
}
58+
res.json({'ERROR':false})
59+
});
5360

5461
})
5562

src/server/storage.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ const storage = {
1313
result.trace_id = null;
1414
connection.query('INSERT INTO `trace` SET ?',result , function (err, rows, fields) {
1515
if (err){
16+
console.log(trace);
1617
console.log(err);
17-
}else{
18-
console.log('Affected rows:',rows);
18+
process.exit(0);
1919
}
2020
});
2121
connection.end()
@@ -29,6 +29,11 @@ const storage = {
2929
flushStorage:function(cb){
3030
let connection = mysql.createConnection(appConfig.mysql);
3131
connection.query('TRUNCATE `trace`',cb);
32+
},
33+
34+
createSchema:function(schema,cb){
35+
let connection = mysql.createConnection(appConfig.mysql);
36+
connection.query(schema,cb);
3237
}
3338
};
3439

0 commit comments

Comments
 (0)