Backfill semver for terraform modules
Context
In Terraform registry: "Latest version for a speci... (#474746 - closed), it was reported that when requesting the latest version of a terraform module, it sometimes doesn't resolve correctly. That's because the sorting is performed in the database on the version string (1.0.3 for example). And unfortunately, the database doesn’t natively understand semantic versions.
To solve this issue, it is necessary to extract the version components to separate columns in the database as explained in this documentation guide. This was implemented in Add semver to terraform module metadata (!183428 - merged)
In this MR, we backfill the semver for all existing terraform modules in the Terraform Registry. To do so, we implement a background migration that iterates over all terraform modules and whether create a new row (if there's none) in the packages_terraform_module_metadata database table (it's the table we use to persist the module's semver component in), or update the existing row with the semver parts (semever_major, semver_minor, semver_patch & semver_prerelease).
What does this MR do and why?
- Addig a background migration to backfill the semever for all existing terraform modules in the Terraform Registry.
References
Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.
- Terraform registry: "Latest version for a speci... (#474746 - closed)
- Add semver to terraform module metadata (!183428 - merged)
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
N/A
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
-
In rails console, we will create some terraform modules:
# stub file upload def fixture_file_upload(*args, **kwargs) Rack::Test::UploadedFile.new(*args, **kwargs) end p1 = FactoryBot.create(:terraform_module_package, version: '1.0.3', project: Project.first) p2 = FactoryBot.create(:terraform_module_package, version: '1.55.9-rc1', project: Project.first) # keep the ids of p1 & p2 -
Make sure that
sidekiqis running:gdk status rails-background-jobs -
Execute the migration:
rails db:migrate:main -
Now we have to wait until the background migration is executed. It might take up to
10-15min.The status of background migrations could be checked on: http://gdk.test:3000/admin/background_migrations
-
Open rails console and check that the semver was correctly populated for the terraform modules in the metadata table:
# check semver_major, semver_minor, semver_patch & semver_prerelease values in the returned rows Packages::TerraformModule::Metadatum.where(package_id: [p1.id, p2.id])
Related to #474746 (closed)