# The rezin command-line tool

`rezin` works on your Rezin Core projects from a terminal: look at tables, run SQL, apply migrations, set secrets, read the audit trail, upload files, deploy functions.

## Install

It is one file with no dependencies and needs Node 20 or newer.

```
curl -fsSL https://rezincore.com/docs/downloads/rezin.mjs -o rezin.mjs
node rezin.mjs help
```

To call it as `rezin`, make it executable and put it on your path:

```
chmod +x rezin.mjs
mv rezin.mjs /usr/local/bin/rezin
```

Read the file before you run it, as you should with anything you download. It is short.

## Sign in

1. Make a [personal access token](https://rezincore.com/docs/tools/access-tokens.md) in the console under **Your account → Access tokens**.
2. Run `rezin login` and paste the token.

The token is saved in `~/.config/rezin/config.json`, readable only by you. It is never taken from the command line, where other programs could see it.

In CI, set `REZIN_TOKEN` instead of signing in.

## Commands

```
rezin login                         save a personal access token (asked for, or piped in)
rezin logout                        forget it
rezin whoami                        which account and token this is
rezin projects                      project IDs, names, your role
rezin use <project id>              remember a project, so -p can be left out

rezin tables                        tables, columns, row-level security
rezin sql "select * from notes"     read-only
rezin sql --write "update ..."      needs a read-write token
rezin sql -f report.sql             read the SQL from a file

rezin migrations list               migrations already applied
rezin migrations push [dir]         apply the .sql files not yet applied, in name order (default ./migrations)

rezin secrets list                  names only; values are never sent back
rezin secrets set PAYMENT_KEY       the value is asked for, or piped in

rezin logs -n 50                    newest audit entries for the project
rezin storage ls <bucket> [prefix]
rezin storage upload <bucket> <file> [path-in-bucket]

rezin functions list                the project's functions and how they have been running
rezin functions deploy <name> <file.js>   store the file as the next version and make it live
rezin functions get <name>          print a function's current code
rezin functions set <name> [enabled=true|false] [requireUser=true|false] [timeoutSeconds=10]
                                    also everyMinutes=<n> and secrets=NAME,NAME
rezin functions invoke <name> ['{"json":"body"}']   run it once as a test
rezin functions logs <name>         how recent runs ended and what they printed
rezin functions delete <name>
```

### Moving out and in

```
rezin export                       # everything in the project, in ordinary formats; waits and saves the file
rezin export --encrypt             # the same, encrypted with a passphrase you are asked for
rezin export list
rezin import supabase --company <company id> --name "Orchard" --dump dump.sql      # prints the dry run and stops
rezin import supabase --company <company id> --name "Orchard" --dump dump.sql --yes
rezin import status <import id> --company <company id>
rezin import apply-rules <import id> --company <company id>
```

`rezin export` needs a read-write token given **Database** and **Files**, held by an owner. `rezin import` needs a read-write token for the whole company given **Your account and companies**, **Database** and **Files**, held by an owner. See [Export your project](https://rezincore.com/docs/moving/export.md) and [Move a project in](https://rezincore.com/docs/moving/overview.md).

## Options and environment

| Option | Meaning |
|---|---|
| `-p`, `--project <id>` | Which project. Or set `REZIN_PROJECT`, or run `rezin use`. |
| `--org <id>` | Which organization a file belongs to. Default: the project's first. |
| `--json` | Print the raw answer, for scripts |
| `--write` | With `sql`: allow the statement to change data or structure |
| `-f <file>` | With `sql`: read the statement from a file |
| `-n <count>` | With `logs`: how many entries |

| Variable | Meaning |
|---|---|
| `REZIN_TOKEN` | Overrides the saved token. For CI. |
| `REZIN_PROJECT` | The project, when `-p` is not given |
| `REZIN_CONFIG_DIR` | Where the saved token lives, in place of `~/.config/rezin` |

## How SQL and migrations run

Inside one project, as that project's own confined database role: they reach the project's section of the database and nothing else.

- `rezin sql` is read-only unless you add `--write`, and `--write` needs a read-write token.
- `rezin functions deploy`, `set` and `delete` need a token with **May deploy functions** ticked. `rezin whoami` shows a token's parts and whether it may deploy.
- At most 1,000 rows come back from one statement.
- A migration runs in one transaction and its name is recorded, so it is applied once.
- A table you create starts with row-level security on and no rule, so your application is given no rows from it until you add a rule: on the console's Access rules page, or in the same migration with `create policy` and a `grant` to the application's role, which `rezin projects --json` shows.

See [SQL and migrations](https://rezincore.com/docs/database/sql.md).

## A typical session

```
rezin login
rezin projects
rezin use abcdefghijklmnopqrst
rezin tables
rezin migrations push ./migrations
rezin sql "select count(*) from notes"
rezin logs -n 20
```

## In CI

```
export REZIN_TOKEN=…        # from your CI's secret store: a read-write token scoped to one project
export REZIN_PROJECT=abcdefghijklmnopqrst
node rezin.mjs migrations push ./migrations
```

## What is recorded

Every command is one line on the project's audit record: your account, which token, what kind of thing was done. SQL statements are recorded as the console records them. Secret values and file contents are not.

## The API underneath

`rezin` calls the [management API](https://rezincore.com/docs/reference/management-api.md). Anything the tool does you can do with `curl`.
