Enable rollback testing for scripts/regenerate-schema
What does this MR do and why?
This is to add the feature to enable rollback testing so that we can check if the migration is reversible or not in a clean state easily
NOTE: this is different from scripts/validate_migration_schema
:
-
scripts/regenerate-schema
can be used to update thedb/structure.sql
for theup
part before the change should be committed -
scripts/validate_migration_schema
is used to validate the committeddb/structure.sql
change
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
-
Generate a simple migration, e.g.:
rails g post_deployment_migration add_abc_view
-
Update migration file content with:
def up execute(<<~SQL) CREATE VIEW abc AS SELECT current_timestamp; SQL end def down execute(<<~SQL) DROP VIEW abc; SQL end
-
Run the following command
scripts/regenerate-schema -r
-
Check the output and see if rollback is executed with the version for the above migration file
-
Check if
db/structure.sql
is in a clean state
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Tianwen Chen