-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(in-mail-service): added migration in all services (#179)
MIGRATION CHANGE: migration-20210501132806- added migration for notif service BREAKING CHANGE: need to add env in existing projects to skip auto-migrations gh-124
- Loading branch information
1 parent
42458b5
commit 10aa077
Showing
38 changed files
with
1,389 additions
and
1,943 deletions.
There are no files selected for viewing
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
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,6 @@ | ||
DB_HOST= | ||
DB_PORT= | ||
DB_USER= | ||
DB_PASSWORD= | ||
DB_DATABASE= | ||
DB_SCHEMA= |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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
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
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,6 @@ | ||
DB_HOST= | ||
DB_PORT= | ||
DB_USER= | ||
DB_PASSWORD= | ||
DB_DATABASE= | ||
DB_SCHEMA= |
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 |
---|---|---|
|
@@ -3,4 +3,5 @@ dist/ | |
coverage/ | ||
|
||
migrations/ | ||
migration.js | ||
.eslintrc.js |
Empty file.
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
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
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,76 @@ | ||
const dotenv = require('dotenv'); | ||
const dotenvExt = require('dotenv-extended'); | ||
const fs = require('fs'); | ||
const DBMigrate = require('db-migrate'); | ||
const path = require('path'); | ||
let isLocal = false; | ||
dotenv.config({path: path.join(process.env.INIT_CWD, '.env')}); | ||
|
||
try { | ||
if (fs.existsSync('.infolder')) { | ||
isLocal = true; | ||
} | ||
} catch (err) { | ||
console.info('\n'); | ||
} | ||
|
||
if ( | ||
isLocal || | ||
process.env.INMAIL_MIGRATION_SKIP || | ||
process.env.SOURCELOOP_MIGRATION_SKIP | ||
) { | ||
console.info(`Skipping migrations`); | ||
} else { | ||
dotenvExt.load({ | ||
schema: path.join(`.`, `migrations`, `.env.schema`), | ||
path: path.join(process.env.INIT_CWD, '.env'), | ||
errorOnMissing: true, | ||
includeProcessEnv: true, | ||
}); | ||
const dbmigrate = DBMigrate.getInstance(true); | ||
dbmigrate.up(); | ||
} | ||
|
||
if ( | ||
process.env.SOURCELOOP_MIGRATION_COPY || | ||
process.env.INMAIL_MIGRATION_COPY | ||
) { | ||
copyFileSync(path.join('.', 'database.json'), process.env.INIT_CWD); | ||
copyFolderRecursiveSync(path.join('.', '/migrations'), process.env.INIT_CWD); | ||
} | ||
|
||
function copyFileSync(source, target) { | ||
var targetFile = target; | ||
|
||
// If target is a directory, a new file with the same name will be created | ||
if (fs.existsSync(target)) { | ||
if (fs.lstatSync(target).isDirectory()) { | ||
targetFile = path.join(target, path.basename(source)); | ||
} | ||
} | ||
|
||
fs.writeFileSync(targetFile, fs.readFileSync(source)); | ||
} | ||
|
||
function copyFolderRecursiveSync(source, target) { | ||
var files = []; | ||
|
||
// Check if folder needs to be created or integrated | ||
var targetFolder = path.join(target, path.basename(source)); | ||
if (!fs.existsSync(targetFolder)) { | ||
fs.mkdirSync(targetFolder); | ||
} | ||
|
||
// Copy | ||
if (fs.lstatSync(source).isDirectory()) { | ||
files = fs.readdirSync(source); | ||
files.forEach(function (file) { | ||
var curSource = path.join(source, file); | ||
if (fs.lstatSync(curSource).isDirectory()) { | ||
copyFolderRecursiveSync(curSource, targetFolder); | ||
} else { | ||
copyFileSync(curSource, targetFolder); | ||
} | ||
}); | ||
} | ||
} |
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,6 @@ | ||
DB_HOST= | ||
DB_PORT= | ||
DB_USER= | ||
DB_PASSWORD= | ||
DB_DATABASE= | ||
DB_SCHEMA= |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.