Add script to refresh migrations timestamps
What does this MR do and why?
Add script to refresh migrations timestamps
Usage:
-
./scripts/refresh-migration-timestamps
- updates the timestamps to a value starting from now. -
./scripts/refresh-migration-timestamps --after 'a week from tomorrow'
- regenerates the timestamps to start from a week from the moment of execution. This uses Chronic to parse the expression.
This is useful for reordering migrations when they depend on a different merge request and as an easier alternative to https://docs.gitlab.com/ee/development/migration_style_guide.html#migration-timestamp-age
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
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
With new migrations:
marius@rocket-sled ~/W/g/gitlab (mb-refresh-migration-timestamp)> rails g post_deployment_migration partition_ci_pipelines_config_table
create db/post_migrate/20240904104311_partition_ci_pipelines_config_table.rb
marius@rocket-sled ~/W/g/gitlab (mb-refresh-migration-timestamp)> ./scripts/refresh-migration-timestamps --after 'a week from tomorrow'
$ git ls-files --others --exclude-standard -- db/migrate db/post_migrate
db/post_migrate/20240904104311_partition_ci_pipelines_config_table.rb
$ git merge-base master HEAD
275a56e8bbbeb113dffa546f601f9e953758c5e3
$ git diff --name-only --diff-filter=A 275a56e8bbbeb113dffa546f601f9e953758c5e3 -- db/migrate db/post_migrate
$ mv db/post_migrate/20240904104311_partition_ci_pipelines_config_table.rb db/post_migrate/20240912090004_partition_ci_pipelines_config_table.rb
$ ./scripts/regenerate-schema
# output from regenerate schema
With existing migrations
marius@rocket-sled ~/W/g/gitlab (469056-partition-ci_pipelines_config)> ./scripts/refresh-migration-timestamps --after 'a week from tomorrow'
$ git ls-files --others --exclude-standard -- db/migrate db/post_migrate
$ git merge-base master HEAD
275a56e8bbbeb113dffa546f601f9e953758c5e3
$ git diff --name-only --diff-filter=A 275a56e8bbbeb113dffa546f601f9e953758c5e3 -- db/migrate db/post_migrate
db/migrate/20240903073815_create_p_ci_pipelines_config.rb
db/post_migrate/20240903074608_fk_ci_pipelines_config_ci_pipelines.rb
db/post_migrate/20240903074926_partition_ci_pipelines_config.rb
$ mv db/migrate/20240903073815_create_p_ci_pipelines_config.rb db/migrate/20240912090005_create_p_ci_pipelines_config.rb
$ mv db/post_migrate/20240903074608_fk_ci_pipelines_config_ci_pipelines.rb db/post_migrate/20240912090009_fk_ci_pipelines_config_ci_pipelines.rb
$ mv db/post_migrate/20240903074926_partition_ci_pipelines_config.rb db/post_migrate/20240912090012_partition_ci_pipelines_config.rb
$ ./scripts/regenerate-schema
# output from regenerate schema
Edited by Marius Bobin