Skip to content
This repository was archived by the owner on Nov 12, 2024. It is now read-only.

Commit 94c1727

Browse files
committed
fix sql connection
1 parent 9ad68d0 commit 94c1727

File tree

7 files changed

+150
-116
lines changed

7 files changed

+150
-116
lines changed

config/app.json.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"hostname": "www.hpcs.cs.tsukuba.ac.jp",
44
"port": 80,
5-
"host": "127.0.0.1",
5+
"host": "0.0.0.0",
66
"baseUrl": "/",
77
"title": "CFPs @Architecture-team, HPCS Lab."
88
}

db/mysql_change_column_name.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
var mysql = require('mysql');
17-
var config = require('../config/db');
16+
var mysql = require("mysql2");
17+
var config = require("../config/db");
1818

1919
var client = mysql.createConnection({
20-
host: config.host,
21-
user: config.user,
22-
password: config.password
20+
host: config.host,
21+
user: config.user,
22+
password: config.password,
2323
});
2424

25-
client.query('use ' + config.database);
25+
client.query("use " + config.database);
2626

27-
old_name = 'cite'
28-
new_name = 'site varchar(2048) default NULL'
27+
old_name = "cite";
28+
new_name = "site varchar(2048) default NULL";
2929

30-
client.query('alter table cfps change column ' + old_name + ' ' + new_name);
30+
client.query("alter table cfps change column " + old_name + " " + new_name);
3131

3232
client.end();

db/mysql_connection.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
var mysql = require('mysql');
17-
var config = require('../config/db');
16+
var mysql = require("mysql2");
17+
var config = require("../config/db");
1818

1919
var connection = mysql.createConnection(config);
2020

21-
connection.connect(function(err) {
21+
connection.connect(function (err) {
2222
if (err) {
23-
console.error('error connecting: ' + err.stack);
24-
}
25-
else {
26-
console.log('connected as id ' + connection.threadId);
23+
console.error("error connecting: " + err.stack);
24+
} else {
25+
console.log("connected as id " + connection.threadId);
2726
}
2827
});
2928

db/mysql_initialize.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,54 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
var mysql = require('mysql');
17-
var config = require('../config/db');
16+
var mysql = require("mysql2");
17+
var config = require("../config/db");
1818

1919
var client = mysql.createConnection({
20-
host: config.host,
21-
user: config.user,
22-
password: config.password
20+
host: config.host,
21+
user: config.user,
22+
password: config.password,
2323
});
2424

25-
client.query('create database ' + config.database
26-
, function(err) {
27-
if(err) {
25+
client.query(
26+
"create database if not exists " + config.database,
27+
function (err) {
28+
if (err) {
2829
throw err;
2930
}
30-
});
31+
}
32+
);
3133

32-
client.query('use ' + config.database);
34+
client.query("use " + config.database);
3335

3436
client.query(
35-
'create table cfps' +
36-
'(' +
37-
' cfp_id INT NOT NULL AUTO_INCREMENT,' +
38-
' name varchar(16) NOT NULL UNIQUE,' +
39-
' fullname varchar(128) default NULL,' +
40-
' venue varchar(64) default NULL,' +
41-
' date_beg date default NULL,' +
42-
' date_end date default NULL,' +
43-
' site varchar(2048) default NULL,' +
44-
' remarks varchar(1024) default NULL,' +
45-
' updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,' +
46-
' PRIMARY KEY(cfp_id)' +
47-
')'
37+
"create table cfps" +
38+
"(" +
39+
" cfp_id INT NOT NULL AUTO_INCREMENT," +
40+
" name varchar(16) NOT NULL UNIQUE," +
41+
" fullname varchar(128) default NULL," +
42+
" venue varchar(64) default NULL," +
43+
" date_beg date default NULL," +
44+
" date_end date default NULL," +
45+
" site varchar(2048) default NULL," +
46+
" remarks varchar(1024) default NULL," +
47+
" updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP," +
48+
" PRIMARY KEY(cfp_id)" +
49+
")"
4850
);
4951

5052
client.query(
51-
'create table deadlines' +
52-
'(' +
53-
'deadlines_id INT NOT NULL AUTO_INCREMENT,' +
54-
'cfp_id INT NOT NULL,' +
55-
'abst_deadline date default NULL,' +
56-
'submission_deadline date default NULL,' +
57-
'notification_date date default NULL,' +
58-
'camera_deadline date default NULL,' +
59-
'PRIMARY KEY(deadlines_id),' +
60-
'FOREIGN KEY(cfp_id) references cfps(cfp_id)' +
61-
')'
53+
"create table deadlines" +
54+
"(" +
55+
"deadlines_id INT NOT NULL AUTO_INCREMENT," +
56+
"cfp_id INT NOT NULL," +
57+
"abst_deadline date default NULL," +
58+
"submission_deadline date default NULL," +
59+
"notification_date date default NULL," +
60+
"camera_deadline date default NULL," +
61+
"PRIMARY KEY(deadlines_id)," +
62+
"FOREIGN KEY(cfp_id) references cfps(cfp_id)" +
63+
")"
6264
);
6365

6466
client.end();

docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
services:
2+
init_db:
3+
build: .
4+
command: db/mysql_initialize.js
5+
volumes:
6+
- type: bind
7+
target: /work/config/app.json
8+
source: config/app.json.sample
9+
- type: bind
10+
target: /work/config/db.json
11+
source: config/db.json.sample
12+
depends_on:
13+
- mysql
214
server:
315
build: .
416
ports:
@@ -11,11 +23,15 @@ services:
1123
target: /work/config/db.json
1224
source: config/db.json.sample
1325
restart: unless-stopped
26+
depends_on:
27+
- init_db
1428
mysql:
1529
image: mysql:9
1630
environment:
1731
- MYSQL_DATABASE=cfps_user
1832
- MYSQL_USER=cfps_user
1933
- MYSQL_PASSWORD=cfps_pass
2034
- MYSQL_ROOT_PASSWORD=cfps_pass
35+
ports:
36+
- 3306:3306
2137
restart: unless-stopped

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"express": "^4.21.1",
1414
"jquery": "^3.7.1",
1515
"moment": "^2.30.1",
16-
"mysql": "^2.18.1",
16+
"mysql2": "^3.11.3",
1717
"pug": "^2.0.4",
1818
"underscore": "^1.13.7"
1919
}

0 commit comments

Comments
 (0)