Skip to content

Check for changes in `structure.sql` in tests

Manoj M J [On PTO] requested to merge schema-check-test into master

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

#211521

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

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 Manoj M J [On PTO]

Merge request reports