32 lines
1011 B
Markdown
32 lines
1011 B
Markdown
# Data and database compatibility
|
|
|
|
ushort stores data in SQLite. The database can be mounted directly across
|
|
upgrades; no export or import is required.
|
|
|
|
```sql
|
|
CREATE TABLE urls (
|
|
short_code TEXT PRIMARY KEY,
|
|
original_url TEXT NOT NULL,
|
|
created_at INTEGER NOT NULL,
|
|
visit_count INTEGER NOT NULL DEFAULT 0,
|
|
retention_days INTEGER NOT NULL DEFAULT 0
|
|
);
|
|
```
|
|
|
|
Older databases missing `retention_days` are upgraded in place with a default
|
|
of zero. Expired records are removed on startup and before each GET, POST, or
|
|
DELETE request, using a strict expiry boundary.
|
|
|
|
## Backups
|
|
|
|
Take a consistent backup before every production update. SQLite's online
|
|
backup command avoids copying a database while a WAL transaction is active:
|
|
|
|
```bash
|
|
sqlite3 data/urlshort.db ".backup data/urlshort.db.pre-update"
|
|
sqlite3 data/urlshort.db.pre-update "PRAGMA integrity_check;"
|
|
```
|
|
|
|
Retain the backup until the updated release has passed health, redirect,
|
|
write, and database-integrity checks.
|