| 1 |
# pgimport |
| 2 |
|
| 3 |
One-off migration script to import ntfy data from SQLite to PostgreSQL. |
| 4 |
|
| 5 |
This is **not** a generic migration tool. It only works with specific SQLite schema versions |
| 6 |
(message cache v14, user db v6, web push v1) and their corresponding PostgreSQL schemas. |
| 7 |
If your database versions differ, this tool will refuse to run. |
| 8 |
|
| 9 |
## Build |
| 10 |
|
| 11 |
```bash |
| 12 |
go build -o pgimport ./tools/pgimport/ |
| 13 |
``` |
| 14 |
|
| 15 |
## Usage |
| 16 |
|
| 17 |
```bash |
| 18 |
# Using CLI flags |
| 19 |
pgimport \ |
| 20 |
--database-url "postgres://user:pass@host:5432/ntfy?sslmode=require" \ |
| 21 |
--cache-file /var/cache/ntfy/cache.db \ |
| 22 |
--auth-file /var/lib/ntfy/user.db \ |
| 23 |
--web-push-file /var/lib/ntfy/webpush.db |
| 24 |
|
| 25 |
# Using --create-schema to set up PostgreSQL schema automatically |
| 26 |
pgimport \ |
| 27 |
--create-schema \ |
| 28 |
--database-url "postgres://user:pass@host:5432/ntfy?sslmode=require" \ |
| 29 |
--cache-file /var/cache/ntfy/cache.db \ |
| 30 |
--auth-file /var/lib/ntfy/user.db \ |
| 31 |
--web-push-file /var/lib/ntfy/webpush.db |
| 32 |
|
| 33 |
# Using server.yml (flags override config values) |
| 34 |
pgimport --config /etc/ntfy/server.yml |
| 35 |
``` |
| 36 |
|
| 37 |
## Prerequisites |
| 38 |
|
| 39 |
- PostgreSQL schema must already be set up, either by running ntfy with `database-url` once, |
| 40 |
or by passing `--create-schema` to pgimport to create the initial schema automatically |
| 41 |
- ntfy must not be running during the import |
| 42 |
- All three SQLite files are optional; only the ones specified will be imported |
| 43 |
|
| 44 |
## Notes |
| 45 |
|
| 46 |
- The tool is idempotent and safe to re-run |
| 47 |
- After importing, row counts and content are verified against the SQLite sources |
| 48 |
- Invalid UTF-8 in messages is replaced with the Unicode replacement character |