-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_init.js
37 lines (31 loc) · 1.03 KB
/
db_init.js
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
const mysql = require('mysql2');
const con = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'sasa'
});
con.connect(function(err) {
if (err) throw err;
con.query('CREATE DATABASE IF NOT EXISTS translate', function (err) {
if (err) throw err;
});
con.changeUser({database: 'translate'}, function (err) {
if (err) throw err;
});
const createTable = `CREATE TABLE IF NOT EXISTS strings
(id int primary key auto_increment, keyword VARCHAR(255), locale VARCHAR(20), translation VARCHAR(4056))
DEFAULT CHARSET=utf8
`;
con.query(createTable, function (err) {
if (err) throw err;
});
const dropIndex = 'ALTER TABLE `strings` DROP INDEX `keyword_locale_index`';
con.query(dropIndex, function (err) {
// if (err) throw err;
});
const addIndex = 'ALTER TABLE `strings` ADD INDEX `keyword_locale_index` (`keyword`,`locale`)';
con.query(addIndex, function (err) {
// if (err) throw err;
});
console.log('database initialized');
});