Skip to content

Add script to regenerate schema for current branch

Toon Claes requested to merge tc-schema-regenerator into master

What does this MR do?

Users can now use scripts/regenerate-schema to create a clean db/structure.sql for their branch.

What the script does:

  1. Disable the migrations (move them where Rails would ignore them)
  2. Check out out a clean db/structure.sql
  3. Reset the test database to this schema
  4. Enable the migrations again
  5. Run the migrations on the test database

This recreates db/structure.sql with the migrations added in the current branch.

There are several methods the script uses to check out the schema file from the target branch:

  • When CI_MERGE_REQUEST_TARGET_BRANCH_SHA is set, it assumes it's running from CI and it will curl the file from CI_PROJECT_URL because it assumes a shallow clone is in place.
  • You can set TARGET, like TARGET=stable scripts/regenerate-schema to set the target branch. In this case git checkout $TARGET is used to checkout db/structure.sql.
  • Otherwise master is assumed and used to git checkout.

This MR is an attempt to avoid errors like !28635 (merged).

This addresses #211521.

Does this MR meet the acceptance criteria?

Conformity

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Yorick Peterse

Merge request reports