# API Update Workflow

From time to time, it can happen that Nazara becomes incompatible with the newest NetBox release.

Follow these steps in order to bring Nazara up to speed again.

To do this, you will need to install `Thanix` and clone the [`thanix_client` repository](https://codeberg.org/nazara-project/thanix_client).

## 1. Create Version Branch

The first thing we do, is **lock the current version into a new branch**.
This ensures we have a fallback, and allows users to patch the version that may still be 
compatible to their running NetBox instance.

To do this, use this format:

```bash
$ git checkout -b version/alpha-2
```

Or for full release versions:

```bash
$ git checkout -b version/vX.Y.Z
```

## 2. Update `thanix_client`

`thanix_client` is the crate we use to handle API requests to and from NetBox.
It is generated by [Thanix](https://codeberg.org/nazara-project/Thanix) using the current upstream NetBox API schema.

### 2.1 Get the latest API schema

[Get the latest API schema YAML](https://demo.netbox.dev/api/schema) (Download may take a couple seconds)

### 2.2 Generate new `thanix_client` crate

Throw the downloaded YAML file into `Thanix` to generate a new crate. You will get a new directory
wherever you executed it containing a completely new `thanix_client` repo.

**Take the `src` directory from that output and copy it**, in its entirety, into the `thanix_client` repository
you cloned from GitHub. If prompted, agree to overtwrite all existing files.

**Update the version numbers in `thanix_client` accordingly**.

Test build the crate by running:

```
$ cargo build --release
```

This may take a while depending on your system.
If all is good, publish it to [crates.io](https://crates.io/crates/thanix_client):

```bash
$ cargo publish
```

## 3. Perform Port of Nazara

First thing you need to do is to update the `thanix_client` version number in Nazara's Cargo.toml file.

It is almost guaranteed that Nazara won't build after updating that API client.
This means that you have to go and fix all the issues that arise. Most likely these will be linked to the payloads
and their corresponding fields (like it was moving from 3.x to 4.x).

You will have to fix these in order to fully port Nazara to the newest NetBox version.

## 4. Follow Release Workflow

Ports of the API client like these are **always a separate minor release**.

After the codebase is updated, and has been tested and verified and the associated PRs merged, a new release
will have to be created.

For this, [follow the release workflow](./release_workflow.md).

