feat: OS image popularity, reinstall with new image, admin VM transfer#179
Merged
Conversation
- #70: add popularity (fraction of active VMs) to GET /api/v1/image - #177: allow optional image_id in PATCH /api/v1/vm/{id}/re-install - #178: add POST /api/admin/v1/vms/{id}/transfer for admin VM ownership transfer Adds DB methods count_vms_by_os_image and admin_transfer_vm, a Transferred VM-history action + logger, mock impls, unit/e2e tests, and doc updates.
The 20260720130000_cascade_delete_child_tables migration combined `DROP FOREIGN KEY x, ADD CONSTRAINT x ...` in a single ALTER, which InnoDB (MySQL & MariaDB) rejects with errno 121 (duplicate key) because the old constraint name still exists while the same-named new one is added. This crashed API startup on a fresh DB, breaking the e2e run. Split each into two separate ALTER statements. Verified all migrations apply cleanly on a fresh mariadb:latest.
The auto-generated FK names for referral/referral_payout (created without explicit CONSTRAINT names) are server-version dependent, so the hardcoded `referral_ibfk_1` drop failed on CI's MariaDB (error 1091). Resolve the real constraint name from information_schema and drop it via PREPARE/EXECUTE so the migration is version-independent. Verified end-to-end through the real sqlx migrator against mariadb:latest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Batch implementation of three issues.
#70 — OS image popularity
GET /api/v1/imagenow returns apopularityfield per image: the fraction (0.0–1.0) of active VMs currently using it. New DB methodcount_vms_by_os_image.#177 — Change OS (reinstall)
PATCH /api/v1/vm/{id}/re-installnow accepts an optional{ image_id }body to switch OS image during reinstall. The image must exist and be enabled; the change is persisted before the reinstall pipeline and recorded in VM history.#178 — Transfer VM (admin)
New
POST /api/admin/v1/vms/{id}/transfer(virtual_machines::update) reassigns a VM (and its billing subscription) to another user, clearing the old owner's SSH key. Adds aTransferredVM-history action + logger. Rejects deleted VMs / self-transfers (409) and unknown users (404).Tests & docs
Fixes #70
Fixes #177
Fixes #178