Migrations

Migrations module is introduced in [[changelog#1 1 1|v1.1.1]] of API and provides one-shot migrations which cannot be performed from the NixOS configuration file changes. These migrations are checked and ran before every start of the API.

You can disable certain migrations if needed by creating an array at api.skippedMigrations in userdata.json and populating it with IDs of the migrations to skip. Adding DISABLE_ALL to that array disables the migrations module entirely.

For example:

...
    "api": {
        "token": "secret_token",
        "enableSwagger": false,
		"skippedMigrations": [ "fix_nixos_config_branch", "create_tokens_json" ]
    },
...

Fix NixOS configuration branch

Migration ID: fix_nixos_config_branch

Introduced in: [[changelog#1 1 1|v1.1.1]]

Description

Mobile SelfPrivacy app introduced a bug in version 0.4.0. New servers were initialized with a rolling-testing nixos config branch. This was fixed in app version 0.4.2, but existing servers were not updated. This migration fixes this by changing the nixos config branch to master.

Run conditions

Git repository at /etc/nixos is using rolling-testing branch.

Migration process

  1. Moving context to /etc/nixos.
  2. Running git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/* to fix the consequences of --single-branch flag.
  3. git fetch --all to fetch all existing branches.
  4. git pull to pull them.
  5. git checkout master moves to master.
  6. Leaving the context.

Create tokens JSON file

Migration ID: create_tokens_json

Introduced in: [[changelog#1 2 0|v1.2.0]]

Description

Selfprivacy API used a single token in userdata.json for authentication. This migration creates a new tokens.json file with the old token in it.

Run conditions

/etc/nixos/userdata/tokens.json does not exist.

Migration process

  1. Current token is retrieved from userdata.json.
  2. tokens.json is created with 0600 permission.
  3. File is populated with the following data:
{
	"tokens": [
		{
			"token": "token_string",
			"name": "primary_token",
			"date": "current date from str(datetime.now())",
		}
	]
}