Commit e802c3cc by Иван Кубота

migrations are now ok

parent 41cd6875
{
"dev": {
"multipleStatements": true,
"driver": "mysql",
"database": "tg_bot",
"user": "root",
"password": {"ENV": "DEVELOP_MYSQL_PASSWORD"}
"user": "user",
"password": "yourpassword",
"d":{"ENV": "DEVELOP_MYSQL_PASSWORD"}
}
}
\ No newline at end of file
'use strict';
var dbm;
var type;
var seed;
/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};
exports.up = function(db, callback) {
return null;
};
exports.down = function(db, callback) {
return null;
};
exports._meta = {
"version": 1
};
'use strict';
const async = require('async');
var dbm;
var type;
var seed;
/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};
exports.up = function(db, callback){
const locale = require( '../locale/locale.ru' );
const queries = [
db.createTable.bind( db, 'chat', {
columns: {
id: {
type: 'bigint',
primaryKey: true
}
},
ifNotExists: true
} ),
db.createTable.bind( db, 'chat', {
columns: {
id: {
type: 'bigint',
primaryKey: true
}
},
ifNotExists: true
} ),
db.createTable.bind( db, 'user', {
columns: {
userID: {
type: 'bigint'
},
chatID: {
type: 'bigint'
},
data: {
type: 'string'
}
},
ifNotExists: true
} ),
db.addIndex.bind( db, 'user', 'user_chat', [ 'chatID', 'userID' ], true ),
db.createTable.bind( db, 'locale', {
columns: {
k: { type: 'string' },
v: { type: 'string' }
},
ifNotExists: true
} )
];
for(const k in locale){
queries.push(db.insert.bind(db,'locale', ['k', 'v'], [k, locale[k]]));
}
return async.series(queries, callback)
};
exports.down = function(db, callback) {
db.dropTable('chat', function(err) {
if (err) { callback(err); return; }
db.dropTable('user', function(err) {
if (err) { callback(err); return; }
db.removeIndex('user', 'user_chat', function(err) {
if (err) { callback(err); return; }
db.dropTable('locale', function(err) {
if (err) { callback(err); return; }
callback();
})
})
})
});
};
exports._meta = {
"version": 1
};
'use strict';
var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var Promise;
/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
Promise = options.Promise;
};
exports.up = function(db) {
var filePath = path.join(__dirname, 'sqls', '20190824142547-initsql-up.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);
resolve(data);
});
})
.then(function(data) {
const locale = require( '../locale/locale.ru' );
const queries = [];
for(const k in locale){
queries.push({key: k, value:locale[k]});
}
data += '\nINSERT INTO locale (`key`, `value`) values'+(
queries.map((pair)=>'(\''+db.escape(pair.key)+'\',\''+db.escape(pair.value)+'\')').join(',')
)+';';//("ti pidor","PIDOR"),("ti pidor2","PIDOR2");`;
return db.runSql(data);
});
};
exports.down = function(db) {
var filePath = path.join(__dirname, 'sqls', '20190824142547-initsql-down.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);
resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};
exports._meta = {
"version": 1
};
DROP TABLE `chat`;
DROP INDEX `user_chat` ON `user`;
DROP TABLE `user`;
DROP TABLE `locale`;
\ No newline at end of file
CREATE TABLE IF NOT EXISTS `chat` (
`id` BIGINT PRIMARY KEY
);
CREATE TABLE IF NOT EXISTS `user` (
`userID` BIGINT,
`chatID` BIGINT,
`data` TEXT
);
CREATE INDEX IF NOT EXISTS `user_chat` on `user` (`userID`, `chatID`);
CREATE TABLE IF NOT EXISTS `locale` (
`key` TEXT,
`value` TEXT
);
const
\ No newline at end of file
const EventEmitter = require('events').eventEmiter;
const TelegramBotMock = function(token, cfg){
assert.notEqual(token, void 0)
};
module.exports = TelegramBotMock;
\ No newline at end of file
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment