Merge branch '343978-verify-schema' into 'master'
Make sure CI job `db:check-schema` can catch corrupted `structure.sql` See merge request gitlab-org/gitlab!73298
This commit is contained in:
commit
c88c1ea036
|
@ -338,17 +338,46 @@ rspec fast_spec_helper minimal:
|
||||||
- .minimal-rspec-tests
|
- .minimal-rspec-tests
|
||||||
- .rails:rules:ee-and-foss-fast_spec_helper:minimal
|
- .rails:rules:ee-and-foss-fast_spec_helper:minimal
|
||||||
|
|
||||||
|
db:rollback:
|
||||||
|
extends: .db-job-base
|
||||||
|
script:
|
||||||
|
- bundle exec rake db:migrate VERSION=20181228175414
|
||||||
|
- bundle exec rake db:migrate SKIP_SCHEMA_VERSION_CHECK=true
|
||||||
|
|
||||||
db:migrate:reset:
|
db:migrate:reset:
|
||||||
extends: .db-job-base
|
extends: .db-job-base
|
||||||
script:
|
script:
|
||||||
- bundle exec rake db:migrate:reset
|
- bundle exec rake db:migrate:reset
|
||||||
|
|
||||||
|
db:migrate-from-previous-major-version:
|
||||||
|
extends: .db-job-base
|
||||||
|
variables:
|
||||||
|
USE_BUNDLE_INSTALL: "false"
|
||||||
|
SETUP_DB: "false"
|
||||||
|
PROJECT_TO_CHECKOUT: "gitlab-foss"
|
||||||
|
TAG_TO_CHECKOUT: "v13.12.9"
|
||||||
|
before_script:
|
||||||
|
- !reference [.default-before_script, before_script]
|
||||||
|
- '[[ -d "ee/" ]] || export PROJECT_TO_CHECKOUT="gitlab"'
|
||||||
|
- '[[ -d "ee/" ]] || export TAG_TO_CHECKOUT="${TAG_TO_CHECKOUT}-ee"'
|
||||||
|
- retry 'git fetch https://gitlab.com/gitlab-org/$PROJECT_TO_CHECKOUT.git $TAG_TO_CHECKOUT'
|
||||||
|
- git checkout -f FETCH_HEAD
|
||||||
|
- SETUP_DB=false USE_BUNDLE_INSTALL=true bash scripts/prepare_build.sh
|
||||||
|
- run_timed_command "bundle exec rake db:drop db:create db:structure:load db:migrate db:seed_fu"
|
||||||
|
- git checkout -f $CI_COMMIT_SHA
|
||||||
|
- SETUP_DB=false USE_BUNDLE_INSTALL=true bash scripts/prepare_build.sh
|
||||||
|
script:
|
||||||
|
- run_timed_command "bundle exec rake db:migrate"
|
||||||
|
|
||||||
db:check-schema:
|
db:check-schema:
|
||||||
extends:
|
extends:
|
||||||
- .db-job-base
|
- db:migrate-from-previous-major-version
|
||||||
- .rails:rules:ee-mr-and-default-branch-only
|
- .rails:rules:ee-mr-and-default-branch-only
|
||||||
|
variables:
|
||||||
|
TAG_TO_CHECKOUT: "v14.4.0"
|
||||||
script:
|
script:
|
||||||
- source scripts/schema_changed.sh
|
- run_timed_command "bundle exec rake db:migrate"
|
||||||
|
- scripts/schema_changed.sh
|
||||||
- scripts/validate_migration_timestamps
|
- scripts/validate_migration_timestamps
|
||||||
|
|
||||||
db:check-migrations:
|
db:check-migrations:
|
||||||
|
@ -360,30 +389,6 @@ db:check-migrations:
|
||||||
- scripts/validate_migration_schema
|
- scripts/validate_migration_schema
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
db:migrate-from-previous-major-version:
|
|
||||||
extends: .db-job-base
|
|
||||||
variables:
|
|
||||||
USE_BUNDLE_INSTALL: "false"
|
|
||||||
SETUP_DB: "false"
|
|
||||||
PROJECT_TO_CHECKOUT: "gitlab-foss"
|
|
||||||
TAG_TO_CHECKOUT: "v13.12.9"
|
|
||||||
script:
|
|
||||||
- '[[ -d "ee/" ]] || export PROJECT_TO_CHECKOUT="gitlab"'
|
|
||||||
- '[[ -d "ee/" ]] || export TAG_TO_CHECKOUT="${TAG_TO_CHECKOUT}-ee"'
|
|
||||||
- retry 'git fetch https://gitlab.com/gitlab-org/$PROJECT_TO_CHECKOUT.git $TAG_TO_CHECKOUT'
|
|
||||||
- git checkout -f FETCH_HEAD
|
|
||||||
- SETUP_DB=false USE_BUNDLE_INSTALL=true bash scripts/prepare_build.sh
|
|
||||||
- run_timed_command "bundle exec rake db:drop db:create db:structure:load db:migrate db:seed_fu"
|
|
||||||
- git checkout -f $CI_COMMIT_SHA
|
|
||||||
- SETUP_DB=false USE_BUNDLE_INSTALL=true bash scripts/prepare_build.sh
|
|
||||||
- run_timed_command "bundle exec rake db:migrate"
|
|
||||||
|
|
||||||
db:rollback:
|
|
||||||
extends: .db-job-base
|
|
||||||
script:
|
|
||||||
- bundle exec rake db:migrate VERSION=20181228175414
|
|
||||||
- bundle exec rake db:migrate SKIP_SCHEMA_VERSION_CHECK=true
|
|
||||||
|
|
||||||
db:gitlabcom-database-testing:
|
db:gitlabcom-database-testing:
|
||||||
extends: .rails:rules:db:gitlabcom-database-testing
|
extends: .rails:rules:db:gitlabcom-database-testing
|
||||||
stage: test
|
stage: test
|
||||||
|
|
|
@ -1,25 +1,21 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
schema_changed() {
|
if [ -n "$(git diff --name-only -- db/structure.sql)" ]; then
|
||||||
if [ ! -z "$(git diff --name-only -- db/structure.sql)" ]; then
|
printf "Schema changes are not cleanly committed to db/structure.sql\n"
|
||||||
printf "Schema changes are not cleanly committed to db/structure.sql\n"
|
printf "The diff is as follows:\n"
|
||||||
printf "The diff is as follows:\n"
|
diff=$(git diff -p --binary -- db/structure.sql)
|
||||||
diff=$(git diff -p --binary -- db/structure.sql)
|
printf "%s" "$diff"
|
||||||
printf "%s" "$diff"
|
exit 1
|
||||||
exit 1
|
else
|
||||||
else
|
printf "Schema changes are correctly applied to db/structure.sql\n"
|
||||||
printf "Schema changes are correctly applied to db/structure.sql\n"
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -z "$(git add -A -n db/schema_migrations)" ]; then
|
if [ -n "$(git add -A -n db/schema_migrations)" ]; then
|
||||||
printf "Schema version files have not been committed to the repository:\n"
|
printf "Schema version files have not been committed to the repository:\n"
|
||||||
printf "The following files should be committed:\n"
|
printf "The following files should be committed:\n"
|
||||||
diff=$(git add -A -n db/schema_migrations)
|
diff=$(git add -A -n db/schema_migrations)
|
||||||
printf "%s" "$diff"
|
printf "%s" "$diff"
|
||||||
exit 2
|
exit 2
|
||||||
else
|
else
|
||||||
printf "Schema changes are correctly applied to db/structure.sql and db/schema_migrations/\n"
|
printf "Schema changes are correctly applied to db/structure.sql and db/schema_migrations/\n"
|
||||||
fi
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
schema_changed
|
|
||||||
|
|
Loading…
Reference in a new issue