Skip to content

Enable rollback testing for scripts/regenerate-schema

Tianwen Chen requested to merge enable-rollback-for-regenerate-schema into master

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 the db/structure.sql for the up part before the change should be committed
  • scripts/validate_migration_schema is used to validate the committed db/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.

Edited by Tianwen Chen

Merge request reports