Last active
November 7, 2021 15:15
-
-
Save f-huang/7309db1154b54728803b33f8ab1e66f0 to your computer and use it in GitHub Desktop.
Continous Integration: Make Sure Database Changes are Included using GitLab CI/CD
This file contains hidden or 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
Migration-Check: | |
stage: Test | |
services: | |
- postgres:11.5 | |
image: node:12.15-alpine | |
script: | |
- yarn run-migration:ci | |
- migration_result=$(yarn schema-log:ci) | |
- | | |
matching_migration_is_up_date=`echo $migration_result | grep 'Your schema is up to date - there are no queries to be executed by schema syncronization.'` | |
if [ ! -z "$matching_migration_is_up_date" ]; then | |
echo "Entities are sync with DB" | |
exit 0 | |
else | |
echo "Missing some migrations" | |
exit 1 | |
fi |
This file contains hidden or 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
module.exports = { | |
name: "default", | |
type: "postgres", | |
host: "postgres", | |
port: "5432", | |
username: "runner", // This is the database user of GitLab CI with the postgres service | |
database: "libeo-test", | |
migrations: ["./dist/migration/*.js"], | |
entities: ["./dist/**/*.entity.js"], | |
cli: { | |
migrationsDir: "src/migration", | |
}, | |
}; |
This file contains hidden or 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
"scripts": { | |
"schema-log:ci": "yarn ts-node -r tsconfig-paths/register ../node_modules/typeorm/cli.js --config ormconfig-ci.ts schema:log", | |
"run-migration:ci": "yarn ts-node -r tsconfig-paths/register ../node_modules/typeorm/cli.js --config ormconfig-ci.ts migration:run", | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment