-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chat-service): add mysql db migrations (#1867)
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
1 parent
c36a2e3
commit feede9a
Showing
9 changed files
with
597 additions
and
22 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
51 changes: 51 additions & 0 deletions
51
services/chat-service/migrations/mysql/migrations/20231221002804-init.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
11 changes: 11 additions & 0 deletions
11
services/chat-service/migrations/mysql/migrations/sqls/20231221002804-init-down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.