yuebao liang
2019-07-06 4e24302f99ed426e24194b423513b7e9e8ba3c58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var mysql = require('mysql');
var moment = require('moment');
var config = require('./config');
 
var mysqlClient = mysql.createConnection(config.mysql_2);
mysqlClient.connect(function(error) { if (error) return; });
 
var partition_name = "p" + moment().add(1, 'M').format("YYYYMM");
var partition_date = moment().add(2, 'M').format("YYYYMM01");
 
var sql = "ALTER TABLE history_minutely ADD PARTITION (PARTITION " + partition_name + " VALUES LESS THAN ('" + partition_date + "'))";
mysqlClient.query(sql, function (error, results, fields) { if (error) {console.log("history_minutely:", error);} });
 
sql = "ALTER TABLE history_10min ADD PARTITION (PARTITION " + partition_name + " VALUES LESS THAN (TO_DAYS('" + partition_date + "')))";
mysqlClient.query(sql, function (error, results, fields) { if (error) {console.log("history_10min:", error);} });
 
sql = "ALTER TABLE history_hourly ADD PARTITION (PARTITION " + partition_name + " VALUES LESS THAN (TO_DAYS('" + partition_date + "')))";
mysqlClient.query(sql, function (error, results, fields) { if (error) {console.log("history_hourly:", error);} });
 
sql = "ALTER TABLE history_daily ADD PARTITION (PARTITION " + partition_name + " VALUES LESS THAN (TO_DAYS('" + partition_date + "')))";
mysqlClient.query(sql, function (error, results, fields) { if (error) {console.log("history_daily:", error);} });
 
mysqlClient.end();