Migrate from Railway

Move a Railway project to Hangar with your AI agent over MCP or by hand, with its services, variables, databases and domains, keeping Railway running until the switch.

Updated

Markdown

Hangar works the way Railway does: a project holds services built from a repository, databases run next to them on a private network, and you pay for what they use. Hangar builds with Railpack, the builder Railway created, so a repository that builds on Railway builds on Hangar without changes.

This page is written so an AI agent can follow it step by step through Hangar's MCP server. Every step names the tool the agent calls. You can follow it by hand in the dashboard too.

Railway keeps running during the whole move. Nothing changes for your users until you switch DNS in the last step.

With your AI agent#

  1. Connect Hangar to your agent. For Claude Code:
Terminal
claude mcp add --transport http --scope user hangar https://mcp.tryhangar.io/mcp
  1. Install the Railway CLI, sign in with railway login, and run railway link in the repository so the agent can read the project.

  2. In the repository, ask:

Text
Move this Railway project to Hangar following https://tryhangar.io/docs/migrate-from-railway.
Keep Railway running. Ask me before restoring data and before any DNS change.

The rest of this page is what the agent does.

1Take stock of the Railway project#

Before creating anything, list what has to move:

  • Services. For each one: its repository, branch and root directory, or its Docker image. railway status names the project and environment; the Railway dashboard lists the services.
  • Variables. railway variables --service <name> --json prints a service's variables with their values. Note which ones are references, such as ${{Postgres.DATABASE_URL}} or ${{shared.API_KEY}}.
  • Config as code. A railway.json or railway.toml in the repository holds build and deploy settings: builder, Dockerfile path, build command, start command, pre-deploy command, watch patterns and cron schedule.
  • Databases. Engine and size of each one.
  • Volumes. Mount path and size of each one.
  • Domains. Every custom domain on every service.
  • Code that names Railway. Search the repository for RAILWAY_ and railway.internal.

Show this inventory to the user before going on.

2Create the project#

Call create_project with the Railway project's name. It returns the environmentId of the production environment, where every service below goes. If the Railway project has a staging environment you want too, add it with create_environment.

Pick the region closest to the one Railway used: list_regions lists Hangar's regions. Put every service and database of the project in the same region.

3Create the databases#

For each Railway database, call create_database with the same engine (postgres, mysql, mongo or redis), a name and the region. Hangar generates the password.

4Copy the data#

Ask the user before this step: it reads production data from Railway.

  1. On Railway, take the database's public URL from its variables: DATABASE_PUBLIC_URL for PostgreSQL, MYSQL_PUBLIC_URL for MySQL, MONGO_PUBLIC_URL for MongoDB.
  2. On Hangar, the user turns on Public networking for the new database (see Connect from outside). Then get_database_connection with reveal: true returns its publicUrl.
  3. Dump from Railway and restore into Hangar on the machine the agent runs on:
Terminal
# PostgreSQL
pg_dump "$RAILWAY_URL" --format=custom --no-owner --no-acl --file=railway.dump
pg_restore --no-owner --no-acl --dbname="$HANGAR_URL" railway.dump

# MySQL: the clients take host, port, user and password from each URL as flags
mysqldump --single-transaction --routines --triggers \
  -h <railway-host> -P <railway-port> -u <user> -p<password> <database> > railway.sql
mysql -h <hangar-host> -P <hangar-port> -u <user> -p<password> <database> < railway.sql

# MongoDB
mongodump --uri="$RAILWAY_URL" --archive=railway.archive
mongorestore --uri="$HANGAR_URL" --archive=railway.archive

Use client tools of the same major version as the database or newer. A Redis that only holds a cache or a queue usually needs no copy.

  1. Compare row counts of the main tables on both sides, then have the user turn public networking off again. Delete the dump file when you are done.

This copy is a rehearsal. You take a final one right before the DNS switch, in step 9.

5Create the services#

For each Railway service built from GitHub, call create_app_from_github with:

  • environmentId from step 2;
  • repository and branch, the ones Railway deploys;
  • rootDirectory, if Railway's root directory is not the repository root;
  • builder: leave it out for Railpack, or dockerfile (with dockerfile for a path other than Dockerfile) when Railway builds a Dockerfile;
  • regionId, the same region as the databases.

If Hangar's GitHub App cannot see the repository, the answer has a link: give it to the user, then try again.

The first deployment starts right away and may fail without its variables. That is expected; the service is deployed again in step 7.

6Move the settings and variables#

Build and deploy settings. Map railway.json or railway.toml to configure_service:

RailwayHangar (configure_service)
build.builderbuilder, in lowercase (RAILPACK becomes railpack)
build.dockerfilePathdockerfile
build.buildCommandbuildCommand
build.watchPatternswatchPaths
deploy.startCommandstartCommand
deploy.preDeployCommandpreDeployCommand
deploy.cronSchedulecronSchedule, then deploy once. See Cron jobs
deploy.numReplicasreplicas

The file can stay in the repository; Hangar ignores it.

Variables. Set them with set_env, one call per service:

  • Plain values are copied as they are.
  • Database references such as ${{Postgres.DATABASE_URL}} are not copied. Call connect_database with the app, the database from step 3 and the variable name instead. It writes the internal URL, password included, without it passing through the conversation.
  • Shared variables (${{shared.KEY}}) are copied as values into each service that uses them. To keep one copy, the user can create an environment variable in the dashboard and reference it as ${{environment.KEY}}. See Environment variables.
  • Railway's own variables are left out. Hangar sets PORT. If the code reads RAILWAY_PUBLIC_DOMAIN, RAILWAY_ENVIRONMENT_NAME or another RAILWAY_ variable, set a variable of your own with the Hangar value and update the code to read it.
  • Service-to-service calls over <name>.railway.internal are pointed at the other service's URL, which get_service shows.

What the agent cannot do through MCP, and the user does in the dashboard:

  • Volumes. Create one with the same mount path in the service's Settings → Storage, and copy its files. See Volumes.

7Deploy and check#

For each service, call deploy_service, then wait_for_deployment. If a build fails, read get_deployment_logs, fix the cause and deploy again.

Once a service is live:

  • open its generated URL, from get_service, and check the main pages or endpoints;
  • read get_service_logs with minLevel: "error";
  • read list_requests with errorsOnly: true after some traffic.

Ask the user to test the app on its generated address before going on.

8Add the domains#

For each custom domain, call add_domain with the service, the host and the port the app listens on. The answer gives the DNS record to create. Do not create it yet. Give the records to the user for step 9.

9Switch over#

This is the only step with a short pause in writes. The user decides when.

  1. Put the app on Railway in maintenance mode, or stop the workers that write, so the database stops changing.
  2. Take the final copy of each database, as in step 4, restoring over the rehearsal data. For PostgreSQL, add --clean --if-exists to pg_restore.
  3. Deploy the Hangar services again, so they start against the final data.
  4. The user changes the DNS records at their DNS provider to the values from step 8. HTTPS turns on once they resolve.
  5. Watch get_service_logs and list_requests while traffic moves over.

Keep the Railway project for a few days, stopped, in case you need to look something up. Then delete it on Railway.

What carries over#

RailwayHangar
Project, environment, serviceThe same: project, environment and service
Railpack and Dockerfile buildsThe same builders. See Builds
PostgreSQL, MySQL, MongoDB, RedisThe same engines, plus MariaDB and libSQL. See Databases
TCP proxy for a databasePublic networking
VolumesVolumes
Cron scheduleCron jobs
PR environmentsPreview deployments
Custom domainsDomains and HTTPS
railway up from a local folderprepare_upload through MCP. See AI agents (MCP)

For pricing and the differences between the two platforms, see Hangar vs Railway.

Frequently asked questions

Can my AI agent move my Railway project to Hangar?
Yes. Connect Hangar's MCP server to Claude Code, Cursor or another client, open the repository and ask the agent to follow this page. It creates the project, databases and services, copies the variables, restores the data and deploys, and leaves the DNS switch to you.
Do I need to change my code to move from Railway to Hangar?
Usually not. Hangar builds with Railpack, the builder Railway uses, and builds Dockerfiles the same way, so a repository that deploys on Railway deploys on Hangar. What changes is configuration that names Railway, such as RAILWAY_ variables and railway.internal hostnames.
Is there downtime when moving from Railway to Hangar?
Only for the writes made between the last database dump and the DNS switch. Railway keeps serving traffic while you build and test everything on Hangar's generated addresses. For a database that takes writes all the time, pause writes or put the app in maintenance mode for the final dump.