mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-09 00:24:20 +01:00
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:
19
src/db/migrations/020_pgfts.ts
Normal file
19
src/db/migrations/020_pgfts.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -42,8 +42,17 @@ class EventsDB implements NStore {
|
||||
};
|
||||
|
||||
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, {
|
||||
fts5: Conf.databaseUrl.protocol === 'sqlite:',
|
||||
fts,
|
||||
indexTags: EventsDB.indexTags,
|
||||
searchText: EventsDB.searchText,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user