# Install and upgrade

> Set up a self-hosted install, and apply each new release.

## Install

1. Create the database and its user.
2. Load the schema by running `bin/rails db:prepare` with the image, in the same environment as the app.
3. Create the first user and their account the same way:

    ```bash
    bin/rails install:first_account EMAIL=you@example.com ACCOUNT="Your company" NAME="Your name"
    ```

    It prints a link to choose the password, valid for 6 hours. The user is an administrator of the install, who can also see the background jobs (`/jobs`) and run maintenance tasks (`/maintenance_tasks`). It only works on an install with no users yet.
4. Start the web and jobs containers, open the link and choose the password.
5. Invite the rest of your team from **Settings → People**.

Set `DISABLE_USER_SIGNUP=true` from the start, so nobody else can create an account on your install.

## Versions and upgrades

Releases are numbered `x.y.z`:

- `x` changes when a release breaks something you rely on. Its notes say what.
- `y` changes when a release changes the database. The `x.y.0` release only adds the database changes, on the previous release's code, so you can migrate while the running version keeps working.
- `z` changes for releases without database changes. `x.y.1` is the first one with the code that uses the new database changes.

Each release comes with notes: what changed, the database migrations it carries, and any step to take after deploying it.

To upgrade:

1. Back up the database.
2. Run the migrations by running `bin/rails db:migrate` with the new image.
3. Replace the web and jobs containers with the new image.
4. Do any step the release notes ask for, such as running a maintenance task from `/maintenance_tasks`.

Going to the next release, the version still running keeps working while the migrations run, since a release never removes from the database what the previous one uses.

You can skip versions: `db:migrate` applies every migration you haven't run yet, in order. Migrations from the releases in between may remove what your running version still uses, though, so stop it before step 2.
