mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Add db:import task
This commit is contained in:
parent
3bec54ee76
commit
ba3f816955
4 changed files with 44 additions and 3 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
"dev": "deno run -A --watch src/server.ts",
|
"dev": "deno run -A --watch src/server.ts",
|
||||||
"hook": "deno run --allow-read --allow-run --allow-write https://deno.land/x/deno_hooks@0.1.1/mod.ts",
|
"hook": "deno run --allow-read --allow-run --allow-write https://deno.land/x/deno_hooks@0.1.1/mod.ts",
|
||||||
"db:export": "deno run -A scripts/db-export.ts",
|
"db:export": "deno run -A scripts/db-export.ts",
|
||||||
|
"db:import": "deno run -A scripts/db-import.ts",
|
||||||
"db:migrate": "deno run -A scripts/db-migrate.ts",
|
"db:migrate": "deno run -A scripts/db-migrate.ts",
|
||||||
"nostr:pull": "deno run -A scripts/nostr-pull.ts",
|
"nostr:pull": "deno run -A scripts/nostr-pull.ts",
|
||||||
"debug": "deno run -A --inspect src/server.ts",
|
"debug": "deno run -A --inspect src/server.ts",
|
||||||
|
|
|
||||||
8
deno.lock
generated
8
deno.lock
generated
|
|
@ -35,9 +35,11 @@
|
||||||
"jsr:@std/fs@^0.229.3": "jsr:@std/fs@0.229.3",
|
"jsr:@std/fs@^0.229.3": "jsr:@std/fs@0.229.3",
|
||||||
"jsr:@std/internal@^1.0.0": "jsr:@std/internal@1.0.1",
|
"jsr:@std/internal@^1.0.0": "jsr:@std/internal@1.0.1",
|
||||||
"jsr:@std/io@^0.224": "jsr:@std/io@0.224.4",
|
"jsr:@std/io@^0.224": "jsr:@std/io@0.224.4",
|
||||||
|
"jsr:@std/json@^0.223.0": "jsr:@std/json@0.223.0",
|
||||||
"jsr:@std/media-types@^0.224.1": "jsr:@std/media-types@0.224.1",
|
"jsr:@std/media-types@^0.224.1": "jsr:@std/media-types@0.224.1",
|
||||||
"jsr:@std/path@0.217": "jsr:@std/path@0.217.0",
|
"jsr:@std/path@0.217": "jsr:@std/path@0.217.0",
|
||||||
"jsr:@std/path@^0.221.0": "jsr:@std/path@0.221.0",
|
"jsr:@std/path@^0.221.0": "jsr:@std/path@0.221.0",
|
||||||
|
"jsr:@std/streams@^0.223.0": "jsr:@std/streams@0.223.0",
|
||||||
"npm:@isaacs/ttlcache@^1.4.1": "npm:@isaacs/ttlcache@1.4.1",
|
"npm:@isaacs/ttlcache@^1.4.1": "npm:@isaacs/ttlcache@1.4.1",
|
||||||
"npm:@noble/hashes@^1.4.0": "npm:@noble/hashes@1.4.0",
|
"npm:@noble/hashes@^1.4.0": "npm:@noble/hashes@1.4.0",
|
||||||
"npm:@scure/base@^1.1.6": "npm:@scure/base@1.1.6",
|
"npm:@scure/base@^1.1.6": "npm:@scure/base@1.1.6",
|
||||||
|
|
@ -272,6 +274,9 @@
|
||||||
"jsr:@std/bytes@^1.0.2-rc.3"
|
"jsr:@std/bytes@^1.0.2-rc.3"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"@std/json@0.223.0": {
|
||||||
|
"integrity": "9a4a255931dd0397924c6b10bb6a72fe3e28ddd876b981ada2e3b8dd0764163f"
|
||||||
|
},
|
||||||
"@std/media-types@0.224.1": {
|
"@std/media-types@0.224.1": {
|
||||||
"integrity": "9e69a5daed37c5b5c6d3ce4731dc191f80e67f79bed392b0957d1d03b87f11e1"
|
"integrity": "9e69a5daed37c5b5c6d3ce4731dc191f80e67f79bed392b0957d1d03b87f11e1"
|
||||||
},
|
},
|
||||||
|
|
@ -286,6 +291,9 @@
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"jsr:@std/assert@^0.221.0"
|
"jsr:@std/assert@^0.221.0"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"@std/streams@0.223.0": {
|
||||||
|
"integrity": "d6b28e498ced3960b04dc5d251f2dcfc1df244b5ec5a48dc23a8f9b490be3b99"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npm": {
|
"npm": {
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,21 @@ const store = await Storages.db();
|
||||||
|
|
||||||
console.warn('Exporting events...');
|
console.warn('Exporting events...');
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
for await (const msg of store.req([{}])) {
|
for await (const msg of store.req([{}])) {
|
||||||
if (msg[0] === 'EVENT') console.log(JSON.stringify(msg[2]));
|
if (msg[0] === 'EOSE') {
|
||||||
if (msg[0] === 'EOSE') break;
|
break;
|
||||||
|
}
|
||||||
|
if (msg[0] === 'EVENT') {
|
||||||
|
console.log(JSON.stringify(msg[2]));
|
||||||
|
count++;
|
||||||
|
}
|
||||||
if (msg[0] === 'CLOSED') {
|
if (msg[0] === 'CLOSED') {
|
||||||
console.error('Database closed unexpectedly');
|
console.error('Database closed unexpectedly');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.warn('Done!');
|
console.warn(`Exported ${count} events`);
|
||||||
|
Deno.exit();
|
||||||
|
|
|
||||||
24
scripts/db-import.ts
Normal file
24
scripts/db-import.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import { NostrEvent } from '@nostrify/nostrify';
|
||||||
|
import { JsonParseStream } from '@std/json/json-parse-stream';
|
||||||
|
import { TextLineStream } from '@std/streams/text-line-stream';
|
||||||
|
|
||||||
|
import { Storages } from '@/storages.ts';
|
||||||
|
|
||||||
|
const store = await Storages.db();
|
||||||
|
|
||||||
|
console.warn('Importing events...');
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
|
const readable = Deno.stdin.readable
|
||||||
|
.pipeThrough(new TextDecoderStream())
|
||||||
|
.pipeThrough(new TextLineStream())
|
||||||
|
.pipeThrough(new JsonParseStream());
|
||||||
|
|
||||||
|
for await (const event of readable) {
|
||||||
|
await store.event(event as unknown as NostrEvent);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.warn(`Imported ${count} events`);
|
||||||
|
Deno.exit();
|
||||||
Loading…
Add table
Reference in a new issue