Skip to content

feat: add migrate:desk_assets task - #107

Merged
stakach merged 1 commit into
masterfrom
feat/desk-assets-migration
Nov 1, 2026
Merged

stakach merged 1 commit into
masterfrom
feat/desk-assets-migration

Conversation

@stakach

@stakach stakach commented Oct 30, 2026

Copy link
Copy Markdown
Member

Closes #106

Adds task migrate:desk_assets [dry_run=true]. It moves desks from desks metadata on level zones into the asset table, all in one transaction.

  • Collect: authorities with config.org_zone → walk the zone tree → for each level, its branch (org, region if any, building, level) and its desks metadata
  • Migrate:
    • Per authority, create or reuse the _DESKS_ category and type
    • Upsert assets on (type, zone_id, map_id), following the field map in the issue
    • Remap asset_id/asset_ids on desk bookings, plus asset overrides on booking_instances. When a desk id exists on several levels, booking.zones decides which one
    • Deep-merge {"desk": {"use_assets": true}} into each org zone's settings
  • Summary: per domain created/updated/skipped desks and settings changes, plus booking totals: remapped, already migrated and missed (with the missed desk ids)

Re-runs update existing assets in place, and bookings that already point at a desk asset are counted as "already migrated". dry_run=true prints the summary and then rolls back.

init had no specs, so this adds ./test, a docker compose file, a models migrator (copied from rest-api) and a CI test job.

Review

  • ./test: 6 examples, 0 failures
  • Smoke test of the built task binary against migrated Postgres: dry run (nothing written) → run (2 assets, 2 bookings remapped, 1 stale miss, settings merged and existing keys kept) → re-run (0 created, 2 updated, 2 already migrated, no duplicates)
  • Notes:
    • Bookings are updated with raw SQL on purpose, so no booking callbacks, notifications or history entries are written
    • Uses Database.connection { db.exec(..., args: [...]) } rather than exec_sql. exec_sql opens a new connection outside the transaction, and the splat form crashed the Crystal compiler in the spec build
    • Asset#name isn't in the mapping, so it stays nil
    • Known limitation: if a booking's desk was deleted but a desk with the same id exists on exactly one level of another domain, the booking is remapped to that desk

🤖 Generated with Claude Code

Migrates level zone desk metadata into assets, remaps desk bookings to the
new asset ids and enables desk.use_assets in org settings, in a single
transaction. Re-runnable, with an opt-in dry_run. Adds a spec suite.

Closes #106

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@stakach stakach mentioned this pull request Oct 30, 2026
8 tasks done
@github-actions github-actions Bot added the type: enhancement new feature or request label Oct 30, 2026
@stakach
stakach merged commit d2c05a5 into master Nov 1, 2026
11 checks passed
@stakach
stakach deleted the feat/desk-assets-migration branch November 1, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement new feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate desk metadata to assets

1 participant