-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate_db_geo.js
More file actions
42 lines (37 loc) · 1.16 KB
/
Copy pathupdate_db_geo.js
File metadata and controls
42 lines (37 loc) · 1.16 KB
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
35
36
37
38
39
40
41
42
const mysql = require('mysql');
require('dotenv').config();
const db = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "myapp"
});
db.connect((err) => {
if (err) throw err;
console.log("Connected to database.");
const sql1 = "ALTER TABLE disaster_reports ADD COLUMN latitude DECIMAL(10, 8) NULL";
const sql2 = "ALTER TABLE disaster_reports ADD COLUMN longitude DECIMAL(11, 8) NULL";
db.query(sql1, (err, result) => {
if (err) {
if (err.code === 'ER_DUP_FIELDNAME') {
console.log("Column latitude already exists.");
} else {
console.error(err);
}
} else {
console.log("Added latitude column.");
}
db.query(sql2, (err, result) => {
if (err) {
if (err.code === 'ER_DUP_FIELDNAME') {
console.log("Column longitude already exists.");
} else {
console.error(err);
}
} else {
console.log("Added longitude column.");
}
process.exit();
});
});
});