Skip to content

Deploy a changed app to a running server

matterdata deploy changes the application of a tenant that matterdata serve is serving. The server stays up. Only the tenant that you change pauses, for as long as the migration of a copy of its data takes.

Use the command for these cases:

You want to Use
change an application while you develop it on your computer matterdata dev
change an application on a server that is serving matterdata deploy
move a stopped node to a new engine version matterdata upgrade

deploy applies the same migration as upgrade, with the same refusals and the same flags. The difference is that it runs inside the server and it needs no stop.

deploy does not change a file itself. It writes a request into the tenant directory, and the running server applies it. The server accepts a request only when the files belong to its own user. On a node, run the command as the user that runs serve:

Terminal window
sudo -u matterdata matterdata deploy -dir /var/lib/matterdata -tenant verein -app apps/sports-club

Use the same -dir as serve. Name every application that the tenant holds with -app, one flag for each. The tenant must exist. deploy never creates a tenant. To create one, use matterdata install.

On a system that is not Unix, the server cannot compare the owner of the files. It still refuses symbolic links and any path that leaves the copy of the sources.

A preview runs the whole migration on a copy of the serving file and applies nothing. The tenant does not pause.

Terminal window
matterdata deploy -dir data -tenant expenses -app expenses -preview
app expenses at /: model v1 -> v2
steps: 4, destructive: 0, policies: 0
| 1. rebuild_table claims
…
plan-digest: 3b2d7e404c40fe23
preview: the plan was checked on a copy of the serving file. Nothing was applied and expenses was not
paused. To apply exactly this plan, run the command again without -preview and with -expect-plan 3b2d7e404c40fe23

The plan digest identifies the plan. Read the plan, then pass the digest with -expect-plan. The deploy is refused when the plan changed after your preview, for example because a write changed which rows a step affects, or because somebody installed another version.

Run the command again without -preview:

Terminal window
matterdata deploy -dir data -tenant expenses -app expenses -expect-plan 3b2d7e404c40fe23

The command does these steps:

  1. It compiles the sources on your computer and prints each error as file:line:column. Sources that do not compile are not sent.
  2. It copies the .mtd sources, the .ts hook modules and the files of -backfill into a directory beside the tenant. No other file is copied.
  3. The server finds the request within one second. It runs the migration on a copy, outside any pause. If the plan is refused, the tenant never pauses.
  4. If the plan passes, the server pauses the tenant. Requests in flight finish. New requests wait. The server takes a new copy, runs the migration again, checks that the plan digest is the same, and replaces the file. The requests that waited are served from the new version.
  5. The command prints one line and exits with status 0.
deploy: deployed expenses: 4 steps (rebuild_table claims, …), model v1 -> v2; window 22 ms (0 ms waiting for requests in flight); digest 3b2d7e404c40fe23

The window is how long a request that arrived at the start of the pause waited. It grows with the size of the tenant file. A window never lasts longer than 15 seconds. If the migration needs more time, the deploy is refused and the old version keeps serving.

The server keeps one earlier generation of the file as <tenant>.db.pre-deploy. It is a hard link, so it uses no extra space. There is no rollback command. To go back, deploy the earlier sources again. To restore the file and lose the writes made since the deploy, stop the server and move <tenant>.db.pre-deploy over <tenant>.db.

A deploy refuses what upgrade refuses: a step that deletes data, a change of a retention rule, and a new column that existing rows would leave empty. The refusal names the flag that allows it. The tenant keeps its old version, and the command exits with status 1:

deploy: refused; nothing was applied and expenses keeps serving its last model:
- drop_column expenses.claims.note destroys data … Pass -allow-destructive expenses.claims.note …
deploy: to apply this change if it is what you mean to do, run the command again with: -allow-destructive expenses.claims.note
Flag Effect
-allow-destructive <app>.<table>[.<column>] Allow a step that the application acknowledged with !destructive. Comma-separated, repeatable.
-allow-policy <app>.<table>[.<field>] Allow a change of a retention rule.
-accept-null <app>.<table>.<column> Allow a new column to stay empty on rows that exist.
-backfill <app>=<file.sql> Run the statements of the file after the migration of the application, in the same transaction.
-expect-plan <digest> Refuse unless the plan has this digest.

The command waits 60 seconds for the result. Use -wait for another time. If no server answers, the command says so and exits with status 1:

deploy: no answer within 60s.
The request is still pending, and the next `serve` of that directory applies it. …

The request stays in the directory. The next serve of the directory applies it, even hours later. Only one request can wait for each tenant. To withdraw it, run:

Terminal window
matterdata deploy -dir data -tenant expenses -cancel

-cancel cannot stop a request that a server has already started.

A server that is busy with the deploy of another tenant answers after that deploy ends. The server applies one request at a time.

Flag Effect
-tenant <name> The tenant to change. Required.
-app <dir> The directory of one application. Repeat it for every application of the tenant.
-dir <dir> The tenant directory that the server reads. The default is data.
-preview Plan on a copy and apply nothing.
-wait <duration> How long to wait for the server. The default is 60s.
-typecheck Make a type check that did not run an error. A type error always stops the deploy.
-cancel Withdraw the pending request of the tenant.
  • It has no rollback command, as step 3 describes.
  • The server does not run tsc, and it stores the .ts hook modules as they are. The command refuses a module that cannot be turned into JavaScript, and prints its file:line:col.
  • It runs tsc --noEmit on your computer, before it writes a request, only when the application has a tsconfig.json, a tsc is found, and .matterdata/sdk.d.ts exists. A type error stops the deploy. With -typecheck, a check that did not run stops it too. See Write a hook in TypeScript with types.
  • It does not load seed/ files. A seed loads into a new tenant only.
  • It does not create a tenant or add an application. Use matterdata install.
  • It does not change a tenant file when no server runs. Use matterdata upgrade on a stopped node.

Website privacy policy