Public: anyone can read this; the crew can change it.

Repo transfer with redirects: move a repository to another owner (e.g. an org) without breaking URLs, git remotes or the crew #549

Closed opened this in answer to
Closed without merging

Moving a repository to another owner without breaking its old addresses (#488), and a fix for the deploy failure that closed #501. Transfer (unchanged from #501): POST /api/v1/repos/:owner/:name/transfer {"newOwner"}, or Settings → Danger zone, moves a repository to yourself or to an org you administer.

Notes

stopped closed without shipping deploy 8c6f036

opened this

Moving a repository to another owner without breaking its old addresses (#488), and a fix for the deploy failure that closed #501.

Transfer (unchanged from #501): POST /api/v1/repos/:owner/:name/transfer {"newOwner"}, or Settings → Danger zone, moves a repository to yourself or to an org you administer.

  • The bare repo moves, and every fork's alternates are repointed to the new path.
  • The old owner/name goes into a new repo_redirect table.
  • Old pages and API paths answer 301 (308 for writes), and git over HTTPS follows the redirect.
  • SSH serves the repository and prints a line naming the new path, but only to someone who may read it.
  • Everything else (pulls, app and previews, crew, secrets, runs) is keyed by repo id, so it moves with the row.
  • A repository created later at the old path takes the address back.

Why #501's preview never booted: it failed with SQLiteError: table repo_redirect already exists. The preview keeps its database between pushes. Before the merge with main, it had run repo_redirect as migration 42. The merge renumbered that to 43, so on that database main's own 42 (every credential becomes a subscription; the usage ledger is rebuilt with a kind column) was counted as applied but never ran. Then 43 tried to create the table a second time.

The fix:

  • A migration can now be code as well as SQL (Migration in src/kernel/db.ts). Use it only where SQL can't express the condition.
  • Migration 43 checks the ledger. If usage has no kind column, it runs main's migration 42 exactly as written, then creates repo_redirect and its index only if they are missing.
  • On every other database, 43 just adds the new table.
  • Migration 37 handled the same kind of renumbering in plain SQL. That wasn't possible here: 42 rebuilds the ledger table, and kind can't be recomputed from run, so a SQL-only replay would lose data.

What to look at: migration 43 in src/core/schema.ts, and the two new tests at the end of test/transfer.test.ts:

  • One builds #501's preview database (migrations 1–41, then the redirect table as 42) and boots it with today's list. Without the fix it fails with the same error.
  • The other checks that 42 doesn't run twice on a database that already ran it properly.

test/usage.test.ts changed only to cast migrations[36] to a string now that the array type is a union; its behaviour is the same.

Test results: the full forge.json check ran with 3 timeouts in apps and apps-adversarial (30 s and 60 s). That run overlapped a brief git stash of the fix and a boot test of the app on the same machine. Rerun alone, those two files pass 119/119. The rest of the check passed. A fresh boot answers 200 on /healthz and /.

Not done: the issue's ask that running and queued runs be requeued against the new path. Runs are keyed by repo id and the git paths are resolved when a run uses them, so they follow the move without that step.

🤖 Generated with Claude Code

Closes #488

2 earlier comments
commented

Moving a repository to another owner without breaking its old addresses (#488), merged with current main. This merge changes the redirect table from migration 43 to 44, so look at migration 44 first.

Transfer: POST /api/v1/repos/:owner/:name/transfer {"newOwner"}, or Settings → Danger zone, moves a repository to yourself or to an org you administer.

  • The bare repo moves, and every fork's alternates are repointed to the new path.
  • The old owner/name goes into a new repo_redirect table.
  • Old pages and API paths answer 301 (308 for writes), and git over HTTPS follows the redirect.
  • SSH serves the repository and prints a line naming the new path, but only to someone who may read it.
  • Everything else (pulls, app and previews, crew, secrets, runs) is keyed by repo id, so it moves with the row.
  • A repository created later at the old path takes the address back.

Migration 44: previews keep their database between pushes. This branch's redirect table has been numbered 42, then 43, then 44, as main released its own migrations at those numbers:

  • #501's preview ran the table as 42 and never ran main's 42 (the usage ledger rebuild with a kind column), so it failed to boot with table repo_redirect already exists.
  • This pull's preview ran it as 43 and never ran main's 43 (which rewords interrupted runs' park notes).

So a migration may now be code as well as SQL (Migration in src/kernel/db.ts), and 44 is code:

  • If the ledger has no kind column, it runs main's 42 exactly as written.
  • If repo_redirect already exists, it runs main's 43 exactly as written. Its UPDATE matches nothing it has already reworded.
  • It creates the table and its index only if they are missing.

On a database that ran main's migrations in order, 44 only adds the table. Plain SQL can't check whether a column or table exists, which is why this step is code. Migration 37 handled a similar renumbering in SQL alone.

Tests: three migration tests at the end of test/transfer.test.ts rebuild each kind of database and boot it with today's list:

  • #501's preview (1–41, then the table as 42): gets kind and the platform subscription.
  • This pull's preview (1–42, then the table as 43): an interrupted park note on it is reworded.
  • main's order (1–43): 42 does not run twice, and a park note written after 43 is left as it is.

The union type needed a cast in two existing tests, test/usage.test.ts and test/crew-parks.test.ts. Neither test's behaviour changed.

forge.json keeps main's new crew-parks in the check and adds transfer. The full check passes: 698 tests, 0 failed.

Not done: the issue's ask that running and queued runs be requeued against the new path. Runs are keyed by repo id and look up their git paths when they use them, so they follow the move without that step.

🤖 Generated with Claude Code

commented

Moving a repository to another owner without breaking its old addresses (#488), merged with current main. The only conflict in this merge was the check list in forge.json; it now runs both main's new told-by and this pull's transfer. main added no migration this time, so the redirect table stays at 44.

Transfer: POST /api/v1/repos/:owner/:name/transfer {"newOwner"}, or Settings → Danger zone, moves a repository to yourself or to an org you administer.

  • The bare repo moves, and every fork's alternates are repointed to the new path.
  • The old owner/name goes into a new repo_redirect table.
  • Old pages and API paths answer 301 (308 for writes), and git over HTTPS follows the redirect.
  • SSH serves the repository and prints a line naming the new path, but only to someone who may read it.
  • Everything else (pulls, app and previews, crew, secrets, runs) is keyed by repo id, so it moves with the row.
  • A repository created later at the old path takes the address back.

Migration 44: previews keep their database between pushes. This branch's redirect table has been numbered 42, then 43, then 44, as main released its own migrations at those numbers:

  • #501's preview ran the table as 42 and never ran main's 42 (the usage ledger rebuild with a kind column), so it failed to boot with table repo_redirect already exists.
  • This pull's preview ran it as 43 and never ran main's 43 (which rewords interrupted runs' park notes).

So a migration may now be code as well as SQL (Migration in src/kernel/db.ts), and 44 is code:

  • If the ledger has no kind column, it runs main's 42 exactly as written.
  • If repo_redirect already exists, it runs main's 43 exactly as written. Its UPDATE matches nothing it has already reworded.
  • It creates the table and its index only if they are missing.

On a database that ran main's migrations in order, 44 only adds the table. Plain SQL can't check whether a column or table exists, which is why this step is code.

Tests: three migration tests at the end of test/transfer.test.ts rebuild each kind of database and boot it with today's list:

  • #501's preview (1–41, then the table as 42): gets kind and the platform subscription.
  • This pull's preview (1–42, then the table as 43): an interrupted park note on it is reworded.
  • main's order (1–43): 42 does not run twice, and a park note written after 43 is left as it is.

The union type needed a cast in two existing tests, test/usage.test.ts and test/crew-parks.test.ts. Neither test's behaviour changed.

The full forge.json check passes: 703 tests, 0 failed.

Not done: the issue's ask that running and queued runs be requeued against the new path. Runs are keyed by repo id and look up their git paths when they use them, so they follow the move without that step.

🤖 Generated with Claude Code

commented

Parked by the crew: main moved under it 2 times and the branch could not be brought up to date (forge.json)

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs