---
name: openflare-migrate
description: Migrate a Cloudflare Workers project to a self-hosted OpenFlare. Use when the user wants to move, port or deploy an existing wrangler project (wrangler.toml/json/jsonc or cloudflare.config.ts) onto OpenFlare, check whether a Workers project is compatible with OpenFlare, or map Cloudflare bindings (KV, D1, R2, Durable Objects, Queues, Workflows) to OpenFlare resources.
---

# Migrate a Cloudflare Workers project to OpenFlare

OpenFlare runs the real `workerd` runtime and reads wrangler-style config, so most Workers code runs unchanged. The work is in configuration, resource ids, data, secrets and DNS. Never modify the user's Cloudflare account, and never run a command that sends data anywhere without telling the user what it will do.

## Ground rules

- Do not invent flags or behavior. If you are not sure an `of` flag exists, run `of <command> --help` or read the OpenFlare docs before using it.
- Never put secret values in command-line arguments, committed files or chat. Pass them through stdin (`printf '%s' "$VALUE" | of secret put ...`, or `--secrets-file -`).
- Do not cut over DNS or delete anything on Cloudflare. Stop and hand those steps to the user.
- Keep the Cloudflare deployment intact; it is the rollback.

## Step 1: Audit (read-only)

Find the config file. `of` reads, in precedence order: `vrt.toml`, `cloudflare.config.ts`, `cloudflare.config.js`, `wrangler.json`, `wrangler.jsonc`, `wrangler.toml`. `wrangler.config.ts/js` is never executed and fails closed.

Report every hit against these lists.

Rejected keys (deploy fails with `VRT_CONFIG_UNSUPPORTED_FIELD`): `ai`, `ai_search`, `ai_search_namespaces`, `mtls_certificates`, `pipelines`, `dispatch_namespaces`, `containers`, `wasm_modules`, `text_blobs`, `data_blobs`, `logpush`, `site`, `node_compat`, and wildcard `custom_domain` routes.

Accepted and ignored (safe to leave): `account_id`, `workers_dev`, `send_metrics`, `keep_vars`, `build`, `alias`, `tsconfig`, `preserve_file_names`, `upload_source_maps`, `cwd`, `config`, `placement`. Note that `build` is not executed: if the project needs a build step, it must run before `of deploy`.

Restricted: `limits` accepts only `cpu_ms` and `subrequests`; `unsafe` accepts only `unsafe_eval`; R2 `jurisdiction` and `storage_class` are rejected; D1 `migrations_table` is unsupported; `transferred_classes` in Durable Object migrations is rejected.

Support level by binding:

| Level | Features |
| --- | --- |
| Drop-in | KV, Cron Triggers, Version metadata |
| Partial | R2, D1, Durable Objects, Queues, Workflows, Cache API, Service bindings, Hyperdrive, Postgres, Rate limiting, Static assets, WebSockets, Vars and secrets, Secrets Store, Vectorize, Tail Workers, Analytics Engine, Worker loaders, Unsafe eval, Flagship, Images, `send_email` (outbound only), K2 (produce only), Browser (not Chromium) |
| Unsupported | Workers AI, AI Search, Pipelines, mTLS certificates, dispatch namespaces, Containers, legacy `wasm_modules`/`text_blobs`/`data_blobs` |

Scan the source for code that behaves differently and list each occurrence with file and line:

- `request.cf` fields other than `country`, `colo`, `httpProtocol`, `asn`, `asOrganization`, `city`, `continent`, `region`, `regionCode`, `metroCode`, `postalCode`, `timezone`, `latitude`, `longitude`, `isEUCountry` (others, including `botManagement` and `tls*`, are absent).
- Cache API use: per host, in memory, not persistent; `ignoreMethod`, `ignoreSearch`, `ignoreVary`, `cacheName` and edge `cacheTtl` are not implemented.
- WebSocket hibernation (not emulated; 300 s idle timeout, 4 h maximum).
- Rate limiting (fixed window per process, not global).
- `env.AI`, `env.BROWSER`, `env.IMAGES`, `env.VECTORIZE`.
- Dependence on Smart Placement or edge locality.
- Workers idle for long periods (scale to zero: first request after idle is slower; Durable Object and Workflow tenants never freeze).

Produce a short report: blockers (unsupported features), required changes, and behavior differences to test. If there are blockers, stop and ask the user how to proceed.

## Step 2: Target readiness

Confirm with the user that an OpenFlare is running and that `of` is installed and logged in (`of whoami` succeeds). If not, point them to the OpenFlare quickstart; do not try to install the platform yourself. The login token is the plane admin token and must be provided by the user through stdin or a 0600 token file.

Check the pinned runtime so `compatibility_date` and flags are accepted: `GET /api/v1/worker-compatibility` on the plane returns the pinned `workerd` version, `maxDate`, `maxFlags` and supported flags. Lower `compatibility_date` if it is newer than `maxDate`.

## Step 3: Create resources and rewrite config

OpenFlare mints resource ids. The `id`, `database_id` or `bucket_name` in config is used to look up a resource already created on OpenFlare, so Cloudflare ids do not carry over. Create each resource, then set the config to refer to it by the name used at creation.

| Cloudflare | Config key | Create |
| --- | --- | --- |
| KV | `kv_namespaces` | `of kv namespace create <title>` |
| D1 | `d1_databases` | `of d1 create <name>` |
| R2 | `r2_buckets` | `of r2 bucket create <name>` (or a proxy bucket to Cloudflare R2/S3, created in the console or API) |
| Queues | `queues` | `of queues create <name>` |
| Hyperdrive | `hyperdrive` | `of hyperdrive create` (credential-less `postgres://host[:port]/db` origin, password on stdin) |
| Secrets Store | `secrets_store_secrets` | `of secrets-store put` (needs the `secretsStore` cell capability) |
| Durable Objects, Workflows, Cron, Analytics Engine, Static assets, Service bindings | respective keys | Declared and upserted by `of deploy`; deploy target workers of service bindings first |

Prefer to keep the user's Cloudflare config untouched: put OpenFlare values in an `[env.openflare]` block and deploy with `--env openflare`. If a config defines environments, `of deploy` fails without `--env` and lists the names.

Show the user the config diff before writing it.

## Step 4: Check and deploy

```sh
of check [--env openflare] <worker_dir>      # offline gate, writes nothing
of deploy --dry-run [--env openflare] <worker_dir>
of deploy [--env openflare] <worker_dir>
```

Deploy only to a hostname that carries no production traffic. A deploy creates an immutable version and publishes a signed snapshot; the publication status moves `PENDING` to `APPLIED`. If `of deploy` refuses because the existing worker uses control-plane features the CLI cannot reproduce, tell the user to manage that worker in the console or API.

## Step 5: Data and secrets

Export from Cloudflare is done by the user with Cloudflare's tooling; do not use Cloudflare credentials unless the user explicitly provides them for this purpose. Import with `of`.

- KV: `of kv bulk put <keys.json> --namespace <title>`. Values UTF-8, at most 1 MiB; 1 to 1000 items and at most 8 MiB per call; not atomic, so batch and re-run failures; `expiration_ttl` at least 60 s and not combined with `expiration`.
- D1: apply schema with `of d1 migrations apply <db> --config <wrangler-file>` (never applied by deploy; at most 512 migrations per call, 256 KiB each). Load data with `of d1 query <db> --file <part.sql>`, at most 100 KiB per call, so split dumps. Load only into an empty database. Compare row counts afterward.
- R2: either create a proxy bucket pointing at the existing Cloudflare R2 or S3 storage (no copy; needs a runtime build with proxy backends), or copy objects. `of r2 object put <key> --bucket <name> --file <path>` suits only small objects (the request is capped at 1 MiB after base64); use a worker bound to both buckets for larger ones.
- Durable Objects: there is no documented import of existing object storage. Tell the user state must be rebuilt or repopulated.
- Queues and Workflows: in-flight messages and running instances do not move; ask the user to drain or let them finish before cutover.
- Secrets: Cloudflare never returns values. Ask the user to provide them from their own secret store, then `printf 'KEY=%s\n' "$KEY" | of deploy --secrets-file - <dir>` or `printf '%s' "$KEY" | of secret put --worker <name> KEY`. A name cannot be both a var and a secret. Verify with `of secret ls --worker <name>` (names only).

## Step 6: Verify

Report pass or fail for each: `of check` exits 0; publication `APPLIED`; key routes return the same status, headers and body as Cloudflare; KV sample reads; D1 row counts and key queries; R2 list and sample fetch; every declared secret listed; cron triggers fire (`of logs --worker <name>`); cold-start latency after idle; WebSockets through the final hostname; error rate under load. Explicitly exercise code paths touching the behavior differences found in Step 1.

## Step 7: Hand off the cutover

Do not perform these yourself. Give the user the sequence: lower DNS TTL ahead of time; attach the production hostname (`of hostnames add --worker <name> <host>`), publish the `_openflare.<host>` TXT record, verify (token expires after 24 hours); confirm TLS for that name; point DNS at the OpenFlare edge; disable the Cloudflare route at the same moment; watch logs. Rollback is to repoint DNS at Cloudflare and re-enable the route; writes made on OpenFlare during the window do not sync back, so ask how they want to reconcile. Within OpenFlare, `of versions list --worker <name>` and `of rollback --worker <name> <version_id>` revert code without touching DNS.

## Errors

| Error | Meaning |
| --- | --- |
| `VRT_CONFIG_UNSUPPORTED_FIELD` | A rejected key. Remove it or report a blocker. |
| `VRT_COMPATIBILITY_DATE_INVALID`, `VRT_COMPATIBILITY_FLAG_UNSUPPORTED`, `VRT_COMPATIBILITY_FLAGS_LIMIT`, `COMPAT_FLAG_CONFLICT` | Date newer than `maxDate`, or flag problems. Query `/api/v1/worker-compatibility`. |
| `409` + `VRT_CELL_CAPABILITY_MISSING` | The cell does not advertise a required capability. |
| `VRT_HOSTNAME_NOT_ALLOWED` | Reserved label or hostname outside the configured base domain. |
| Deploy fails on missing resource | Config id does not match a resource created on OpenFlare. |
| Deploy fails on a secret | Declared secret has no value. |
