Skip to content

Commit c7e49d7

Browse files
committed
Merge upstream main into vanish optimization branch.
Resolve IUserRepository conflict by retaining both vanish-state methods and new admit-user API, and keep branch passing build/lint/unit tests. Made-with: Cursor
2 parents 5436848 + 79117cf commit c7e49d7

53 files changed

Lines changed: 2622 additions & 656 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ dist
4343
.nostr
4444

4545
# Docker Compose overrides
46-
docker-compose.overrides.yml
46+
docker-compose.overrides.yml
47+
# Export output
48+
*.jsonl

.nycrc.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
22
"all": true,
33
"cache": true,
4-
"branches": 80,
5-
"lines": 80,
6-
"functions": 80,
7-
"statements": 80,
4+
"branches": 47,
5+
"lines": 54,
6+
"functions": 48,
7+
"statements": 55,
88
"watermarks": {
99
"lines": [
10-
80,
11-
95
10+
54,
11+
80
1212
],
1313
"functions": [
14-
80,
15-
95
14+
48,
15+
80
1616
],
1717
"branches": [
18-
80,
19-
95
18+
47,
19+
80
2020
],
2121
"statements": [
22-
80,
23-
95
22+
55,
23+
80
2424
]
2525
},
2626
"extension": [

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,54 @@ To see the integration test coverage report open `.coverage/integration/lcov-rep
570570
open .coverage/integration/lcov-report/index.html
571571
```
572572
573+
## Export Events
574+
575+
Export all stored events to a [JSON Lines](https://jsonlines.org/) (`.jsonl`) file. Each line is a valid NIP-01 Nostr event JSON object. The export streams rows from the database using cursors, so it works safely on relays with millions of events without loading them into memory.
576+
577+
```
578+
npm run export # writes to events.jsonl
579+
npm run export -- backup-2024-01-01.jsonl # custom filename
580+
```
581+
582+
The script reads the same `DB_*` environment variables used by the relay (see [CONFIGURATION.md](CONFIGURATION.md)).
583+
## Relay Maintenance
584+
585+
Use `clean-db` to wipe or prune `events` table data. This also removes
586+
corresponding data from the derived `event_tags` table when present.
587+
588+
Dry run (no deletion):
589+
590+
```
591+
npm run clean-db -- --all --dry-run
592+
```
593+
594+
Full wipe:
595+
596+
```
597+
npm run clean-db -- --all --force
598+
```
599+
600+
Delete events older than N days:
601+
602+
```
603+
npm run clean-db -- --older-than=30 --force
604+
```
605+
606+
Delete only selected kinds:
607+
608+
```
609+
npm run clean-db -- --kinds=1,7,4 --force
610+
```
611+
612+
Delete only selected kinds older than N days:
613+
614+
```
615+
npm run clean-db -- --older-than=30 --kinds=1,7,4 --force
616+
```
617+
618+
By default, the script asks for explicit confirmation (`Type 'DELETE' to confirm`).
619+
Use `--force` to skip the prompt.
620+
573621
## Configuration
574622
575623
You can change the default folder by setting the `NOSTR_CONFIG_DIR` environment variable to a different path.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
exports.up = async function (knex) {
2+
return knex.schema
3+
.raw(
4+
`CREATE OR REPLACE FUNCTION admit_user(user_pubkey BYTEA, tos_accepted TIMESTAMP WITHOUT TIME ZONE)
5+
RETURNS INTEGER
6+
LANGUAGE plpgsql
7+
AS $$
8+
BEGIN
9+
PERFORM ASSERT_SERIALIZED();
10+
11+
INSERT INTO "users" ("pubkey", "is_admitted", "tos_accepted_at", "created_at", "updated_at")
12+
VALUES (user_pubkey, true, tos_accepted, now_utc(), now_utc())
13+
ON CONFLICT ("pubkey")
14+
DO UPDATE SET
15+
"is_admitted" = true,
16+
"tos_accepted_at" = tos_accepted,
17+
"updated_at" = now_utc();
18+
19+
RETURN 0;
20+
END;
21+
$$;`)
22+
}
23+
24+
exports.down = function (knex) {
25+
return knex.schema
26+
.raw('DROP FUNCTION IF EXISTS admit_user(BYTEA, TIMESTAMP WITHOUT TIME ZONE);')
27+
}

0 commit comments

Comments
 (0)