Add auth store migration (#637)

This commit is contained in:
Misha Bragin
2026-02-27 08:37:28 +02:00
committed by GitHub
parent b35de5b477
commit 58625d69f6

View File

@@ -121,4 +121,118 @@ docker compose logs netbird-server | grep store
You should see:
```
using Postgres store engine
```
## Migrate Auth Store
The embedded identity provider (Dex) uses a separate SQLite database (`idp.db`) to store authentication data such as users, passwords, connectors, sessions, and tokens. You can optionally migrate this to PostgreSQL as well.
### Create the Auth Database
```bash
docker exec postgres-server psql -U postgres -c "CREATE DATABASE netbird_auth;"
```
### Create the Auth Migration File
Create a file called `auth-sqlite.load` with the following content:
```
LOAD DATABASE
FROM sqlite:///root/combined/backup/idp.db
INTO postgresql://postgres:password@localhost:5432/netbird_auth
WITH include drop, create tables, create indexes, reset sequences
CAST
column client.public to boolean,
column auth_request.force_approval_prompt to boolean,
column auth_request.logged_in to boolean,
column auth_request.claims_email_verified to boolean,
column auth_code.claims_email_verified to boolean,
column refresh_token.claims_email_verified to boolean
;
```
<Note>
Update the SQLite path and PostgreSQL connection string to match your environment.
</Note>
### Run the Auth Migration
```bash
pgloader auth-sqlite.load
```
### Update config.yaml
Add the `authStore` section to your `config.yaml`:
```yaml
server:
# ... existing settings ...
authStore:
engine: "postgres"
dsn: "host=postgres-server port=5432 user=postgres password=password dbname=netbird_auth sslmode=disable"
```
### Restart and Verify
```bash
docker compose up -d
```
## Migrate Activity Store
The activity events store uses a separate SQLite database (`events.db`) to record user and system activity. You can optionally migrate this to PostgreSQL as well.
### Create the Activity Database
```bash
docker exec postgres-server psql -U postgres -c "CREATE DATABASE netbird_events;"
```
### Create the Activity Migration File
Create a file called `activity-sqlite.load` with the following content:
```
LOAD DATABASE
FROM sqlite:///root/combined/backup/events.db
INTO postgresql://postgres:password@localhost:5432/netbird_events
WITH include drop, create tables, create indexes, reset sequences
;
```
<Note>
No boolean CAST rules are needed for the activity store — all columns use standard integer and text types.
Update the SQLite path and PostgreSQL connection string to match your environment.
</Note>
### Run the Activity Migration
```bash
pgloader activity-sqlite.load
```
### Update config.yaml
Add the `activityStore` section to your `config.yaml`:
```yaml
server:
# ... existing settings ...
activityStore:
engine: "postgres"
dsn: "host=postgres-server port=5432 user=postgres password=password dbname=netbird_events sslmode=disable"
```
### Restart and Verify
```bash
docker compose up -d
```