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

Commit

Permalink
fix sql connection
Browse files Browse the repository at this point in the history
  • Loading branch information
namachan10777 committed Oct 20, 2024
1 parent 9ad68d0 commit 94c1727
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 116 deletions.
2 changes: 1 addition & 1 deletion config/app.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"hostname": "www.hpcs.cs.tsukuba.ac.jp",
"port": 80,
"host": "127.0.0.1",
"host": "0.0.0.0",
"baseUrl": "/",
"title": "CFPs @Architecture-team, HPCS Lab."
}
18 changes: 9 additions & 9 deletions db/mysql_change_column_name.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var mysql = require('mysql');
var config = require('../config/db');
var mysql = require("mysql2");
var config = require("../config/db");

var client = mysql.createConnection({
host: config.host,
user: config.user,
password: config.password
host: config.host,
user: config.user,
password: config.password,
});

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

old_name = 'cite'
new_name = 'site varchar(2048) default NULL'
old_name = "cite";
new_name = "site varchar(2048) default NULL";

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

client.end();
13 changes: 6 additions & 7 deletions db/mysql_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var mysql = require('mysql');
var config = require('../config/db');
var mysql = require("mysql2");
var config = require("../config/db");

var connection = mysql.createConnection(config);

connection.connect(function(err) {
connection.connect(function (err) {
if (err) {
console.error('error connecting: ' + err.stack);
}
else {
console.log('connected as id ' + connection.threadId);
console.error("error connecting: " + err.stack);
} else {
console.log("connected as id " + connection.threadId);
}
});

Expand Down
70 changes: 36 additions & 34 deletions db/mysql_initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,54 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var mysql = require('mysql');
var config = require('../config/db');
var mysql = require("mysql2");
var config = require("../config/db");

var client = mysql.createConnection({
host: config.host,
user: config.user,
password: config.password
host: config.host,
user: config.user,
password: config.password,
});

client.query('create database ' + config.database
, function(err) {
if(err) {
client.query(
"create database if not exists " + config.database,
function (err) {
if (err) {
throw err;
}
});
}
);

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

client.query(
'create table cfps' +
'(' +
' cfp_id INT NOT NULL AUTO_INCREMENT,' +
' name varchar(16) NOT NULL UNIQUE,' +
' fullname varchar(128) default NULL,' +
' venue varchar(64) default NULL,' +
' date_beg date default NULL,' +
' date_end date default NULL,' +
' site varchar(2048) default NULL,' +
' remarks varchar(1024) default NULL,' +
' updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,' +
' PRIMARY KEY(cfp_id)' +
')'
"create table cfps" +
"(" +
" cfp_id INT NOT NULL AUTO_INCREMENT," +
" name varchar(16) NOT NULL UNIQUE," +
" fullname varchar(128) default NULL," +
" venue varchar(64) default NULL," +
" date_beg date default NULL," +
" date_end date default NULL," +
" site varchar(2048) default NULL," +
" remarks varchar(1024) default NULL," +
" updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP," +
" PRIMARY KEY(cfp_id)" +
")"
);

client.query(
'create table deadlines' +
'(' +
'deadlines_id INT NOT NULL AUTO_INCREMENT,' +
'cfp_id INT NOT NULL,' +
'abst_deadline date default NULL,' +
'submission_deadline date default NULL,' +
'notification_date date default NULL,' +
'camera_deadline date default NULL,' +
'PRIMARY KEY(deadlines_id),' +
'FOREIGN KEY(cfp_id) references cfps(cfp_id)' +
')'
"create table deadlines" +
"(" +
"deadlines_id INT NOT NULL AUTO_INCREMENT," +
"cfp_id INT NOT NULL," +
"abst_deadline date default NULL," +
"submission_deadline date default NULL," +
"notification_date date default NULL," +
"camera_deadline date default NULL," +
"PRIMARY KEY(deadlines_id)," +
"FOREIGN KEY(cfp_id) references cfps(cfp_id)" +
")"
);

client.end();
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
services:
init_db:
build: .
command: db/mysql_initialize.js
volumes:
- type: bind
target: /work/config/app.json
source: config/app.json.sample
- type: bind
target: /work/config/db.json
source: config/db.json.sample
depends_on:
- mysql
server:
build: .
ports:
Expand All @@ -11,11 +23,15 @@ services:
target: /work/config/db.json
source: config/db.json.sample
restart: unless-stopped
depends_on:
- init_db
mysql:
image: mysql:9
environment:
- MYSQL_DATABASE=cfps_user
- MYSQL_USER=cfps_user
- MYSQL_PASSWORD=cfps_pass
- MYSQL_ROOT_PASSWORD=cfps_pass
ports:
- 3306:3306
restart: unless-stopped
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"express": "^4.21.1",
"jquery": "^3.7.1",
"moment": "^2.30.1",
"mysql": "^2.18.1",
"mysql2": "^3.11.3",
"pug": "^2.0.4",
"underscore": "^1.13.7"
}
Expand Down
Loading

0 comments on commit 94c1727

Please sign in to comment.