Merge branch 'pgfts' into 'main'

Upgrade Nostrify to v0.20.0, enable Postgres FTS

See merge request soapbox-pub/ditto!269
This commit is contained in:
Alex Gleason 2024-05-16 22:24:21 +00:00
commit 04980089b4
3 changed files with 30 additions and 2 deletions

View File

@ -21,7 +21,7 @@
"@db/sqlite": "jsr:@db/sqlite@^0.11.1", "@db/sqlite": "jsr:@db/sqlite@^0.11.1",
"@isaacs/ttlcache": "npm:@isaacs/ttlcache@^1.4.1", "@isaacs/ttlcache": "npm:@isaacs/ttlcache@^1.4.1",
"@noble/secp256k1": "npm:@noble/secp256k1@^2.0.0", "@noble/secp256k1": "npm:@noble/secp256k1@^2.0.0",
"@nostrify/nostrify": "jsr:@nostrify/nostrify@^0.19.2", "@nostrify/nostrify": "jsr:@nostrify/nostrify@^0.20.0",
"@sentry/deno": "https://deno.land/x/sentry@7.112.2/index.mjs", "@sentry/deno": "https://deno.land/x/sentry@7.112.2/index.mjs",
"@soapbox/kysely-deno-sqlite": "jsr:@soapbox/kysely-deno-sqlite@^2.1.0", "@soapbox/kysely-deno-sqlite": "jsr:@soapbox/kysely-deno-sqlite@^2.1.0",
"@soapbox/stickynotes": "jsr:@soapbox/stickynotes@^0.4.0", "@soapbox/stickynotes": "jsr:@soapbox/stickynotes@^0.4.0",

View File

@ -0,0 +1,19 @@
import { Kysely, sql } from 'kysely';
import { Conf } from '@/config.ts';
export async function up(db: Kysely<any>): Promise<void> {
if (['postgres:', 'postgresql:'].includes(Conf.databaseUrl.protocol!)) {
await db.schema.createTable('nostr_pgfts')
.ifNotExists()
.addColumn('event_id', 'text', (c) => c.primaryKey().references('nostr_events.id').onDelete('cascade'))
.addColumn('search_vec', sql`tsvector`, (c) => c.notNull())
.execute();
}
}
export async function down(db: Kysely<any>): Promise<void> {
if (['postgres:', 'postgresql:'].includes(Conf.databaseUrl.protocol!)) {
await db.schema.dropTable('nostr_pgfts').ifExists().execute();
}
}

View File

@ -42,8 +42,17 @@ class EventsDB implements NStore {
}; };
constructor(private kysely: Kysely<DittoTables>) { constructor(private kysely: Kysely<DittoTables>) {
let fts: 'sqlite' | 'postgres' | undefined;
if (Conf.databaseUrl.protocol === 'sqlite:') {
fts = 'sqlite';
}
if (['postgres:', 'postgresql:'].includes(Conf.databaseUrl.protocol!)) {
fts = 'postgres';
}
this.store = new NDatabase(kysely, { this.store = new NDatabase(kysely, {
fts5: Conf.databaseUrl.protocol === 'sqlite:', fts,
indexTags: EventsDB.indexTags, indexTags: EventsDB.indexTags,
searchText: EventsDB.searchText, searchText: EventsDB.searchText,
}); });