Files, code and terminal

Run migrations, seed scripts and other commands for your app

Run npm scripts, Prisma or Django migrations and one-off commands with your app's environment variables — one click in App settings, or cn-env in the Terminal.

  1. Why a normal terminal command says "Missing DATABASE_URL"
  2. One click: App settings → Run a command
  3. In the Terminal or over SSH: cn-env
  4. Prisma on a live site
  5. Good to know

Why a normal terminal command says "Missing DATABASE_URL"

Your environment variables (App settings → Environment variables) are given to your running app, not to every terminal session. A command such as npm run prisma:generate reads DATABASE_URL and the other settings, so it needs them too.

One click: App settings → Run a command

Open App settings, choose the app, and find Run a command in the Deploy card. Every script in your package.json has a button (long-running ones like dev and start are left out), and you can type any other command. It runs in your app folder with your variables, and the output appears below.

In the Terminal or over SSH: cn-env

Put cn-env in front of the command. Inside ~/web/yourdomain.com/ it uses that site's variables; elsewhere add -d yourdomain.com. cn-env on its own lists the variable names.

cd ~/web/yourdomain.com/app
cn-env npm run cms:seed
cn-env npx prisma migrate deploy
cn-env -d yourdomain.com python manage.py migrate

Prisma on a live site

  • Use Apply database migrations (prisma migrate deploy) — it applies the migrations in your repository and never deletes data.
  • prisma migrate dev is for your own computer: it needs rights to create a temporary database and can reset data, so it fails or is unsafe on a live server.
  • prisma generate and the build run automatically on every Git deploy.

Good to know

  • Commands run as your own account, with the same access as the Terminal, for up to 15 minutes.
  • Builds and restarts are done by Deploy (or Git deployments); you rarely need npm run build by hand.
  • To create an admin with a script, add its variables (for example ADMIN_EMAIL and ADMIN_PASSWORD) in Environment variables first, run it, then remove the password variable again.

Stuck? Our engineers answer support tickets around the clock. Contact us, or create an account and open a ticket from the dashboard — the same guides are there too.

Next step

Move your site, or your whole cloud estate

Shared hosting you can buy in two minutes. Infrastructure and managed services quoted by an engineer within one business day.