Skip to content

Instantly share code, notes, and snippets.

@f-huang
Last active November 7, 2021 15:15
Show Gist options
  • Save f-huang/7309db1154b54728803b33f8ab1e66f0 to your computer and use it in GitHub Desktop.
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
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
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",
},
};
"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