Skip to content

Commit

Permalink
feat(chat-service): add mysql db migrations (#1867)
Browse files Browse the repository at this point in the history
MIGRATION CHANGE:
migration-20231221002804- seperate migrations for mysql db
migration-20201103141746-  seperate migrations for mysql db

add support for mysql db by creating seperate directories for mysql and pg migrations

gh-1836

Co-authored-by: yeshamavani <83634146+yeshamavani@users.noreply.github.com>
  • Loading branch information
sf-sahil-jassal and yeshamavani committed Dec 29, 2023
1 parent c36a2e3 commit feede9a
Show file tree
Hide file tree
Showing 9 changed files with 597 additions and 22 deletions.
22 changes: 0 additions & 22 deletions services/chat-service/database.json

This file was deleted.

24 changes: 24 additions & 0 deletions services/chat-service/migrations/mysql/database.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"defaultEnv": "master",
"master": {
"driver": "mysql",
"multipleStatements": true,
"host": {
"ENV": "DB_HOST"
},
"port": {
"ENV": "DB_PORT"
},
"user": {
"ENV": "DB_USER"
},
"password": {
"ENV": "DB_PASSWORD"
},
"database": {
"ENV": "DB_DATABASE"
}
},
"sql-file": true
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'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', '20231221002804-init-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) {
return db.runSql(data);
});
};

exports.down = function (db) {
var filePath = path.join(__dirname, 'sqls', '20231221002804-init-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,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Removing foreign keys
ALTER TABLE messages
DROP FOREIGN KEY fk_messages_messages;

ALTER TABLE message_recipients
DROP FOREIGN KEY fk_message_recipients_messages;

-- Deleting tables
DROP TABLE IF EXISTS audit_logs;
DROP TABLE IF EXISTS messages;
DROP TABLE IF EXISTS message_recipients;
Loading

0 comments on commit feede9a

Please sign in to comment.