Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function update_schema(conn, path, cb) {
var conn_config = conn.config.connectionConfig;
var filePath = path + '/' + 'schema.sql';
fs.unlink(filePath, function() {
var cmd = "mysqldump --no-data ";
var cmd = "mysqldump --no-data --routines --events";
if (conn_config.host) {
cmd = cmd + " -h " + conn_config.host;
}
Expand Down
68 changes: 68 additions & 0 deletions test/core_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,74 @@ describe('core_functions.js', function() {
testCommons(done);
});

context('update schema', function () {
it('saves procedures', function (done) {
var name = 'test_procedure_3c71dcc968da49c4bfded38d9da26107';
mysql.query(`
CREATE PROCEDURE ${name}()
BEGIN
SELECT 1;
END
`, function (error, results) {
if (error) throw error;
coreFunctions.update_schema(mysql, __dirname + '/migrations', function () {
mysql.query('DROP PROCEDURE ' + name, function (error, results) {
if (error) throw error;
const schema = fs.readFileSync(__dirname + '/migrations/schema.sql', { encoding: 'utf-8' });
assert.match(schema, new RegExp(name), 'Schema includes procedure');
done();
});
});
});
});
it('saves functions', (done) => {
var name = 'test_function_1391c8019b96453da1515ecd4a15a055';
mysql.query(`
CREATE FUNCTION IF NOT EXISTS ${name}(a INT, b INT)
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE result INT;
SET result = a + b;
RETURN result;
END
`, function (error, results) {
if (error) throw error;
coreFunctions.update_schema(mysql, __dirname + '/migrations', function () {
mysql.query('DROP FUNCTION IF EXISTS ' + name, function (error, results) {
if (error) throw error;
const schema = fs.readFileSync(__dirname + '/migrations/schema.sql', { encoding: 'utf-8' });
assert.match(schema, new RegExp(name), 'Schema includes function');
done();
});
});
});
});
it('saves events', (done) => {
var name = 'test_event_128c055bb3d64cde8dd88874d8f5f346';
mysql.query(`
CREATE EVENT IF NOT EXISTS ${name}
ON SCHEDULE
EVERY 1 DAY
STARTS CURRENT_TIMESTAMP
DO
BEGIN
SELECT 1;
END;
`, function (error, results) {
if (error) throw error;
coreFunctions.update_schema(mysql, __dirname + '/migrations', function () {
mysql.query('DROP EVENT IF EXISTS ' + name, function (error, results) {
if (error) throw error;
const schema = fs.readFileSync(__dirname + '/migrations/schema.sql', { encoding: 'utf-8' });
assert.match(schema, new RegExp(name), 'Schema includes event');
done();
});
});
});
});
})

context('add_migration', function () {
it('should add migration', function (done) {
var commands = ['node', 'migration', 'add', 'migration', 'create_user2'];
Expand Down