Add script to regenerate schema for current branch
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:
- Disable the migrations (move them where Rails would ignore them)
- Check out out a clean
db/structure.sql
- Reset the test database to this schema
- Enable the migrations again
- 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 willcurl
the file fromCI_PROJECT_URL
because it assumes a shallow clone is in place. - You can set
TARGET
, likeTARGET=stable scripts/regenerate-schema
to set the target branch. In this casegit checkout $TARGET
is used to checkoutdb/structure.sql
. - Otherwise
master
is assumed and used togit checkout
.
This MR is an attempt to avoid errors like !28635 (merged).
This addresses #211521.
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
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