Check for changes in `structure.sql` in tests
What does this MR do?
Running Rails migrations using rake db:migrate
simply dumps the current database structure of your local database to structure.sql
. However, changes in your local database can differ from another developer's structure.sql
. (based on the order of merge, migrations that you forgot to revert after discarding it etc)
Ideally, we should only have a SSOT for this and it should be ordered in timestamp
order.
However, currently, we can discard the timestamp order in structure.sql
by manually editing that file, and our tests do not fail in such a case.
The same applies to a scenario where a developer writes a new migration and pushes just the migration file, without pushing the changes to structure.sql
(But this can be easily caught during code review)
Ideally the test should have failed when the order of structure.sql
is not in timestamp order or if the required changes to structure.sql
are not pushed along with a new migration.
Slack discussion : https://gitlab.slack.com/archives/C3NBYFJ6N/p1587016378198100
Changes made
We already had a job to test for these changes, but it was not invoked correctly. I am making the change to invoke it correctly and also correcting the current structure.sql
to reflect the correct state of the database.
After the change, the test fail as expected if there is a mismatch in structure.sql
: https://gitlab.com/gitlab-org/gitlab/-/jobs/513398092
Correcting the state of structure.sql
was done by running rake db:drop db:create db:migrate
in my local and pushing all the changes in structure.sql
Related issues
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
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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